1

I have created a script in R using the RSToolbox and raster packages in R to process multiband images from Landsat 7 and 8. The code works fine and it is giving me the outputs I need; however, due to the amount of data contained in these images, it takes a long time to run (~30-40 minutes per image and I have nearly 200 images to analyse).

To reduce the analysis time, I tried cropping the image to just the area I am interested in, which worked really well, but after a couple of calculations, the image becomes over 1GB in size and an error comes up saying that R is unable to process an image that size. I then noticed that when using the crop function, the image becomes about 10 times larger than the original one, even though it is cropped to about half its original spatial extent. I am not really sure why this is the case.

The image was cropped using the following code:

library(raster)  
cropMB = crop(MB,RioDoce) 

where MB is the stacked layer of a Landsat 7 or 8 image, and RioDoce is a point vector representing the path of a river (uploaded to R as a shapefile).

Landsat images were stacked using the following code:

library(RSToolbox)  
meta = readMeta("filepath to Landsat image metadata")  
MB = stackMeta(meta)  

Would anyone here be able to suggest a way to decrease the time of the analysis by decreasing the size of the original image? For reference, I am doing the following with each set of images:
- Create a raster stack containing all bands
- Transform green and NIR bands from DN to TOA
- Calculate NDWI using the previously mentioned bands
- Apply two masks to original raster stack so only areas with water bodies and no clouds remain
- Transformation of DN values to at-surface-reflectance of the masked raster stack
- Extract spectral band values to a point layer representing the path of a river

How can I reduce the analysis time?

closed as off-topic by Vince, nmtoken, xunilk, Spacedman, JGH Jan 20 '18 at 22:16

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – Vince, nmtoken, xunilk
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Welcome to GIS SE. As a new user, please take the Tour. Please Edit your question to focus on the procedure you utilize to crop your image, and explain how it both "worked really well" and increased the image size by two orders of magnitude. You will need to include your actual clipping code. – Vince Jan 20 '18 at 12:54
  • Take a look into raster::removeTmpFiles() function. This can be used to reduce time into loops (works great in my scripts) – aldo_tapia Jan 22 '18 at 11:54
  • Thanks @aldo_tapia, I will try this out once the code finishes running. – lidefi87 Jan 27 '18 at 6:48

Browse other questions tagged or ask your own question.