|
72 | 72 | "import logging\n", |
73 | 73 | "import warnings\n", |
74 | 74 | "import time\n", |
| 75 | + "import json\n", |
| 76 | + "from IPython.display import clear_output\n", |
75 | 77 | "# atl03 plotting imports\n", |
76 | 78 | "import numpy as np\n", |
77 | 79 | "import matplotlib.lines\n", |
|
123 | 125 | "# create global variables\n", |
124 | 126 | "url_textbox = None\n", |
125 | 127 | "atl06_rsps = None\n", |
126 | | - "parms = None\n", |
| 128 | + "atl06_parms = None\n", |
127 | 129 | "results = []\n", |
128 | 130 | "SRwidgets = ipysliderule.widgets()\n", |
129 | 131 | "points_dropdown = None\n", |
130 | 132 | "update_button = widgets.Button(description=\"Update Map\")\n", |
131 | 133 | "run_button = widgets.Button(description=\"Run SlideRule!\")\n", |
132 | 134 | "run_output = widgets.Output()\n", |
133 | 135 | "refresh_button = widgets.Button(description=\"Refresh Plot\")\n", |
134 | | - "refresh_output = widgets.Output()" |
| 136 | + "refresh_output = widgets.Output()\n", |
| 137 | + "show_code06_button = widgets.Button(description=\"Show Code\")\n", |
| 138 | + "show_code06_output = widgets.Output()" |
135 | 139 | ] |
136 | 140 | }, |
137 | 141 | { |
|
228 | 232 | "\n", |
229 | 233 | "# build and transmit requests to SlideRule\n", |
230 | 234 | "def runSlideRule():\n", |
231 | | - " global url_textbox, parms, results\n", |
| 235 | + " global url_textbox, atl06_parms, results\n", |
232 | 236 | " \n", |
233 | 237 | " # set the url for the sliderule service\n", |
234 | 238 | " icesat2.init(url_textbox.value, loglevel=logging.ERROR, max_resources=1000)\n", |
|
237 | 241 | " asset = SRwidgets.asset.value\n", |
238 | 242 | "\n", |
239 | 243 | " # build sliderule parameters using latest values from widget\n", |
240 | | - " parms = {\n", |
| 244 | + " atl06_parms = {\n", |
241 | 245 | " # surface type: 0-land, 1-ocean, 2-sea ice, 3-land ice, 4-inland water\n", |
242 | 246 | " \"srt\": SRwidgets.surface_type.index,\n", |
243 | 247 | " # length of ATL06-SR segment in meters\n", |
|
267 | 271 | " # for each region of interest\n", |
268 | 272 | " for poly in m.regions:\n", |
269 | 273 | " # add polygon from map to sliderule parameters\n", |
270 | | - " parms[\"poly\"] = poly \n", |
| 274 | + " atl06_parms[\"poly\"] = poly \n", |
271 | 275 | " # make the request to the SlideRule (ATL06-SR) endpoint\n", |
272 | 276 | " # and pass it the request parameters to request ATL06 Data\n", |
273 | | - " gdf = gdf.append(icesat2.atl06p(parms, asset, callbacks={'eventrec': demo_logeventrec, 'exceptrec': demo_exceptrec}))\n", |
| 277 | + " gdf = gdf.append(icesat2.atl06p(atl06_parms, asset, callbacks={'eventrec': demo_logeventrec, 'exceptrec': demo_exceptrec}))\n", |
274 | 278 | " \n", |
275 | 279 | " return gdf\n", |
276 | 280 | "\n", |
|
309 | 313 | " print(f'Plotting {max_plot_points} of {atl06_rsps.shape[0]} elevations. This may take 10-60+ seconds for larger point datasets.')\n", |
310 | 314 | " m.GeoData(atl06_rsps, column_name=SRwidgets.variable.value, cmap=SRwidgets.colormap, max_plot_points=max_plot_points)\n", |
311 | 315 | "\n", |
| 316 | + "# show code action\n", |
| 317 | + "def on_show_code06_clicked(b):\n", |
| 318 | + " global url_textbox, atl06_parms\n", |
| 319 | + " with show_code06_output:\n", |
| 320 | + " clear_output()\n", |
| 321 | + " print(f'icesat2.init(\"{url_textbox.value}\")')\n", |
| 322 | + " print('parms = ', json.dumps(atl06_parms, indent=4), sep='')\n", |
| 323 | + " print('gdf = icesat2.atl06p(parms, asset=\"nsidc-s3\")')\n", |
| 324 | + " \n", |
312 | 325 | "# link buttons\n", |
313 | 326 | "run_button.on_click(on_run_clicked)\n", |
314 | | - "refresh_button.on_click(on_refresh_clicked)" |
| 327 | + "refresh_button.on_click(on_refresh_clicked)\n", |
| 328 | + "show_code06_button.on_click(on_show_code06_clicked)" |
315 | 329 | ] |
316 | 330 | }, |
317 | 331 | { |
|
371 | 385 | "\n", |
372 | 386 | "# display buttons\n", |
373 | 387 | "display(run_button)\n", |
374 | | - "display(refresh_button, refresh_output)" |
| 388 | + "display(refresh_button, refresh_output)\n", |
| 389 | + "display(show_code06_button, show_code06_output)" |
375 | 390 | ] |
376 | 391 | }, |
377 | 392 | { |
|
393 | 408 | "source": [ |
394 | 409 | "# globals for atl03 processing\n", |
395 | 410 | "atl03_rsps = None\n", |
| 411 | + "atl03_parms = None\n", |
| 412 | + "show_code03_button = widgets.Button(description=\"Show Code\")\n", |
| 413 | + "show_code03_output = widgets.Output()\n", |
396 | 414 | "elev_dropdown = None\n", |
397 | 415 | "pc_button = widgets.Button(description=\"Plot Photon Cloud\")\n", |
398 | 416 | "pc_output = widgets.Output()\n", |
|
445 | 463 | "%matplotlib widget\n", |
446 | 464 | "# ATL03 Subsetter\n", |
447 | 465 | "def runATL03Subsetter():\n", |
448 | | - " global url_textbox, parms\n", |
| 466 | + " global url_textbox, atl03_parms\n", |
449 | 467 | " \n", |
450 | 468 | " # set the url for the sliderule service\n", |
451 | 469 | " if url_textbox.value == 'local':\n", |
|
458 | 476 | " asset = SRwidgets.asset.value\n", |
459 | 477 | "\n", |
460 | 478 | " # build sliderule parameters using latest values from widget\n", |
461 | | - " parms = {\n", |
| 479 | + " atl03_parms = {\n", |
462 | 480 | " # processing parameters\n", |
463 | 481 | " \"srt\": SRwidgets.surface_type.index,\n", |
464 | 482 | " \"len\": SRwidgets.length.value,\n", |
|
482 | 500 | " }\n", |
483 | 501 | "\n", |
484 | 502 | " # make call to sliderule\n", |
485 | | - " rsps = icesat2.atl03sp(parms, asset)\n", |
| 503 | + " rsps = icesat2.atl03sp(atl03_parms, asset)\n", |
486 | 504 | " \n", |
487 | 505 | " # return geodataframe\n", |
488 | 506 | " return rsps\n", |
|
529 | 547 | " SRwidgets.ground_track.value = gt2str[feature[\"properties\"][\"gt\"]]\n", |
530 | 548 | "\n", |
531 | 549 | "# install click handler callback\n", |
532 | | - "m.add_selected_callback(click_handler)" |
| 550 | + "m.add_selected_callback(click_handler)\n", |
| 551 | + "\n", |
| 552 | + "# show code action\n", |
| 553 | + "def on_show_code03_clicked(b):\n", |
| 554 | + " global url_textbox, atl03_parms\n", |
| 555 | + " with show_code03_output:\n", |
| 556 | + " clear_output()\n", |
| 557 | + " print(f'icesat2.init(\"{url_textbox.value}\")')\n", |
| 558 | + " print('parms = ', json.dumps(atl03_parms, indent=4), sep='')\n", |
| 559 | + " print('gdf = icesat2.atl03sp(parms, asset=\"nsidc-s3\")')\n", |
| 560 | + " \n", |
| 561 | + "# install click handler callback\n", |
| 562 | + "show_code03_button.on_click(on_show_code03_clicked)" |
533 | 563 | ] |
534 | 564 | }, |
535 | 565 | { |
|
566 | 596 | "display(SRwidgets.plot_classification)\n", |
567 | 597 | "display(elev_dropdown)\n", |
568 | 598 | "display(pc_button)\n", |
569 | | - "display(pc_output)" |
| 599 | + "display(pc_output)\n", |
| 600 | + "display(show_code03_button, show_code03_output)" |
570 | 601 | ] |
571 | 602 | } |
572 | 603 | ], |
|
604 | 635 | "name": "python", |
605 | 636 | "nbconvert_exporter": "python", |
606 | 637 | "pygments_lexer": "ipython3", |
607 | | - "version": "3.10.6" |
| 638 | + "version": "3.8.15" |
608 | 639 | }, |
609 | 640 | "toc-showtags": false |
610 | 641 | }, |
|
0 commit comments