Upsampling via python's SentinelHubRequest

Hi everyone,

I’m trying to generate a request using SentinelHubRequest from the python package using the ‘upsampling’ option. However, I’m having trouble in finding documentation on how to do it.

If my request looks like that:

request = SentinelHubRequest(
        evalscript=evalscript,
        input_data=[
            SentinelHubRequest.input_data(
                data_source=DataSource.SENTINEL2_L2A,
                time_interval=('2020-04-01', '2020-04-30'),
                mosaicking_order='leastCC'
            )
        ],
        responses=[
            SentinelHubRequest.output_response('default', MimeType.PNG)
        ],
        bbox=bbox,
        size=bbox_size,
        config=config
    )

how should I include the upsampling information? I would expect something like adding an option upsampling='bilinear', or something similar.

Thanks!

Hi @ademiquel,

As per API reference it is possible. The way to achieve it with SentinelHubRequest is to pass other_args to SentinelHubRequest.input_data, like so:

request = SentinelHubRequest(
        evalscript=evalscript,
        input_data=[
            SentinelHubRequest.input_data(
                data_source=DataSource.SENTINEL2_L2A,
                time_interval=('2020-04-01', '2020-04-30'),
                mosaicking_order='leastCC',
                other_args={'processing': {'upsampling': 'BICUBIC', 'downsampling':'BILINEAR'}} 
            )
        ],
        responses=[
            SentinelHubRequest.output_response('default', MimeType.PNG)
        ],
        bbox=bbox,
        size=bbox_size,
        config=config
    )

Officially available methods are: “BILINEAR”, “BICUBIC”, and “NEAREST”.

1 Like

Ah perfect, that worked. I had tried the other_args option before, but without the processing key.

Thanks a lot @batic !!

1 Like

@batic, just a follow up question. Is there a support for the MODE resampling to select the value which appears most often of all the sampled pixels? If not, how is categorical data (e.g. land cover) resampled by default?

Thanks,
Yuri

TL;DR:

No, “MODE” resampling is not available and “NEAREST” is the default interpolation unless you specify otherwise.

The rest of the answer is going to be rather technical, but I’ll try to give you some ideas what to do…

When you request an image from SH service, for your AOI and time interval, you request it at some resolution. SH then finds the most appropriate overview/zoom level from jp2 (e.g. in case of Sentinels) or cog (e.g. in case of BYOC dataset, or LandSat collection, …) for your request, and fetches it. To get to your requested resolution, SH interpolates (either up or down-scales) the data.

With the processing parameters for upsampling and downsampling you are controlling what kind of algorithm will be used in this last step of SH interpolation.

That being said, there are a few more things to be aware of:

  • the type of data (you mention yourself categorical data, where proper interpolation is very important)
  • the interpolation algorithm that was used to create overview (e.g. in cogs - e.g. when preparing your COGs, you can already create overviews with “MODE” resampling)
  • the resolution being requested

So in principle, if you

  • prepare your cog overviews with MODE resampling
  • request your data at appropriate resolutions (that equal to original/overview resolutions) and in the same coordinate reference system (i.e. remove the need to do spatial interpolation)
    you will be ok.

The default interpolation is always “NEAREST”. That being said, with categorical data (like Scene classification layers (SCL) for Sentinel2-L2A), the SH requests data from the highest resolution much more (also when it could already be requesting lower resolution data from jp2), just so that the data is as close to original as possible. I’ll argue that since SCL is created at 10m resolution, resampling it to lower resolution is generally “wrong”, and only makes sense in particular use cases.

1 Like

Thank you for the detailed answer, @batic. It makes a lot of sense. So, if I’m working with the DataCollection.WorldCover how do I find out the interpolation algorithm that was used to create overviews for this data collection and its available zoom levels?