# Path: lmatools/vis/small_multiples.py
# class small_multiples_plot(object):
#     
#     def __init__(self, fig=None, *args, **kwargs):
#         if fig is None:
#             raise AssertionError("A valid figure must be passed in.")
#             # fig = figure()
#         self.fig = fig
#         self.fig.subplots_adjust(bottom=0.20, left = 0.1, right=0.9, top=0.9)
#         self.colorbar_ax = fig.add_axes((0.1, 0.1, 0.8, 0.05))
#         self.multiples = small_multiples(self.fig, **kwargs)
#         
#     def label_edges(self, bool_val):
#         m = self.multiples
#         leftside = m[:,0]
#         for ax in leftside:
#             ax.yaxis.tick_left()
#             ax.yaxis.set_visible(bool_val)
# 
#         #last row
#         bottomedge = m[-1,:]
#         for ax in bottomedge:
#             ax.xaxis.tick_bottom()
#             ax.xaxis.set_visible(bool_val)


from .small_multiples import small_multiples_plot
from datetime import datetime, timedelta
    from netCDF4 import Dataset as NetCDFFile
    from scipy.io.netcdf import NetCDFFile
from matplotlib.figure import figaspect, Figure
from matplotlib.colorbar import ColorbarBase
from matplotlib.cm import get_cmap
from matplotlib.ticker import FuncFormatter
from matplotlib.dates import mx2num, date2num, DateFormatter
from matplotlib.backends.backend_agg import FigureCanvasAgg  
from math import ceil
        from hotshot import stats
import os
import gc
import numpy as np
import matplotlib
        import hotshot
        import sys
   
    xedge = centers_to_edges(x)
    x_range = xedge.max() - xedge.min()
    yedge = centers_to_edges(y)
    y_range = yedge.max() - yedge.min()
    dx = (xedge[1]-xedge[0])

    # count_scale_factor = dx # / 1000.0
    # max_count_baseline = 450 * count_scale_factor #/ 10.0
    min_count, max_count = 1, grid[:].max() #max_count_baseline*(t[1]-t[0])
    if (max_count == 0) | (max_count == 1 ):
        max_count = min_count+1

    default_vmin = -0.2
    if np.log10(max_count) <= default_vmin:
        vmin_count = np.log10(max_count) + default_vmin
    else:
        vmin_count = default_vmin

    # If the range of values for the colorbar is manually specified, 
    # overwrite what we did above
    if grid_range is not None:
        vmin_count = grid_range[0]
        max_count = grid_range[1]
            
    # w, h = figaspect(float(n_rows)/n_cols) # breaks for large numbers of frames - has a hard-coded max figure size
    w, h, n_rows_perpage, n_pages = multiples_figaspect(n_rows, n_cols, x_range, y_range, fig_width=8.5, max_height=None)
    fig = Figure(figsize=(w,h))
    canvas = FigureCanvasAgg(fig)
    fig.set_canvas(canvas)

# Path: lmatools/vis/small_multiples.py
# class small_multiples_plot(object):
#     
#     def __init__(self, fig=None, *args, **kwargs):
#         if fig is None:
#             raise AssertionError("A valid figure must be passed in.")
#             # fig = figure()
#         self.fig = fig
#         self.fig.subplots_adjust(bottom=0.20, left = 0.1, right=0.9, top=0.9)
#         self.colorbar_ax = fig.add_axes((0.1, 0.1, 0.8, 0.05))
#         self.multiples = small_multiples(self.fig, **kwargs)
#         
#     def label_edges(self, bool_val):
#         m = self.multiples
#         leftside = m[:,0]
#         for ax in leftside:
#             ax.yaxis.tick_left()
#             ax.yaxis.set_visible(bool_val)
# 
#         #last row
#         bottomedge = m[-1,:]
#         for ax in bottomedge:
#             ax.xaxis.tick_bottom()
#             ax.xaxis.set_visible(bool_val)


# Path: lmatools/vis/multiples_nc.py
from .small_multiples import small_multiples_plot
from datetime import datetime, timedelta
    from netCDF4 import Dataset as NetCDFFile
    from scipy.io.netcdf import NetCDFFile
from matplotlib.figure import figaspect, Figure
from matplotlib.colorbar import ColorbarBase
from matplotlib.cm import get_cmap
from matplotlib.ticker import FuncFormatter
from matplotlib.dates import mx2num, date2num, DateFormatter
from matplotlib.backends.backend_agg import FigureCanvasAgg  
from math import ceil
        from hotshot import stats
import os
import gc
import numpy as np
import matplotlib
        import hotshot
        import sys

   
    xedge = centers_to_edges(x)
    x_range = xedge.max() - xedge.min()
    yedge = centers_to_edges(y)
    y_range = yedge.max() - yedge.min()
    dx = (xedge[1]-xedge[0])

    # count_scale_factor = dx # / 1000.0
    # max_count_baseline = 450 * count_scale_factor #/ 10.0
    min_count, max_count = 1, grid[:].max() #max_count_baseline*(t[1]-t[0])
    if (max_count == 0) | (max_count == 1 ):
        max_count = min_count+1

    default_vmin = -0.2
    if np.log10(max_count) <= default_vmin:
        vmin_count = np.log10(max_count) + default_vmin
    else:
        vmin_count = default_vmin

    # If the range of values for the colorbar is manually specified, 
    # overwrite what we did above
    if grid_range is not None:
        vmin_count = grid_range[0]
        max_count = grid_range[1]
            
    # w, h = figaspect(float(n_rows)/n_cols) # breaks for large numbers of frames - has a hard-coded max figure size
    w, h, n_rows_perpage, n_pages = multiples_figaspect(n_rows, n_cols, x_range, y_range, fig_width=8.5, max_height=None)
    fig = Figure(figsize=(w,h))
    canvas = FigureCanvasAgg(fig)
    fig.set_canvas(canvas)

    p = small_multiples_plot(fig=fig, rows=n_rows, columns=n_cols)