Skip to content

Commit 8082f99

Browse files
authored
Merge pull request #3031 from YouvaEUMex/fix_2898
Fix the handling of AMVs unit to units by applying suggestion in #2898
2 parents 6fc15fe + 38d106d commit 8082f99

File tree

2 files changed

+25
-35
lines changed

2 files changed

+25
-35
lines changed

satpy/readers/fci_l2_nc.py

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def ssp_lon(self):
6060
f"of {SSP_DEFAULT} degrees east instead")
6161
return SSP_DEFAULT
6262

63-
def _get_global_attributes(self):
63+
def _get_global_attributes(self, product_type="pixel"):
6464
"""Create a dictionary of global attributes to be added to all datasets.
6565
6666
Returns:
@@ -70,26 +70,36 @@ def _get_global_attributes(self):
7070
ssp_lon: longitude of subsatellite point
7171
sensor: name of sensor
7272
platform_name: name of the platform
73+
Only for AMVs product:
74+
channel: channel at which the AMVs have been retrieved
75+
7376
7477
"""
7578
attributes = {
7679
"filename": self.filename,
7780
"spacecraft_name": self.spacecraft_name,
78-
"ssp_lon": self.ssp_lon,
7981
"sensor": self.sensor_name,
8082
"platform_name": self.spacecraft_name,
83+
"ssp_lon": self.ssp_lon,
8184
}
85+
86+
if product_type=="amv":
87+
attributes["channel"] = self.filename_info["channel"]
88+
8289
return attributes
8390

84-
def _set_attributes(self, variable, dataset_info, segmented=False):
91+
def _set_attributes(self, variable, dataset_info, product_type="pixel"):
8592
"""Set dataset attributes."""
86-
if segmented:
87-
xdim, ydim = "number_of_FoR_cols", "number_of_FoR_rows"
88-
else:
89-
xdim, ydim = "number_of_columns", "number_of_rows"
93+
if product_type in ["pixel", "segmented"]:
94+
if product_type == "pixel":
95+
xdim, ydim = "number_of_columns", "number_of_rows"
96+
elif product_type == "segmented":
97+
xdim, ydim = "number_of_FoR_cols", "number_of_FoR_rows"
9098

91-
if dataset_info["nc_key"] not in ["product_quality", "product_completeness", "product_timeliness"]:
92-
variable = variable.swap_dims({ydim: "y", xdim: "x"})
99+
if dataset_info["nc_key"] not in ["product_quality",
100+
"product_completeness",
101+
"product_timeliness"]:
102+
variable = variable.swap_dims({ydim: "y", xdim: "x"})
93103

94104
variable.attrs.setdefault("units", None)
95105
if "unit" in variable.attrs:
@@ -98,7 +108,7 @@ def _set_attributes(self, variable, dataset_info, segmented=False):
98108
del variable.attrs["unit"]
99109

100110
variable.attrs.update(dataset_info)
101-
variable.attrs.update(self._get_global_attributes())
111+
variable.attrs.update(self._get_global_attributes(product_type=product_type))
102112

103113
import_enum_information = dataset_info.get("import_enum_information", False)
104114
if import_enum_information:
@@ -382,7 +392,7 @@ def get_dataset(self, dataset_id, dataset_info):
382392
if "fill_value" in dataset_info:
383393
variable = self._mask_data(variable, dataset_info["fill_value"])
384394

385-
variable = self._set_attributes(variable, dataset_info, segmented=True)
395+
variable = self._set_attributes(variable, dataset_info, product_type="segmented")
386396

387397
return variable
388398

@@ -457,26 +467,6 @@ def nc(self):
457467
}
458468
)
459469

460-
def _get_global_attributes(self):
461-
"""Create a dictionary of global attributes to be added to all datasets.
462-
463-
Returns:
464-
dict: A dictionary of global attributes.
465-
filename: name of the product file
466-
spacecraft_name: name of the spacecraft
467-
sensor: name of sensor
468-
platform_name: name of the platform
469-
470-
"""
471-
attributes = {
472-
"filename": self.filename,
473-
"spacecraft_name": self.spacecraft_name,
474-
"sensor": self.sensor_name,
475-
"platform_name": self.spacecraft_name,
476-
"channel": self.filename_info["channel"]
477-
}
478-
return attributes
479-
480470
def get_dataset(self, dataset_id, dataset_info):
481471
"""Get dataset using the nc_key in dataset_info."""
482472
var_key = dataset_info["nc_key"]
@@ -489,7 +479,6 @@ def get_dataset(self, dataset_id, dataset_info):
489479
return None
490480

491481
# Manage the attributes of the dataset
492-
variable.attrs.update(dataset_info)
493-
variable.attrs.update(self._get_global_attributes())
482+
variable = self._set_attributes(variable, dataset_info, product_type="amv")
494483

495484
return variable

satpy/tests/reader_tests/test_fci_l2_nc.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,13 +616,14 @@ def test_all_basic(self, amv_filehandler, amv_file):
616616
assert amv_filehandler.sensor_name == "test_data_source"
617617
assert amv_filehandler.ssp_lon == 0.0
618618

619-
global_attributes = amv_filehandler._get_global_attributes()
619+
global_attributes = amv_filehandler._get_global_attributes(product_type="amv")
620620
expected_global_attributes = {
621621
"filename": amv_file,
622622
"spacecraft_name": "test_platform",
623623
"sensor": "test_data_source",
624624
"platform_name": "test_platform",
625-
"channel": "test_channel"
625+
"channel": "test_channel",
626+
"ssp_lon": 0.0,
626627
}
627628
assert global_attributes == expected_global_attributes
628629

0 commit comments

Comments
 (0)