# Path: lmatools/vis/multiples_nc.py
# def centers_to_edges(x):
#     xedge=np.zeros(x.shape[0]+1)
#     xedge[1:-1] = (x[:-1] + x[1:])/2.0
#     dx = np.mean(np.abs(xedge[2:-1] - xedge[1:-2]))
#     xedge[0] = xedge[1] - dx
#     xedge[-1] = xedge[-2] + dx
#     return xedge        


import glob
import itertools
import numpy as np
from datetime import datetime, timedelta
    from netCDF4 import Dataset as NetCDFFile
    from scipy.io.netcdf import NetCDFFile
from lmatools.vis.multiples_nc import centers_to_edges
        from lmatools.coordinateSystems import GeographicSystem, MapProjection
        self._time_lookup = {} # populated by self._frame_times_for_file
        self.times = [t for t in self._all_times()]
        self.times.sort()
        
    def data_for_time(self, t0, return_nc=False):
        """ Read data from the file corresponding to datetime t.
            Returns xedge, yedge, and density for the file 
        
            If return_nc is True, also return the NetCDFFile corresponding
            to the data as a fourth return value
        """
        fname, i = self._time_lookup[t0]  #i is the frame id for this time in NetCDFFile f
        
        f = NetCDFFile(fname)
        
        data = f.variables  # dictionary of variable names to nc_var objects
        dims = f.dimensions # dictionary of dimension names to sizes
        x = data[self.x_name]
        y = data[self.y_name]
        t = data[self.t_name]
        grid = data[self.grid_name]
        indexer = [slice(None),]*len(grid.shape)
        
        grid_dims = grid.dimensions # tuple of dimension names
        name_to_idx = dict((k, i) for i, k in enumerate(grid_dims))
        
        grid_t_idx = name_to_idx[t.dimensions[0]]
        grid_x_idx = name_to_idx[x.dimensions[0]]
        grid_y_idx = name_to_idx[y.dimensions[0]]
                

# Path: lmatools/vis/multiples_nc.py
# def centers_to_edges(x):
#     xedge=np.zeros(x.shape[0]+1)
#     xedge[1:-1] = (x[:-1] + x[1:])/2.0
#     dx = np.mean(np.abs(xedge[2:-1] - xedge[1:-2]))
#     xedge[0] = xedge[1] - dx
#     xedge[-1] = xedge[-2] + dx
#     return xedge        


# Path: lmatools/grid/grid_collection.py
import glob
import itertools
import numpy as np
from datetime import datetime, timedelta
    from netCDF4 import Dataset as NetCDFFile
    from scipy.io.netcdf import NetCDFFile
from lmatools.vis.multiples_nc import centers_to_edges
        from lmatools.coordinateSystems import GeographicSystem, MapProjection

        self._time_lookup = {} # populated by self._frame_times_for_file
        self.times = [t for t in self._all_times()]
        self.times.sort()
        
    def data_for_time(self, t0, return_nc=False):
        """ Read data from the file corresponding to datetime t.
            Returns xedge, yedge, and density for the file 
        
            If return_nc is True, also return the NetCDFFile corresponding
            to the data as a fourth return value
        """
        fname, i = self._time_lookup[t0]  #i is the frame id for this time in NetCDFFile f
        
        f = NetCDFFile(fname)
        
        data = f.variables  # dictionary of variable names to nc_var objects
        dims = f.dimensions # dictionary of dimension names to sizes
        x = data[self.x_name]
        y = data[self.y_name]
        t = data[self.t_name]
        grid = data[self.grid_name]
        indexer = [slice(None),]*len(grid.shape)
        
        grid_dims = grid.dimensions # tuple of dimension names
        name_to_idx = dict((k, i) for i, k in enumerate(grid_dims))
        
        grid_t_idx = name_to_idx[t.dimensions[0]]
        grid_x_idx = name_to_idx[x.dimensions[0]]
        grid_y_idx = name_to_idx[y.dimensions[0]]
                

        xedge = centers_to_edges(x)