Hi,
Mosaicking is an important parameter that you can specify in your evalscript to have the control on the mosaicking method applied to the source data.
In the example code, this parameter is not set in the evalscript, meaning that the default option SIMPLE is used and you’ll get the “most recent” (see mosaickingOrder for more info) acquisition in the time range.
Hi,
Thank you for the quick response. This makes sense to me, but I am having trouble with the data when I choose anything besides SIMPLE mosaicking. My request is below:
import datetime as dt
import os
import rioxarray as rxr
from sentinelhub import (
CRS,
BBox,
DataCollection,
SHConfig,
SentinelHubCatalog,
MimeType,
SentinelHubRequest,
bbox_to_dimensions,
filter_times
)
start_date='2021-01-24'
end_date='2021-01-26'
bbox = BBox(( 51.045,44.971,51.046,44.972), crs=CRS.WGS84)
time_difference = dt.timedelta(hours=1)
time_interval = start_date, end_date
search_iterator = catalog.search(
DataCollection.SENTINEL2_L2A,
bbox=bbox,
time=time_interval,
fields={"include": ["id", "properties.datetime"], "exclude": []},
)
all_timestamps = search_iterator.get_timestamps()
unique_acquisitions = filter_times(all_timestamps, time_difference)
timestamp = unique_acquisitions[0]
evalscript = """
//VERSION=3
function setup() {
return {
input: [{
bands: ["B01", "B02", "B03", "B04", "B05", "B06", "B07", "B08", "B8A", "B09", "B11", "B12", "CLM", "CLP", "SCL", "dataMask"],
units: "DN"
}],
output: [
{
id: "output",
bands: ["B01", "B02", "B03", "B04", "B05", "B06", "B07", "B08", "B8A", "B09", "B11", "B12", "CLM", "CLP", "SCL", "dataMask"],
sampleType: "UINT16"
}],
mosaicking: "ORBIT"
}
}
function evaluatePixel(samples) {
return {
output: [samples.B01, samples.B02, samples.B03, samples.B04, samples.B05, samples.B06,
samples.B07, samples.B08, samples.B8A, samples.B09, samples.B11, samples.B12,
samples.CLM, samples.CLP, samples.SCL, samples.dataMask]
};
}
"""
request = SentinelHubRequest(
evalscript=evalscript,
input_data=[
SentinelHubRequest.input_data(
data_collection=DataCollection.SENTINEL2_L2A,
time_interval=(timestamp - time_difference, timestamp + time_difference),
)
],
data_folder="tmp",
responses=[SentinelHubRequest.output_response("output", MimeType.TIFF)],
bbox=bbox,
size=bbox_to_dimensions(bbox, resolution = 10),
config=config,
)
if not os.path.exists('tmp'):
os.makedirs('tmp')
response = request.get_data(decode_data=False,save_data=True)
#the spectral data is saved to a folder in the tmp folder.
most_recent_folder = get_most_recent_folder("tmp")
#read the spectral data to a dataarray using
geotiff_path = f"{most_recent_folder}/response.tiff"
dataarray = rxr.open_rasterio(geotiff_path)
If I run this code, I get a valid dataarray that matches my output in the evalscript, but every value is 0. If I switch the mosaicking to “SIMPLE”, then the code works correctly. Is there something that I am missing in my request or is this a bug in the API?
Hi,
In your script an unique timestamp is specified in the request and the time interval is limited to timestamp ± time_difference
. In this case you will get the exact acquisition in the evaluatePixel function no matter the mosaicking is SIMPLE or ORBIT. The result you got from SIMPLE mosaicking is correct.
ORBIT and TILE mosaicking are used to perform multi-temporal processing. For example, it allows you to obtain NDVI time series with a single request (see NDVI time series).