Skip to content

Commit 3af7e1e

Browse files
Merge pull request #347 from azlinszkysinergise/sentinel2_magic_eyes
Agri Growth Stage for Quarterly Mosaics
2 parents 6075859 + 4decb99 commit 3af7e1e

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

sentinel-2/agriculture_growth_stage/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ grand_parent: Sentinel
55
layout: script
66
permalink: /sentinel-2/agriculture_growth_stage/
77
nav_exclude: true
8+
scripts:
9+
- [Copernicus Browser, script.js]
10+
- [Sentinel-2 mosaic, quarterly_mosaics.js]
811
examples:
912
- zoom: '11'
1013
lat: '45.6246'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
//VERSION=3 (auto-converted from 1)
2+
/*
3+
Source: @HarelDan - https://github.com/hareldunn/GIS_Repo/blob/master/Multi-Temporal%20NDVI%20for%20Sentinel%20Hub%20Custom%20Scripts
4+
Visualizing NDVI multi-temporal trends in Sentinel-2 imagery.
5+
will take the current image as baseline and calculate average NDVI for the previous 2 months
6+
Based on:
7+
https://twitter.com/sentinel_hub/status/922813457145221121
8+
https://twitter.com/sentinel_hub/status/1020755996359225344
9+
Script requires multi-temporal processing so parameter TEMPORAL=true should be added to the request.
10+
*/
11+
12+
function setup() {
13+
return {
14+
input: [
15+
{
16+
bands: ["B04", "B08"],
17+
},
18+
],
19+
output: { bands: 3 },
20+
mosaicking: "ORBIT",
21+
};
22+
}
23+
24+
function calcNDVI(sample) {
25+
var denom = sample.B04 + sample.B08;
26+
return denom != 0 ? (sample.B08 - sample.B04) / denom : 0.0;
27+
}
28+
function stretch(val, min, max) {
29+
return (val - min) / (max - min);
30+
}
31+
32+
function evaluatePixel(samples, scenes) {
33+
var avg1 = 0;
34+
var count1 = 0;
35+
var avg2 = 0;
36+
var count2 = 0;
37+
var avg3 = 0;
38+
var count3 = 0;
39+
var endMonth = scenes[0].date.getMonth();
40+
41+
for (var i = 0; i < samples.length; i++) {
42+
var ndvi = calcNDVI(samples[i]);
43+
if (scenes[i].date.getMonth() == endMonth) {
44+
avg3 = avg3 + ndvi;
45+
count3++;
46+
} else if (scenes[i].date.getMonth() == endMonth - 1) {
47+
avg2 = avg2 + ndvi;
48+
count2++;
49+
} else {
50+
avg1 = avg1 + ndvi;
51+
count1++;
52+
}
53+
}
54+
avg1 = avg1 / count1;
55+
avg2 = avg2 / count2;
56+
avg3 = avg3 / count3;
57+
avg1 = stretch(avg1, 0.1, 0.7);
58+
avg2 = stretch(avg2, 0.1, 0.7);
59+
avg3 = stretch(avg3, 0.1, 0.7);
60+
61+
return [avg1, avg2, avg3];
62+
}
63+
64+
function preProcessScenes(collections) {
65+
collections.scenes.orbits = collections.scenes.orbits.filter(function (
66+
orbit
67+
) {
68+
var orbitDateFrom = new Date(orbit.dateFrom);
69+
return (
70+
orbitDateFrom.getTime() >=
71+
collections.to.getTime() - 3 * 31 * 24 * 3600 * 1000
72+
);
73+
});
74+
return collections;
75+
}

sentinel-5p/sentinel-5p.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ Sentinel-5P provides atmospheric measurements, relating to air quality, climate
4141
- [Cloud Optical Thickness](/sentinel-5p/cloud-optical-thickness)
4242
- [Cloud Effective Radiometric Fraction](/sentinel-5p/cloud-radiometric-fraction)
4343

44-
#### Additional Products
44+
#### Additional Products
4545

4646
- [Nitrogen Dioxide monthly mean](/sentinel-5p/no2_monthly_mean)

0 commit comments

Comments
 (0)