Skip to content

Instantly share code, notes, and snippets.

request = SentinelHubRequest(evalscript=evalscript,
input_data = [SentinelHubRequest.input_data(
data_collection=DataCollection.SENTINEL2_L2A,
time_interval=('2020-07-12', '2020-08-06'),)],
responses=[SentinelHubRequest.output_response('ndvi_t1', MimeType.TIFF),
SentinelHubRequest.output_response('ndvi_t2', MimeType.TIFF),
SentinelHubRequest.output_response('bsi_t2', MimeType.TIFF),
SentinelHubRequest.output_response('harvested', MimeType.TIFF),],
geometry=full_geometry,
data_folder=results_dir,
//VERSION=3
function setup() {
return {
input: [{
bands: ["B01", "B02", "B03", "B04", "B05", "B06", "B07", "B08", "B8A", "B09", "B11", "B12"],
units: "DN"
}],
output: {
id: "default",
bands: 12,
//VERSION=3
function setup() {
return{
input: [{
bands: ["B04", "B08"],
units: "DN"
}],
output: {
id: "default",
bands: 1,
//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: {
# here you can place default parameters which will be overwritten by the
# actual parameters in a new cell below
spatial_res = 0.00018
aoi = "POLYGON ((11.519165 41.786673, 11.519165 42.259016, 12.420044 42.259016, 12.420044 41.786673, 11.519165 41.786673))"
# here you can place default parameters which will be overwritten by the
# actual parameters in a new cell below
spatial_res = 0.00072
aoi = "POLYGON ((11.519165 41.786673, 11.519165 42.259016, 12.420044 42.259016, 12.420044 41.786673, 11.519165 41.786673))"
time_range= "2022-02-15/2022-03-14"
output_dir = Path("/home/jovyan/BYOA_example/byoa-sample-algorithm/output")
from datetime import date, timedelta
from xcube_sh.config import CubeConfig
from xcube_sh.cube import open_cube
import xcube.core.maskset as maskset
import xarray as xr
# time range conversion
x = time_range.split("/")
# Define NDVI in visualisation
ndvi = ((ndvi_cube.B08-ndvi_cube.B04)/(ndvi_cube.B08+ndvi_cube.B04))
ndvi.attrs['long_name']='NDVI'
ndvi.attrs['units']='unitless'
ndvi_cube['NDVI']= ndvi
ndvi_sum = ndvi_cube.NDVI.sum(dim="time")
ndvi_count = ndvi_cube.NDVI.count(dim="time")
# here you can place default parameters which will be overwritten by the
# actual parameters in a new cell below
spatial_res = 0.00001
aoi = "POLYGON((11.580840855935284 42.450395132068884,13.009063512185284 42.450395132068884,13.009063512185284 41.65093511375355,11.580840855935284 41.65093511375355,11.580840855935284 42.450395132068884))"
time_range= "2022-02-15/2022-03-14"
x = time_range.split("/")
# calculate the area based on input parameters
import shapely.wkt