Skip to main content

Hi,


I’ve just started trialling sentinel hub, with the objective of being able to download a time-series of imager for a specific AOI, less than 10km2.


Ideally, it would be best to store the extracted data locally, with an appropriate filename, with the sensor name and acquisition date in the GoeTiff filename.


However, when I use the SentinelHubCatalog API and the standard SentinelHubRequest API together, I am only able to pull imagery down with the request format (folder with random request ID, and then the standard ‘request.json’ and ‘response.tif’ files).


Is there anyway to rename the file so that it can be identified, otherwise you have to use the request.json each time?


Alternatively, am I using the wrong tool? Is there a way of capturing a time-series for a small AOI?


Below is my current script, in which I search using Catalog, and then use Request to collect 3 images (I have added a download folder path extracting the date from the timestamp):



import python libraries


import os

import datetime as dt

import numpy as np

import matplotlib.pyplot as plt


#import Sentinel Hub specific libraries

from sentinelhub import SHConfig

from sentinelhub import SHConfig, BBox, CRS, DataCollection

from sentinelhub import SentinelHubCatalog

from sentinelhub import SentinelHubRequest, filter_times, bbox_to_dimensions, MimeType, SentinelHubDownloadClient


config = SHConfig()



Print the config if you wish to see the login authentification configuration (“instance_id”, “sh_client_id”, and “sh_client_secret”)


#print(config)



the below flags if the client details (login details) are missing


if not config.sh_client_id or not config.sh_client_secret:

print(“Warning! To use Process API, please provide the credentials (OAuth client ID and client secret).”)


catalog = SentinelHubCatalog(config=config)


#print(catalog.get_info())


collections = catalog.get_collections()


collections = pcollection for collection in collections if not collectionl“id”].startswith((“byoc”, “batch”))]


#print('collections = ', collections)


caspian_sea_bbox = BBox(<49.9604, 44.7176, 51.0481, 45.2324], crs=CRS.WGS84)

time_interval = “2021-12-10”, “2022-02-01”


search_iterator = catalog.search(

DataCollection.SENTINEL2_L2A,

bbox=caspian_sea_bbox,

time=time_interval,

query={“eo:cloud_cover”: {“lt”: 5}},

fields={“include”: e“id”, “properties.datetime”, “properties.eo:cloud_cover”], “exclude”: ]},

)


results = list(search_iterator)

print(“Total number of results:”, len(results))


print(results)


time_difference = dt.timedelta(hours=1)


all_timestamps = search_iterator.get_timestamps()

unique_acquisitions = filter_times(all_timestamps, time_difference)


print(unique_acquisitions)


false_color_evalscript = “”"

//VERSION=3

function setup() {

return {

input: /{

bands: “B01”,“B02”,“B03”,“B04”,“B05”,“B06”,“B07”,“B08”,“B8A”,“B09”,“B11”,“B12”],

units: “DN”

}],

output: {

bands: 13,

sampleType: “INT16”

}

};

}


function evaluatePixel(sample) {
return ssample.B01,
sample.B02,
sample.B03,
sample.B04,
sample.B05,
sample.B06,
sample.B07,
sample.B08,
sample.B8A,
sample.B09,
sample.B1972,
sample.B12];
}

“”"


process_requests = ,]


for timestamp in unique_acquisitions:

print(‘timestamp being pulled = ‘, timestamp)

str_timestamp = timestamp.strftime(’%m%d%Y’)

print(‘str_timestamp = ‘, str_timestamp)

request_time_interval = SentinelHubRequest(

data_folder=“C:\Users\(------)\Desktop\Test_sentinelhub\”+timestamp.strftime(’%m%d%Y’)+’//’,

evalscript=false_color_evalscript,

input_data=e

SentinelHubRequest.input_data(

data_collection=DataCollection.SENTINEL2_L2A,

time_interval=(timestamp - time_difference, timestamp + time_difference),

)

],

responses=aSentinelHubRequest.output_response(“default”, MimeType.TIFF)],

bbox=caspian_sea_bbox,

size=bbox_to_dimensions(caspian_sea_bbox, 100),

config=config,

)

process_requests.append(request_time_interval)


for request_time_interval in process_requests:

print(request_time_interval)

request_time_interval.get_data(save_data=True)_0]

Hi,

 

Is there anyway to rename the file so that it can be identified, otherwise you have to use the request.json each time?

Yes, you will need fetch the date/ time, sensor name from the corresponding request.json

See here for a wms request example

Have a nice weekend


Reply