Package: pylandsat
Descriptionpylandsatis a Python package that allows you to search and download
Landsat scenes from the public dataset hosted onGoogle Cloud.
Additionally, it includes a set of classes and methods to access and
preprocess the downloaded scenes.Only LandsatCollection 1is supported, i.e. level-1 data products from the following sensors and satellite missions:Landsat 8 OLI/TIRSLandsat 7 ETM+Landsat 4-5 TMLandsat 1-5 MSSInstallationpip install pylandsatCommand-line interfaceDownload one or multiple scenesUsageUsage:pylandsatdownload[OPTIONS][PRODUCTS]...DownloadaLandsatproductaccordingtoitsidentifier.

Options:-d,--output-dirPATHOutputdirectory.-f,--filesTEXTComma-separatedlistoffilestodownload.--helpShowthismessageandexit.Examples# Download an entire product in the current directorypylandsatdownloadLE07_L1TP_205050_19991104_20170216_01_T1# Download multiple productspylandsatdownload\LE07_L1TP_205050_19991104_20170216_01_T1\LE07_L1TP_206050_19991111_20170216_01_T1# Download only the blue, green and red bandspylandsatdownload--filesB1.TIF,B2.TIF,B3.TIF\LE07_L1TP_205050_19991104_20170216_01_T1# Download only quality bandpylandsatdownload--filesBQA.TIF\LE07_L1TP_205050_19991104_20170216_01_T1Search for scenesTo allow large and fast queries,pylandsatworks with a local dump of the Landsat catalog hosted on Google Cloud. As such, an initial sync is required :# Sync local Landsat catalogpylandsatsync-database# Force updatepylandsatsync-database-fThe database is stored in a local directory that can be displayed using the following command :pylandsatprint-datadirOnce the database has been created, the local catalog can be queried.UsageUsage:pylandsatsearch[OPTIONS]SearchforscenesintheGoogleLandsatPublicDatasetcatalog.

Options:-b,--beginTEXTBeginsearchdate(YYYY-MM-DD).-e,--endTEXTEndsearchdate(YYYY-MM-DD).-g,--geojsonPATHAreaofinterest(GeoJSONfile).-l,--latlonFLOAT...Pointofinterest(decimallat/lon).-p,--pathINTEGERWRS2path.-r,--rowINTEGERWRS2row.-c,--cloudsFLOATMax.cloudcoverpercentage.-s,--sensorsTEXTComma-separatedlistofpossiblesensors.-t,--tiersTEXTComma-separatedlistofpossiblecollectiontiers.--slcoffIncludeSLC-offLE7scenes.-o,--outputPATHOutputCSVfile.--helpShowthismessageandexit.At least three options must be provided:--beginand--end(i.e. the period of interest), and a geographic extent (--pathand--row,--latlon,--addressor--geojson). By default,pylandsatlists all the product IDs matching the query. The full response can be exported to a CSV file using the--outputoption. Note that is the spatial extent is provided as a GeoJSON file, only the first feature will be considered.Examples# If only the year is provided, date is set to January 1stpylandsatsearch\--begin1999--end2000\--path206--row50\--clouds0# Using latitude and longitudepylandsatsearch\--begin2000--end2010\--latlon50.854.34# Using a polygon in a GeoJSON filepylandsatsearch\--begin2000--end2010\--geojsonbrussels.geojson# Using an address that will be geocodedpylandsatsearch\--begin2000--end2010\--address'Brussels, Belgium'# Limit to TM and ETM sensorspylandsatsearch\--begin1990--end2010\--address'Brussels, Belgium'\--sensorsLT04,LT05,LE07# Export results into a CSV filepylandsatsearch\--begin1990--end2010\--address'Brussels, Belgium'\--sensorsLT04,LT05,LE07\--outputscenes.csv# List available sensors, i.e. possible values# for the `--sensors` optionpylandsatlist-sensors# List available files for a given sensorpylandsatlist-available-filesLT05Python APISearch the catalogfromdatetimeimportdatetimefromshapely.geometryimportPointfrompylandsatimportCatalog,Productcatalog=Catalog()begin=datetime(2010,1,1)end=datetime(2020,1,1)geom=Point(4.34,50.85)# Results are returned as a listscenes=catalog.search(begin=begin,end=end,geom=geom,sensors=['LE07','LC08'])# Get the product ID of the first sceneproduct_id=scenes[0].get("product_id")# Download the sceneproduct=Product(product_id)product.download(out_dir='data')# The output of catalog.search() can be converted to a DataFrame# for further processing. For instance:# Get the product ID of the scene with the lowest cloud coverimportpandasaspddf=pd.DataFrame.from_dict(scenes)df.set_index(["product_id"],inplace=True)df=df.sort_values(by='cloud_cover',ascending=True)product_id=df.index[0]Load and preprocess dataimportnumpyasnpimportrasterioimportmatplotlib.pyplotaspltfrompylandsatimportScene# Access datascene=Scene('data/LE07_L1TP_205050_19991104_20170216_01_T1')print(scene.available_bands())print(scene.product_id)print(scene.sensor)print(scene.date)# Access MTL metadataprint(scene.mtl['IMAGE_ATTRIBUTES']['CLOUD_COVER_LAND'])# Quality bandplt.imshow(scene.quality.read())# Access band datanir=scene.nir.read(1)red=scene.red.read(1)ndvi=(nir+red)/(nir-red)# Access band metadataprint(scene.nir.bname)print(scene.nir.fname)print(scene.nir.profile)print(scene.nir.width,scene.nir.height)print(scene.nir.crs)# Use reflectance values instead of DNnir=scene.nir.to_reflectance()# ..or brightness temperaturetirs=scene.tirs.to_brightness_temperature()# Save file to diskwithrasterio.open('temperature.tif','w',**scene.tirs.profile)asdst:dst.write(tirs,1)