Skip to content

Cryo 84: Refactor tutorials to use earthaccess and xarray #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ notebook/static/lab/*bundle.js
notebooks/itslive/data/*.nc
notebooks/iceflow/data
notebooks/*/Outputs
notebooks/SMAP/data
.python-version
node_modules
*.py[co]
38 changes: 17 additions & 21 deletions notebooks/SMAP/01_download_smap_data.ipynb
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
"source": [
"## **1. Tutorial Introduction/Overview**\n",
"\n",
"We will use the `earthaccess` library to authenticate with our Earthdata Login credentials and to search for and bulk download SMAP data. For this tutorial we wil use SPL3SMP version 008 as an example, but the same method can be applied to any other SMAP data sets archived at NSIDC. \n"
"We will use the `earthaccess` library to authenticate with our Earthdata Login credentials and to search for and bulk download SMAP data. For this tutorial we wil use SPL3SMP version 009 as an example, but the same method can be applied to any other SMAP data sets archived at NSIDC. \n"
]
},
{
@@ -31,7 +31,7 @@
"source": [
"### **Credits**\n",
"\n",
"This tutorial is based on the notebooks originally provided to NSIDC by Adam Purdy. Jennifer Roebuck of NSIDC updated the tutorials to include the latest version of SMAP data and use `earthaccess` for authentication, seatching for and downloading the data in order to incorporate it into the NSIDC-Data-Tutorials repo. \n",
"This tutorial is based on the notebooks originally provided to NSIDC by Adam Purdy. Jennifer Roebuck of NSIDC updated the tutorials to include the latest version of SMAP data and use `earthaccess` for authentication, searching for and downloading the data in order to incorporate it into the NSIDC-Data-Tutorials repo. Andy Barrett refactored the notebook to use `pathlib.Path` and updated the version of the data set used.\n",
"\n",
"For questions regarding the notebook, or to report problems, please create a new issue in the [NSIDC-Data-Tutorials repo](https://github.com/nsidc/NSIDC-Data-Tutorials/issues)."
]
@@ -85,7 +85,7 @@
"metadata": {},
"source": [
"### **Import libraries**\n",
"We need just two libraries, `os` for creating the directory to store the downloaded data in and `earthaccess` to authenticate, search for and download the data. "
"We need two libraries for this tutorial: `pathlib` for creating the directory to store the downloaded data; and `earthaccess` to authenticate, search for and download the data. "
]
},
{
@@ -95,9 +95,7 @@
"metadata": {},
"outputs": [],
"source": [
"#Import libraries \n",
"\n",
"import os # needed to create the directory to store the downloaded data\n",
"from pathlib import Path # used for creating paths and listing directory contents\n",
"import earthaccess # used for authentication and searching for downloading the data"
]
},
@@ -131,14 +129,16 @@
"tags": []
},
"source": [
"### **Search for SPL3SMP data using spatial and temporal filters**\n",
"We will use the `search_data` method from the `earthaccess` library and the following variabes to search for granules within the SPL3SMP data set:\n",
"### **Search for SPL3SMP data using a temporal filter**\n",
"We will use the `search_data` method from the `earthaccess` library to search for granules in the SPL3SMP data set for March 2017.\n",
"\n",
"We use the following search parameters: \n",
"* `short_name` - this is the data set ID e.g. SPL3SMP. It can be found in the data set title on the data set landing page.\n",
"* `version` - data set version number, also included in the data set title.\n",
"* `cloud_hosted` - NSIDC is in the process of migrating data sets to the cloud. The data set we are interested is currently still archived on-premises so we will set this to False.\n",
"* `cloud_hosted` - SMAP data are available both from NASA Earthdata Cloud on AWS and from the severs on-premises at NSIDC_DAAC. We will access the cloud-hosted version.\n",
"* `temporal` - set a temporal filter by specifying a start and end date in the format YYYY-MM-DD. In this tutorial we will look for data for the month of March 2017.\n",
"\n",
"It will output the number of granules that meet the search criteria."
"You can find the number of results returned by getting the number of elements in `results` using the `len` function."
]
},
{
@@ -148,14 +148,13 @@
"metadata": {},
"outputs": [],
"source": [
"#Search for SPL3SMP files \n",
"\n",
"results = earthaccess.search_data(\n",
" short_name = 'SPL3SMP',\n",
" version = '008',\n",
" version = '009',\n",
" cloud_hosted = False,\n",
" temporal = ('2017-03-01','2017-03-31')\n",
")"
")\n",
"print(f\"Found: {len(results)}\")"
]
},
{
@@ -174,11 +173,8 @@
"metadata": {},
"outputs": [],
"source": [
"this_dir = os.getcwd()\n",
"DATA_DIR = os.path.join(this_dir, 'data/L3_SM_P')\n",
"\n",
"if not os.path.exists(DATA_DIR):\n",
" os.makedirs(DATA_DIR)\n"
"DOWNLOAD_PATH = Path.cwd() / \"data\" / \"L3_SM_P\"\n",
"DOWNLOAD_PATH.mkdir(parents=True, exist_ok=True) # creates parents if they don't exist and fails silently if path exists"
]
},
{
@@ -196,7 +192,7 @@
"metadata": {},
"outputs": [],
"source": [
"smap_files = earthaccess.download(results,DATA_DIR)"
"smap_files = earthaccess.download(results,DOWNLOAD_PATH)"
]
},
{
@@ -236,7 +232,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.15"
"version": "3.10.14"
}
},
"nbformat": 4,
8 changes: 8 additions & 0 deletions notebooks/SMAP/environment/environment.yml
Original file line number Diff line number Diff line change
@@ -9,9 +9,17 @@ dependencies:
- xarray
- rioxarray
- h5netcdf
- dask
- matplotlib
- cartopy
- affine
- numpy<2.1

#- vaex
#- jupyter-offlinenotebook
#- sidecar
#- geoviews

- pipreqsnb
- conda-lock>=1.2.1
- mamba>=1.0
Loading