From 14dd1b8b7966357d0223973c04f10592ce5eb66c Mon Sep 17 00:00:00 2001 From: aoun Date: Tue, 14 Jan 2025 15:25:53 +0000 Subject: [PATCH 1/8] Fix the handling of AMVs unit to units by applying suggestion in #2898 --- satpy/readers/fci_l2_nc.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/satpy/readers/fci_l2_nc.py b/satpy/readers/fci_l2_nc.py index 8971eb4996..579e66a5f7 100644 --- a/satpy/readers/fci_l2_nc.py +++ b/satpy/readers/fci_l2_nc.py @@ -81,14 +81,16 @@ def _get_global_attributes(self): } return attributes - def _set_attributes(self, variable, dataset_info, segmented=False): + def _set_attributes(self, variable, dataset_info, product_type="pixel"): """Set dataset attributes.""" - if segmented: - xdim, ydim = "number_of_FoR_cols", "number_of_FoR_rows" - else: + if product_type == "pixel": xdim, ydim = "number_of_columns", "number_of_rows" + elif product_type == "segmented": + xdim, ydim = "number_of_FoR_cols", "number_of_FoR_rows" - if dataset_info["nc_key"] not in ["product_quality", "product_completeness", "product_timeliness"]: + if product_type in ["pixel", "segmented"] and dataset_info["nc_key"] not in ["product_quality", + "product_completeness", + "product_timeliness"]: variable = variable.swap_dims({ydim: "y", xdim: "x"}) variable.attrs.setdefault("units", None) @@ -382,7 +384,7 @@ def get_dataset(self, dataset_id, dataset_info): if "fill_value" in dataset_info: variable = self._mask_data(variable, dataset_info["fill_value"]) - variable = self._set_attributes(variable, dataset_info, segmented=True) + variable = self._set_attributes(variable, dataset_info, product_type="segmented") return variable @@ -489,7 +491,6 @@ def get_dataset(self, dataset_id, dataset_info): return None # Manage the attributes of the dataset - variable.attrs.update(dataset_info) - variable.attrs.update(self._get_global_attributes()) + variable = self._set_attributes(variable, dataset_info, product_type="amv") return variable From b5a27be7cb32e783d29148029a7b89a582030ffc Mon Sep 17 00:00:00 2001 From: aoun Date: Wed, 15 Jan 2025 13:07:32 +0000 Subject: [PATCH 2/8] Move the if condition for pixel and segmented above to avoid going trhough the loop when reading amvs --- satpy/readers/fci_l2_nc.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/satpy/readers/fci_l2_nc.py b/satpy/readers/fci_l2_nc.py index 579e66a5f7..1179ca07e9 100644 --- a/satpy/readers/fci_l2_nc.py +++ b/satpy/readers/fci_l2_nc.py @@ -83,15 +83,16 @@ def _get_global_attributes(self): def _set_attributes(self, variable, dataset_info, product_type="pixel"): """Set dataset attributes.""" - if product_type == "pixel": - xdim, ydim = "number_of_columns", "number_of_rows" - elif product_type == "segmented": - xdim, ydim = "number_of_FoR_cols", "number_of_FoR_rows" - - if product_type in ["pixel", "segmented"] and dataset_info["nc_key"] not in ["product_quality", - "product_completeness", - "product_timeliness"]: - variable = variable.swap_dims({ydim: "y", xdim: "x"}) + if product_type in ["pixel", "segmented"]: + if product_type == "pixel": + xdim, ydim = "number_of_columns", "number_of_rows" + elif product_type == "segmented": + xdim, ydim = "number_of_FoR_cols", "number_of_FoR_rows" + + if dataset_info["nc_key"] not in ["product_quality", + "product_completeness", + "product_timeliness"]: + variable = variable.swap_dims({ydim: "y", xdim: "x"}) variable.attrs.setdefault("units", None) if "unit" in variable.attrs: From ee12792495461f19321a1e65435e3c2091040ac5 Mon Sep 17 00:00:00 2001 From: aoun Date: Wed, 15 Jan 2025 13:45:46 +0000 Subject: [PATCH 3/8] Add a default values to avoid breaking the default behavior --- satpy/readers/fci_l2_nc.py | 52 ++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/satpy/readers/fci_l2_nc.py b/satpy/readers/fci_l2_nc.py index 1179ca07e9..77b92f82f4 100644 --- a/satpy/readers/fci_l2_nc.py +++ b/satpy/readers/fci_l2_nc.py @@ -60,7 +60,7 @@ def ssp_lon(self): f"of {SSP_DEFAULT} degrees east instead") return SSP_DEFAULT - def _get_global_attributes(self): + def _get_global_attributes(self,product_type="pixel"): """Create a dictionary of global attributes to be added to all datasets. Returns: @@ -70,15 +70,23 @@ def _get_global_attributes(self): ssp_lon: longitude of subsatellite point sensor: name of sensor platform_name: name of the platform + Only for AMVS product: + channel: channel at which the AMVs have been retrieved + """ attributes = { "filename": self.filename, "spacecraft_name": self.spacecraft_name, - "ssp_lon": self.ssp_lon, "sensor": self.sensor_name, "platform_name": self.spacecraft_name, } + + if product_type=="amv": + attributes["channel"] = self.filename_info["channel"] + else: + attributes["ssp_lon"] = self.ssp_lon + return attributes def _set_attributes(self, variable, dataset_info, product_type="pixel"): @@ -101,7 +109,7 @@ def _set_attributes(self, variable, dataset_info, product_type="pixel"): del variable.attrs["unit"] variable.attrs.update(dataset_info) - variable.attrs.update(self._get_global_attributes()) + variable.attrs.update(self._get_global_attributes(product_type)) import_enum_information = dataset_info.get("import_enum_information", False) if import_enum_information: @@ -460,25 +468,25 @@ def nc(self): } ) - def _get_global_attributes(self): - """Create a dictionary of global attributes to be added to all datasets. - - Returns: - dict: A dictionary of global attributes. - filename: name of the product file - spacecraft_name: name of the spacecraft - sensor: name of sensor - platform_name: name of the platform - - """ - attributes = { - "filename": self.filename, - "spacecraft_name": self.spacecraft_name, - "sensor": self.sensor_name, - "platform_name": self.spacecraft_name, - "channel": self.filename_info["channel"] - } - return attributes + # def _get_global_attributes(self): + # """Create a dictionary of global attributes to be added to all datasets. + + # Returns: + # dict: A dictionary of global attributes. + # filename: name of the product file + # spacecraft_name: name of the spacecraft + # sensor: name of sensor + # platform_name: name of the platform + + # """ + # attributes = { + # "filename": self.filename, + # "spacecraft_name": self.spacecraft_name, + # "sensor": self.sensor_name, + # "platform_name": self.spacecraft_name, + # "channel": self.filename_info["channel"] + # } + # return attributes def get_dataset(self, dataset_id, dataset_info): """Get dataset using the nc_key in dataset_info.""" From e2a78363e2553c50d6fd0faac003fdcc3f5ca3dd Mon Sep 17 00:00:00 2001 From: aoun Date: Wed, 15 Jan 2025 13:47:10 +0000 Subject: [PATCH 4/8] Fix AMV test_all_basic by adding the prodcut_type values dedicated to AMVs behavior --- satpy/tests/reader_tests/test_fci_l2_nc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/satpy/tests/reader_tests/test_fci_l2_nc.py b/satpy/tests/reader_tests/test_fci_l2_nc.py index 830f793d00..79f4549316 100644 --- a/satpy/tests/reader_tests/test_fci_l2_nc.py +++ b/satpy/tests/reader_tests/test_fci_l2_nc.py @@ -616,7 +616,7 @@ def test_all_basic(self, amv_filehandler, amv_file): assert amv_filehandler.sensor_name == "test_data_source" assert amv_filehandler.ssp_lon == 0.0 - global_attributes = amv_filehandler._get_global_attributes() + global_attributes = amv_filehandler._get_global_attributes(product_type="amv") expected_global_attributes = { "filename": amv_file, "spacecraft_name": "test_platform", From c7495a3615a5e02bfa1f366aa09f5e6a3a33d267 Mon Sep 17 00:00:00 2001 From: aoun Date: Wed, 15 Jan 2025 13:48:50 +0000 Subject: [PATCH 5/8] Remove the _get_global_attributes methode from the AMV file handler since it is now covered by the one in the common function --- satpy/readers/fci_l2_nc.py | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/satpy/readers/fci_l2_nc.py b/satpy/readers/fci_l2_nc.py index 77b92f82f4..2c5434e4e8 100644 --- a/satpy/readers/fci_l2_nc.py +++ b/satpy/readers/fci_l2_nc.py @@ -468,26 +468,6 @@ def nc(self): } ) - # def _get_global_attributes(self): - # """Create a dictionary of global attributes to be added to all datasets. - - # Returns: - # dict: A dictionary of global attributes. - # filename: name of the product file - # spacecraft_name: name of the spacecraft - # sensor: name of sensor - # platform_name: name of the platform - - # """ - # attributes = { - # "filename": self.filename, - # "spacecraft_name": self.spacecraft_name, - # "sensor": self.sensor_name, - # "platform_name": self.spacecraft_name, - # "channel": self.filename_info["channel"] - # } - # return attributes - def get_dataset(self, dataset_id, dataset_info): """Get dataset using the nc_key in dataset_info.""" var_key = dataset_info["nc_key"] From c317c174ba30e4a20f9d91055238e9ccce993fa1 Mon Sep 17 00:00:00 2001 From: aoun Date: Wed, 15 Jan 2025 16:41:06 +0000 Subject: [PATCH 6/8] Remove the ssp_lon as a conditional attribute but here for all --- satpy/readers/fci_l2_nc.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/satpy/readers/fci_l2_nc.py b/satpy/readers/fci_l2_nc.py index 2c5434e4e8..cfde51100b 100644 --- a/satpy/readers/fci_l2_nc.py +++ b/satpy/readers/fci_l2_nc.py @@ -80,12 +80,11 @@ def _get_global_attributes(self,product_type="pixel"): "spacecraft_name": self.spacecraft_name, "sensor": self.sensor_name, "platform_name": self.spacecraft_name, + "ssp_lon": self.ssp_lon, } if product_type=="amv": attributes["channel"] = self.filename_info["channel"] - else: - attributes["ssp_lon"] = self.ssp_lon return attributes From fdeeed4a8ce8d3c0bf5b041916580f472de37a3f Mon Sep 17 00:00:00 2001 From: aoun Date: Wed, 15 Jan 2025 16:42:42 +0000 Subject: [PATCH 7/8] Fix typo and improve readbility for the call of the get_global_attribute with the product_type --- satpy/readers/fci_l2_nc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/satpy/readers/fci_l2_nc.py b/satpy/readers/fci_l2_nc.py index cfde51100b..000847f4b1 100644 --- a/satpy/readers/fci_l2_nc.py +++ b/satpy/readers/fci_l2_nc.py @@ -70,7 +70,7 @@ def _get_global_attributes(self,product_type="pixel"): ssp_lon: longitude of subsatellite point sensor: name of sensor platform_name: name of the platform - Only for AMVS product: + Only for AMVs product: channel: channel at which the AMVs have been retrieved @@ -108,7 +108,7 @@ def _set_attributes(self, variable, dataset_info, product_type="pixel"): del variable.attrs["unit"] variable.attrs.update(dataset_info) - variable.attrs.update(self._get_global_attributes(product_type)) + variable.attrs.update(self._get_global_attributes(product_type=product_type)) import_enum_information = dataset_info.get("import_enum_information", False) if import_enum_information: From d42c00d703afe04a64084f5d7b3cf6396f2009cd Mon Sep 17 00:00:00 2001 From: aoun Date: Wed, 15 Jan 2025 16:44:59 +0000 Subject: [PATCH 8/8] Add ssp_lon to the dict of attribute to be tested --- satpy/tests/reader_tests/test_fci_l2_nc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/satpy/tests/reader_tests/test_fci_l2_nc.py b/satpy/tests/reader_tests/test_fci_l2_nc.py index 79f4549316..a3f7e6318c 100644 --- a/satpy/tests/reader_tests/test_fci_l2_nc.py +++ b/satpy/tests/reader_tests/test_fci_l2_nc.py @@ -622,7 +622,8 @@ def test_all_basic(self, amv_filehandler, amv_file): "spacecraft_name": "test_platform", "sensor": "test_data_source", "platform_name": "test_platform", - "channel": "test_channel" + "channel": "test_channel", + "ssp_lon": 0.0, } assert global_attributes == expected_global_attributes