Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix writer crashing on missing orbital parameters #107

Merged
merged 1 commit into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 40 additions & 27 deletions pygac_fdr/tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,18 @@ def scene_lonlats(self):
lats = [[1, 2], [3, 4]]
return lons, lats

@pytest.fixture(params=[True, False])
def with_orbital_parameters(self, request):
return request.param

@pytest.fixture
def scene_dataset_attrs(self, scene_lonlats):
def scene_dataset_attrs(self, scene_lonlats, with_orbital_parameters):
lons, lats = scene_lonlats
return {
attrs = {
"platform_name": "noaa15",
"sensor": "avhrr-1",
"sun_earth_distance_correction_factor": 0.9,
"calib_coeffs_version": "patmos-x 2012",
"orbital_parameters": {"tle": "my_tle"},
"long_name": "my_long_name",
"units": "my_units",
"standard_name": "my_standard_name",
Expand All @@ -83,6 +86,9 @@ def scene_dataset_attrs(self, scene_lonlats):
"start_time": dt.datetime(2000, 1, 1),
"end_time": dt.datetime(2000, 1, 1),
}
if with_orbital_parameters:
attrs["orbital_parameters"] = {"tle": "my_tle"}
return attrs

@pytest.fixture
def scene(self, scene_dataset_attrs, scene_lonlats):
Expand Down Expand Up @@ -132,7 +138,35 @@ def scene(self, scene_dataset_attrs, scene_lonlats):
return scene

@pytest.fixture
def expected(self):
def attrs_exp(self, with_orbital_parameters):
attrs = {
"author": "Turtles",
"end_time": "19700101T000001Z",
"geospatial_lat_max": 4,
"geospatial_lat_min": 1,
"geospatial_lat_resolution": "1234.0 meters",
"geospatial_lat_units": "degrees_north",
"geospatial_lon_max": 8,
"geospatial_lon_min": 5,
"geospatial_lon_resolution": "1234.0 meters",
"geospatial_lon_units": "degrees_east",
"instrument": "Earth Remote Sensing Instruments > Passive Remote Sensing > "
"Spectrometers/Radiometers > Imaging Spectrometers/Radiometers "
"> AVHRR-1",
"platform": "Earth Observation Satellites > NOAA POES > NOAA-15",
"start_time": "19700101T000000Z",
"sun_earth_distance_correction_factor": 0.9,
"time_coverage_start": "19981026T005400Z",
"version_calib_coeffs": "patmos-x 2012",
"Conventions": "CF-1.8",
"product_version": "1.2.3",
}
if with_orbital_parameters:
attrs["orbital_parameters_tle"] = "my_tle"
return attrs

@pytest.fixture
def expected(self, attrs_exp):
acq_time = xr.DataArray(
np.array([0, 1], dtype="datetime64[s]"),
dims="y",
Expand Down Expand Up @@ -200,31 +234,10 @@ def expected(self):
"meanings.",
},
)

return xr.Dataset(
{"brightness_temperature_channel_4": bt_ch4, "qual_flags": qual_flags},
attrs={
"author": "Turtles",
"end_time": "19700101T000001Z",
"geospatial_lat_max": 4,
"geospatial_lat_min": 1,
"geospatial_lat_resolution": "1234.0 meters",
"geospatial_lat_units": "degrees_north",
"geospatial_lon_max": 8,
"geospatial_lon_min": 5,
"geospatial_lon_resolution": "1234.0 meters",
"geospatial_lon_units": "degrees_east",
"instrument": "Earth Remote Sensing Instruments > Passive Remote Sensing > "
"Spectrometers/Radiometers > Imaging Spectrometers/Radiometers "
"> AVHRR-1",
"orbital_parameters_tle": "my_tle",
"platform": "Earth Observation Satellites > NOAA POES > NOAA-15",
"start_time": "19700101T000000Z",
"sun_earth_distance_correction_factor": 0.9,
"time_coverage_start": "19981026T005400Z",
"version_calib_coeffs": "patmos-x 2012",
"Conventions": "CF-1.8",
"product_version": "1.2.3",
},
attrs=attrs_exp,
)

@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion pygac_fdr/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ def _compute_global_attrs(self):
"geospatial_lon_resolution": "{} meters".format(resol),
"geospatial_lat_resolution": "{} meters".format(resol),
"time_coverage_start": time_cov_start.strftime(TIME_FMT),
"orbital_parameters": ch_attrs["orbital_parameters"],
"orbital_parameters": ch_attrs.get("orbital_parameters", {}),
}
if time_cov_end: # Otherwise still operational
global_attrs["time_coverage_end"] = time_cov_end.strftime(TIME_FMT)
Expand Down