Skip to content

optionally clip data in crude_stretch #90

Description

@gerritholl

Feature Request

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

Users generating NinJoTIFF files with Satpy who wish to use the pyninjotiff clipping functionality currently have to define the boundaries of their data values in two places:

  • In their enhancements file (enhancements/generic.yaml) in the units to which the data are calibrated; for example, for solar infrared channels, this is in brightness temperature in units of Kelvin, such as:
      method: !!python/name:satpy.enhancements.stretch
      kwargs: {stretch: crude, min_stretch: 313.5, max_stretch: 186}
  • As keyword arguments to the NinJoTIFF writer, with keywords ch_min_measurement_unit and ch_max_measurement_unit, now in units such as interpreted by NinJo, which may be in °C. From a trollflow2.yaml example:
  physic_unit: C
  ch_min_measurement_unit: 40
  ch_max_measurement_unit: -87.5

This happens because stretch (implemented in trollimage.xrimage.XRImage.crude_stretch) stretches the data between the two values such that 0 maps to the indicated minimum and 1 maps to the indicated maximum; and then pyninjotiff clips the data (in pyninjotiff.ninjotiff._finalize) and rescales it making place for a fill value.

It is the responsibility of the user to make sure those two match, or values as interpreted by the client software (in this case NinJo) will be incorrect.

This is problematic, because:

  • the user needs to configure the limits twice, possibly in different units, which is redundant work and can be error-prone;
  • the ninjotiff writer is altering the data in a way that should not be the responsibility of the writer.

There is ongoing work to replace the ninjotiff writer by a ninjogeotiff writer (see pytroll/satpy#1839). This new writer provides an opportunity for a cleanup. As part of that cleanup, the two problems with the current approach can be resolved. This feature request is triggered by a need fo rthe ninjogeotiff writer.

Describe the solution you'd like

I would like that trollimage.xrimage.XRImage.crude_stretch optionally clips the data to the indicated range. This can be implemented by an additional boolean keyword argument clip, which would default to False (the current behaviour). This would allow the user to configure their limits only in one place and the satpy writer to focus on actual writing.

Describe any changes to existing user workflow

The status quo would remain the default, so this change should be fully backwards compatible.

Additional context

Perhaps the satpy writer could still take care of the clipping, but look up the clip limits in the enhancement history, which may contain the parameters to crude stretch. This feels wrong.

Perhaps the stretch-that-can-clip would be a different enhancement than the current crude-stretch, rather than the current enhancement with a new keyword argument. I think a keyword argument fits better.

Perhaps clipping should be a separate step from enhancing, and there should be two enhancements applied if users want clipping. I don't know how to apply two enhancements.

Perhaps there are other approaches that I'm not thinking of.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions