Coder Social home page Coder Social logo

sentinel-hub / custom-scripts Goto Github PK

View Code? Open in Web Editor NEW
643.0 56.0 292.0 1.11 GB

A repository of custom scripts to be used with Sentinel Hub

Home Page: https://custom-scripts.sentinel-hub.com/

License: Creative Commons Attribution Share Alike 4.0 International

JavaScript 97.01% HTML 0.53% SCSS 0.33% Ruby 0.02% Jupyter Notebook 2.11%
sentinel-hub remote-sensing earth-observation

custom-scripts's Introduction

Sentinel Hub Custom Script Repository

Examples of visualizations

This repository contains a collection of custom scripts for Sentinel Hub, which can be fed to the services via the URL.

Custom scripts are a piece of Javascript code, used to visualize satellite imagery and to control what values the Sentinel Hub services will return. Any visualization of any constellation (e.g. Sentinel-2 satellite), even a simple true color composite, is dictated by a custom script.

See here for more information on how to write your own evalscript.

Contribute to Custom Scripts

Have a look at the template for an example of how a script page can be structured.

You can also have a look at other scripts to see how they are structured.

For instructions on how custom scripts are structured have a look at this tutorial, or at the official documenation.


How to publish your own product

  • Fork the repository to get your own copy of the custom-scripts
    It is easiest to fork the repository on GitHub, but as some of you might not have GitHub account, or don't want to bother with all this versioning and collaboration tools, you can also just download the whole repository as Zip file and work from there.
  • Create a new directory entry for your custom script
    Copy the example directory to proper directory, based on which datasource (satellite) you are publishing the product for, to something that describes what the product is about, say my_algorithm.
    Preferably use "snake_case" (underscores instead of spaces) if more than one word is used.
  • Fill in the details about the project in the README.md file.
    Obviously, you'll want to remove this chapter, but use the rest of the file as a template.
    Have a look around at other README.md files to see how to include images, format the text and generally use the GitHub markdown (e.g. here for mathematical formulas or here for adding images).
  • Implement the product in the script.js file.
    The most work is of course the JavaScript implementation of the product. The example folder includes an empty custom script with comments that will hopefully help you build your own custom script.
  • Add an entry pointing to your script to the top level markdown file (i.e. if adding a script for Sentinel 2 add the link to sentinel-2.md in the folder sentinel-2).
    A link and a short description will do.
  • And create a pull request :). There is extensive help on creating pull requests on GitHub help, but if you feel overwhelmed by this step and would still like to contribute, send us the folder you've created and we will take care of it for you.

Publishing your product should be easy, nevertheless, any feedback and ideas how to improve or make the process simpler is very appreciated.

Test your changes locally

This is optional but makes Pull Requests quicker to handle since they should have less mistakes.
Before you create the PR you can check if everything looks right on the website. To do this follow these steps which are based on Testing your GitHub Pages site locally with Jekyll page:

Linux
  • In the root directory of your fork open a terminal
  • Install ruby
    • Ubuntu: sudo apt install ruby ruby-dev
  • Install bundler
    • gem install bundler
    • On Ubuntu you might have to add sudo
  • Create a Gemfile
    • In the root folder of the repository (where the _config.yml file is) create a new file Gemfile.
    • i.e touch Gemfile
    • and add the following content:
source 'https://rubygems.org'
gem "github-pages", "~> GH_VERSION", group: :jekyll_plugins
gem "just-the-docs"

Replace GH_VERSION with the version number that is displayed next to github-pages here.

  • Serve the page
    • First install all necessary gems with bundle install
    • then the site can be built with bundle exec jekyll serve
    • The site should then be visible on 127.0.0.1:4000
macOS
  • In the root directory of your fork open a terminal

  • Install ruby

    • brew install chruby ruby-install xz

      • If homebrew hasn't been installed yet, intall homebrew
      /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
      
    • ruby-install ruby 3.1.3

    • After installation run the following codes:

    echo "source $(brew --prefix)/opt/chruby/share/chruby/chruby.sh" >> ~/.zshrc
    echo "source $(brew --prefix)/opt/chruby/share/chruby/auto.sh" >> ~/.zshrc
    echo "chruby ruby-3.1.3" >> ~/.zshrc # run 'chruby' to see actual version
    
    • Quit and relaunch Terminal, then check that everything with ruby -v
    • It should show ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) or a newer version
  • Install Jekyll

    • gem install jekyll
  • Install bundler

    • gem install bundler
  • Following the Create a Gemfile step in the Linux section

  • Serve the page

    • First install all necessary gems with bundle install

    • Add the missing webrick package with bundle add webrick

      • Run this command again when the following error message pops out:
      bundler: failed to load command: jekyll
      
    • then the site can be built with bundle exec jekyll serve

    • The site should then be visible on 127.0.0.1:4000

custom-scripts's People

Contributors

azlinszkysinergise avatar batic avatar blazs avatar chorng avatar domagojkorais avatar dorothyron avatar dorothyrono avatar dthiex avatar esc-qu avatar gmajcen avatar gmilcinski avatar hareldunn avatar horvatdino avatar ignasieb avatar jonasviehweger avatar kampen1988 avatar kcankar avatar lugeo17 avatar markwilliammatthews avatar matthew-ballard avatar maximlamare avatar mkadunc avatar monjasebela avatar mrepse avatar msterk avatar pacongh avatar prashansa avatar s-kganz avatar sabinadolenc avatar willrayeo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

custom-scripts's Issues

Multi-temporal Data isuue

Hi,
I am unable to run the script (sar_multi-temporal_backscatter_coefficient_composite) in EO browser custom scipt.
can please you help me in this?
I think there is issue with temporal data.
Thank you!

NBR formula

According to the reference page reported in the script, the bands that should be used for this index are 9 and 12, not 8 and 12.

Text in geology composite wrong

This composite, often called the Agriculture RGB composite, uses bands SWIR-1 (B11), near-infrared (B08) and blue (B02). It’s mostly used to monitor crop health, as both short-wave and near infrared bands are particularly good at highlighting dense vegetation, which appears dark green in the composite. SWIR measurements can help scientists estimate how much water is present in plants and soil, as water reflects SWIR light. Shortwave-infrared bands are also useful for distinguishing between snow, and ice, all of which appear white in visible light. Newly burned land reflects strongly in SWIR bands, making them valuable for mapping fire damage.

Can anyone help me to isolate any of the indicators one by one? Se2WaQ

Hi, herewith down this post is the complete script for analysing all 6 indicators Se2WaQ (Sentinel-2 Water Quality Script),
Could anybody help me to isolate the script for anyone of them?
Im afraid my knowledge in scripting is still very basic,

I really appreciate it!
Alberto
geovisualization.net

var FLAGparam = 4;
var FLAGbackGround = 2;

var Black = [0]; // FLAGbackGround = 0
//var NDVI = index(B08, B04); // FLAGbackGround = 1
var NDVI = 1;
var NDWI = index(B03, B08);
var TrueColor = [B042.5, B032.5, B022.5]; // FLAGbackGround = 2
var Chl_a = 4.26 * Math.pow(B03/B01, 3.94); // FLAGparam = 0; S2-L2A; [1] Unit: mg/m2;
var Cya = 115530.31 * Math.pow(B03 * B04 / B02, 2.38); // FLAGparam = 1; S2-L2A; [1] Unit: 10^3 cell/ml;
var Turb = 8.93 * (B03/B01) - 6.39; // FLAGparam = 2; S2-L2A; [1] Unit: NTU;
var CDOM = 537 * Math.exp(-2.93
B03/B04); // FLAGparam = 3; S2-L1C; [2] Unit: mg/l;
var DOC = 432 * Math.exp(-2.24B03/B04); // FLAGparam = 4; S2-L1C; [2] Unit: mg/l;
var Color = 25366 * Math.exp(-4.53
B03/B04); // FLAGparam = 5; S2-L1C; [2] Unit: mg.Pt/l;

var scaleChl_a = [0, 6, 12, 20, 30, 50];
var scaleCya = [0, 10, 20, 40, 50, 100];
var scaleTurb = [0, 4, 8, 12, 16, 20];
var scaleCDOM = [0, 1, 2, 3, 4, 5];
var scaleDOC = [0, 5, 10, 20, 30, 40];
var scaleColor = [0, 10, 20, 30, 40, 50];

var s = 255;
var colorScale =
[
[73/s, 111/s, 242/s],
[130/s, 211/s, 95/s],
[254/s, 253/s, 5/s],
[253/s, 0/s, 4/s],
[142/s, 32/s, 38/s],
[217/s, 124/s, 245/s]
];

if (NDWI<0) {
if ( FLAGbackGround == 0 ) {
return Black;
} else if ( FLAGbackGround == 1 ) {
return [0, .5*(NDVI+1), 0];
} else if ( FLAGbackGround == 2 ) {
return TrueColor;
}
} else {
switch ( FLAGparam ) {
case 0:
return colorBlend(Chl_a, scaleChl_a, colorScale);
break;
case 1:
return colorBlend(Cya, scaleCya, colorScale);
break;
case 2:
return colorBlend(Turb, scaleTurb, colorScale);
break;
case 3:
return colorBlend(CDOM, scaleCDOM, colorScale);
break;
case 4:
return colorBlend(DOC, scaleDOC, colorScale);
break;
case 5:
return colorBlend(Color, scaleColor, colorScale);
break;
default:
return TrueColor;
}
}

Question about directly using LAI calculation codes in GEE

Hi there,

It is great to see the shared codes on LAI calculation using Sentinel-2 images. I want to run the script in GEE to calculate the LAI actually, but was wondering about which Sentinel-2 sensor the weights and bias in your codes fit as the algorithm handbook reads different neural networks were deployed for S2A and S2B respectively.

Many thanks,
Alex

Sentinel-2 indices might be invalid

Many indices for Sentinel-2 are based on https://www.indexdatabase.de website.

Consider Sentinel-2A entry from indexdatabase.de.
Notice table Bands/Channels with columns Nr. and Name.

After analysis I've came up with interpretation of this site, which is significantly different from
interpretation postulated in many indices on this repo.

Proposed index formula interpretation

(The interpretation is based on my guess, however the following reasoning supports it.
Please correct me if I am wrong.)

  • band value in violet italic is entry from Nr. column,
  • band value in violet straight is entry from Name column.

For example:

  • 9 in violet italic is Band B8A,
  • 9 in violet straight is Band B09.

Why this interpretation is valid?

Consider sentinel-hub ARVI script.

The general formula has as a first term NIR. Specific formula starts (on indexdatabase.de) with 9 in violet italic.

  • in proposed interpretation, this corresponds to row with Nr. = 9, which is a band with Name = 8a. This gives "Narrow NIR" band.
  • on this repo this is interpreted as band with Name = 9. This gives "Water vapour".

Since general formula mentions "NIR", I believe that proposed interpretation in this issue is valid.

I've attached PR with proposed fix for ARVI, which follows this reasoning.

Which indices are affected?

Many Sentinel-2 indices, including:

  • ARVI
  • EVI, which assigned to 9 in violet italic a band B08 (instead of B09 like in ARVI),
  • many other indices, which refer to bands higher than 8.

Potentially this interpretation problem can be present in indices for other satellites.

How to run the code

Greetings from WA,

Many thanks for the code @sabinadolenc . I am new here and was wondering how to run the code of https://github.com/sentinel-hub/custom-scripts/tree/master/sentinel-1/seldom_and_regular_water_surface_detection . (apologies if this is not the right place to post this).

The way I did was

  1. select Sentinel-1 from the eo-browser from
    https://apps.sentinel-hub.com/eo-browser/?lat=-31.95995&lng=115.83967&zoom=13

  2. search from 2019-01-01 - 2019-10-20, resulting in 32 results (select the most recent one for viewing)

  3. create custom rendering and choose custom script

  4. Use URL and put "https://raw.githubusercontent.com/sentinel-hub/custom-scripts/master/sentinel-1/seldom_and_regular_water_surface_detection/seldom_and_regular_water_surface_detection.js" in

  5. Then I got nothing similar to what has been shown here.

I am sure I missed something very simple, but can you please kindly help?

Thanks.
BT

B12 of Observation outlier detector

Frist, Than you so much for sharing your great script.

I have a question about Observation outlier detector.
Line 22 of script is below

let shadow = predict(sample.B01, sample.B02, sample.B03, sample.B04, sample.B05, sample.B06, sample.B07, sample.B08, sample.B08A, sample.B09, sample.B10, sample.B11, sample.B11, NDVI, NBSI) > 0.5

Why do you use two B11? Should it be B12?

ARVI formula says NIR, so shouldn't use B08?

Hi, nice work, just one question, about ARVI:
The present script for ARVI used at
https://github.com/sentinel-hub/custom-scripts/blob/master/sentinel-2/arvi/script.js
states:
let index = (B09 - B04 - y * (B04 - B02)) / (B09 + B04 - y * (B04 - B02));

But, since:

  1. As said in https://www.indexdatabase.de/db/si-single.php?sensor_id=96&rsindex_id=4 :

General Formula: NIR−RED−y(RED−BLUE) / NIR+RED−y(RED−BLUE)
Specific Formula: 9−5−y(5−1) / 9+5−y(5−1)

  1. true NIR is B08, and true RED is B04 (https://en.wikipedia.org/wiki/Sentinel-2#Instruments);
  2. it was already changed in the script "5" for "B04" (so it could be expected to change "9" for "B08");
    So, isn't a mistake in both the "Specific Formula" and the "arvi/script.js"?
    Shouldn't it be used just B08|B04|B02 , like :
    let index = (B08 - B04 - y * (B04 - B02)) / (B08 + B04 - y * (B04 - B02));

?
Thanks in advance

Contrast and Luminance

Hello,

In my web application, I wanted to include a slider that allows the user to control the contrast and luminosity of the images. While using Sentinel Playground, I noticed the WMS service has parameters "Gain" and "Gamma", I tried using both of them in my application but I had no results. So I searched even more online, and found this 2017 article:
https://www.sentinel-hub.com/faq/what-has-changed-2017-11-release
It says that the parameters Gamma and Gain were deprecated, and should now be defined in a custom Script.
It would be nice if you could explain to me how can I do this.
Ps: I don't want to overwrite the script that is already used for my layer, but just change contrast and luminosity.

Thank you.

custom-scripts/sentinel-1/sar_false_color_visualization

Cannot get the Sentinel-1 false-color script (custom-scripts/sentinel-1/sar_false_color_visualization) to work, using standard S1 GRD products from the Copernicus SciHub (linear amplitude, UINT16) as input.
Apologies for the trivial questions:

  • what is the expected input backscatter type of the "VV" and "VH" variables (logaritmic scale (dB), linear amplitude, linear power) and data type (UINT16, FLOAT32?) for the script?
  • what is the expected data type of the output variables "band1", "band2", "band3?
    Many thanks - AR

Add breadcrumbs to script pages

Accessing the scripts through search (or direct links) presents the user with a page without a clear information on what satellite data the script uses. Sometimes it is written in the description, but that's not so straightforward and the information is sometimes missing altogether. Using a script with the wrong satellite data collection will result in errors.

I'd suggest to add breadcrumbs to the individual script pages right on the top of the page, so a user always knows to which source the script applies.

Log scale

Is there any function that i could use to visualize my values with colours in logarithmic scale?

Issues using EvalScript Parameter

Hello,

I am currently working on a project in which I am using Sentinel Hub 2 WMS URLs. I need to point out that I am very noob in web development.

In my project, I use I have a small interface allowing the user to choose 3 bands to allocate to the RGB Bands (juste like in the Sentinel Hub Playground custom tool). Using HTML and JavaScript, I collect the data from the interface and create a variable for the custom Eval Script according to the basic script style (return [ 2.5*B01...).

I then set this variable as the parameter 'EVALSCRIPT' of the URL:
_source.getParams()['EVALSCRIPT']=_customScript;

This doesn't seem to work.

On the other hand, using the parameter EVALSCRIPTURL seems to work if I give it the URL to a JS file containing the script:
_source.getParams()['EVALSCRIPTURL']='https://geobretagne.fr/apps/sentinel/customcontrols/evalscript.js';

For various reasons, I need to use the EVALSCRIPT parameter and not the EVALSCRIPTURL one. Do you have an idea why isn't it working ? Or is my understanding of the EVALSCRIPT parameter wrong ?

Thank you.

Question about data fusion

Hi all, I would like to use different datasets for doing some partical detection, specifically I want to use data from Sentinel-1 and Sentinel-2.
I am using this script as guidance https://github.com/sentinel-hub/custom-scripts/blob/master/data-fusion/ship_detection_s1_s2/script.js
however I am stuck at its execution because of an incomprensible error for me, that is the following:

Failed to evaluate script!
evalscript.js:20: TypeError: Cannot read property 'B03' of undefined
let ndwi = (S2L1C.B03 - S2L1C.B08) / (S2L1C.B03 + S2L1C.B08)
^
TypeError: Cannot read property 'B03' of undefined
at evaluatePixel (evalscript.js:20:19)
at executeForMultipleSources (:17:17)

I try different broswers but the results is exactly the same. What I am doing wrong ?

Broken datafusion script

The following script has issues and will not display in Eo Browser: https://custom-scripts.sentinel-hub.com/data-fusion/s2l1c_s1grd_cloud_replacement/

  • First error Invalid script! Band 'VV' of collection 'S1GRD' requested in unsupported units 'REFLECTANCE'! Supported units for this band: [LINEAR_POWER]. -> the units need to be replaced by LINEAR_POWER
  • Second error: Invalid script! Band 'CLM' of collection 'S2L1C' requested in unsupported units 'REFLECTANCE'! Supported units for this band: [DN]. -> the easiest fix would be to change the units to DN and adjust the return for the RGB (factor of 10k).

Example query for agricultural growth stage

Hi! I would like to try this @hareldunn script (https://github.com/sentinel-hub/custom-scripts/blob/master/sentinel-2/agriculture_growth_stage/script.js) but I get this error [CDATA[ Failed to evaluate script!\nTypeError: Cannot read property \'getMonth\' of undefined ]].

My query has parameters:

{'TIME': '2016-05-01/2018-04-21', 
'GEOMETRY': <shapely.geometry.polygon.Polygon object at 0x7f90505e0b70>, 
'WIDTH': 1280, 'HEIGHT': 1280, 
'CRS': 'EPSG:4326', 
'ATM_FILTER': 'ATMCOR', 
'EVALSCRIPTURL': 'https://raw.githubusercontent.com/sentinel-hub/custom-scripts/master/sentinel-2/agriculture_growth_stage/script.js', 
'LAYER': 'NDVI'}

querying the FIS service (though I get the same error querying WMS too). I'm sure I'm making a simple mistake, could I get an example of a working query using this script?

Thanks! Let me know if this wasn't clear enough.

Chlorophyll Red-Edge on Sentinel Hub - correct equation

I noticed that on the Sentinel Hub custom scripts page which is used in EO Browser and Sentinel Playground, for Chlorophyll Red-Edge the equation is not the correct one. It states:

General formula: ([760:800]/[690:720])^(-1), and the custom script also uses the equation with mathematical power (if the power was indeed -1, it would be just the inverse equation).

The correct formula should be (B07 / B05) -1, ie like in this paper:
(https://www.mdpi.com/2072-4292/13/14/2732)

How to run these scripts

HI just wondering is there any documentation on how to use/run these scripts?

Thanks in advance for help

Why is the LAI output divided by 3

Hello,

Looking at the code I was wondering what was the rational of divided the LAI output by 3 ?

var lai = denormalize(l2, 0.000319182538301, 14.4675094548151);
return {
default: [lai / 3]
}

Thanks for your input,
Best
HB

V variable ?

Thank you for code
I translat it to GEE
It is not clear for what V wariable , gain?
why always return the same?
Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.