Newer
Older
from netCDF4 import Dataset
import xarray as xr
import numpy as np
def read_data(sensor: str, l1b_filename: str, geo_filename: str):
data = xr.open_dataset(l1b_filename, group='observation_data', decode_cf=False)
in_data = xr.Dataset()
if sensor.lower() == 'viirs':
for band in list(data.variables):
if 'reflectance' in data[band].long_name:
if hasattr(data[band], 'VCST_scale_factor'):
scale_factor = data[band].VCST_scale_factor * data[band].bias_correction
else:
scale_factor = data[band].radiance_scale_factor
in_data[band] = (('number_of_lines', 'number_of_pixels'),
data[band].values * scale_factor)
elif 'radiance' in data[band].long_name:
in_data[band] = (('number_of_lines', 'number_of_pixels'),
data[f'{band}_brightness_temperature_lut'].values[data[band].values])
else:
pass
data = xr.open_dataset(geo_filename, group='geolocation_data')
in_data = in_data.merge(data)
return in_data