Set up a time interval in mosaic script

Hello everyone,

I’m very new to using custom SentinelHub scripts so I apologize in advance if my question is obvious.

I am a Python programmer and I don’t have a lot of javascript experience, so I’m accessing Sentinel hub with the python API but I still have to use JS for custom evalscripts.

I’m trying to retrieve a mosaic of a very small area (1km x 1 km) without clouds, by aggregating imagery over a month. I have seen the cloudless mosaic script :

But it gathers all imagery within the last year, while I’m only interested in images within a specified time interval, let’s say from 2022-02-01 to 2022-02-28.

The script presented in answer to this post seems to contain such a function :

I have no idea in this case where the time_interval (s1,s2) is defined, does it take input from the time_interval argument of the SentinelHubRequest?

I would like to merge these 2 scripts to create a mosaic of a time window I am able to define. I would also love if you could explain me where to define this time window or interval when using the sentinelhub-py api!

Thanks a lot in advance

Hi @octave.antoni,

The time interval can be defined within the preProcessScenes() in the script. In the linked custom script, the time interval considered is 3 months before the date set in the request.

function preProcessScenes(collections) {
  collections.scenes.orbits = collections.scenes.orbits.filter(function (orbit) {
    var orbitDateFrom = new Date(orbit.dateFrom)
    return orbitDateFrom.getTime() >= ( - 3 * 31 * 24 * 3600 * 1000);
  return collections

You can find more about this function and how to customize the script in the documentation. Hope this helps. Feel free to get back to me if you have further questions.

Hello @megha.devaraju and thank you for your answer,

So basically I can replace the preProcessScenes function with this :

function preProcessScenes (collections) {
    collections.scenes.orbits = collections.scenes.orbits.filter(function (orbit) {
        return (new Date(orbit.dateFrom) < new Date("2022-02-01T00:00:00Z")) ||
               (new Date(orbit.dateFrom) >= new Date("2022-02-28T00:00:00Z"))
    return collections

to get the right time interval?

Is there any way to edit the time interval outside of javascript, perhaps by interacting with the time_interval that can be defined within the SentinelHubRequest ?

Yes. You can define the dates within the SentinelHubRequest instead. The preProcessScenes() is an optional function that acts as an additional filter for the scenes selected for processing. You can find plenty of examples in our documentation here.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.