Process API (via Python request) get only the one image

Does Process API only return one image per request, regardless of the requested time period?

This is the script I use:

input_arg = {“bounds”: { “geometry”:poly,“properties”: {“crs”: f"http://www.opengis.net/def/crs/EPSG/0/{EPSG_code}"}},
“data”: [{ “type”: “sentinel-2-l2a”,“dataFilter”: {“timeRange”: {“from”: f"{sd}T00:00:00Z",“to”: f"{ed}T00:00:00Z"}}}]}

output_arg = {“resx”: res,“resy”: res,“responses”: [{“identifier”: “default”,“format”: { “type”: “image/tiff”}}]}

evalscript = ‘’’
//VERSION=3
function setup() {
return {
input: [“B04”, “B08”],
output:
{
bands: 1,
sampleType: “FLOAT32”
}
}
}

function evaluatePixel(sample) {

return [(sample.B08-sample.B04)/(sample.B08+sample.B04)];
}
‘’’

json_request = {‘input’:input_arg,‘output’:output_arg,‘evalscript’:evalscript}

url_request = ‘https://services.sentinel-hub.com/api/v1/process
headers_request = {“Authorization” : “Bearer %s” %token[‘access_token’]}

response = oauth.request(“POST”, url_request, headers=headers_request, json=json_request)

print(response.status_code)
print(response.headers[‘x-processingunits-spent’])

When I execute the above script I get the same PU (0.0133333337) whether the requested time period is a week or a year.

When I read the

response.content

I only see one 2D array (I assume it is of the last image in the requested time period.

Hi @org_accounts ,

In the evalscript, mosaicking is an optional property of the setup function. It defines how the source data is mosaicked. Since mosaicking is not specified in your script, it uses the default SIMPLE mosaicking method which flattens the mosaicked image based on the mosaickingOrder of your choice, e.g., there are 3 mosaickingOrder available for Sentinel-2 L2A data collection. Again, mostRecent is the default option so you get an image of the last acquisition within your requested time period in your request.

To get a multi-temporal result, the mosaicking needs to be set to ORBIT or TILE. We have a webinar demonstrating multi-temporal scripts and data fusion and an example evalscript to extract a time series of NDVI values using Sentinel-2 L2A data which may be a good starting point for you.

//VERSION=3
// Script to extract a time series of NDVI values using 
// Sentinel 2 Level 2A data and  metadata file.
function setup() {
  return {
    input: [{
      bands: ["B04", "B08"],
      units: "DN"
    }],
    output: {
      id: "S2_L2A",
      bands: 1,
      sampleType: SampleType.FLOAT32
    },
    mosaicking: Mosaicking.ORBIT
  }
  
}

// The following function is designed to update the number of
// output bands without knowing beforehand how many there are
function updateOutput(outputs, collection) {
    Object.values(outputs).forEach((output) => {
        output.bands = collection.scenes.length;
    });
}
// function to generate a json file with a list of the NDVI 
// dates used in the analysis. 
function updateOutputMetadata(scenes, inputMetadata, outputMetadata) {
    var dds = [];
    for (i=0; i<scenes.length; i++){
      dds.push(scenes[i].date)
    }
    outputMetadata.userData = { "acquisition_dates":  JSON.stringify(dds) }
}

function evaluatePixel(samples) {
  // Precompute an array to contain NDVI observations
  var n_observations = samples.length;
  let ndvi = new Array(n_observations).fill(0);
  
  // Fill the array with NDVI values
  samples.forEach((sample, index) => {
    ndvi[index] = (sample.B08 - sample.B04) / (sample.B08 + sample.B04) ;
  });
                     
  return ndvi;
}

Best Regards

@chung.horng - thanks I’ll go over it. But just to be clear, I am not interested in mosaicking the images in the sense of having one image which is somekind of aggregation, rather I am interested in multiple images for the requested time frame. Is that possible? or should I send a request per date or per image?

Yes it is possible. When using ORBIT or TILE, you’re getting the data of your AOI based on orbits and tiles. The figures below will give you a quick look of how they work: