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 the handling of AMVs unit to units by applying suggestion in #2898 #3031

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
56 changes: 23 additions & 33 deletions satpy/readers/fci_l2_nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -70,26 +70,37 @@ 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:
YouvaEUMex marked this conversation as resolved.
Show resolved Hide resolved
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

YouvaEUMex marked this conversation as resolved.
Show resolved Hide resolved
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:
xdim, ydim = "number_of_columns", "number_of_rows"
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"})
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:
Expand All @@ -98,7 +109,7 @@ def _set_attributes(self, variable, dataset_info, segmented=False):
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))
YouvaEUMex marked this conversation as resolved.
Show resolved Hide resolved

import_enum_information = dataset_info.get("import_enum_information", False)
if import_enum_information:
Expand Down Expand Up @@ -382,7 +393,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

Expand Down Expand Up @@ -457,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"]
Expand All @@ -489,7 +480,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
2 changes: 1 addition & 1 deletion satpy/tests/reader_tests/test_fci_l2_nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down