How do I access data stored in Earthdata Cloud in Python?

Direct Access

When you have found the data you want to use, you have two options. You can download the data to work locally, or access the data directly to work in the cloud. This second way of working is called “Direct Cloud Access” or simply, “Direct Access”. Your compute instance needs to be in Amazon Web Services (AWS) Region us-west-2 in order for the code to run successfully. We authenticate using a netrc file and an Earthdata Login, see the appendix for more information on Earthdata Login and netrc setup.

Python

We can use the earthaccess python library to grab the file URLs and then access them with the xarray library.

#Import packages
import earthaccess
import xarray as xr
#Authentication with Earthdata Login
auth = earthaccess.login()
#Access land ice height from ATLAS/ICESat-2 V007 (10.5067/ATLAS/ATL06.007), searching for data over western Greenland coast over two weeks in July 2022. The data are provided as HDF5 granules (files) that span about 1/14th of an orbit.

results = earthaccess.search_data(short_name="ATL06",
                                  version="007",
                                  cloud_hosted=True,
                                  temporal = ("2022-07-17","2022-07-31"),
                                  bounding_box = (-51.96423,68.10554,-48.71969,70.70529))
#Use xarray to load the data as a multifile dataset for a single group in the HDF5 file, in this case land ice segments:
ds = xr.open_mfdataset(earthaccess.open(results), group='/gt1l/land_ice_segments')
ds
<xarray.Dataset> Size: 11MB
Dimensions:                (delta_time: 240873)
Coordinates:
  * delta_time             (delta_time) datetime64[ns] 2MB 2022-07-18T01:00:4...
    latitude               (delta_time) float64 2MB dask.array<chunksize=(10000,), meta=np.ndarray>
    longitude              (delta_time) float64 2MB dask.array<chunksize=(10000,), meta=np.ndarray>
Data variables:
    atl06_quality_summary  (delta_time) int8 241kB dask.array<chunksize=(10000,), meta=np.ndarray>
    fpb_warning_flag       (delta_time) int8 241kB dask.array<chunksize=(10000,), meta=np.ndarray>
    h_li                   (delta_time) float32 963kB dask.array<chunksize=(10000,), meta=np.ndarray>
    h_li_sigma             (delta_time) float32 963kB dask.array<chunksize=(10000,), meta=np.ndarray>
    segment_id             (delta_time) float64 2MB dask.array<chunksize=(10000,), meta=np.ndarray>
    sigma_geo_h            (delta_time) float32 963kB dask.array<chunksize=(10000,), meta=np.ndarray>
Attributes:
    data_rate:    Data within this group are sparse.  Data values are provide...
    description:  The land_ice_height group contains the primary set of deriv...

End User License Agreement (EULA)

Sometimes, accessing data in NASA Earthdata Cloud requires an End-User License Agreement (EULA). If you cannot access a dataset, this may be your issue! See these instructions for how to authorize EULAs.

Alternative Access Method without earthaccess

An alternative approach to accessing data is outlined in some notebooks in the Earthdata Cloud Cookbook Appendix! The earthaccess package uses these methods for its back end. See this GitHub folder.