Package: landsatxplore
DescriptionThelandsatxplorePython package provides an interface to theEarthExplorerportal to search and downloadLandsat Collectionsscenes through a command-line interface or a Python API.The following datasets are supported:Dataset NameDataset IDLandsat 5 TM Collection 2 Level 1landsat_tm_c2_l1Landsat 5 TM Collection 2 Level 2landsat_tm_c2_l2Landsat 7 ETM+ Collection 2 Level 1landsat_etm_c2_l1Landsat 7 ETM+ Collection 2 Level 2landsat_etm_c2_l2Landsat 8 Collection 2 Level 1landsat_ot_c2_l1Landsat 8 Collection 2 Level 2landsat_ot_c2_l2Landsat 9 Collection 2 Level 1landsat_ot_c2_l1Landsat 9 Collection 2 Level 2landsat_ot_c2_l2Quick startSearching for Landsat 5 TM scenes that contains the location (12.53, -1.53) acquired during the year 1995.landsatxplore search --dataset landsat_tm_c2_l1 --location 12.53 -1.53 \
    --start 1995-01-01 --end 1995-12-31Search for Landsat 7 ETM scenes in Brussels with less than 5% of clouds. Save the returned results in a.csvfile.landsatxplore search --dataset landsat_tm_c2_l2 \
    --location 50.83 4.38 --clouds 5 > results.csvDownloading three Landsat scenes from different datasets in the current directory.landsatxplore download LT51960471995178MPS00 LC80390222013076EDC00 LC82150682015350LGN01To use the package, Earth Explorer credentials are required (registration).InstallationThe package can be installed using pip.pip install landsatxploreUsagelandsatxplorecan be used both through its command-line interface and as a Python module.Command-line interfacelandsatxplore --helpUsage: landsatxplore [OPTIONS] COMMAND [ARGS]...

Options:
  --help  Show this message and exit.

Commands:
  download  Download one or several Landsat scenes.
  search    Search for Landsat scenes.CredentialsCredentials for the Earth Explorer portal can be obtainedhere.--usernameand--passwordcan be provided as command-line options or as environment variables:exportLANDSATXPLORE_USERNAME=<your_username>exportLANDSATXPLORE_PASSWORD=<your_password>Searchinglandsatxplore search --helpUsage: landsatxplore search [OPTIONS]

  Search for Landsat scenes.

Options:
  -u, --username TEXT             EarthExplorer username.
  -p, --password TEXT             EarthExplorer password.
  -d, --dataset [landsat_tm_c1|landsat_etm_c1|landsat_8_c1|landsat_tm_c2_l1|landsat_tm_c2_l2|landsat_etm_c2_l1|landsat_etm_c2_l2|landsat_ot_c2_l1|landsat_ot_c2_l2|sentinel_2a]
                                  Landsat data set.
  -l, --location FLOAT...         Point of interest (latitude, longitude).
  -b, --bbox FLOAT...             Bounding box (xmin, ymin, xmax, ymax).
  -c, --clouds INTEGER            Max. cloud cover (1-100).
  -s, --start TEXT                Start date (YYYY-MM-DD).
  -e, --end TEXT                  End date (YYYY-MM-DD).
  -o, --output [entity_id|display_id|json|csv]
                                  Output format.
  -m, --limit INTEGER             Max. results returned.
  --help                          Show this message and exit.Downloadinglandsatxplore download --helpUsage: landsatxplore download [OPTIONS] [SCENES]...

  Download one or several Landsat scenes.

Options:
  -u, --username TEXT    EarthExplorer username.
  -p, --password TEXT    EarthExplorer password.
  -d, --dataset TEXT     Dataset.
  -o, --output PATH      Output directory.
  -t, --timeout INTEGER  Download timeout in seconds.
  --skip
  --help                 Show this message and exit.If the--datasetis not provided, the dataset is automatically guessed from the scene identifier. Note that only the newer Landsat Product Identifiers contain information related to collection number and processing level. To download Landsat Collection 2 products, use Product IDs or set the--datasetoption correctly.APIEarthExplorer APIlandsatxploreprovides an interface to the Earth Explorer JSON API. Please refer to the official (documentation) for possible request codes and parameters.Basic usagefromlandsatxplore.apiimportAPI# Initialize a new API instance and get an access keyapi=API(username,password)# Perform a request. Results are returned in a dictionnaryresponse=api.request('<request_endpoint>',params={"param_1":value_1,"param_2":value_2})# Log outapi.logout()Please refer to the officialJSON API Referencefor a list of all available requests.Searching for scenesimportjsonfromlandsatxplore.apiimportAPI# Initialize a new API instance and get an access keyapi=API(username,password)# Search for Landsat TM scenesscenes=api.search(dataset='landsat_tm_c2_l1',latitude=50.85,longitude=-4.35,start_date='1995-01-01',end_date='1995-10-01',max_cloud_cover=10)print(f"{len(scenes)}scenes found.")# Process the resultforsceneinscenes:print(scene['acquisition_date'].strftime('%Y-%m-%d'))# Write scene footprints to diskfname=f"{scene['landsat_product_id']}.geojson"withopen(fname,"w")asf:json.dump(scene['spatial_coverage'].__geo_interface__,f)api.logout()Output:4 scenes found.
1995-09-23
1995-08-22
1995-08-15
1995-06-28Downloading scenesfromlandsatxplore.earthexplorerimportEarthExploreree=EarthExplorer(username,password)ee.download('LT51960471995178MPS00',output_dir='./data')ee.logout()