How to download Actual Evapotranspiration ET raster data (MYD16A2) with Python and Earthaccess - Tutorial
/Evaluation of environmental processes requires a spatial temporal approach with the right tools to represent, process and analyze raster data. The process of satellite imagery selection on a web server is highly manual with limited options to manage an intensive amount of datasets. There are packages available to download certain Nasa imagery with Python, but the Earthaccess library allows users to download different dataset with options to login, select by time and location, and define folders to download data.
We have done a complete process to download actual evapotranspiration (MYD16A2) imagery with Python and Earthaccess for a given period and location. The files are stored in a folder and represented with QGIS.
Tutorial
Code
#!pip install earthaccess
import earthaccess
auth = earthaccess.login()
EARTHDATA_USERNAME and EARTHDATA_PASSWORD are not set in the current environment, try setting them or use a different strategy (netrc, interactive)
No .netrc found in C:\Users\saulm
Enter your Earthdata Login username: saulmontoya
Enter your Earthdata password: ········
You're now authenticated with NASA Earthdata Login
Using token with expiration date: 11/13/2023
Using user provided credentials for EDL
#earthaccess.search_data?
results = earthaccess.search_data(
short_name='MYD16A2',
cloud_hosted=True,
bounding_box=(-77.6, -9.9, -76.9, -9.2),
temporal=("2021-01-01", "2021-01-10"),
#count=10
)
Granules found: 2
# if the data set is cloud hosted there will be S3 links available. The access parameter accepts "direct" or "external", direct access is only possible if you are in the us-west-2 region in the cloud.
data_links = [granule.data_links(access="direct") for granule in results]
data_links[:10]
[['s3://lp-prod-protected/MYD16A2.061/MYD16A2.A2021001.h10v09.061.2021067224124/MYD16A2.A2021001.h10v09.061.2021067224124.hdf'],
['s3://lp-prod-protected/MYD16A2.061/MYD16A2.A2021009.h10v09.061.2021068070135/MYD16A2.A2021009.h10v09.061.2021068070135.hdf']]
# or if the data is an on-prem dataset
#data_links = [granule.data_links(access="external") for granule in results]
files = earthaccess.download(results, "./mydImages_2")
Getting 2 granules, approx download size: 0.05 GB
QUEUEING TASKS | : 0%| | 0/2 [00:00<?, ?it/s]
PROCESSING TASKS | : 0%| | 0/2 [00:00<?, ?it/s]
COLLECTING RESULTS | : 0%| | 0/2 [00:00<?, ?it/s]