Skip to content

Commit

Permalink
demo updates for latest client
Browse files Browse the repository at this point in the history
  • Loading branch information
jpswinski committed May 3, 2024
1 parent 0b93ae3 commit 79f80bb
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 59 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Example notebooks that use SlideRule's Python client for processing Earth scienc
## Overview
Detailed [documentation](https://slideruleearth.io/rtd/) on installing and using the SlideRule Python client can be found at [slideruleearth.io](https://slideruleearth.io/).

> NOTE: As of 3/10/2023 the source code for SlideRule's Python client has moved to the [sliderule](https://github.com/ICESat2-SlideRule/sliderule) repository. This [sliderule-python](https://github.com/ICESat2-SlideRule/sliderule-python) repository continues to function as a collection of example notebooks that use the SlideRule Python client and demonstrate common workflows.
> NOTE: As of 3/10/2023 the source code for SlideRule's Python client has moved to the [sliderule](https://github.com/SlideRuleEarth/sliderule) repository. This [sliderule-python](https://github.com/SlideRuleEarth/sliderule-python) repository continues to function as a collection of example notebooks that use the SlideRule Python client and demonstrate common workflows.
## Getting Started

Expand Down
3 changes: 2 additions & 1 deletion demo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ demo-docker: # make the python client demo docker image; needs VERSION
cp ../environment.yml $(DEMO_STAGE_DIR)
cp voila_demo.ipynb $(DEMO_STAGE_DIR)
cp docker/demo/* $(DEMO_STAGE_DIR)
# cp -R ../../sliderule $(DEMO_STAGE_DIR) # used to install local copy of client (only if necessary during development, see dockerfile for additional steps)
# used to install local copy of client (only if necessary during development, see dockerfile for additional steps)
cp -R ../../sliderule $(DEMO_STAGE_DIR)
chmod +x $(DEMO_STAGE_DIR)/docker-entrypoint.sh
cd $(DEMO_STAGE_DIR) && docker build $(DOCKEROPTS) -t $(REPO)/demo-client:latest .
docker tag $(REPO)/demo-client:latest $(REPO)/demo-client:$(VERSION)
Expand Down
4 changes: 2 additions & 2 deletions demo/docker/demo/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ RUN conda install -c conda-forge voila
COPY voila_demo.ipynb /voila_demo.ipynb

# Local install of client (only if necessary)
# COPY sliderule /sliderule
# RUN cd /sliderule/clients/python && pip install .
COPY sliderule /sliderule
RUN cd /sliderule/clients/python && pip install .

# Entry point
COPY docker-entrypoint.sh /usr/local/etc/
Expand Down
95 changes: 41 additions & 54 deletions demo/voila_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@
"\n",
"#### SlideRule is an on-demand science data processing service that runs in the cloud and responds to REST API calls to process and return science results.\n",
"\n",
"This web page demonstrates a simple use of SlideRule to return elevations within a small region of interest using processing parameters specified at the time of the request. The web page is implemented inside a Jupyter Notebook using SlideRule's Python client, and is statically served using Voila. For more information on SlideRule, and how to install and use it for your own analysis applications, please see our website at [slideruleearth.io](https://slideruleearth.io).\n",
"This web page is _not_ SlideRule but is a demonstration of using public SlideRule APIs to return elevations within a small region of interest. The web page is implemented inside a Jupyter Notebook using SlideRule's Python client, and is statically served using Voila. For more information on SlideRule, and how to install and use it for your own analysis applications, please see our website at [slideruleearth.io](https://slideruleearth.io).\n",
"\n",
"| Step 1 | Step 2 | Step 3 | Step 4 | Step 5 |\n",
"|--------|--------|--------|--------|--------|\n",
"| Select Region of Interest | Choose Processing Parameters and Run SlideRule | Explore Data Points and Refresh Plot | Plot Photon Cloud of Ground Track | Build Your Own Notebook |\n",
"| Use the map to draw a polygon or bounding box around your region of interest. | Select the processing parameters to use to calculate geolocated elevations for the region of interest created above. Then click the \"Run SlideRule!\" button to initiate a https://github.com/ICESat2-SlideRule/sliderule-python/blob/main/examples/api_widgets_demo.ipynb request to SlideRule. Once all granules have been processed, the above map will be updated with a scatter plot of the different elevations. | The results are returned as a GeoDataFrame with multiple columns. Choose a field in the returned results to plot, and then click \"Refresh Plot\" to see the map updated with values from that column. | Enter the reference ground track, the cycle, and the individual ground track in the input boxes below. If you click on an individual elevation in the map, it will automatically populate these inputs with the correct values. | Check out our [API widgets demo](https://github.com/ICESat2-SlideRule/sliderule-python/blob/main/examples/api_widgets_demo.ipynb) for a guided walkthrough of how SlideRule works along with code you can use to start your own notebook. |"
"For more detailed example notebooks that use SlideRule APIs, check out these example notebooks at [github.com/SlideRuleEarth/sliderule-python](https://github.com/SlideRuleEarth/sliderule-python/tree/main/examples)."
]
},
{
Expand All @@ -45,7 +42,7 @@
}
},
"source": [
"## Segment Elevations ([atl06p](https://slideruleearth.io/rtd/api_reference/icesat2.html#atl06p))"
"### Surface Elevations ([atl06p](https://slideruleearth.io/rtd/api_reference/icesat2.html#atl06p))"
]
},
{
Expand All @@ -65,26 +62,8 @@
},
"outputs": [],
"source": [
"# load the necessary packages\n",
"from io import BytesIO\n",
"from sliderule import icesat2, ipysliderule, io, sliderule\n",
"import ipywidgets as widgets\n",
"import geopandas\n",
"import logging\n",
"import warnings\n",
"import base64\n",
"import time\n",
"import copy\n",
"import json\n",
"import re\n",
"from IPython import display\n",
"# atl03 plotting imports\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"# autoreload\n",
"%load_ext autoreload\n",
"%autoreload 2\n",
"%matplotlib inline"
"warnings.filterwarnings('ignore') # turn off warnings for demo"
]
},
{
Expand All @@ -104,8 +83,25 @@
},
"outputs": [],
"source": [
"# turn off warnings for demo\n",
"warnings.filterwarnings('ignore')"
"# load the necessary packages\n",
"from io import BytesIO\n",
"from sliderule import icesat2, ipysliderule, io, sliderule\n",
"import ipywidgets as widgets\n",
"import geopandas\n",
"import logging\n",
"import base64\n",
"import time\n",
"import copy\n",
"import json\n",
"import re\n",
"from IPython import display\n",
"# atl03 plotting imports\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"# autoreload\n",
"%load_ext autoreload\n",
"%autoreload 2\n",
"%matplotlib inline"
]
},
{
Expand All @@ -126,7 +122,6 @@
"outputs": [],
"source": [
"# create global variables\n",
"url_textbox = None\n",
"atl06_rsps = None\n",
"atl06_parms = None\n",
"SRwidgets = ipysliderule.widgets()\n",
Expand All @@ -142,7 +137,7 @@
"SRwidgets.file_format.options = [\"GeoJSON\",\"csv\",\"geoparquet\"]\n",
"SRwidgets.file_format.value = 'geoparquet'\n",
"show_code06_button = widgets.Button(description=\"Show Code\")\n",
"show_code06_output = widgets.Output()\n"
"show_code06_output = widgets.Output()"
]
},
{
Expand Down Expand Up @@ -251,18 +246,18 @@
"\n",
"# build and transmit requests to SlideRule\n",
"def runSlideRule():\n",
" global url_textbox, atl06_parms, granule_count\n",
" global atl06_parms, granule_count\n",
"\n",
" # reset granule count\n",
" granule_count = 0\n",
"\n",
" # set the url for the sliderule service\n",
" icesat2.init(url_textbox.value, loglevel=logging.ERROR, max_resources=1000)\n",
" icesat2.init(\"slideruleearth.io\", loglevel=logging.ERROR, max_resources=1000)\n",
"\n",
" # build sliderule parameters using latest values from widget\n",
" atl06_parms = {\n",
" # surface type: 0-land, 1-ocean, 2-sea ice, 3-land ice, 4-inland water\n",
" \"srt\": SRwidgets.surface_type.index,\n",
" \"srt\": icesat2.SRT_DYNAMIC,\n",
" # length of ATL06-SR segment in meters\n",
" \"len\": SRwidgets.length.value,\n",
" # step distance for successive ATL06-SR segments in meters\n",
Expand Down Expand Up @@ -362,7 +357,7 @@
" global url_textbox, atl06_parms\n",
" with show_code06_output:\n",
" display.clear_output()\n",
" print(f'icesat2.init(\"{url_textbox.value}\")')\n",
" print(f'icesat2.init()')\n",
" # validate boolean entries to be in title case\n",
" atl06_json = json.dumps(atl06_parms, indent=4)\n",
" atl06_json = re.sub(r'\\b(true|false)', lambda m: m.group(1).title(), atl06_json)\n",
Expand Down Expand Up @@ -428,15 +423,6 @@
},
"outputs": [],
"source": [
"# url input text box\n",
"url_textbox = widgets.Text(\n",
" value='slideruleearth.io',\n",
" placeholder='Input box for SlideRule url',\n",
" description='URL:',\n",
" disabled=False\n",
")\n",
"display.display(url_textbox)\n",
"\n",
"# points to plot drop down\n",
"points_dropdown = widgets.Dropdown(\n",
" options = [\"10K\", \"100K\", \"all\"],\n",
Expand All @@ -447,7 +433,6 @@
"\n",
"# display widgets for setting SlideRule parameters\n",
"display.display(widgets.VBox([\n",
" SRwidgets.surface_type,\n",
" SRwidgets.length,\n",
" SRwidgets.step,\n",
" SRwidgets.confidence,\n",
Expand Down Expand Up @@ -517,7 +502,7 @@
}
},
"source": [
"## Photon Cloud ([atl03sp](https://slideruleearth.io/rtd/api_reference/icesat2.html#atl03sp))"
"### Photon Cloud ([atl03sp](https://slideruleearth.io/rtd/api_reference/icesat2.html#atl03sp))"
]
},
{
Expand All @@ -543,19 +528,14 @@
"%matplotlib widget\n",
"# ATL03 Subsetter\n",
"def runATL03Subsetter():\n",
" global url_textbox, atl03_parms\n",
" global atl03_parms\n",
"\n",
" # set the url for the sliderule service\n",
" if url_textbox.value == 'local':\n",
" url = 'host.docker.internal'\n",
" else:\n",
" url = url_textbox.value\n",
" icesat2.init(url, loglevel=logging.ERROR)\n",
" icesat2.init(\"slideruleearth.io\", loglevel=logging.ERROR)\n",
"\n",
" # build sliderule parameters using latest values from widget\n",
" atl03_parms = {\n",
" # processing parameters\n",
" \"srt\": SRwidgets.surface_type.index,\n",
" \"srt\": icesat2.SRT_DYNAMIC,\n",
" \"len\": SRwidgets.length.value,\n",
" \"res\": SRwidgets.step.value,\n",
"\n",
Expand Down Expand Up @@ -638,7 +618,7 @@
" global url_textbox, atl03_parms\n",
" with show_code03_output:\n",
" display.clear_output()\n",
" print(f'icesat2.init(\"{url_textbox.value}\")')\n",
" print(f'icesat2.init()')\n",
" # validate boolean entries to be in title case\n",
" atl03_json = json.dumps(atl03_parms, indent=4)\n",
" atl03_json = re.sub(r'\\b(true|false)', lambda m: m.group(1).title(), atl03_json)\n",
Expand Down Expand Up @@ -694,6 +674,13 @@
"display.display(SRwidgets.HBox([download_atl03_button, SRwidgets.file_format]))\n",
"display.display(show_code03_button, show_code03_output)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down Expand Up @@ -730,7 +717,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
"version": "3.12.0"
},
"toc-showtags": false
},
Expand Down
2 changes: 1 addition & 1 deletion examples/atl03_subsetter.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
parser.add_argument('--ignore_poly_for_cmr', type=bool, default=None)
parser.add_argument('--name', type=str, default='output')
parser.add_argument('--no_geo', action='store_true', default=False)
parser.add_argument('--output_path', '-p', type=str, default="s3://sliderule/data/stage") # "hosted" tells sliderule to host results in a bucket it owns
parser.add_argument('--output_path', '-p', type=str, default="hosted") # "hosted" tells sliderule to host results in a bucket it owns
parser.add_argument('--timeout', '-t', type=int, default=600) # seconds
parser.add_argument('--generate', action='store_true', default=False)
parser.add_argument('--simulate_delay', type=float, default=1)
Expand Down

0 comments on commit 79f80bb

Please sign in to comment.