• Stars
    star
    413
  • Rank 104,801 (Top 3 %)
  • Language
    Python
  • License
    MIT License
  • Created over 3 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Python Library for NASA Earthdata APIs

earthaccess, a python library to search, download or stream NASA Earth science data with just a few lines of code

Art Designer: Allison Horst Package version Conda Versions Python Versions Documentation Status

Overview

earthaccess is a python library to search, download or stream NASA Earth science data with just a few lines of code.

In the age of cloud computing, the power of open science only reaches its full potential if we have easy-to-use workflows that facilitate research in an inclusive, efficient and reproducible way. Unfortunately β€”as it stands todayβ€” scientists and students alike face a steep learning curve adapting to systems that have grown too complex and end up spending more time on the technicalities of the tools, cloud and NASA APIs than focusing on their important science.

During several workshops organized by NASA Openscapes, the need to provide easy-to-use tools to our users became evident. Open science is a collaborative effort; it involves people from different technical backgrounds, and the data analysis to solve the pressing problems we face cannot be limited by the complexity of the underlying systems. Therefore, providing easy access to NASA Earthdata regardless of the data storage location (hosted within or outside of the cloud) is the main motivation behind this Python library.

Installing earthaccess

You will need Python 3.8 or higher installed.

Install the latest release using conda

conda install -c conda-forge earthaccess

Using Pip

pip install earthaccess

Try it in your browser without installing anything! Binder

Usage

With earthaccess we can login, search and download data with a few lines of code and even more relevant, our code will work the same way if we are running it in the cloud or from our laptop. earthaccess handles authentication with NASA's Earthdata Login (EDL), search using NASA's CMR and access through fsspec.

The only requirement to use this library is to open a free account with NASA EDL.

Authentication

Once you have an EDL account, you can authenticate using one of the following three methods:

  1. Using a .netrc file
    • Can use earthaccess to read your EDL credentials (username and password) from a .netrc file
  2. Reading your EDL credentials from environment variables
    • if available you can use environment variables EARTHDATA_USERNAME and EARTHDATA_PASSWORD
  3. Interactively entering your EDL credentials
    • You can be prompted for these credentials and save them to a .netrc file
import earthaccess

auth = earthaccess.login()

Once you are authenticated with NASA EDL you can:

  • Get a file from a DAAC using a fsspec session.
  • Request temporary S3 credentials from a particular DAAC (needed to download or stream data from an S3 bucket in the cloud).
  • Use the library to download or stream data directly from S3.
  • Regenerate CMR tokens (used for restricted datasets)

Searching for data

Once we have selected our dataset we can search for the data granules using doi, short_name or concept_id. If we are not sure or we don't know how to search for a particular dataset, we can start with the "Introducing NASA earthaccess" tutorial or through the NASA Earthdata Search portal. For a complete list of search parameters we can use visit the extended API documentation.

results = earthaccess.search_data(
    short_name='SEA_SURFACE_HEIGHT_ALT_GRIDS_L4_2SATS_5DAY_6THDEG_V_JPL2205',
    cloud_hosted=True,
    bounding_box=(-10, 20, 10, 50),
    temporal=("1999-02", "2019-03"),
    count=10
)

Now that we have our results we can do multiple things: We can iterate over them to get HTTP (or S3) links, we can download the files to a local folder, or we can open these files and stream their content directly to other libraries e.g. xarray.

Accessing the data

Option 1: Using the data links

If we already have a workflow in place for downloading our data, we can use earthaccess as a search-only library and get HTTP links from our query results. This could be the case if our current workflow uses a different language and we only need the links as input.

# 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]

# or if the data is an on-prem dataset
data_links = [granule.data_links(access="external") for granule in results]

Note: earthaccess can get S3 credentials for us, or auhenticated HTTP sessions in case we want to use them with a different library.

Option 2: Download data to a local folder

This option is practical if you have the necessary space available on disk. The earthaccess library will print out the approximate size of the download and its progress.

files = earthaccess.download(results, "./local_folder")

Option 3: Direct S3 Access - Stream data directly to xarray

This method works best if you are in the same Amazon Web Services (AWS) region as the data (us-west-2) and you are working with gridded datasets (processing level 3 and above).

import xarray as xr

files = earthaccess.open(results)

ds = xr.open_mfdataset(files)

And that's it! Just one line of code, and this same piece of code will also work for data that are not hosted in the cloud, i.e. located at NASA storage centers.

More examples coming soon!

Compatibility

Only Python 3.8+ is supported.

Contributors

Contributors

Contributing Guide

Welcome! πŸ˜ŠπŸ‘‹

Please see the Contributing Guide.

Project Board.

Glossary

NASA Earth Science Glossary

License

earthaccess is licensed under the MIT license. See LICENSE.

Level of Support


This repository is not actively supported by NSIDC but we welcome issue submissions and pull requests in order to foster community contribution.

More Repositories

1

vagrant-vsphere

VMware vSphere provider for Vagrant
Ruby
609
star
2

NSIDC-Data-Tutorials

Jupyter notebook-based tutorials to learn how to access and work with select NSIDC DAAC data.
Jupyter Notebook
77
star
3

NSIDC-Data-Access-Notebook

A Jupyter notebook exploring data coverage, size, and customization service availability along with direct data download utilizing the NSIDC DAAC's access and service API.
Jupyter Notebook
56
star
4

smap_python_notebooks

Python
38
star
5

qgreenland

Source code for generating the QGreenland package hosted at https://qgreenland.org/
Python
36
star
6

OpenSearchlight

An OpenSearch client in JavaScript
JavaScript
21
star
7

polarstereo-lonlat-convert-py

Python functions for converting polar stereographic coordinates.
Python
19
star
8

ol3-projection-switcher

OpenLayers 3 Projection Switcher Control
JavaScript
15
star
9

cloud-optimized-icesat2

Jupyter Notebook
9
star
10

Antarctica_Today

The "Antarctica Today" code and datasets
Python
7
star
11

nsidc_open_science

Towards developing an Open Science Strategy for the National Snow and Ice Data Center
Jupyter Notebook
6
star
12

tech-radar

Helps NSIDC understand the spectrum of technology that is relevant to our work
5
star
13

snow-today-webapp

Visualize near-real-time snow data
TypeScript
5
star
14

polar_stereo

NSIDC Polar Stereographic Projection
5
star
15

AGU-2019-NSIDC-Data-Tutorial

Jupyter Notebook
5
star
16

easegrids-easeconv

EASE-Grid map transformation utilities for IDL.
IDL
4
star
17

ms2gt

MODIS Swath-to-Grid Toolbox
IDL
4
star
18

qgreenland-plugin

Python
4
star
19

snow-today-webapp-server

Serve data the snow-today-webapp depends on
Python
4
star
20

NSIDC-Data-Cookbook

A collection of how-to guides, tutorials and references for searching, accessing and working with NSIDC data.
Jupyter Notebook
4
star
21

polarstereo-reformat

Scripts for working with NSIDC data in polar stereographic projections.
Python
3
star
22

seaice_ecdr

Sea Ice Concentration 12.5km Enhanced CDR
Python
3
star
23

nsidc0756-scripts

Scripts related to NSIDC-0756
Python
3
star
24

pm_icecon

Sea Ice Concentrations from Passive Microwave Data
Python
3
star
25

mapxmaps

A collection of Map Projection Parameter (.mpp) and Grid Parameter Definition (.gpd) files for use with NSIDC's mapx software
Makefile
3
star
26

git-training

Git training for NSIDC
Shell
3
star
27

icebridge-tools

NSIDC Tools for reading and viewing NASA IceBridge data
MATLAB
3
star
28

JIRA-GitHub-ETL

Python scripts to transform JIRA xml export to GitHub Issues
Python
3
star
29

HMA_GLAM_BioLith-RT_5

Matlab code for Glacier Lake Assisted Melting of Glaciers
MATLAB
3
star
30

presentation-reusable-workflows

A presentation about re-usable workflows in GitHub Actions
2
star
31

mapx

The NSIDC mapx library and associated binary tools for gridding/reprojection.
C
2
star
32

gi_cat_driver

Ruby
2
star
33

beer_lambert_rt

Beer-Lambert Radiative Transfer Model used for Stroeve et al 2021
Python
2
star
34

aross-map

Arctic Rain on Snow Study LEO Network Observation Map
TypeScript
2
star
35

slackbotr

An application for hosting/serving Python slackbots
Python
2
star
36

search-interface

An Opensearch based single page search interface
JavaScript
2
star
37

earthaccess-gallery

earthaccess gallery with examples
Jupyter Notebook
2
star
38

qgreenland-customizer

Prototype/spike on QGreenland Customizer Plugin
Python
2
star
39

revealjs_presentation_template

Presentation templates for NSIDC using Revealjs
SCSS
2
star
40

search-solr-tools

This is a gem that contains: Ruby translators to transform various metadata feeds into solr documents and a command-line utility to access/utilize the gem's translators to harvest metadata into a working solr instance.
Ruby
2
star
41

earthaccess-proposal-2024-nasa-roses

A proposal for sustainment funding for _earthaccess_ under NASA ROSES 2024 F.07
TeX
1
star
42

icesat2-notebooks

notebooks to test IS2 datasets
Jupyter Notebook
1
star
43

nsidc0447-scripts

Scripts related to NSIDC-0447
Python
1
star
44

cumulus-migration-dependencies

collect versions for various dependencies and components in the Cumulus Migration stack
Python
1
star
45

dataset-search-services

OpenSearch interface to a Solr backend.
Ruby
1
star
46

data_strategies_for_future_us

1
star
47

Shapefile_to_grid

This python code was written specifically to convert the shapefiles from the NSIDC dataset G10007 to a grid that matches the data in the NSIDC data G10010 dataset
Python
1
star
48

presentation-pangeo-forge

A brief intro to Pangeo Forge
1
star
49

2022-bookclub-exercises

Euler Project problems and other exercises through which we are learning Scheme together
Racket
1
star
50

.github

1
star
51

open-science-reading-club

A website and community space for the NSIDC open science reading club
SCSS
1
star
52

ros-animator-widget

A widget for controlling animations of Rain on Snow events
TypeScript
1
star
53

polarstereo-latlon-convert-fortran

FORTRAN program that transforms between I,J and latitude,longitude coordinates of an SSM/I grid cell.
Fortran
1
star