Landsat Collection 2: Stacking and subsetting 

Steps:

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

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

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]


for i in */*_e; do gdal_translate -of ENVI -projwin 210000 3970000 350000 3880000 ${i} ${i}_sub; done

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

for i in */*Scale.hdr; do echo 'wavelength = {0.48, 0.56, 0.665, 0.83, 1.6, 2.2}' >> ${i}; done

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!):


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.