diff --git a/monetio/sat/_modis_l2_mm.py b/monetio/sat/_modis_l2_mm.py index 0bf35b11..b09c5c09 100644 --- a/monetio/sat/_modis_l2_mm.py +++ b/monetio/sat/_modis_l2_mm.py @@ -1,6 +1,7 @@ import logging import sys from collections import OrderedDict +from datetime import datetime, timezone from glob import glob import numpy as np @@ -20,18 +21,23 @@ def read_dataset(fname, variable_dict): """ from monetio.sat.hdfio import hdf_close, hdf_list, hdf_open, hdf_read + epoch_1993 = int(datetime(1993, 1, 1, tzinfo=timezone.utc).timestamp()) + print("reading " + fname) ds = xr.Dataset() f = hdf_open(fname) hdf_list(f) - latitude = hdf_read(f, "Latitude") # noqa: F841 - longitude = hdf_read(f, "Longitude") # noqa: F841 - start_time = hdf_read(f, "Scan_Start_Time") # noqa: F841 + # Geolocation and Time Parameters + latitude = hdf_read(f, "Latitude") + longitude = hdf_read(f, "Longitude") + # convert seconds since 1993 to since 1970 + start_time = hdf_read(f, "Scan_Start_Time") + epoch_1993 for varname in variable_dict: print(varname) values = hdf_read(f, varname) + print("min, max: ", values.min(), " ", values.max()) if "scale" in variable_dict[varname]: values = variable_dict[varname]["scale"] * values if "minimum" in variable_dict[varname]: @@ -46,6 +52,15 @@ def read_dataset(fname, variable_dict): ds.attrs["quality_thresh"] = variable_dict[varname]["quality_flag"] hdf_close(f) + ds = ds.assign_coords( + { + "lon": (["dim_0", "dim_1"], longitude), + "lat": (["dim_0", "dim_1"], latitude), + "time": (["dim_0", "dim_1"], start_time), + } + ) + ds = ds.rename_dims({"dim_0": "Cell_Along_Swath", "dim_1": "Cell_Across_Swath"}) + return ds @@ -81,7 +96,10 @@ def read_mfdataset(fnames, variable_dict, debug=False): logging_level = logging.DEBUG logging.basicConfig(stream=sys.stdout, level=logging_level) - files = sorted(glob(fnames)) + if isinstance(fnames, str): + files = sorted(glob(fnames)) + else: + files = fnames granules = OrderedDict()