Landsat Collection 2: Stacking and subsetting
Steps:
Download data as .tar.gz files
Extract so each data is a folder
In a UNIX shell with gdal installed, navigate to the folder containing all the data folder and execute the following command:
Landsat 4-7
for i in */*LT0[4-5]*B1.TIF; do gdal_merge.py -of ENVI -o ${i%???????}_e ${i} ${i%?????}2.TIF ${i%?????}3.TIF ${i%?????}4.TIF ${i%?????}5.TIF ${i%?????}7.TIF -separate; done
Landsat 8-9
for i in */*LC0[8-9]*B1.TIF; do gdal_merge.py -of ENVI -o ${i%???????}_e ${i} ${i%?????}2.TIF ${i%?????}3.TIF ${i%?????}4.TIF ${i%?????}5.TIF ${i%?????}6.TIF ${i%?????}7.TIF -separate; done
Landsat 8-9 C2L2 Bulk Download
VSWIR - [for i in *LC0[8-9]*B2.TIF; do gdal_merge.py -of ENVI -o ${i%???????}_e ${i} ${i%?????}3.TIF ${i%?????}4.TIF ${i%?????}5.TIF ${i%?????}6.TIF ${i%?????}7.TIF -separate; done]
Thermal - [for i in *LC0[8-9]*B10.TIF; do gdal_merge.py -of ENVI -o ${i%???????}e_T ${i} -separate; done]
(Optional) At the same location execute the following command, replacing the numbers with bounding X and Y coordinates of your spatial subset:
for i in */*_e; do gdal_translate -of ENVI -projwin 210000 3970000 350000 3880000 ${i} ${i}_sub; done
In Python, run the following script to convert to [0,1] reflectance values: ds_scaleC2L2.py
for i in */*_e.hdr; do sed 's/data type = 12/data type = 4/' ${i} > ${i%????}Scale.hdr; done
for i in */*Scale.hdr; do echo 'wavelength units = Micrometers' >> ${i}; done
Landsat 4-7
for i in */*Scale.hdr; do echo 'wavelength = {0.48, 0.56, 0.665, 0.83, 1.6, 2.2}' >> ${i}; done
Landsat 8-9
for i in */*Scale.hdr; do echo 'wavelength = {0.44, 0.48, 0.56, 0.665, 0.83, 1.6, 2.2}' >> ${i}; done
Band centers from: https://www.usgs.gov/faqs/what-are-band-designations-landsat-satellites
New instructions for Windows machines in Storm Hall (Mar 10 2025 - Thanks to Sam Madonia!):
Download images from ESA's Copernicus DataSpace (https://dataspace.copernicus.eu/)
Unzip each .zip file
Set up WSL:
In Powershell, run wsl --install and restart your computer.
If WSL fails to install, run ipconfig /flushdns and then try installing again.
Open WSL terminal (I used Ubuntu). You may need to enter a username and password. Run the following commands:
sudo apt update
sudo apt install gdal-bin
Run the code as directed in either L1C or L2A instructions
Note:
In WSL, the directory is set differently than in Powershell. If the file path to your directory is C:\Directory, then use the command cd /mnt/c/Directory
If setting your directory to a location on an external drive fails, check the mounted drives by running ls /mnt/. If the external drive isn’t accessible, run wsl --shutdown and restart your computer with the drive still plugged in. Then, try setting the directory again.