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

GenericCompositor discards dataset metadata #2829

Open
BoehnkeC opened this issue Jun 18, 2024 · 3 comments
Open

GenericCompositor discards dataset metadata #2829

BoehnkeC opened this issue Jun 18, 2024 · 3 comments

Comments

@BoehnkeC
Copy link

Describe the bug
Creating a composite with the GenericCompositor overwrites initial band/dataset metadata. This is also directly commented in the code itself although I find this behavior disputable:

new_attrs = combine_metadata(*datasets)
        # remove metadata that shouldn't make sense in a composite
        new_attrs["wavelength"] = None
        new_attrs.pop("units", None)
        new_attrs.pop("calibration", None)
        new_attrs.pop("modifiers", None)

To Reproduce

composite = composites.GenericCompositor(name="overview")
composite = composite(scene[3.8],
                      scene[10.8],
                      scene[12.0]
)

with scene being an instance of Satpy's Scene class.

Calling the attributes of an individual dataset, e.g. scene[3.8].attrs["wavelength"] prints: 3.8 µm (3.71-3.89 µm).
Calling the attributes of the same dataset in the composite with composite[0].attrs["wavelength"] prints None.

It is not possible to alter the dataset attributes within the composite.

Expected behavior
Discarding the original dataset attributes removes a lot of useful metadata and hampers visualization of the written composite file as crucial band information is missing. If band metadata would be forwarded or if there would be an option editing the metadata of the composite directly, further offline work with the saved image would be possible.

@gerritholl
Copy link
Collaborator

What value would you expect for a "wavelength" attribute for a composite RGB built with channels 3.8 µm, 10.8 µm, and 12.0 µm? How about "calibration"?

@BoehnkeC
Copy link
Author

BoehnkeC commented Jul 30, 2024

When I call the composite with composite.attrs, I'd expect some kind of list or dictionary for the wavelength key. Something like composite.attrs = {wavelength: [3.8, 10.8, 12.0], ...} or composite.attrs = {wavelength: {R: 3.8, G: 10.8, B: 12.0}, ...}. If this behavior is not supported when creating composites, I"d expect it when editing the composite metadata as described in https://satpy.readthedocs.io/en/stable/quickstart.html#creating-new-datasets.

@djhoese
Copy link
Member

djhoese commented Jul 30, 2024

Interesting idea, but I'm not sure how I feel about it. It is very likely that this request that specifically mentions wavelength could require a larger more generic solution for accessing all the information from dependencies used in a composite.

Could you clarify what in the referenced documentation (the quickstart you linked to) you have a problem with? Is it that combine_metadata removes some metadata as part of the combining process, but this documentation section doesn't state that?

There are a couple complications with trying to implement something like this:

  1. Scene.__getitem__ (the scn[0.6] syntax) uses the wavelength to get a dataset by wavelength rather than by name. This functionality would need to be updated but also what would the behavior be if RGBs were involved? Only consider the single band products maybe?
  2. Composites are not always RGBs, sometimes they have an Alpha channel too or they could be in a different colorspace (ex. HSV or HSL although not very common). So the solution would need to account for all of this and still make sense.
  3. What if the RGB is using a rayleigh corrected or other atmospheric correction for one or more of the bands? Does the wavelength still apply? For other metadata fields like resolution we do retain the original value in .attrs even after resampling has changed the spatial resolution so it wouldn't be crazy to keep the wavelength in this case, but maybe is a bit misleading.

You mentioned:

or if there would be an option editing the metadata of the composite directly

What do you mean by "directly"?

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

No branches or pull requests

3 participants