Saturday, March 9, 2024

Cropping Landsat Scenes from their Bounding Field utilizing Python | by Conor O’Sullivan | Feb, 2024

Must read


Eradicating the outer border of Landsat satellite tv for pc pictures utilizing the stac file

Towards Data Science
(supply: creator)

Telling tales with satellite tv for pc pictures is simple. The mesmerising landscapes do a lot of the work. But, visualising them takes some work reminiscent of deciding on and scaling the RGB channels. On this article, we’ll go additional. We’ll see how we are able to eliminate that ugly bounding field. Particularly, we’ll:

  • Crop and rotate Landsat scenes utilizing the stac file
  • Focus on how we are able to do that but in addition maintain the geolocation of pixels

We’ll talk about key items of Python code and yow will discover the total venture on GitHub.

We begin by downloading a Landsat scene. You are able to do this utilizing the EarthExplorer portal. Alternatively, if you wish to use Python, the article beneath takes you thru the method:

In the long run, it is best to have a folder like Determine 1. These are all of the recordsdata out there for a Landsat stage 2 science product. We’ll be working with the highlighted recordsdata. These are the three seen gentle bands and the SR_stac file.

Determine 1: Landsat level-2 science product recordsdata (supply: creator)

This explicit scene was taken above Cape City, South Africa. To see this we visualise the seen gentle bands utilizing the get_rgb operate. This takes the file title/ ID as a parameter. It can then load the bands (traces 8–10), stack them (line 13), scale them (line 14) and clip them (line 17).

import tifffile as tiff
import numpy as np
data_file = "./information/"

def get_rgb(ID):

# Load Blue (B2), Inexperienced (B3) and Pink (B4) bands
R = tiff.imread(data_file +'{}/{}_SR_B4.TIF'.format(ID, ID))
G = tiff.imread(data_file +'{}/{}_SR_B3.TIF'.format(ID…



Supply hyperlink

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article