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

ninjogeotiff geos error message sometimes unhelpful #2924

Open
gerritholl opened this issue Oct 11, 2024 · 0 comments
Open

ninjogeotiff geos error message sometimes unhelpful #2924

gerritholl opened this issue Oct 11, 2024 · 0 comments

Comments

@gerritholl
Copy link
Member

Describe the bug

NinJo cannot read geostationary projections, and the ninjogeotiff writer cannot write geostationary projections. When the user tries this anyway, NinJoGeoTIFFWriter.get_projection() is supposed to give a helpful error message when called during tag collection. But the order of tag collection is undefined, and sometimes NinJoGeoTIFFWriter.get_ref_lat_1() gets called first and fails with a different error message. This error message is particularly unhelpful if data come from a GeoSegmentYAMLReader, as the original area description is lost and is just called fill.

To Reproduce

import hdf5plugin
from satpy import Scene
from glob import glob
fci_files = glob("/media/nas/x23352/MTG/FCI/L1c-cases/202309_10-cwg/10/01/08/W_XX-EUMETSAT-Darmstadt,IMG+SAT,MTI1+FCI-1C-RRAD-FDHSI-FD--CHK-BODY---NC4E_C_EUMT_20231001*_IDPFI_VAL_20231001*_20231001*_N__C_0054_003*.nc")
sc = Scene(filenames={"fci_l1c_nc": fci_files})
sc.load(["ir_105"], upper_right_corner="NE")
sc.save_dataset("ir_105",
    writer="ninjogeotiff",
    ChannelID="IR 105",
    DataType="GORN",
    PhysicUnit="K",
    PhysicValue="Temperature",
    SatelliteNameID="MTG Europe-Africa",
    fill_value=0)

Expected behaviour

The desirable behaviour sometimes happens when passing 40 granules:

Traceback (most recent call last):
  File "/data/gholl/checkouts/protocode/mwe/ngt-unhelpful-error-message.py", line 7, in <module>
    sc.save_dataset("ir_105",
  File "/data/gholl/checkouts/satpy/satpy/scene.py", line 1234, in save_dataset
    return writer.save_dataset(self[dataset_id],
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/gholl/checkouts/satpy/satpy/writers/__init__.py", line 885, in save_dataset
    return self.save_image(img, filename=filename, compute=compute, fill_value=fill_value, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/gholl/checkouts/satpy/satpy/writers/ninjogeotiff.py", line 193, in save_image
    ninjo_tags = {f"ninjo_{k:s}": v for (k, v) in ntg.get_all_tags().items()}
                                                  ^^^^^^^^^^^^^^^^^^
  File "/data/gholl/checkouts/satpy/satpy/writers/ninjogeotiff.py", line 346, in get_all_tags
    tags[tag] = self.get_tag(tag)
                ^^^^^^^^^^^^^^^^^
  File "/data/gholl/checkouts/satpy/satpy/writers/ninjogeotiff.py", line 362, in get_tag
    return getattr(self, f"get_{self.dynamic_tags[tag]:s}")()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/gholl/checkouts/satpy/satpy/writers/ninjogeotiff.py", line 463, in get_projection
    raise ValueError(
ValueError: Unknown mapping from area 'MTG FCI Full Disk Scanning Service area definition with 1 km resolution' with CRS coordinate operation name Geostationary Satellite (Sweep Y) to NinJo projection.  NinJo understands only equidistant cylindrical, mercator, or stereographic projections.

Although even here, we might add a hint that the user needs to resample the data to a non-geostationary projection (or to a lat/lon unprojected area).

Actual results

However, when passing less than 40 granules and using filling, the best case is:

Traceback (most recent call last):
  File "/data/gholl/checkouts/protocode/mwe/ngt-unhelpful-error-message.py", line 7, in <module>
    sc.save_dataset("ir_105",
  File "/data/gholl/checkouts/satpy/satpy/scene.py", line 1234, in save_dataset
    return writer.save_dataset(self[dataset_id],
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/gholl/checkouts/satpy/satpy/writers/__init__.py", line 885, in save_dataset
    return self.save_image(img, filename=filename, compute=compute, fill_value=fill_value, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/gholl/checkouts/satpy/satpy/writers/ninjogeotiff.py", line 193, in save_image
    ninjo_tags = {f"ninjo_{k:s}": v for (k, v) in ntg.get_all_tags().items()}
                                                  ^^^^^^^^^^^^^^^^^^
  File "/data/gholl/checkouts/satpy/satpy/writers/ninjogeotiff.py", line 346, in get_all_tags
    tags[tag] = self.get_tag(tag)
                ^^^^^^^^^^^^^^^^^
  File "/data/gholl/checkouts/satpy/satpy/writers/ninjogeotiff.py", line 362, in get_tag
    return getattr(self, f"get_{self.dynamic_tags[tag]:s}")()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/gholl/checkouts/satpy/satpy/writers/ninjogeotiff.py", line 463, in get_projection
    raise ValueError(
ValueError: Unknown mapping from area 'fill' with CRS coordinate operation name Geostationary Satellite (Sweep Y) to NinJo projection.  NinJo understands only equidistant cylindrical, mercator, or stereographic projections.

Worse, in some cases we get:

Traceback (most recent call last):
  File "/data/gholl/checkouts/protocode/mwe/ngt-unhelpful-error-message.py", line 7, in <module>
    sc.save_dataset("ir_105",
  File "/data/gholl/checkouts/satpy/satpy/scene.py", line 1234, in save_dataset
    return writer.save_dataset(self[dataset_id],
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/gholl/checkouts/satpy/satpy/writers/__init__.py", line 885, in save_dataset
    return self.save_image(img, filename=filename, compute=compute, fill_value=fill_value, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/gholl/checkouts/satpy/satpy/writers/ninjogeotiff.py", line 193, in save_image
    ninjo_tags = {f"ninjo_{k:s}": v for (k, v) in ntg.get_all_tags().items()}
                                                  ^^^^^^^^^^^^^^^^^^
  File "/data/gholl/checkouts/satpy/satpy/writers/ninjogeotiff.py", line 346, in get_all_tags
    tags[tag] = self.get_tag(tag)
                ^^^^^^^^^^^^^^^^^
  File "/data/gholl/checkouts/satpy/satpy/writers/ninjogeotiff.py", line 362, in get_tag
    return getattr(self, f"get_{self.dynamic_tags[tag]:s}")()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/gholl/checkouts/satpy/satpy/writers/ninjogeotiff.py", line 480, in get_ref_lat_1
    raise ValueError(
ValueError: Could not find reference latitude for area fill

Which one happens appears undefined. A user came to me with the justified question what "Could not find reference latitude for area fill" means.

Environment Info:

  • OS: Linux
  • Satpy Version: main

Additional context

The error message could be improved by:

  • Ensuring get_projection() gets called before get_ref_lat_1(), or
  • Calling a dedicated method that ensures the data can be stored as ninjogeotiff, or
  • Adding a helpful hint to the error message in get_ref_lat_1().

In addition, we could consider the filled area to have a description that includes the original area description (f"filled area derived from {orig_area.description:s}" or so).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant