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

Allow to keep units in composite #2023

Closed
gerritholl opened this issue Feb 15, 2022 · 3 comments
Closed

Allow to keep units in composite #2023

gerritholl opened this issue Feb 15, 2022 · 3 comments
Assignees
Labels
backwards-incompatibility Causes backwards incompatibility or introduces a deprecation component:compositors component:enhancements component:writers enhancement code enhancements, features, improvements

Comments

@gerritholl
Copy link
Collaborator

Feature Request

Is your feature request related to a problem? Please describe.

We have single-band "composites" that we use for our IR channels, so that we can apply a crude stretch enhancement. For reference, our enhancement is:

  dwd_IR_120:
    standard_name: dwd_IR_120
    operations:
    - name: stretch
      method: !!python/name:satpy.enhancements.stretch
      kwargs: {stretch: crude, min_stretch: 313.5, max_stretch: 186}

and the composite

  dwd_IR_120:
    compositor: !!python/name:satpy.composites.GenericCompositor
    prerequisites:
      - wavelength: 12.0
    standard_name: dwd_IR_120

Using this composite, we write files that contain temperature units in the header. There are presently wrong; see #2018. We cannot presently use the solution in #2021 (which sets an offset prior to applying any other enhancements), because Satpy helpfully deletes units metadata when constructing the composite:

# 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)

With the unit metadata gone by the time we are saving our data file, we cannot safely convert the units between K and °C.

Describe the solution you'd like

I would like that either:

  1. The GenericCompositor retains units (and other) metadata if the compositor has exactly one input, or
  2. the GenericCompositor retains units metadata if all inputs have the same units, or
  3. the GenericCompositor retains units metadata if explicitly asked for by the user, or
  4. a different solution I'm not thinking of right now.

Describe any changes to existing user workflow

Alternatives 1 and 2 may result in composites retaining unit metadata where this is not currently the case. Depending on operations applied, those metadata may not be meaningful. Alternative 3 should not lead to any changes to existing user workflow.

Additional context

We could pass a flag to the writer forcing the temperature conversion without checking. This is a risky alternative, but would not require any changes to the widely used GenericCompositor.

I am open to other ideas.

@gerritholl gerritholl added enhancement code enhancements, features, improvements component:writers component:enhancements component:compositors backwards-incompatibility Causes backwards incompatibility or introduces a deprecation labels Feb 15, 2022
@gerritholl gerritholl self-assigned this Feb 15, 2022
@gerritholl
Copy link
Collaborator Author

  • The GenericCompositor retains units (and other) metadata if the compositor has exactly one input, or

  • the GenericCompositor retains units metadata if all inputs have the same units, or

  • the GenericCompositor retains units metadata if explicitly asked for by the user, or

  • a different solution I'm not thinking of right now.

Another option could be to define an entirely different compositor for this use case.

@gerritholl
Copy link
Collaborator Author

Oh, maybe we should be using SingleBandCompositor

@djhoese
Copy link
Member

djhoese commented Feb 15, 2022

Yes, SingleBandCompositor is designed for this use case. If you use GenericCompositor it assumes you are creating an image and makes some rigid decisions based on that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backwards-incompatibility Causes backwards incompatibility or introduces a deprecation component:compositors component:enhancements component:writers enhancement code enhancements, features, improvements
Projects
None yet
Development

No branches or pull requests

2 participants