Multitemporal visualization of the 3-month NDWI averages (June — August) of 2019, Italy. Processed by Sentinel Hub. 🌐

Custom scripts: faster, cheaper, better!

15 tips for better scripts and more responsive requests

Monja Šebela
Nov 18 · 7 min read

Authors: Monja Šebela and Marko Repše

Do you use the Sentinel Hub API? Do you want to improve your evalscripts while saving processing time and cost?

With advanced custom scripts, it’s important to write clear and efficient code. When every second of processing counts, every line of code matters. This blog post will give you some tips on how to write efficient evalscripts (custom scripts). It will also provide insights into possible uses of evalscripts which are not necessarily obvious at first glance.

When it comes to optimization, while making a single OGC/API request, the performance differences are often negligible. In some cases, however, they are not, and with even a single request the difference in responsiveness can be easily visible. Of course, when making thousands of requests and/or very large requests, even small differences add up.

At Sentinel Hub, we are constantly striving to shorten processing time while increasing flexibility. We want to share the best tips from our expert team with you, which will hopefully help you write faster scripts.

Enhanced false color visualization of different cloud types above the Indian ocean. Acquired on 18.6.2019, processed by Sentinel Hub.🌐

Tip 1: Avoid map! Use FOR loops

Use for loops instead of the javascript functions .map, .reduce, .filter, .find in evaluatePixel. Your app may be noticeably slower if using these functions. While they may be convenient, they are not fast. And for very simple map functions even a for loop may be redundant, as it may be possible to compute the values explicitly for each component.

Additionally, avoid foreach, as for loops are still faster.

The performance hit can be significant!



Or in this most simple case even:

Tip 2: Request what you need

Enhanced false color visualization of salt aggregations (blue) of the Aral sea. Acquired on 21. 7. 2019, processed by Sentinel Hub. 🌐

Tip 3: Delete code that isn’t used

Tip 4: Calculate as needed



Enhanced true color visualization of the Rakaia river outflow in New Zealand. Acquired on 28.2.2019, processed by Sentinel Hub. 🌐

Tip 5: Avoid excess input bands

Tip 6: Avoid unnecessary output formats

False color visualization of the landscape east of the Khatanga Gulf, Russia. Acquired on 13.6.2018, processed by Sentinel Hub. 🌐

Tip 7: Output smaller formats

Tip 8: Use digital numbers if possible

Additionally, requesting UINT16 data of Sentinel-2 digital numbers carries the same information as FLOAT32 data, while costing fewer processing units and requiring less bandwidth (thus faster).

Enhanced false color visualization of the Kilauea volcano, Hawaii. Custom script by Pierre Markuse. Processed by Sentinel Hub.

Tip 9: Use global variables

Tip 10: Use visualizers

You can use visualizers with two different functions:

  • viz.process(value) is used when only working with one value/band
  • viz.processList(valueArray) is used when working with multiple values/bands. (The availability of this depends on the visualizer)

For example:

NDVI visualization of Gunbower and Torrumbary, Australia. Acquired on 10.7.2019, processed by Sentinel Hub. 🌐

Tip 11: Use predefined products

Note, that you should select the “set product” option instead of “copy to script editor”, to get all the latest updates.

Tip 12: Use a single request for multiple visualizations

To do so, first, in the output object in setup, specify both outputs by giving them IDs, the number of output bands and a sample type. Next, under evaluatePixel, return both outputs pointing to their corresponding IDs set above. A full request for the NDVI can be found here.

False color visualization of the northern Canada coast. Acquired on 25.6.2016, processed by Sentinel Hub. 🌐

Tip 13: Use data masks

Tip 14: Filter your scenes

Enhanced false color visualization of the landscape south-east of Brasilia, Brazil. Acquired on 23.7.2019, processed by Sentinel Hub.🌐

Tip 15: Read the docs, see the examples

We, therefore, invite you to visit our ever-improving evalscript documentation and the examples pages. These are written by us and represent various best-practices approaches to evalscripts. They should hopefully get you up to speed without causing overload and provide a starting point for scripts and requests, which can be modified to your specific needs.

Finally, if you haven’t yet seen, the second Sentinel Hub Custom Script Contest is currently ongoing! We hope you find these tips useful and don’t forget to send in your best scripts for a chance to win attractive prizes!

Happy scripting!

Sentinel Hub Blog

Stories from the next generation satellite imagery platform

Thanks to Marko Repse, Sabina Dolenc, Marjan Šterk, and Anja Vrecko

Monja Šebela

Written by

Sentinel Hub Blog

Stories from the next generation satellite imagery platform

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade