Skip to content

Commit

Permalink
Merge branch 'development' of github.com:ICESat2-SlideRule/sliderule-…
Browse files Browse the repository at this point in the history
…python into development
  • Loading branch information
elidwa committed Jan 11, 2023
2 parents 73f5f74 + d829363 commit 586bf2c
Show file tree
Hide file tree
Showing 16 changed files with 517 additions and 162 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Example usage:
from sliderule import icesat2

# initialize
icesat2.init("slideruleearth.io", verbose=True)
icesat2.init("slideruleearth.io", verbose=False)

# region of interest
region = [ {"lon":-105.82971551223244, "lat": 39.81983728534918},
Expand Down
7 changes: 4 additions & 3 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ dependencies:
- geopandas
- h5py
- ipykernel
- ipywidgets>=7.6,<8.0
- ipyleaflet>=0.15
- jupyterlab=3
- ipywidgets
- ipyleaflet
- jupyterlab
- jupyterlab_widgets
- matplotlib
- ipympl
Expand All @@ -25,5 +25,6 @@ dependencies:
- shapely
- tk
- xyzservices
- pyarrow
- pip:
- -e ./
188 changes: 188 additions & 0 deletions examples/arcticdem.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "acb12a75-1636-471a-9649-48a408801d4f",
"metadata": {},
"outputs": [],
"source": [
"from sliderule import icesat2\n",
"import matplotlib.pyplot as plt\n",
"import matplotlib\n",
"import geopandas"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b8167cbe-3fe3-4dc9-a5ad-0cbba51c8a07",
"metadata": {},
"outputs": [],
"source": [
"icesat2.init(\"slideruleearth.io\", verbose=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "98ef750a-e88b-4125-b951-d1e29ce50ce2",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"asset = \"nsidc-s3\"\n",
"resource = \"ATL03_20190314093716_11600203_005_01.h5\"\n",
"region = icesat2.toregion(\"../tests/data/dicksonfjord.geojson\")\n",
"parms = { \"poly\": region['poly'],\n",
" \"cnf\": \"atl03_high\",\n",
" \"ats\": 5.0,\n",
" \"cnt\": 5,\n",
" \"len\": 20.0,\n",
" \"res\": 10.0,\n",
" \"maxi\": 1,\n",
" \"samples\": {\"mosaic\": {\"asset\": \"arcticdem-mosaic\", \"radius\": 10.0, \"zonal_stats\": True}} }\n",
"gdf = icesat2.atl06p(parms, asset=asset, resources=[resource])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fd15bf14-ab10-4cf6-9524-592962a8f8b2",
"metadata": {},
"outputs": [],
"source": [
"gdf"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "59ea096b-3443-4b9a-b114-e818f143ca45",
"metadata": {},
"outputs": [],
"source": [
"gdf[\"value_delta\"] = gdf[\"h_mean\"] - gdf[\"mosaic.value\"]\n",
"gdf[\"value_delta\"].describe()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f80cd750-9b91-406a-ac6a-dc04937cd811",
"metadata": {},
"outputs": [],
"source": [
"gdf[\"mean_delta\"] = gdf[\"h_mean\"] - gdf[\"mosaic.mean\"]\n",
"gdf[\"mean_delta\"].describe()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4e8fe135-bc15-4b8b-887f-ae16ac81487f",
"metadata": {},
"outputs": [],
"source": [
"gdf[\"median_delta\"] = gdf[\"h_mean\"] - gdf[\"mosaic.median\"]\n",
"gdf[\"median_delta\"].describe()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d6785ed8-cb0d-49cb-9de1-30ac5792884a",
"metadata": {},
"outputs": [],
"source": [
"# Setup Plot\n",
"fig,ax = plt.subplots(num=None, figsize=(10, 8))\n",
"fig.set_facecolor('white')\n",
"fig.canvas.header_visible = False\n",
"ax.set_title(\"SlideRule vs. ArcticDEM Elevations\")\n",
"ax.set_xlabel('UTC')\n",
"ax.set_ylabel('height (m)')\n",
"legend_elements = []\n",
"\n",
"# Plot SlideRule ATL06 Elevations\n",
"df = gdf[(gdf['rgt'] == 1160) & (gdf['gt'] == 10) & (gdf['cycle'] == 2)]\n",
"sc1 = ax.scatter(df.index.values, df[\"h_mean\"].values, c='red', s=2.5)\n",
"legend_elements.append(matplotlib.lines.Line2D([0], [0], color='red', lw=6, label='ATL06-SR'))\n",
"\n",
"# Plot ArcticDEM Elevations\n",
"sc2 = ax.scatter(df.index.values, df[\"mosaic.value\"].values, c='blue', s=2.5)\n",
"legend_elements.append(matplotlib.lines.Line2D([0], [0], color='blue', lw=6, label='ArcticDEM'))\n",
"\n",
"# Plot ArcticDEM Mean Elevations\n",
"sc2 = ax.scatter(df.index.values, df[\"mosaic.value\"].values, c='green', s=2.5)\n",
"legend_elements.append(matplotlib.lines.Line2D([0], [0], color='green', lw=6, label='ArcticDEM'))\n",
"\n",
"# Display Legend\n",
"lgd = ax.legend(handles=legend_elements, loc=3, frameon=True)\n",
"lgd.get_frame().set_alpha(1.0)\n",
"lgd.get_frame().set_edgecolor('white')\n",
"\n",
"# Show Plot\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "82c65e28-468e-463e-9afe-2b52064e7bae",
"metadata": {},
"outputs": [],
"source": [
"# Setup Plot\n",
"fig,ax = plt.subplots(num=None, figsize=(10, 8))\n",
"fig.set_facecolor('white')\n",
"fig.canvas.header_visible = False\n",
"ax.set_title(\"Delta Elevations between SlideRule and ArcticDEM\")\n",
"ax.set_xlabel('UTC')\n",
"ax.set_ylabel('height (m)')\n",
"ax.yaxis.grid(True)\n",
"\n",
"# Plot Deltas\n",
"df1 = gdf[(gdf['rgt'] == 1160) & (gdf['gt'] == 10) & (gdf['cycle'] == 2)]\n",
"sc1 = ax.scatter(df1.index.values, df1[\"value_delta\"].values, c='blue', s=2.5)\n",
"\n",
"# Plot Deltas\n",
"df2 = gdf[(gdf['rgt'] == 1160) & (gdf['gt'] == 10) & (gdf['cycle'] == 2)]\n",
"sc2 = ax.scatter(df2.index.values, df2[\"mean_delta\"].values, c='green', s=2.5)\n",
"\n",
"# Show Plot\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "eed8f243-dd0c-4473-a952-fcb2bb863e3c",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.15"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
58 changes: 32 additions & 26 deletions examples/voila_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"import warnings\n",
"import time\n",
"import json\n",
"from IPython.display import clear_output\n",
"from IPython import display\n",
"# atl03 plotting imports\n",
"import numpy as np\n",
"import matplotlib.lines\n",
Expand Down Expand Up @@ -158,12 +158,18 @@
},
"outputs": [],
"source": [
"# create ipyleaflet map in specified projection\n",
"m = ipysliderule.leaflet(SRwidgets.projection.value)\n",
"# install click handler callback\n",
"m.add_selected_callback(SRwidgets.atl06_click_handler)\n",
"display(m.map)\n",
"display(run_output)"
"def create_map(projection):\n",
" # create ipyleaflet map in specified projection\n",
" global m\n",
" m = ipysliderule.leaflet(projection)\n",
" # install click handler callback\n",
" m.add_selected_callback(SRwidgets.atl06_click_handler)\n",
" display.display(m.map)\n",
"\n",
"# interactively change map when projection widget is changed\n",
"out = widgets.interactive_output(create_map, dict(projection=SRwidgets.projection))\n",
"display.display(out)\n",
"display.display(run_output)"
]
},
{
Expand All @@ -189,17 +195,17 @@
" layers=SRwidgets.layers.value,\n",
" rendering_rule=SRwidgets.rendering_rule\n",
" )\n",
" \n",
"\n",
"# map widgets\n",
"display(widgets.VBox([\n",
"display.display(widgets.VBox([\n",
" SRwidgets.projection,\n",
" SRwidgets.layers,\n",
" SRwidgets.raster_functions\n",
"]))\n",
"\n",
"# update button\n",
"update_button.on_click(on_update_clicked)\n",
"display(update_button)"
"display.display(update_button)"
]
},
{
Expand Down Expand Up @@ -317,7 +323,7 @@
"def on_show_code06_clicked(b):\n",
" global url_textbox, atl06_parms\n",
" with show_code06_output:\n",
" clear_output()\n",
" display.clear_output()\n",
" print(f'icesat2.init(\"{url_textbox.value}\")')\n",
" print('parms = ', json.dumps(atl06_parms, indent=4), sep='')\n",
" print('gdf = icesat2.atl06p(parms, asset=\"nsidc-s3\")')\n",
Expand Down Expand Up @@ -355,7 +361,7 @@
" description='URL:',\n",
" disabled=False\n",
")\n",
"display(url_textbox)\n",
"display.display(url_textbox)\n",
"\n",
"# points to plot drop down\n",
"points_dropdown = widgets.Dropdown(\n",
Expand All @@ -366,7 +372,7 @@
")\n",
"\n",
"# display widgets for setting SlideRule parameters\n",
"display(widgets.VBox([\n",
"display.display(widgets.VBox([\n",
" SRwidgets.surface_type,\n",
" SRwidgets.length,\n",
" SRwidgets.step,\n",
Expand All @@ -384,9 +390,9 @@
"]))\n",
"\n",
"# display buttons\n",
"display(run_button)\n",
"display(refresh_button, refresh_output)\n",
"display(show_code06_button, show_code06_output)"
"display.display(run_button)\n",
"display.display(refresh_button, refresh_output)\n",
"display.display(show_code06_button, show_code06_output)"
]
},
{
Expand Down Expand Up @@ -553,7 +559,7 @@
"def on_show_code03_clicked(b):\n",
" global url_textbox, atl03_parms\n",
" with show_code03_output:\n",
" clear_output()\n",
" display.clear_output()\n",
" print(f'icesat2.init(\"{url_textbox.value}\")')\n",
" print('parms = ', json.dumps(atl03_parms, indent=4), sep='')\n",
" print('gdf = icesat2.atl03sp(parms, asset=\"nsidc-s3\")')\n",
Expand Down Expand Up @@ -590,14 +596,14 @@
" disabled = False,\n",
")\n",
"\n",
"display(SRwidgets.rgt)\n",
"display(SRwidgets.cycle)\n",
"display(SRwidgets.ground_track)\n",
"display(SRwidgets.plot_classification)\n",
"display(elev_dropdown)\n",
"display(pc_button)\n",
"display(pc_output)\n",
"display(show_code03_button, show_code03_output)"
"display.display(SRwidgets.rgt)\n",
"display.display(SRwidgets.cycle)\n",
"display.display(SRwidgets.ground_track)\n",
"display.display(SRwidgets.plot_classification)\n",
"display.display(elev_dropdown)\n",
"display.display(pc_button)\n",
"display.display(pc_output)\n",
"display.display(show_code03_button, show_code03_output)"
]
}
],
Expand Down Expand Up @@ -635,7 +641,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.15"
"version": "3.10.6"
},
"toc-showtags": false
},
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ numpy
fiona
geopandas
shapely
scikit-learn
scikit-learn
pyarrow
Loading

0 comments on commit 586bf2c

Please sign in to comment.