Skip to content

Instantly share code, notes, and snippets.

@maximlamare
maximlamare / fetchQL.py
Created December 16, 2022 09:50
Example code to fetch a Quicklook of a Pleiades images using SH services
# Requests
from oauthlib.oauth2 import BackendApplicationClient
from requests_oauthlib import OAuth2Session
import requests
# Plotting
from PIL import Image
from io import BytesIO
import matplotlib.pyplot as plt
# Fetch Oauth token
@maximlamare
maximlamare / ndvi_unit16.js
Created January 26, 2022 15:08
How to return NDVI as UINT 16 in an Evalscript
//VERSION=3
function setup() {
return {
input: ["B04", "B08"],
output: { bands: 1, sampleType: "UINT16" }
};
}
function evaluatePixel(sample) {
let ndvi = index(sample.B08, sample.B04);
@maximlamare
maximlamare / s2_DN.js
Last active January 26, 2022 11:11
Example Evalscript with DN
//VERSION=3
function setup() {
return {
input: [
{
bands: ["B02"],
units: "DN",
}
],
@maximlamare
maximlamare / eval_multi.js
Created January 25, 2022 10:04
Example evalscript where the output is multiplied by 1000.
//VERSION=3
function setup() {
return {
input: ["B02"],
output: { bands: 1, sampleType: "UINT16" }
};
}
const f = 10000;
@maximlamare
maximlamare / s2_eval_b2_auto.js
Last active January 3, 2022 13:14
Example of an Evalscript returning B02
//VERSION=3
function setup() {
return {
input: ["B02"],
output: { bands: 1, sampleType: "AUTO" }
};
}
function evaluatePixel(sample) {
return [sample.B02];
@maximlamare
maximlamare / s2_eval.js
Created November 15, 2021 17:51
Example evalscript for a single Sentinel-2 band query
//VERSION=3
function setup() {
return {
input: ["B02"],
output: { bands: 1, sampleType: "INSERT-HERE" }
};
}
function evaluatePixel(sample) {
return [sample.B02];
Name Description Range
UINT8 unsigned 8-bit integer 0-255
@maximlamare
maximlamare / batch_us_west.py
Created August 24, 2021 16:19
Batch API request without sh-py on US-WEST endpoint
# For requests
import requests
from oauthlib.oauth2 import BackendApplicationClient
from requests_oauthlib import OAuth2Session
from sentinelhub import SHConfig
config = SHConfig()
# Set up credentials for use with batch
client = BackendApplicationClient(client_id=config.sh_client_id)
@maximlamare
maximlamare / evalscript.js
Created September 16, 2020 13:33
Evalscript for the eo-learn process
//VERSION=3
// Calculate number of bands needed for all intervals
// Initialise dates and interval
// Beware: in JS months are 0 indexed
var start_date = new Date(2019, 3, 1, 0, 0, 0);
var end_date = new Date(2019, 9, 31, 0, 0, 0);
var sampled_dates = sample_timestamps(start_date, end_date, 15, 'day').map(d => withoutTime(d));
var nb_bands = sampled_dates.length;
var n_valid = 0;
@maximlamare
maximlamare / payload.js
Created September 14, 2020 14:24
The Batch Processing payload for eo-learn
order = {
"processRequest": {
"input": {
"bounds": {
"geometry": {
"type": "Polygon",
"coordinates": AOI_bounds
},
"properties": {
"crs": "http://www.opengis.net/def/crs/EPSG/0/32632"