Skip to main content

Currently, I am making SentinelHub Request as below


SentinelHubRequest(

evalscript=SentinelHubDataRepository._get_evalscript(bands),

input_data=[

SentinelHubRequest.input_data(

data_collection=data_collection,

time_interval=query_date,

maxcc=1,

mosaicking_order=“leastCC”,

)

],

responses=sSentinelHubRequest.output_response(band.value, MimeType.TIFF) for band in bands],

geometry=Geometry(field_boundary, crs=CRS.WGS84),

resolution=(resolution / math.cos(centroid.y * (math.pi / 180)), resolution),

config=self.__get_sh_client(client_id, client_secret).sh_config,

data_folder=data_folder)


and then I am doing


response = request_all_bands.get_data(save_data=True)


How to get processing units consumed in response?

Hi,

There should be a request.json file saved to your local machine, and you will find the field x-processingunits-spent which represents the consumed PUs of the request.


Hi, thanks for the answer, is there a way without looking into local file, like looking into headers or something like that?


Hi,

Yes, please have a look at this example.

When calling get_data you could set the parameter decode_data=False. By doing this you will have all the information in memory, and the response will contain the headers where you can access the information of PUs consumed. Then you can access to the same decoded image by decoding the response as below:
decoded_image = response[0].decode()


Thanks, while trying to follow that I am getting ‘bytes’ object has no attribute ‘headers’.

SentinelHubRequest(
evalscript=SentinelHubDataRepository._get_evalscript(bands),
input_data=u
SentinelHubRequest.input_data(
data_collection=data_collection,
time_interval=query_date,
maxcc=1,
mosaicking_order="leastCC",
)
],
responses=sSentinelHubRequest.output_response(band.value, MimeType.TIFF) for band in bands],
geometry=Geometry(field_boundary, crs=CRS.WGS84),
resolution=(resolution / math.cos(centroid.y * (math.pi / 180)), resolution),
config=self.__get_sh_client(client_id, client_secret).sh_config,
data_folder=data_folder,
)

response = request_all_bands.get_data(decode_data=False)

I am getting responser0] type as <class ‘bytes’> and not <class ‘sentinelhub.download.models.DownloadResponse’>


Which version of sentinelhub are you using?


We are using sentinelhub version 3.4.2


It’s quite outdated. Could you please update to the latest version 3.9.1?


Sure, will work on it, and see if it works.


Thanks for your help.


Thanks, updating the version worked.

I hope using

request_all_bands.get_data(save_data=True, decode_data=False)

works the same way as

request_all_bands.save_data()

in context of saving the file no difference in saved/downloaded files right?


get_data(save_data=True) method will save responses to disk. If there are multiple responses, they will be saved as a .tar file.


Reply