Skip to content

Commit 321ba98

Browse files
committed
initial commit
1 parent 4726e22 commit 321ba98

File tree

2 files changed

+216
-0
lines changed

2 files changed

+216
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.cred
2+
.ipynb_checkpoints/
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 2,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"import getpass\n",
10+
"import socket\n",
11+
"import requests\n",
12+
"import json\n",
13+
"import zipfile\n",
14+
"import os\n",
15+
"import io\n",
16+
"import s3fs"
17+
]
18+
},
19+
{
20+
"cell_type": "code",
21+
"execution_count": 7,
22+
"metadata": {},
23+
"outputs": [],
24+
"source": [
25+
"with open('.cred') as json_file: \n",
26+
" data = json.load(json_file)"
27+
]
28+
},
29+
{
30+
"cell_type": "code",
31+
"execution_count": 8,
32+
"metadata": {},
33+
"outputs": [],
34+
"source": [
35+
"# Request token from Common Metadata Repository using Earthdata credentials\n",
36+
"token_api_url = 'https://api.echo.nasa.gov/echo-rest/tokens'\n",
37+
"hostname = socket.gethostname()\n",
38+
"ip = socket.gethostbyname(hostname)\n",
39+
"\n",
40+
"data = {\n",
41+
" 'token': {\n",
42+
" 'username': data['uid'],\n",
43+
" 'password': data['pwd'],\n",
44+
" 'client_id': 'NSIDC_client_id',\n",
45+
" 'user_ip_address': ip\n",
46+
" }\n",
47+
"}\n",
48+
"headers={'Accept': 'application/json'}\n",
49+
"response = requests.post(token_api_url, json=data, headers=headers)\n",
50+
"token = json.loads(response.content)['token']['id']"
51+
]
52+
},
53+
{
54+
"cell_type": "code",
55+
"execution_count": 14,
56+
"metadata": {},
57+
"outputs": [],
58+
"source": [
59+
"response = requests.get(\"https://n5eil02u.ecs.nsidc.org/egi/request?short_name=ATL03&version=205&temporal=2018-10-17T00:00:00,2018-10-17T23:59:59&bounding_box=-115,35,-99,42&agent=NO&token={}&page_size=1&email=arendta@uw.edu\".format(token)) "
60+
]
61+
},
62+
{
63+
"cell_type": "code",
64+
"execution_count": 15,
65+
"metadata": {},
66+
"outputs": [],
67+
"source": [
68+
"with zipfile.ZipFile(io.BytesIO(response.content)) as z:\n",
69+
" z.extractall(os.getcwd())"
70+
]
71+
},
72+
{
73+
"cell_type": "code",
74+
"execution_count": null,
75+
"metadata": {},
76+
"outputs": [],
77+
"source": [
78+
"# Connect to bucket\n",
79+
"import s3fs\n",
80+
"bucket = 'pangeo-data-upload-oregon'\n",
81+
"fs = s3fs.S3FileSystem()\n",
82+
"# List contents\n",
83+
"dataDir = 'pangeo-data-upload-oregon/icesat2/atl03'\n",
84+
"fs.ls(dataDir)"
85+
]
86+
},
87+
{
88+
"cell_type": "code",
89+
"execution_count": null,
90+
"metadata": {},
91+
"outputs": [],
92+
"source": [
93+
"# Download an HDF5 to home directory\n",
94+
"filename = 'ATL06_20181019051247_03140110_203_01.h5'\n",
95+
"data = dataDir + '/' + filename\n",
96+
"fs.get(data, filename)"
97+
]
98+
},
99+
{
100+
"cell_type": "code",
101+
"execution_count": 7,
102+
"metadata": {},
103+
"outputs": [],
104+
"source": [
105+
"import xarray as xr"
106+
]
107+
},
108+
{
109+
"cell_type": "code",
110+
"execution_count": 10,
111+
"metadata": {},
112+
"outputs": [],
113+
"source": [
114+
"ds = xr.open_dataset('ATL03_20181017101822_02870106_205_01.h5')"
115+
]
116+
},
117+
{
118+
"cell_type": "code",
119+
"execution_count": 11,
120+
"metadata": {},
121+
"outputs": [
122+
{
123+
"data": {
124+
"text/plain": [
125+
"<xarray.Dataset>\n",
126+
"Dimensions: (ds_surf_type: 5, ds_xyz: 3)\n",
127+
"Coordinates:\n",
128+
" * ds_surf_type (ds_surf_type) int32 1 2 3 4 5\n",
129+
" * ds_xyz (ds_xyz) int32 1 2 3\n",
130+
"Data variables:\n",
131+
" *empty*\n",
132+
"Attributes:\n",
133+
" granule_type: ATL03\n",
134+
" short_name: ATL03\n",
135+
" level: L2\n",
136+
" description: Photon heights determined by ATBD Alg...\n",
137+
" contributor_name: Thomas E Neumann (thomas.neumann@nasa...\n",
138+
" contributor_role: Instrument Engineer, Investigator, Pr...\n",
139+
" Conventions: CF-1.6\n",
140+
" date_type: UTC\n",
141+
" featureType: trajectory\n",
142+
" geospatial_lat_units: degrees_north\n",
143+
" geospatial_lon_units: degrees_east\n",
144+
" identifier_product_doi: 10.5067/ATLAS/ATL03.001\n",
145+
" identifier_product_doi_authority: http://dx.doi.org\n",
146+
" identifier_product_type: ATL03\n",
147+
" license: Data may not be reproduced or distrib...\n",
148+
" naming_authority: http://dx.doi.org\n",
149+
" spatial_coverage_type: Horizontal\n",
150+
" standard_name_vocabulary: CF-1.6\n",
151+
" time_type: CCSDS UTC-A\n",
152+
" date_created: 2019-02-22T21:36:26.000000Z\n",
153+
" hdfversion: HDF5 1.10.3\n",
154+
" history: 2019-02-22T21:36:26.000000Z;7d7d1217-...\n",
155+
" identifier_file_uuid: 7d7d1217-0a51-32c7-9668-76f9cb6f5abd\n",
156+
" identifier_product_format_version: 3.0\n",
157+
" time_coverage_duration: 511.0\n",
158+
" time_coverage_end: 2018-10-17T10:26:53.000000Z\n",
159+
" time_coverage_start: 2018-10-17T10:18:22.000000Z\n",
160+
" geospatial_lat_min: 27.165281074967876\n",
161+
" geospatial_lon_min: -104.25776485626916\n",
162+
" geospatial_lat_max: 59.45914367107108\n",
163+
" geospatial_lon_max: -99.71800465595649\n",
164+
" publisher_name: NSIDC DAAC > NASA National Snow and I...\n",
165+
" publisher_email: nsidc@nsidc.org\n",
166+
" publisher_url: http://nsidc.org/daac/\n",
167+
" title: ATLAS/ICESat-2 L2A Global Geolocated ...\n",
168+
" identifier_file_product_type: ATL03\n",
169+
" institution: National Aeronautics and Space Admini...\n",
170+
" creator_name: GSFC I-SIPS > ICESat-2 Science Invest...\n",
171+
" summary: The purpose of ATL03 is to provide al...\n",
172+
" keywords: EARTH SCIENCE > CRYOSPHERE > SEA ICE ...\n",
173+
" keywords_vocabulary: NASA/GCMD Science Keywords\n",
174+
" citation: Cite these data in publications as fo...\n",
175+
" processing_level: 2A\n",
176+
" references: http://nsidc.org/data/icesat2/data.html\n",
177+
" project: ICESat-2 > Ice, Cloud, and land Eleva...\n",
178+
" instrument: ATLAS > Advanced Topographic Laser Al...\n",
179+
" platform: ICESat-2 > Ice, Cloud, and land Eleva...\n",
180+
" source: Spacecraft"
181+
]
182+
},
183+
"execution_count": 11,
184+
"metadata": {},
185+
"output_type": "execute_result"
186+
}
187+
],
188+
"source": [
189+
"ds"
190+
]
191+
}
192+
],
193+
"metadata": {
194+
"kernelspec": {
195+
"display_name": "Python 3",
196+
"language": "python",
197+
"name": "python3"
198+
},
199+
"language_info": {
200+
"codemirror_mode": {
201+
"name": "ipython",
202+
"version": 3
203+
},
204+
"file_extension": ".py",
205+
"mimetype": "text/x-python",
206+
"name": "python",
207+
"nbconvert_exporter": "python",
208+
"pygments_lexer": "ipython3",
209+
"version": "3.6.7"
210+
}
211+
},
212+
"nbformat": 4,
213+
"nbformat_minor": 2
214+
}

0 commit comments

Comments
 (0)