Skip to content

[BUG] Keep python-API stable between 1 and >1 results #556

@SlowMo24

Description

@SlowMo24

Describe the bug

SentinelHubRequest.get_data function return value differs in shape depending on the length of the responses input array.

It is a list of arrays, if one response is specified but a list of dicts, if two or more responses are specified. This change in API mimics the return value of the online-API (a response.tiff for one result and a response.tar containting tiffs for more than one) but is confusing on the python-end.

To Reproduce

Steps to reproduce the behavior:

Assume the following setup:

Details

from sentinelhub import SentinelHubRequest, DataCollection, MimeType, SHConfig, BBox, CRS

evalscript_true_color = """
    //VERSION=3

    function setup() {
        return {
            input: [{
                bands: ["B02", "B03", "B04"]
            }],
            output: [{
                id: "default",
                bands: 3
            },{
                id: "other",
                bands: 3
            }]
        };
    }

    function evaluatePixel(sample) {
        return {"default":[sample.B04, sample.B03, sample.B02],
        "other":[sample.B04, sample.B03, sample.B02]};
    }
"""
input_data = [
    SentinelHubRequest.input_data(
        data_collection=DataCollection.SENTINEL2_L1C,
        time_interval=("2020-06-12", "2020-06-13"),
    ),
]
bbox = BBox((
    13.82,
    45.85,
    13.83,
    45.86
), crs=CRS("4326"))
config=SHConfig(your-credentials)

  1. request data with one output
responses = [SentinelHubRequest.output_response("default", MimeType.PNG)]

request = SentinelHubRequest(
    evalscript=evalscript_true_color,
    input_data=input_data,
    responses=responses,
    bbox=bbox,
    config=config,
)

data_one_response = request.get_data()[0]
  1. request data with two outputs
responses = [SentinelHubRequest.output_response("default", MimeType.PNG),
             SentinelHubRequest.output_response("other", MimeType.PNG)]

request = SentinelHubRequest(
    evalscript=evalscript_true_color,
    input_data=input_data,
    responses=responses,
    bbox=bbox,
    config=config,
)

data_two_responses = request.get_data()[0]
  1. see that the API to access the data has changed
type(data_one_response) #ndarray
type(data_two_responses) #dict

actual_data = data_two_responses["original.tif"]

Expected behavior

The API should not change between the two examples. I.e. I suggest the retrieval from the first example would happen via

actual_data = data_one_response["original.tif"]

Environment

  • Python 3.11.11
  • sentinelhub 3.11.1

Desktop (please complete the following information):

  • OS: Ubuntu 22.04
  • Browser: Firefox
  • Version 134.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions