Ejemplo n.º 1
0
 def _read_chunk_data(self, chunk, fields):
     data = {}
     grids_by_file = defaultdict(list)
     if len(chunk.objs) == 0: return data
     for g in chunk.objs:
         if g.filename is None:
             continue
         grids_by_file[g.filename].append(g)
     dtype = self.ds.index._dtype
     bpr = dtype.itemsize
     for filename in grids_by_file:
         grids = grids_by_file[filename]
         grids.sort(key = lambda a: a._offset)
         f = open(filename, "rb")
         for grid in grids:
             data[grid.id] = {}
             grid._seek(f)
             count = grid.ActiveDimensions.prod()
             size = count * bpr
             for field in self.ds.index.field_order:
                 if field in fields:
                     # We read it ...
                     v = np.fromfile(f, dtype=dtype, count=count)
                     v = v.reshape(grid.ActiveDimensions, order='F')
                     data[grid.id][field] = v
                 else:
                     f.seek(size, os.SEEK_CUR)
     return data
Ejemplo n.º 2
0
 def _read_chunk_data(self, chunk, fields):
     data = {}
     grids_by_file = defaultdict(list)
     if len(chunk.objs) == 0: return data
     for g in chunk.objs:
         if g.filename is None:
             continue
         grids_by_file[g.filename].append(g)
     dtype = self.ds.index._dtype
     bpr = dtype.itemsize
     for filename in grids_by_file:
         grids = grids_by_file[filename]
         grids.sort(key = lambda a: a._offset)
         f = open(filename, "rb")
         for grid in grids:
             data[grid.id] = {}
             local_offset = grid._get_offset(f) - f.tell()
             count = grid.ActiveDimensions.prod()
             size = count * bpr
             for field in self.ds.index.field_order:
                 if field in fields:
                     # We read it ...
                     f.seek(local_offset, os.SEEK_CUR)
                     v = np.fromfile(f, dtype=dtype, count=count)
                     v = v.reshape(grid.ActiveDimensions, order='F')
                     data[grid.id][field] = v
                     local_offset = 0
                 else:
                     local_offset += size
     return data
Ejemplo n.º 3
0
 def __init__(self, data_source, figure_size, fontsize):
     self.data_source = data_source
     if iterable(figure_size):
         self.figure_size = float(figure_size[0]), float(figure_size[1])
     else:
         self.figure_size = float(figure_size)
     self.plots = PlotDictionary(data_source)
     self._callbacks = []
     self._field_transform = {}
     self._colormaps = defaultdict(lambda: 'algae')
     font_path = matplotlib.get_data_path() + '/fonts/ttf/STIXGeneral.ttf'
     self._font_properties = FontProperties(size=fontsize, fname=font_path)
     self._font_color = None
     self._xlabel = None
     self._ylabel = None
     self._colorbar_label = PlotDictionary(
         self.data_source, lambda: None)
 def __init__(self, data_source, figure_size, fontsize):
     self.data_source = data_source
     if iterable(figure_size):
         self.figure_size = float(figure_size[0]), float(figure_size[1])
     else:
         self.figure_size = float(figure_size)
     self.plots = PlotDictionary(data_source)
     self._callbacks = []
     self._field_transform = {}
     self._colormaps = defaultdict(lambda: 'algae')
     font_path = matplotlib.get_data_path() + '/fonts/ttf/STIXGeneral.ttf'
     self._font_properties = FontProperties(size=fontsize, fname=font_path)
     self._font_color = None
     self._xlabel = None
     self._ylabel = None
     self._minorticks = {}
     self._cbar_minorticks = {}
     self._colorbar_label = PlotDictionary(
         self.data_source, lambda: None)
Ejemplo n.º 5
0
 def _read_chunk_data(self, chunk, fields):
     data = {}
     grids_by_file = defaultdict(list)
     if len(chunk.objs) == 0: return data
     field_list = set(f[1] for f in fields)
     for grid in chunk.objs:
         if grid.filename is None:
             continue
         f = open(grid.filename, "rb")
         data[grid.id] = {}
         grid_ncells = np.prod(grid.ActiveDimensions)
         grid_dims = grid.ActiveDimensions
         grid0_ncells = np.prod(grid.index.grid_dimensions[0, :])
         read_table_offset = get_read_table_offset(f)
         for field in self.ds.field_list:
             dtype, offsetr = grid.index._field_map[field]
             if grid_ncells != grid0_ncells:
                 offset = offsetr + ((grid_ncells - grid0_ncells) *
                                     (offsetr // grid0_ncells))
             if grid_ncells == grid0_ncells:
                 offset = offsetr
             f.seek(read_table_offset + offset)
             if dtype == 'scalar':
                 v = np.fromfile(f, dtype='>f4',
                                 count=grid_ncells).reshape(grid_dims,
                                                            order='F')
             if dtype == 'vector':
                 v = np.fromfile(f, dtype='>f4', count=3 * grid_ncells)
             if '_x' in field[-1]:
                 v = v[0::3].reshape(grid_dims, order='F')
             elif '_y' in field[-1]:
                 v = v[1::3].reshape(grid_dims, order='F')
             elif '_z' in field[-1]:
                 v = v[2::3].reshape(grid_dims, order='F')
             if grid.ds.field_ordering == 1:
                 data[grid.id][field] = v.T.astype("float64")
             else:
                 data[grid.id][field] = v.astype("float64")
         f.close()
     return data