Why it’s time to stop processing satellite imagery on your laptop
Haven’t moved to the cloud yet? Here is a good reason you should!
If you’re anything like me, and first encountered Earth Observation data 5–10 years ago, in order to analyse satellite data you almost certainly had to download the whole scene, and maybe you’d have to atmospherically correct the imagery before you performed your analysis too. It is pretty likely you did this all on your laptop or desktop PC, downloading the imagery directly from the provider, then processing it on a desktop application like ENVI. If you were really smart, you might have automated the process using Python.
With the glut of data in recent years, the increases in revisit times and more cloud free data, multi-temporal applications have blossomed. For example, back in 2013, you would likely use Landsat 8 which has a 16 day revisit time at 30m resolution. In 2021 though, we now have access to Sentinel-2 with a revisit time of 5 days at 10m resolution. This is without mentioning the numerous commercial constellations now available. While before, it was feasible to process and analyse individual acquisitions, this approach is not so effective today and it makes more sense to process data in the cloud. This is where a service like Sentinel Hub comes in. Our approach contrasts to the traditional methods, with our motto being:
Stop treating satellite data as a set of files to be processed.
Satellite data are a set of pixels with value to be accessed.
Anyway, with all this buzz around how we should be processing our data in the cloud, I wanted to put this to the test. For much of my career I have been a traditionalist; downloading and processing my data in my own local environment. I expect I’m not the only one who has tried to cling on to their traditional methods of preprocessing and analysing satellite imagery! So how to persuade fellow traditional users like me? Let’s dismiss all the marketing noise and quantitatively prove once and for all that using Sentinel Hub will save you time and money! To do this we are going to run a comparison exercise generating a multi-temporal satellite imagery derived product.
We will detail both workflows in this Jupyter Notebook.
The Test Example
So we’re going to conduct a simple test, to compare the effectiveness of both approaches. Firstly, we will download and process Sentinel-2 imagery using the traditional method using open source Python libaries. Secondly, we will use Sentinel Hub services to perform the same analysis in the cloud, before only downloading the final results. In this test, we will produce a simple harvest detection map using the Normalized Difference Vegetation Index (NDVI) and the Bare Soil Index (BSI). Using the difference in NDVI between the most recent and least recent timestamp, the BSI in the most recent timestamp, and thresholding these values, we classify pixels as either harvested or not harvested.
We will download a before and after Sentinel-2 L2A image (already corrected for atmospheric effects), calculating NDVI for both timestamps and BSI (used to filter out false positives, such a vegetation browning) for the after image. This method certainly isn’t the cutting edge, but is useful for demonstration purposes.
Before we start the workflows, for those who are interested, let’s have a look at the computer specs we used for the processing. The workflow was run on a workstation with the following configuration:
- CPU: Intel Core i7–8650U (4 core, 8 threads)
- RAM: 16GB
- Graphics: UHD Graphics 620
- Operating system: Ubuntu 20.04.2 LTS
- Internet Speed: 250MB/s
Area of Interest
For the purpose of this comparison exercise, we will be extracting and analysing satellite data over three small municipalities located in the Charente-Maritime department in the Nouvelle-Aquitaine region of south-western France: Aulnay, Nuaillé-sur-Boutonne and Villemorin.
The municipalities we are interested in are located in the North East of the department. This area is dominated by arable land used to grow Wheat, Corn and Sunflowers with some prairies too. The department is part of the wider region of Nouvelle-Aquitaine and experiences warm summers, cool winters with rainfall evenly distributed over the year.
To find out more about the different crop types in the department you can use the http://agri.nimbo.earth/ geoportal developed by Kermap, enabling you to view the different agricultural land uses across several European countries. We used this geoportal to find a suitable AOI with summer cereal crops that are harvested in late July/early August.
Traditional Workflow
To start, we will show how to run a traditional workflow. We will go through data discovery, download, then the processing and visualisation of the imagery. We’ll be using Sentinel-2 Level 2A (L2A) data, one of the most widely used optical sensors currently.
Discovery & Download
Firstly, before you can even begin processing the images, you need to discover and then download them. In this example we already know what dates we want for the area, but you can use Sentinel Hub’s EO Browser or Copernicus SciHub to browse images in your own AOI. However, the problem with using the Copernicus API as your download source is that it is hard to get to the Long Term Archive (LTA) images. While previously, L2A data was stored for 12 months, this is now only 30 days, making this workflow a cumbersome option.
One option is to order the LTA image from Copernicus SciHub and trigger an order, then request it again later to download it, but this is very inefficient. In this example we accessed the data through CreoDIAS, although there are other options such as Mundi, ONDA, PEPS, or sobloo to name a few. To query the data directly in our Python workflow, we used EODAG, which allows you to easily access the data in within a unified API.
Preprocessing
As can be seen above, the AOI we have picked is in an awkward geographical location, overlapping with several Sentinel-2 tiles. We could have picked an AOI overlapping with a single acquisition but wanted a typical example as it is very rare in real world applications and projects that it is as easy as that! This adds a couple of extra steps, like filtering the acquisitions.
After downloading, the bands required for the analysis can be extracted and the rest of the bands can be discarded (quite a wasteful process). The bands are then cropped to the area of interest and mosaicked into one raster for each band. To do this, several Python functions need to be written specifically for the notebook. This took quite a few hours to work out how to do efficiently.
NDVI and BSI can then be calculated and inserted in the formula explained earlier to generate the “Harvested” product. Below you can see the three products we generated. There is a notable difference between the two NDVI maps and harvested fields can already be identified by eye.
Sentinel Hub Workflow
In contrast to the traditional methods, there are only two steps that need to be made using the Sentinel Hub APIs. This is because Sentinel Hub automatically deals with the data processing steps like tiling and mosaicking, so you can have more time to perform your analysis. Therefore, rather than download 4 separate scenes (Gigabytes of data we you don’t need!) like previously, we only access the pixels that we actually require.
Data Request
First, you need to generate a Sentinel Hub request. Here you specify our evalscript (where the pixel analysis takes place) which we will talk about in a bit. You then need to specify the data collection and time range of interest. Additionally we specify the area of interest, the different responses we are defining in the evalscript, and the output resolution for the raster data.
The Evalscript
This is where we perform the same analysis as above in the traditional workflow. Evalscripts are a piece of Javascript code, used to visualise satellite imagery and to control what values the Sentinel Hub services will return.
In this evalscript, we have three functions:
In function setup()
we specify the required (Sentinel-2) bands as inputs and also specify the output responses with individually assigned ids. We can further customise the number of bands and the raster sampleType
of each output response to your requirements. We also specify the mosaicking method Orbit
. This means you are requesting the flattened mosaicked image for each orbit so that there is only one sample per pixel per orbit.
With the help of preProcessScenes
, we allow only data from the two defined dates to be used, and the Orbit mosaicking method is used to mosaic the two scenes that cover the AOI into a single pixel array.
The third function is where pixel analysis takes place; computing NDVI for both scenes and BSI for the second scene. Lastly, the harvested formula is applied to the two indices you generated.
Advanced evalscripts can be complicated, and what we explain above with all the functions, may not make sense if you are not familiar with them. We invite you to learn all about scripting with Sentinel Hub, starting with tutorials for anyone, including those not familiar with coding or remote sensing
Now that the request and evalscript have been defined, you can call the request using the request.get_data()
function and SentinelHub will process all the data, automatically downloading it once the processing is complete. For this request, the time taken was only 5 seconds. Much faster than the traditional method, and no need to worry about data download, clipping and mosaicking as this is all handled by Sentinel Hub in the background.
Lastly, using scipy, some morphological functions were applied to filter out pixels to generate a clean product. One of the limitations of Sentinel Hub services is that it functions on a per-pixel basis. Therefore to perform a morphological operation on the results we need to open the Harvested product and apply the last step either using a Jupyter Lab locally or in a Euro Data Cube environment. Below is the final result; as you can see it’s not perfect, but, as we said before, there are more advanced methods you can use to get much better results.
Method Comparison
Overall, the Sentinel Hub method was quicker to implement, faster to run and more efficient. The largest difference between the two methods is the amount of data you need to download. The traditional method required 4.7GB of data which on a fast internet connection still took over 10 minutes to download and process. In comparison, all the Sentinel Hub processing occurs on the cloud and only 5.7MB was downloaded taking only 5 seconds. This difference is especially advantageous for users with slower internet connections and others who may have storage issues and don’t want to have to clean up the intermediary data created during processing.
Secondly, we feel it is important to mention that we spent many hours trying to make this work in an efficient way. While we have measured how long the processing takes, the number of man hours required to learn and utilise the tools is certainly not an insignificant outlay. Yes, there is a learning curve with Sentinel Hub but it is far easier and quicker to pick up with extensive documentation and support if needed.
In conclusion, creating this simple analysis is far more efficient using Sentinel Hub whether you measure by processing time and efficiency or time needed to develop and implement. Using Sentinel Hub requests means less time downloading and manipulating your satellite data, meaning more time to actually analyse and visualise your results!
What if I want to process larger areas?
Of course, once you have developed a workflow you will want to scale it up from smaller AOIs into regional, national or even global analyses. Normally, this would add extra complexities to your workflow; e.g. downloading Sentinel-2 scenes for the whole of France would take up a huge amount of internet and storage resources. Using Sentinel Hub APIs you no longer have to worry about building and maintaining the infrastructure and creating an efficient workflow. In fact, you don’t have to make any changes to the evalscript you were using; it’s already ready to use at scale. Developing using Sentinel Hub makes it really easy to scale up, as your code will be fully compatible with our Batch Processing API which you can read much more about in the introductory blog post & our post about the creation of cloudless mosaics.
After reading this I’m pretty sure you should be convinced that cloud processing is the best way to processing your data today! I would now argue that downloading satellite data and processing it locally on the machine is no longer necessary. This doesn’t make your laptop useless, in fact, the possibilities of what you can now do on laptop have grown hugely thanks to cloud computing!
However, if you’re still not convinced why not get in contact and have a chat with us to see how we can solve your problems together!
- Follow our Twitter and LinkedIn for news, so you don’t miss the latest developments and features!
- Feel free to share how Sentinel Hub services have optimised your workflows with us and the Sentinel Hub community via our social media channels!
- If you have questions or encounter any problems, please engage with us and other users from the community in our Sentinel Hub Forum.
If you want to learn more about Sentinel Hub, make sure to listen the MapScaping Podcast: