Skip to content

Instantly share code, notes, and snippets.

@maximlamare
maximlamare / ndvi.js
Last active November 10, 2020 20:44
Calculate NDVI with Sentinel Hub based on Sentinel-1 and 2 Data Fusion
//VERSION=3
function setup (){
return {
input: [
{datasource: "s1grd", bands:["VV", "VH"]},
{datasource: "s2l2a", bands:["B04", "B08", "CLM"], units:"REFLECTANCE"}],
output: [
{id: "default", bands: 3, sampleType: SampleType.AUTO}
]
}
curl --location --request POST 'https://services.sentinel-hub.com/api/v1/process' \
--header 'Authorization: Bearer <your-token-here>' \
--form 'request={
"input": {
"bounds": {
"bbox": [
2.1421623229980464,
41.37796785471600,
2.2084236145019527,
41.40784461738553
@maximlamare
maximlamare / sky_view.py
Last active August 21, 2020 09:16
Sky view factor calculation from Sirguey et al. 2009
def skyview(horz_data, slp, asp):
""" Compute the sky view factor.
Compute the sky view factor for every pixel, i.e. the ratio between diffuse
irradiance received to that on unobstructed surface according to its slope,
aspect and horizon. Algorithm by Dozier et al. 1981, 1990.
Args:
horz_data (ndarray): horizon elevation data computed from the DEM
slp (ndarray): slope calculated from the DEM
asp (ndarray): aspect calculated from the DEM
Returns:
@maximlamare
maximlamare / EOLearn_batch_evalscript.js
Created September 2, 2020 13:26
Evalscript replacing EOLearn import tasks with Batch
//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 / evalscript_batch_eolearn.js
Created September 14, 2020 13:15
Fetch and resample bands for eo-learn
// Evaluate pixels in the bands
function evaluatePixel(samples, scenes) {
// Initialise arrays
var valid_samples = {'B02':[], 'B03':[], 'B04':[], 'B08':[], 'B11':[], 'B12':[]};
var valid_dates = []
// Loop over samples.
for (var i = samples.length-1; i >= 0; i--){
if (is_valid(samples[i])) {
@maximlamare
maximlamare / Batch_to_EoPatches.py
Last active September 17, 2020 09:19
Function to convert Batch Processing API results to EoPatches
# Make class to convert Batch to EOPatches
batch2eolearn = ImportFromAWS(aws_access_key_id, aws_secret_access_key, aws_bucket_name,
batch_request_id, band_names, timestamps, is_data=is_data_band,
out_path=save_folder)
# Convert Batch results in the Amazon Bucket to EOPatches
batch2eolearn.convert_to_EOPatches()
@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"
@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 / 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)
Name Description Range
UINT8 unsigned 8-bit integer 0-255