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

Correct Unexpected floats when reading LI L2 LFL #2998

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions satpy/readers/li_base_nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,11 +439,12 @@ def get_measured_variable(self, var_paths, fill_value=np.nan):
# Also handle fill value here (but only if it is not None, so that we can still bypass this
# step if needed)
arr = self.apply_fill_value(arr, fill_value)

return arr

def apply_fill_value(self, arr, fill_value):
"""Apply fill values, unless it is None."""
"""Apply fill values, unless it is None and when _FillValue is provided."""
ClementLaplace marked this conversation as resolved.
Show resolved Hide resolved
if arr.attrs.get("_FillValue") is None:
return arr
if fill_value is not None:
ClementLaplace marked this conversation as resolved.
Show resolved Hide resolved
if np.isnan(fill_value):
fill_value = np.float32(np.nan)
Expand Down
5 changes: 0 additions & 5 deletions satpy/tests/reader_tests/test_li_l2_nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,6 @@ def test_coords_generation(self, filetype_infos):
products = ["li_l2_af_nc",
"li_l2_afr_nc",
"li_l2_afa_nc"]

for prod in products:
handler = LIL2NCFileHandler("filename", {}, extract_filetype_info(filetype_infos, prod))

Expand All @@ -611,7 +610,6 @@ def test_coords_generation(self, filetype_infos):

elevation = handler.get_measured_variable(handler.swath_coordinates["elevation"])
elevation = handler.apply_use_rescaling(elevation)

# Initialize proj_dict
proj_var = handler.swath_coordinates["projection"]
geos_proj = handler.get_measured_variable(proj_var, fill_value=None)
Expand All @@ -634,9 +632,6 @@ def test_coords_generation(self, filetype_infos):
elevation_vals = elevation.values * point_height
azimuth_vals *= -1
lon_ref, lat_ref = projection(azimuth_vals, elevation_vals, inverse=True)
# Convert to float32:
lon_ref = lon_ref.astype(np.float32)
lat_ref = lat_ref.astype(np.float32)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused here: why do we need to remove the casting to float32 in the test reference data? What is the type of the lon and lat coming from the reader code, after this PR? I would have expected that after this PR the values should be in float32 from both sources and the test should pass without modifications...

Copy link
Contributor Author

@ClementLaplace ClementLaplace Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ameraner in fact lon and lat do not have have a _FillValue attributes and it is natively a np.float64 or before my commit this line bellow was applied which converts the array from a np.float64 to a np.float32

arr = arr.where(arr != arr.attrs.get("_FillValue"), fill_value)

So it means that I have to investigate this method

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm ok, then could you please check where the lon and lat arrays become float64 in the code? As requested, part of the fix we need is to avoid float64 in favour of float32 for float values...


handler.generate_coords_from_scan_angles()
lon = handler.internal_variables["longitude"].values
Expand Down
Loading