|
29 | 29 | }, |
30 | 30 | { |
31 | 31 | "cell_type": "code", |
32 | | - "execution_count": null, |
| 32 | + "execution_count": 1, |
33 | 33 | "id": "4a351534", |
34 | 34 | "metadata": {}, |
35 | 35 | "outputs": [], |
|
51 | 51 | }, |
52 | 52 | { |
53 | 53 | "cell_type": "code", |
54 | | - "execution_count": null, |
| 54 | + "execution_count": 2, |
55 | 55 | "id": "fd44e418", |
56 | 56 | "metadata": {}, |
57 | 57 | "outputs": [], |
58 | 58 | "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", |
64 | 65 | "\n", |
65 | 66 | "# 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, '')" |
67 | 68 | ] |
68 | 69 | }, |
69 | 70 | { |
|
76 | 77 | }, |
77 | 78 | { |
78 | 79 | "cell_type": "code", |
79 | | - "execution_count": null, |
| 80 | + "execution_count": 3, |
80 | 81 | "id": "67021bd8", |
81 | 82 | "metadata": {}, |
82 | 83 | "outputs": [], |
|
97 | 98 | }, |
98 | 99 | { |
99 | 100 | "cell_type": "code", |
100 | | - "execution_count": null, |
| 101 | + "execution_count": 4, |
101 | 102 | "id": "8c5d6c1b", |
102 | 103 | "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 | + ], |
104 | 115 | "source": [ |
105 | 116 | "# Get basemap by name\n", |
106 | 117 | "BASEMAP_NAME = 'global_monthly_2022_05_mosaic'\n", |
|
127 | 138 | "source": [ |
128 | 139 | "### Define our area of interst\n", |
129 | 140 | "\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." |
131 | 142 | ] |
132 | 143 | }, |
133 | 144 | { |
134 | 145 | "cell_type": "code", |
135 | | - "execution_count": null, |
| 146 | + "execution_count": 5, |
136 | 147 | "id": "f353484b", |
137 | 148 | "metadata": {}, |
138 | 149 | "outputs": [], |
|
170 | 181 | "#with open('path/to/my.geojson', 'r') as f:\n", |
171 | 182 | "# aoi = json.load(f)['geometry']\n", |
172 | 183 | "\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))" |
175 | 186 | ] |
176 | 187 | }, |
177 | 188 | { |
|
192 | 203 | }, |
193 | 204 | { |
194 | 205 | "cell_type": "code", |
195 | | - "execution_count": null, |
| 206 | + "execution_count": 6, |
196 | 207 | "id": "22805f17", |
197 | 208 | "metadata": { |
198 | 209 | "scrolled": false |
199 | 210 | }, |
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 | + ], |
201 | 221 | "source": [ |
202 | 222 | "# Construct the quad search url and pass our aoi as the json body to the POST request\n", |
203 | 223 | "# https://api.planet.com/basemaps/v1/mosaics/BASEMAP_ID/quads/search\n", |
204 | 224 | "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", |
206 | 226 | "\n", |
207 | 227 | "# The \"items\" list in the response contains the list on intersected quads\n", |
208 | 228 | "quads = quads_res['items']\n", |
|
235 | 255 | }, |
236 | 256 | { |
237 | 257 | "cell_type": "code", |
238 | | - "execution_count": null, |
| 258 | + "execution_count": 7, |
239 | 259 | "id": "c2010092", |
240 | 260 | "metadata": {}, |
241 | 261 | "outputs": [], |
|
249 | 269 | }, |
250 | 270 | { |
251 | 271 | "cell_type": "code", |
252 | | - "execution_count": null, |
| 272 | + "execution_count": 8, |
253 | 273 | "id": "fec994dd", |
254 | 274 | "metadata": { |
255 | 275 | "scrolled": false |
256 | 276 | }, |
257 | | - "outputs": [], |
| 277 | + "outputs": [ |
| 278 | + { |
| 279 | + "name": "stdout", |
| 280 | + "output_type": "stream", |
| 281 | + "text": [ |
| 282 | + "Found 17 contributing scenes\n" |
| 283 | + ] |
| 284 | + } |
| 285 | + ], |
258 | 286 | "source": [ |
259 | 287 | "# Get all contributing scenes for each quad\n", |
260 | 288 | "\n", |
|
294 | 322 | }, |
295 | 323 | { |
296 | 324 | "cell_type": "code", |
297 | | - "execution_count": null, |
| 325 | + "execution_count": 9, |
298 | 326 | "id": "ac7e9312", |
299 | 327 | "metadata": {}, |
300 | 328 | "outputs": [], |
|
337 | 365 | }, |
338 | 366 | { |
339 | 367 | "cell_type": "code", |
340 | | - "execution_count": null, |
| 368 | + "execution_count": 10, |
341 | 369 | "id": "470c2a7d", |
342 | 370 | "metadata": {}, |
343 | 371 | "outputs": [], |
|
436 | 464 | " # Report output\n", |
437 | 465 | " print('\\nContributing Scenes GeoJSON FeatureCollection:')\n", |
438 | 466 | " \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" |
440 | 470 | ] |
441 | 471 | }, |
442 | 472 | { |
443 | 473 | "cell_type": "code", |
444 | | - "execution_count": null, |
| 474 | + "execution_count": 11, |
445 | 475 | "id": "c2fe02ca", |
446 | 476 | "metadata": { |
447 | 477 | "scrolled": false |
448 | 478 | }, |
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 | + ], |
450 | 494 | "source": [ |
451 | 495 | "# Example Usage:\n", |
452 | 496 | "# 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)" |
454 | 498 | ] |
455 | 499 | } |
456 | 500 | ], |
457 | 501 | "metadata": { |
458 | 502 | "kernelspec": { |
459 | | - "display_name": "Python 3", |
| 503 | + "display_name": "Python 3 (ipykernel)", |
460 | 504 | "language": "python", |
461 | 505 | "name": "python3" |
462 | 506 | }, |
|
470 | 514 | "name": "python", |
471 | 515 | "nbconvert_exporter": "python", |
472 | 516 | "pygments_lexer": "ipython3", |
473 | | - "version": "3.5.6" |
| 517 | + "version": "3.8.13" |
474 | 518 | } |
475 | 519 | }, |
476 | 520 | "nbformat": 4, |
|
0 commit comments