satpy icon indicating copy to clipboard operation
satpy copied to clipboard

Proposal: New enhancement interface

Open djhoese opened this issue 7 years ago • 3 comments

Problem description

The current method for converting data from a data array to an image is limited to a single Scene.save_datasets call. While this is useful for the user since they only have to run one function, it is limiting for anyone who wants to customize things (a major problem in satpy). This caused to_enhanced_image to be created which returns an XRImage that can be used for further customization. This made a lot more sense when we used the masked array based Image class, but now XRImage is just a wrapper around an xarray DataArray.

I propose we add an enhance method to the Scene that returns a new scene with enhanced image arrays. It could do this inplace too, but I'm not sure I like that as the default. The resulting call sequence might look like:

scn = Scene(...)
scn.load([...])
rs_scn = scn.resample(...)
enh_scn = rs_scn.enhance()
enh_scn.save_datasets()

This allows more freedom to customize the enhanced datasets or to not enhance them at all (don't call enhance). It also declutters the save_datasets available keyword arguments.

Admittedly I was the one who originally wanted enhancements to be something the writer had control over, but I'm starting to change my mind the more I use satpy. The original idea was that different writers might want different enhancements. I think for those cases it is up to the user to change what enhancements are used or for the writer to do the enhancements itself when it makes sense (ex. scale factor and offset for NetCDF writing).

Additionally this would make it easier to have different enhancements for the same datasets and save them to the same file format; something I believe @pnuu needed.

djhoese avatar Apr 20 '18 14:04 djhoese

Another feature to add on to this would be the ability to specify an enhancement by name:

new_scn = scn.enhance(enhancements={'I04': 'white_clouds'})

So instead of whatever the default would be, we could force a certain enhancement. It doesn't even have to have a matching set of metadata.

djhoese avatar Jun 29 '18 14:06 djhoese

I'm realizing a major complication of this functionality (now that I want to implement it). Right now writers can be a subclass of Writer or a subclass of Writer called ImageWriter. The ImageWriter automatically does the enhancement for the writer. If I moved enhancing to a separate method of the Scene then there is no way to easily tell (on the user side) when enhancing should or should not be done. I mean logically it should be something the user should think about but it makes it harder to do things easily.

For example, in Geo2Grid if I currently have something like the following:

scn = Scene(...)
scn.load([...])
new_scn = scn.resample(...)
new_scn.save_datasets(...)

I now would have something like:

scn = Scene(...)
scn.load([...])
new_scn = scn.resample(...)
if write_i_want in ['geotiff', 'simple_image', ...]:
    enh_scn = new_scn.enhance(...)
else:
    enh_scn = new_scn
enh_scn.save_datasets(...)

This gets even more complicated since geotiff could save to float or 8-bit and may need to enhance depending on the dtype and the users wishes. I'm not sure how to simplify this. Meaning, how do you make enhancing a separate step without having to know what the writer needs. Maybe this is just a complication in Polar2Grid/Geo2Grid and isn't something Satpy needs to worry about.

djhoese avatar Jun 03 '19 14:06 djhoese

It is relevant to satpy users too I think

mraspaud avatar Jun 03 '19 15:06 mraspaud