in sdap/processors/tilereadingprocessor.py [0:0]
def read_data(self, tile_specifications, file_path, output_tile):
with xr.decode_cf(xr.open_dataset(file_path, decode_cf=False), decode_times=False) as ds:
for section_spec, dimtoslice in tile_specifications:
tile = nexusproto.SwathTile()
# Time Lat Long Data and metadata should all be indexed by the same dimensions, order the incoming spec once using the data variable
ordered_slices = get_ordered_slices(ds, self.variable_to_read, dimtoslice)
tile.latitude.CopyFrom(to_shaped_array(numpy.ma.filled(ds[self.latitude].data[tuple(ordered_slices.values())], numpy.NaN)))
tile.longitude.CopyFrom(to_shaped_array(numpy.ma.filled(ds[self.longitude].data[tuple(ordered_slices.values())], numpy.NaN)))
timetile = ds[self.time][
tuple([ordered_slices[time_dim] for time_dim in ds[self.time].dims])].astype(
'float64',
casting='same_kind',
copy=False)
timeunits = ds[self.time].attrs['units']
try:
start_of_day_date = datetime.datetime.strptime(ds.attrs[self.start_of_day],
self.start_of_day_pattern)
except Exception:
start_of_day_date = None
for index in numpy.ndindex(timetile.shape):
timetile[index] = to_seconds_from_epoch(timetile[index].item(), timeunits=timeunits,
start_day=start_of_day_date, timeoffset=self.time_offset)
tile.time.CopyFrom(to_shaped_array(timetile))
# Read the data converting masked values to NaN
data_array = numpy.ma.filled(ds[self.variable_to_read].data[tuple(ordered_slices.values())], numpy.NaN)
tile.variable_data.CopyFrom(to_shaped_array(data_array))
if self.metadata is not None:
tile.meta_data.add().CopyFrom(
to_metadata(self.metadata, ds[self.metadata].data[tuple(ordered_slices.values())]))
output_tile.tile.swath_tile.CopyFrom(tile)
yield output_tile