Skip to content

Commit b5bb8d7

Browse files
committed
small documentation updates to notebook, save output
1 parent 010b4cf commit b5bb8d7

File tree

1 file changed

+73
-29
lines changed

1 file changed

+73
-29
lines changed

jupyter-notebooks/basemaps_contributing_scene_metadata.ipynb

Lines changed: 73 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
{
3131
"cell_type": "code",
32-
"execution_count": null,
32+
"execution_count": 1,
3333
"id": "4a351534",
3434
"metadata": {},
3535
"outputs": [],
@@ -51,19 +51,20 @@
5151
},
5252
{
5353
"cell_type": "code",
54-
"execution_count": null,
54+
"execution_count": 2,
5555
"id": "fd44e418",
5656
"metadata": {},
5757
"outputs": [],
5858
"source": [
59-
"# We can use an environment variable saved on our computer to store our API key\n",
60-
"PLANET_API_KEY = os.getenv('PL_API_KEY')\n",
61-
"\n",
62-
"# Alternatively, we can just paste in our API \n",
63-
"# PLANET_API_KEY = \"YOUR_API_KEY_HERE\"\n",
59+
"# if your Planet API Key is not set as an environment variable, you can paste it below\n",
60+
"if 'PL_API_KEY' in os.environ:\n",
61+
" API_KEY = os.environ['PL_API_KEY']\n",
62+
"else:\n",
63+
" API_KEY = 'PASTE_YOUR_API_KEY_HERE'\n",
64+
" os.environ['PL_API_KEY'] = API_KEY\n",
6465
"\n",
6566
"# We can use our API key as the \"username\" in the basic auth method for our requests\n",
66-
"auth = HTTPBasicAuth(PLANET_API_KEY, '')"
67+
"auth = HTTPBasicAuth(API_KEY, '')"
6768
]
6869
},
6970
{
@@ -76,7 +77,7 @@
7677
},
7778
{
7879
"cell_type": "code",
79-
"execution_count": null,
80+
"execution_count": 3,
8081
"id": "67021bd8",
8182
"metadata": {},
8283
"outputs": [],
@@ -97,10 +98,20 @@
9798
},
9899
{
99100
"cell_type": "code",
100-
"execution_count": null,
101+
"execution_count": 4,
101102
"id": "8c5d6c1b",
102103
"metadata": {},
103-
"outputs": [],
104+
"outputs": [
105+
{
106+
"name": "stdout",
107+
"output_type": "stream",
108+
"text": [
109+
"Basemap Name: global_monthly_2022_05_mosaic\n",
110+
"Id: 045711ab-a3c1-455a-8a2e-b9ff3b699f8a\n",
111+
"Link: https://api.planet.com/basemaps/v1/mosaics/045711ab-a3c1-455a-8a2e-b9ff3b699f8a?api_key=PLAKd4412d77080146a8bdf3e629239a7b37\n"
112+
]
113+
}
114+
],
104115
"source": [
105116
"# Get basemap by name\n",
106117
"BASEMAP_NAME = 'global_monthly_2022_05_mosaic'\n",
@@ -127,12 +138,12 @@
127138
"source": [
128139
"### Define our area of interst\n",
129140
"\n",
130-
"We'll use a [GeoJSON geometry](https://datatracker.ietf.org/doc/html/rfc7946#section-3.1) to define our area of interest (region) to bound our search for quads in the basemap. The AOI can either be defined manually, or imported from a GeoJSON file on our computer."
141+
"We'll use a [GeoJSON geometry](https://datatracker.ietf.org/doc/html/rfc7946#section-3.1) to define our Area of Interest (AOI) to bound our search for quads in the basemap. The AOI can either be defined manually, or imported from a GeoJSON file on our computer."
131142
]
132143
},
133144
{
134145
"cell_type": "code",
135-
"execution_count": null,
146+
"execution_count": 5,
136147
"id": "f353484b",
137148
"metadata": {},
138149
"outputs": [],
@@ -170,8 +181,8 @@
170181
"#with open('path/to/my.geojson', 'r') as f:\n",
171182
"# aoi = json.load(f)['geometry']\n",
172183
"\n",
173-
"# Inspect our aoi\n",
174-
"#print(json.dumps(aoi, indent=1))"
184+
"# Inspect our AOI\n",
185+
"#print(json.dumps(AOI, indent=1))"
175186
]
176187
},
177188
{
@@ -192,17 +203,26 @@
192203
},
193204
{
194205
"cell_type": "code",
195-
"execution_count": null,
206+
"execution_count": 6,
196207
"id": "22805f17",
197208
"metadata": {
198209
"scrolled": false
199210
},
200-
"outputs": [],
211+
"outputs": [
212+
{
213+
"name": "stdout",
214+
"output_type": "stream",
215+
"text": [
216+
"\n",
217+
"Found 4 quads that intersect region.\n"
218+
]
219+
}
220+
],
201221
"source": [
202222
"# Construct the quad search url and pass our aoi as the json body to the POST request\n",
203223
"# https://api.planet.com/basemaps/v1/mosaics/BASEMAP_ID/quads/search\n",
204224
"quads_url = BASE_URL + BASEMAP_ID + '/quads/search'\n",
205-
"quads_res = requests.post(url=quads_url, auth=auth, json=aoi).json()\n",
225+
"quads_res = requests.post(url=quads_url, auth=auth, json=AOI).json()\n",
206226
"\n",
207227
"# The \"items\" list in the response contains the list on intersected quads\n",
208228
"quads = quads_res['items']\n",
@@ -235,7 +255,7 @@
235255
},
236256
{
237257
"cell_type": "code",
238-
"execution_count": null,
258+
"execution_count": 7,
239259
"id": "c2010092",
240260
"metadata": {},
241261
"outputs": [],
@@ -249,12 +269,20 @@
249269
},
250270
{
251271
"cell_type": "code",
252-
"execution_count": null,
272+
"execution_count": 8,
253273
"id": "fec994dd",
254274
"metadata": {
255275
"scrolled": false
256276
},
257-
"outputs": [],
277+
"outputs": [
278+
{
279+
"name": "stdout",
280+
"output_type": "stream",
281+
"text": [
282+
"Found 17 contributing scenes\n"
283+
]
284+
}
285+
],
258286
"source": [
259287
"# Get all contributing scenes for each quad\n",
260288
"\n",
@@ -294,7 +322,7 @@
294322
},
295323
{
296324
"cell_type": "code",
297-
"execution_count": null,
325+
"execution_count": 9,
298326
"id": "ac7e9312",
299327
"metadata": {},
300328
"outputs": [],
@@ -337,7 +365,7 @@
337365
},
338366
{
339367
"cell_type": "code",
340-
"execution_count": null,
368+
"execution_count": 10,
341369
"id": "470c2a7d",
342370
"metadata": {},
343371
"outputs": [],
@@ -436,27 +464,43 @@
436464
" # Report output\n",
437465
" print('\\nContributing Scenes GeoJSON FeatureCollection:')\n",
438466
" \n",
439-
" return contributing_scenes"
467+
" return\n",
468+
" # Note: un-comment the below line to see the full metadata for all contributing scenes\n",
469+
" # return contributing_scenes"
440470
]
441471
},
442472
{
443473
"cell_type": "code",
444-
"execution_count": null,
474+
"execution_count": 11,
445475
"id": "c2fe02ca",
446476
"metadata": {
447477
"scrolled": false
448478
},
449-
"outputs": [],
479+
"outputs": [
480+
{
481+
"name": "stdout",
482+
"output_type": "stream",
483+
"text": [
484+
"Mosaic Name: global_monthly_2022_05_mosaic\n",
485+
" Mosaic Id: 045711ab-a3c1-455a-8a2e-b9ff3b699f8a\n",
486+
" API Link: https://api.planet.com/basemaps/v1/mosaics/045711ab-a3c1-455a-8a2e-b9ff3b699f8a?api_key=PLAKd4412d77080146a8bdf3e629239a7b37\n",
487+
"\n",
488+
"Found 4 quads that intersect region.\n",
489+
"Found 17 contributing scenes\n",
490+
"Saved contributing scenes to file: global_monthly_2022_05_mosaic-contrib-scenes.geojson\n"
491+
]
492+
}
493+
],
450494
"source": [
451495
"# Example Usage:\n",
452496
"# Get contributing scenes for a region in the May 2022 Global Monthly basemap and save the output\n",
453-
"get_contributing_scenes_for_basemap_region('global_monthly_2022_05_mosaic', aoi, True)"
497+
"get_contributing_scenes_for_basemap_region('global_monthly_2022_05_mosaic', AOI, True)"
454498
]
455499
}
456500
],
457501
"metadata": {
458502
"kernelspec": {
459-
"display_name": "Python 3",
503+
"display_name": "Python 3 (ipykernel)",
460504
"language": "python",
461505
"name": "python3"
462506
},
@@ -470,7 +514,7 @@
470514
"name": "python",
471515
"nbconvert_exporter": "python",
472516
"pygments_lexer": "ipython3",
473-
"version": "3.5.6"
517+
"version": "3.8.13"
474518
}
475519
},
476520
"nbformat": 4,

0 commit comments

Comments
 (0)