How do I access Cloud Data from my Local Machine in Python?

Downloading data

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”.

This page covers downloading data from Earthdata Cloud to your local machine using the earthaccess library.

earthaccess

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(strategy="netrc")
You're now authenticated with NASA Earthdata Login
Using token with expiration date: 10/30/2023
Using .netrc file for EDL
#Access land ice height from ATLAS/ICESat-2 V005 (10.5067/ATLAS/ATL06.005), 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="005",
                                  cloud_hosted=True,
                                  temporal = ("2022-07-17","2022-07-31"),
                                  bounding_box = (-51.96423,68.10554,-48.71969,70.70529))
Granules found: 5
files = earthaccess.download(results, "./local_folder")

downloaded_files = []
for f in files: 
    file = "local_folder/"+ f
    downloaded_files.append(file)
 Getting 5 granules, approx download size: 0.0 GB
File ATL06_20220718010029_03991603_005_01.h5 already downloaded
File ATL06_20220718134522_04071605_005_01.h5 already downloaded
File ATL06_20220722005209_04601603_005_01.h5 already downloaded
File ATL06_20220726004352_05211603_005_01.h5 already downloaded
File ATL06_20220722133704_04681605_005_01.h5 already downloaded
['local_folder/ATL06_20220718010029_03991603_005_01.h5',
 'local_folder/ATL06_20220718134522_04071605_005_01.h5',
 'local_folder/ATL06_20220722005209_04601603_005_01.h5',
 'local_folder/ATL06_20220722133704_04681605_005_01.h5',
 'local_folder/ATL06_20220726004352_05211603_005_01.h5']
#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(downloaded_files, group='/gt1l/land_ice_segments', engine='h5netcdf')
ds
<xarray.Dataset>
Dimensions:                (delta_time: 241711)
Coordinates:
  * delta_time             (delta_time) datetime64[ns] 2022-07-18T01:00:46.67...
    latitude               (delta_time) float64 dask.array<chunksize=(78325,), meta=np.ndarray>
    longitude              (delta_time) float64 dask.array<chunksize=(78325,), meta=np.ndarray>
Data variables:
    atl06_quality_summary  (delta_time) int8 dask.array<chunksize=(78325,), meta=np.ndarray>
    h_li                   (delta_time) float32 dask.array<chunksize=(78325,), meta=np.ndarray>
    h_li_sigma             (delta_time) float32 dask.array<chunksize=(78325,), meta=np.ndarray>
    segment_id             (delta_time) float64 dask.array<chunksize=(78325,), meta=np.ndarray>
    sigma_geo_h            (delta_time) float32 dask.array<chunksize=(78325,), meta=np.ndarray>
Attributes:
    Description:  The land_ice_height group contains the primary set of deriv...
    data_rate:    Data within this group are sparse.  Data values are provide...
    • delta_time
      PandasIndex
      PandasIndex(DatetimeIndex(['2022-07-18 01:00:46.678760592',
                     '2022-07-18 01:00:46.681322640',
                     '2022-07-18 01:00:46.684008720',
                     '2022-07-18 01:00:46.686753504',
                     '2022-07-18 01:00:46.689526560',
                     '2022-07-18 01:00:46.692315280',
                     '2022-07-18 01:00:46.695049040',
                     '2022-07-18 01:00:46.700724096',
                     '2022-07-18 01:00:46.703545872',
                     '2022-07-18 01:00:46.706366832',
                     ...
                     '2022-07-26 00:49:18.806914512',
                     '2022-07-26 00:49:18.809737328',
                     '2022-07-26 00:49:18.812559600',
                     '2022-07-26 00:49:18.815380608',
                     '2022-07-26 00:49:18.818200224',
                     '2022-07-26 00:49:18.821015744',
                     '2022-07-26 00:49:18.823827088',
                     '2022-07-26 00:49:18.826637808',
                     '2022-07-26 00:49:18.829449568',
                     '2022-07-26 00:49:18.832263232'],
                    dtype='datetime64[ns]', name='delta_time', length=241711, freq=None))
  • Description :
    The land_ice_height group contains the primary set of derived ATL06 products. This includes geolocation, height, and standard error and quality measures for each segment. This group is sparse, meaning that parameters are provided only for pairs of segments for which at least one beam has a valid surface-height measurement.
    data_rate :
    Data within this group are sparse. Data values are provided only for those ICESat-2 20m segments where at least one beam has a valid land ice height measurement.