Skip to content

Commit 3e7ff31

Browse files
authored
Merge pull request #106 from nsidc/webinar
notebook for NASA Earthdata webinar short
2 parents 1169f1f + 76a2599 commit 3e7ff31

1 file changed

Lines changed: 322 additions & 0 deletions

File tree

Lines changed: 322 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,322 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "a82d2f01-db24-468b-b7c2-409180961eb0",
6+
"metadata": {},
7+
"source": [
8+
"### Overview\n",
9+
"\n",
10+
"1. <font color=\"red\">Authenticate using Earthdata Login.</font>\n",
11+
"2. Search for data sets using a keyword.\n",
12+
"3. Examine data set metadata.\n",
13+
"4. <font color=\"red\">Search for files within an area of interest and over a specific time range.</font>\n",
14+
"5. <font color=\"red\">Download data.</font>\n",
15+
"6. Open data.\n",
16+
"7. Plot data."
17+
]
18+
},
19+
{
20+
"cell_type": "markdown",
21+
"id": "36f395c7-0eab-45dd-9339-5fa23630253e",
22+
"metadata": {},
23+
"source": [
24+
"### What you will neeed to go through this demo on your own\n",
25+
"\n",
26+
"#### Required\n",
27+
"- A NASA Earthdata Login, which is free - you can sign up here: https://urs.earthdata.nasa.gov\n",
28+
"\n",
29+
"- The latest release of `earthaccess`, which can be installed with mamba, conda or pip - https://earthaccess.readthedocs.io/en/stable/user/quick-start/\n",
30+
"- Python 3.8 or higher\n",
31+
"- `xarray` - for opening up hdf5 files\n",
32+
"- `hvplot` - for creating a scatter plot of some data\n",
33+
"\n",
34+
"#### Recommended\n",
35+
"- [Jupyter lab](https://jupyter.org/) - a user friendly environment in which to run the notebook\n",
36+
"\n",
37+
"- [Github account](https://github.com) - so that you can access a copy of the notebook"
38+
]
39+
},
40+
{
41+
"cell_type": "markdown",
42+
"id": "56f83704-7bab-4633-9f53-6c307868c9b7",
43+
"metadata": {},
44+
"source": [
45+
"### 0. Import packages"
46+
]
47+
},
48+
{
49+
"cell_type": "code",
50+
"execution_count": null,
51+
"id": "5ecdad53-6a40-44d2-b5e3-2598f80e0ac8",
52+
"metadata": {},
53+
"outputs": [],
54+
"source": [
55+
"import earthaccess\n",
56+
"import xarray as xr\n",
57+
"import hvplot.xarray"
58+
]
59+
},
60+
{
61+
"cell_type": "markdown",
62+
"id": "0588665a-a2aa-4d00-8ec0-56452fb1305e",
63+
"metadata": {},
64+
"source": [
65+
"### 1. Authenticate\n",
66+
"\n",
67+
"Login requires your Earthdata Login username and password. You will be prompted to enter them interactively.\n"
68+
]
69+
},
70+
{
71+
"cell_type": "code",
72+
"execution_count": null,
73+
"id": "ceea2228-aa43-45b5-8f9e-8a8ce2b538e0",
74+
"metadata": {},
75+
"outputs": [],
76+
"source": [
77+
"auth = earthaccess.login()"
78+
]
79+
},
80+
{
81+
"cell_type": "markdown",
82+
"id": "6330fe82-cad7-4d9f-99ba-f652b11af8b1",
83+
"metadata": {},
84+
"source": [
85+
"### 2. Search within the NASA Common Metadata Repository for collections by keyword."
86+
]
87+
},
88+
{
89+
"cell_type": "markdown",
90+
"id": "db5e3909-4dda-417a-ab38-b35692f0912a",
91+
"metadata": {},
92+
"source": [
93+
"#### **Sidenote:** \n",
94+
"While you can perform some data discovery and exploration using earthaccess, it makes sense to do this first using resources like the [NASA Earthdata website](https://www.earthdata.nasa.gov) and [Earthdata Search](https://search.earthdata.nasa.gov). The NASA Earthdata website provides access to documentation, tools and educational resources about NASA Earth observing missions and data sets. Earthdata Search allows you to search through the vast catalog of NASA Earthdata using a graphical user interface."
95+
]
96+
},
97+
{
98+
"cell_type": "code",
99+
"execution_count": null,
100+
"id": "434fc8d3-f127-4e2b-953c-ba833551a1a6",
101+
"metadata": {},
102+
"outputs": [],
103+
"source": [
104+
"query = earthaccess.search_datasets(keyword='icesat-2')\n",
105+
"len(query)"
106+
]
107+
},
108+
{
109+
"cell_type": "markdown",
110+
"id": "5b741aa6-4e2c-4f90-a23f-ae4b2ca56103",
111+
"metadata": {},
112+
"source": [
113+
"### 3. Examine some useful metadata using the `get_umm()` earthaccess function."
114+
]
115+
},
116+
{
117+
"cell_type": "code",
118+
"execution_count": null,
119+
"id": "20c0576d-712b-4348-b3f9-365987f8da08",
120+
"metadata": {},
121+
"outputs": [],
122+
"source": [
123+
"for r in query[:10]:\n",
124+
" long_name = r.get_umm('EntryTitle')\n",
125+
" short_name = r.get_umm('ShortName')\n",
126+
" description = r.get_umm('Abstract')\n",
127+
" doi = r.get_umm('DOI')\n",
128+
" print(long_name, short_name, description, doi, sep='\\n')\n",
129+
" print( )"
130+
]
131+
},
132+
{
133+
"cell_type": "markdown",
134+
"id": "0aab7e46-a094-426f-a6ce-469e0aab69b7",
135+
"metadata": {},
136+
"source": [
137+
"#### A non-exhaustive list of some useful metadata elements available to `get_umm()`\n",
138+
"- **ShortName** - abbreviated or short-hand data set name\n",
139+
"- **EntryTitle** - full, long-form data set name including version\n",
140+
"- **Abstract** - short description of a data set including information such as location, temporal range, and data collection methods.\n",
141+
"- **DOI** - a Digital Object Identifier is a unique, permanent alphanumeric code assigned to digital objects—most commonly academic journal articles, books, and research datasets—to provide a persistent, actionable link to their location on the internet. Unlike URLs, which can change, a DOI remains stable over time. \n",
142+
"- **SpatialExtent** - geolocation information about the data set which can include latitude/longitude coordinates for the bounding box that encompasses the data\n",
143+
"- **ScienceKeywords** - science terms associated with the relevant parameters contained in the data set \n",
144+
"- **Version** - data set version\n",
145+
"- **VersionDescription** - description of updates included in most recent version\n",
146+
"- **UseConstraints** - license text and citation instructions\n",
147+
"- **Platforms** - provides satellite and aircraft platforms and sensors, or indicates ground-based observations and instruments"
148+
]
149+
},
150+
{
151+
"cell_type": "markdown",
152+
"id": "a078a9c3-687a-4729-8568-1983b12d7438",
153+
"metadata": {},
154+
"source": [
155+
"### 4. Search within a data set for files that match certain criteria."
156+
]
157+
},
158+
{
159+
"cell_type": "markdown",
160+
"id": "dd2ea38c-2de8-41af-a62c-e6911aa1811c",
161+
"metadata": {},
162+
"source": [
163+
"We'll use the ICESat-2 Land Ice Height data set (ATL06) as an example. We'll narrow down our results to files that fall over the Juneau ice field in Alaska and that were collected during a specific time period."
164+
]
165+
},
166+
{
167+
"cell_type": "code",
168+
"execution_count": null,
169+
"id": "8355a820-7480-4eea-a81b-2cae6a945662",
170+
"metadata": {},
171+
"outputs": [],
172+
"source": [
173+
"results = earthaccess.search_data(\n",
174+
" doi = '10.5067/ATLAS/ATL06.007',\n",
175+
" cloud_hosted = True,\n",
176+
" bounding_box = (-134.7,58.9,-133.9,59.2),\n",
177+
" temporal = ('2020-03-01','2020-04-30'),\n",
178+
")\n",
179+
"len(results)"
180+
]
181+
},
182+
{
183+
"cell_type": "markdown",
184+
"id": "495886d9-681c-4208-a4f8-a89a5b1d321a",
185+
"metadata": {},
186+
"source": [
187+
"Let's get a preview of the files that matched our search criteria."
188+
]
189+
},
190+
{
191+
"cell_type": "code",
192+
"execution_count": null,
193+
"id": "2581bd0e-3ccc-41da-b25a-4c12cda63797",
194+
"metadata": {},
195+
"outputs": [],
196+
"source": [
197+
"[display(r) for r in results]"
198+
]
199+
},
200+
{
201+
"cell_type": "markdown",
202+
"id": "57c4a7b1-e2ad-4560-b6ba-47a0799e9673",
203+
"metadata": {},
204+
"source": [
205+
"### 5. Download the files to our machine."
206+
]
207+
},
208+
{
209+
"cell_type": "code",
210+
"execution_count": null,
211+
"id": "88fb2b60-78de-4eef-b915-db375dd79d1f",
212+
"metadata": {},
213+
"outputs": [],
214+
"source": [
215+
"files = earthaccess.download(results, local_path ='./')"
216+
]
217+
},
218+
{
219+
"cell_type": "markdown",
220+
"id": "cd4dd4cf-3a94-432a-9c33-c0057dd60d92",
221+
"metadata": {},
222+
"source": [
223+
"### 6. Open a sample file using xarray, so that we can examine a variable.\n",
224+
"\n",
225+
"After consulting the ATL06 Land Ice Height data set user guide found on this page https://www.earthdata.nasa.gov/data/catalog/nsidc-cprd-atl06-007, we know the variable of interest is \"h_li\" found within the \"land_ice_segments\" group within each ground track group. The user guide contains useful information about the Land Ice Height data product, as well as about the ATLAS sensor aboard the ICESat-2 satellite."
226+
]
227+
},
228+
{
229+
"cell_type": "code",
230+
"execution_count": null,
231+
"id": "7132f308-3a10-4250-b6ce-240e22de2c09",
232+
"metadata": {
233+
"scrolled": true
234+
},
235+
"outputs": [],
236+
"source": [
237+
"ds = xr.open_dataset(files[1], group='/gt1l/land_ice_segments')\n",
238+
"ds"
239+
]
240+
},
241+
{
242+
"cell_type": "markdown",
243+
"id": "28282e23-3f8b-4dcc-899f-ca48c3212cab",
244+
"metadata": {},
245+
"source": [
246+
"### 7. Use hvplot to plot the variable and start some data exploration."
247+
]
248+
},
249+
{
250+
"cell_type": "code",
251+
"execution_count": null,
252+
"id": "654a5a19-6cf8-4eee-ae11-aaf552970f0d",
253+
"metadata": {},
254+
"outputs": [],
255+
"source": [
256+
"ds['h_li'].hvplot(kind='scatter', x='latitude', s=2)"
257+
]
258+
},
259+
{
260+
"cell_type": "markdown",
261+
"id": "543ca471-a814-4243-a58f-7ba181795ffc",
262+
"metadata": {},
263+
"source": [
264+
"### Recap\n",
265+
"\n",
266+
"1. Authenticated using Earthdata Login.\n",
267+
"2. Searched for data sets using a keyword.\n",
268+
"3. Examined data set metadata.\n",
269+
"4. Searched for files within an area of interest and over a specific time range.\n",
270+
"5. Downloaded data.\n",
271+
"6. Opened a file to examine a data variable.\n",
272+
"7. Plotted a variable from witin the file."
273+
]
274+
},
275+
{
276+
"cell_type": "markdown",
277+
"id": "9c6e5a39-be96-49db-805d-4b30da5cd914",
278+
"metadata": {},
279+
"source": [
280+
"### Get data with 3 lines of code! "
281+
]
282+
},
283+
{
284+
"cell_type": "code",
285+
"execution_count": null,
286+
"id": "ffa45b25-271d-4768-9bb3-23886400770e",
287+
"metadata": {},
288+
"outputs": [],
289+
"source": [
290+
"auth = earthaccess.login()\n",
291+
"results = earthaccess.search_data(\n",
292+
" doi = '10.5067/ATLAS/ATL06.007',\n",
293+
" cloud_hosted = True,\n",
294+
" bounding_box = (-134.7, 58.9, -133.9, 59.2),\n",
295+
" temporal = ('2020-03-01', '2020-04-30')\n",
296+
")\n",
297+
"files = earthaccess.download(results, local_path = './')"
298+
]
299+
}
300+
],
301+
"metadata": {
302+
"kernelspec": {
303+
"display_name": "Python 3 (ipykernel)",
304+
"language": "python",
305+
"name": "python3"
306+
},
307+
"language_info": {
308+
"codemirror_mode": {
309+
"name": "ipython",
310+
"version": 3
311+
},
312+
"file_extension": ".py",
313+
"mimetype": "text/x-python",
314+
"name": "python",
315+
"nbconvert_exporter": "python",
316+
"pygments_lexer": "ipython3",
317+
"version": "3.14.3"
318+
}
319+
},
320+
"nbformat": 4,
321+
"nbformat_minor": 5
322+
}

0 commit comments

Comments
 (0)