As you can see there are many images, can we merge them and get just one image ? Maybe we can do it when mergin the patches as well ?
import earthspy.earthspy as es
import cv2
script = """
//VERSION=3 (auto-converted from 1)
//Basic initialization setup function
function setup() {
return {
//List of all bands, that will be used in the script, either for visualization or for choosing best pixel
input: [{
bands: [
"B04",
"B08",
"SCL"
]
}],
//This can always be the same if one is doing RGB images
output: { bands: 1 },
mosaicking: "ORBIT"
}
}
/*
In this function we limit the scenes, which are used for processing.
These are based also on input variables, coming from Playground.
E.g. if one sets date "2017-03-01" ("TO date") and cloud coverage filter 30%,
all scenes older than 2017-03-01 with cloud coverage 30% will be checked against
further conditions in this function.
The more scenes there are, longer it will take to process the data.
After 60 seconds of processing, there will be a timeout.
*/
function filterScenes (scenes, inputMetadata) {
return scenes.filter(function (scene) {
//Here we limit data between "(TO date - 1 month) to (TO date)
return scene.date.getTime()>=(inputMetadata.to.getTime()-1*31*24*3600*1000) ;
});
}
function calcNDVI(sample) {
var denom = sample.B04+sample.B08;
switch(sample.SCL){
// Unclassified (dark grey)
case 7: return [0];
// Cloud medium probability (grey)
case 8: return [0];
// Cloud high probability (white)
case 9: return [0];
}
return ((denom!=0) ? (sample.B08-sample.B04) / denom : 0.0);
}
function evaluatePixel(samples) {
var max = 0;
for (var i=0;i<samples.length;i++) {
var ndvi = calcNDVI(samples[i]);
max = ndvi > max ? ndvi:max;
}
if (max>0.53) return [1];
else return [0]
}
"""
job = es.EarthSpy("auth.txt")
job.set_query_parameters(
bounding_box=[
37.836908,
36.527295,
43.626709,
38.718198
],
time_interval=["2022-04-01", "2022-04-15"],
evaluation_script=script,
data_collection="SENTINEL2_L2A",
download_mode = 'SM',
store_folder = 'images',
save_name = 'test'
)
image = job.send_sentinelhub_requests()