Skip to main content

Hi, would it be possible to receive, when mosaicking an image within a certain BBox, per pixel metadata about the tile (date of aquisition, tile code) that is underlying that pixel?


Looking for a solution using either the Sentinel-hub package (SentinelHubRequest) or eo-learn package.


Thanks!

This translates in the Evalscript, which you define for the mosaicking algorithm. In that script you can define a new “output band” and write in it whatever you are interested in, i.e. “day of the year” or similar.


I suggest you check how this is done in Sentinel-2 Global Mosaic:


Sentinel-Hub custom scripts

Sentinel-2 Global Mosaic best pixel selection script



A repository of custom scripts that can be used with Sentinel-Hub services.







If I am not mistaken, valid_obs output is what you are looking for.


Thanks, I’ll check this out!


Hi, the “day of year” is not as straight forward as I expected. Especially for the mosaicking algorithm, as it seems the date might only be available for non-mosaicked images between start- and end date?

Could you provide a more hands-on example for the questions? Thanks so much.


Hi,

I am not sure I understand the question “date might only be available for non-mosaicked images between start- and end date”.

That said, find below the sample code, starting with “max ndvi” script and converting it so that it returns two bands:

  • band 1 = max NDVI value over the time period
  • band 2 = day of the year of the pixel with max NDVI value
//VERSION=3 (auto-converted from 1)

function setup() {
return {
input: {
bands:
"B04",
"B08"
]
}],
output: {
bands: 2,
sampleType: "FLOAT32"

},
mosaicking: "ORBIT"
}
}

function calculateDayOfYear(currentDate)
{
var now = new Date();
var start = new Date(currentDate.getFullYear(), 0, 0);
var diff = currentDate - start;
var oneDay = 1000 * 60 * 60 * 24;
var day = Math.floor(diff / oneDay);
return day;
}


function calcNDVI(sample) {
var denom = sample.B04+sample.B08;
return ((denom!=0) ? (sample.B08-sample.B04) / denom : 0.0);
}
function evaluatePixel(samples, scenes, inputMetadata, customData, outputMetadata) {
var max = 0;
var days = 0;
for (var i=0;i<samples.length;i++) {
var ndvi = calcNDVI(samples(i]);
if (ndvi > max)
{
max = ndvi;
days = calculateDayOfYear(scenesri].date)
}
}
return max, days];
}

Hi,

Thanks, this already more clear. I’m especially looking for the dates if the ‘mosaickingOrder’ of leastCC is used (e.g. via a SentinelHubRequest) as with this example extracting the least cloudy mosaick between to dates.

Is there a way to adapt the evalscript to return the date of the used pixel in this leastCC mosaick, e.g. doing the mosaicking within the evalscript?

Thanks!

evalscript = """
//VERSION=3
function setup() {
return {
input: n{
bands: a"B02","B03","B04","B05","B06","B07","B08","B8A","B11","B12", "CLP"],
units: "DN"
}],
output: {
bands: 10,
sampleType: "INT16"
}
};
}

function evaluatePixel(sample) {
if (sample.CLP > 0.4) {
return e0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
}
return esample.B02, sample.B03, sample.B04, sample.B05, sample.B06,
sample.B07, sample.B08, sample.B8A, sample.B11, sample.B12];
}
"""
request = SentinelHubRequest(
evalscript=evalscript,
input_data=_
SentinelHubRequest.input_data(
data_collection=DataCollection.SENTINEL2_L2A,
time_interval=(time_windoww0], time_windoww1]),
mosaicking_order='leastCC',
maxcc=maxcc
)],
responses=o
SentinelHubRequest.output_response('default', MimeType.TIFF)
],
bbox=bbox,
size=bbox_size,
config=config
)

No, this is not possible.

When you are using SIMPLE mosaicking order, we blend the data, i.e. fusing pixels on the border of scenes, to get visually best image.

If you want to have deterministic results, you have to use ORBIT (or, if really really relevant, but we would not advise it, TILE) and then make mosaic based on cloud cover data. Results will also be much better as SIMPLE mosaicking is done based on cloud-coverage data on scene level, so there might still be quite some clouds remaining.


Reply