NASA authentication#
To interact with NASA’s Common Metadata Repository (CMR) and download the required h5 files, icesat2DB requires NASA Earthdata credentials for authentication. This guide will help you set up and securely store your credentials to enable seamless access.
Creating CMR login credentials#
To access ICESat-2 data hosted on NASA’s servers, you need an Earthdata account. If you don’t have one, create an account at the following link:
Storing credentials for authentication#
To avoid re-entering your credentials each time, icesat2DB includes a function that securely saves your login information in a netrc file, enabling automatic authentication for future requests to NASA’s servers.
Use the following code snippet to authenticate and store your credentials in the netrc file:
import icesat2db as isdb
authentificator = isdb.EarthDataAuthenticator()
authentificator.authenticate()
# Example Output:
2025-01-17 15:56:48,114 - INFO - No authentication files found; starting Earthdata authentication.
2025-01-17 15:56:48,115 - INFO - Prompting user to create credentials.
Please enter your Earthdata Login username:
Earthdata Login password:
Explanation:
icesat2db.EarthDataAuthenticatorasks for your credentials in the prompt and verifies them.Once authenticated, the credentials are saved in the
netrcfile for future use, avoiding repeated login prompts.By default credentials files are stores in your home directory.
Authentication cookies are fetched and stored in a .cookies file for efficient reuse.
Credential validation process#
As part of the authentication workflow:
icesat2DB checks for the existence of a .netrc file in the specified or default directory (typically the user’s home directory).
If the file is missing, the user is prompted to input their credentials, which are then securely stored in the .netrc file.
Authentication cookies are retrieved from NASA servers and stored in the .cookies file, reducing the need for repeated credential validation during subsequent requests.
Successful authentication confirmation#
Upon successful authentication, icesat2DB logs messages to confirm that your credentials were correctly stored and verified. Here’s an example of the log output:
2025-01-17 15:57:53,340 - INFO - Credentials added to .netrc file.
2025-01-17 15:57:53,341 - INFO - Attempting to fetch Earthdata cookies and save to /home/$user/.cookies
2025-01-17 15:57:54,364 - INFO - Earthdata cookies successfully fetched and saved to /home/$user//.cookies.
This output confirms:
The directory for Earthdata data exists.
Credentials are securely saved in the
netrcfile.Authentication cookies are fetched from Earthdata servers, enabling easier login in subsequent sessions.
Security considerations#
Testing authentication#
To verify that your credentials are correct and valid:
Run the authentication process using
icesat2db.EarthDataAuthenticator.Check the log messages for successful credential verification and cookie fetching.
Troubleshooting tips:#
Ensure you are using the correct username and password for your Earthdata account.
If authentication fails, check the permissions and format of your
netrcfile.Contact NASA Earthdata support if issues persist: Earthdata Support
With authentication configured, you are now ready to download and process ICESat-2 data using icesat2DB.