Skip to content

Commit aad4e18

Browse files
committed
add crs to geodataframes to address #43
emptyframe as geodataframe with crs save crs as attribute to netcdf and hdf5 files add file load and save widgets Create postBuild match requirements.txt with environment.yml move dockerfile to github workflow move polygon routines from ipysliderule to io use lat and lon keys for io observe load/save labels to set filename add sliderule commit and version to attributes
1 parent c36f762 commit aad4e18

File tree

9 files changed

+337
-109
lines changed

9 files changed

+337
-109
lines changed
File renamed without changes.

.github/workflows/aws-container.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,6 @@ jobs:
5151
# Build a docker container and
5252
# push it to ECR so that it can
5353
# be deployed to ECS.
54-
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
54+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \
55+
--file $GITHUB_ACTION_PATH/Dockerfile
5556
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG

environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ dependencies:
99
- ipykernel
1010
- ipywidgets
1111
- ipyleaflet
12+
- tk
1213
- matplotlib
1314
- numpy
1415
- pandas

examples/api_widgets_demo.ipynb

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"execution_count": null,
2727
"source": [
2828
"from sliderule import icesat2, ipysliderule, io\n",
29-
"import time\n",
3029
"import logging\n",
3130
"import numpy as np\n",
3231
"import matplotlib.pyplot as plt\n",
@@ -107,8 +106,6 @@
107106
"# sliderule asset and data release\n",
108107
"asset = SRwidgets.asset.value\n",
109108
"release = SRwidgets.release.value\n",
110-
"# get sliderule submission time\n",
111-
"submission_time = time.strftime('%Y%m%d%H%M%S',time.gmtime())\n",
112109
"\n",
113110
"# create an empty dataframe\n",
114111
"gdf = icesat2.__emptyframe()\n",
@@ -163,7 +160,7 @@
163160
"# output map of resource location\n",
164161
"f1, ax1 = plt.subplots(num=1, nrows=1, ncols=1, figsize=(10,6),\n",
165162
" subplot_kw=dict(projection=cartopy.crs.PlateCarree()))\n",
166-
"ax1.plot(gdf.geometry.values.x,gdf.geometry.values.y,'r.',\n",
163+
"ax1.plot(gdf.geometry.x,gdf.geometry.y,'r.',\n",
167164
" ms=1,transform=cartopy.crs.Geodetic())\n",
168165
"ax1.set_extent((-180,180,-90,90),crs=cartopy.crs.PlateCarree())\n",
169166
"# add coastlines with filled land and lakes\n",
@@ -182,12 +179,12 @@
182179
"f2, ax2 = plt.subplots(num=2, nrows=1, ncols=1, figsize=(10,6),\n",
183180
" subplot_kw=dict(projection=cartopy.crs.PlateCarree()))\n",
184181
"# create scatter plot of elevations\n",
185-
"sc = ax2.scatter(gdf.geometry.values.x,gdf.geometry.values.y,\n",
182+
"sc = ax2.scatter(gdf.geometry.x,gdf.geometry.y,\n",
186183
" c=gdf.h_mean,s=1,edgecolor='none',cmap=plt.cm.viridis,\n",
187184
" transform=cartopy.crs.PlateCarree())\n",
188185
"# extract latitude and longitude of polygon\n",
189186
"for poly in m.regions:\n",
190-
" lon,lat = ipysliderule.coordinates(poly)\n",
187+
" lon,lat = io.from_region(poly)\n",
191188
" ax2.plot(lon, lat, 'r', lw=1.5, transform=cartopy.crs.PlateCarree())\n",
192189
"# add coastlines with filled land and lakes\n",
193190
"ax2.add_feature(cartopy.feature.LAND, zorder=0, edgecolor='black')\n",
@@ -218,36 +215,66 @@
218215
{
219216
"cell_type": "markdown",
220217
"source": [
221-
"#### Save GeoDataFrame to HDF5\n",
222-
"Outputs as a [pytables](https://www.pytables.org/) HDF5 which is easily read back as a Geopandas GeoDataFrame"
218+
"#### Save GeoDataFrame to output tile\n",
219+
"- [pytables HDF5](https://www.pytables.org/): easily read back as a Geopandas GeoDataFrame\n",
220+
"- [netCDF](https://www.unidata.ucar.edu/software/netcdf): interoperable with other programs"
223221
],
224222
"metadata": {}
225223
},
226224
{
227225
"cell_type": "code",
228226
"execution_count": null,
229227
"source": [
230-
"args = (submission_time,release)\n",
231-
"io.to_file(gdf,\"ATL06-SR_{0}_{1}.h5\".format(*args),\n",
232-
" format='hdf', parameters=parms, regions=m.regions, verbose=True)"
228+
"display(SRwidgets.filesaver)"
229+
],
230+
"outputs": [],
231+
"metadata": {}
232+
},
233+
{
234+
"cell_type": "code",
235+
"execution_count": null,
236+
"source": [
237+
"# append sliderule api version to attributes\n",
238+
"version = icesat2.get_version()\n",
239+
"parms['version'] = version['icesat2']['version']\n",
240+
"parms['commit'] = version['icesat2']['commit']\n",
241+
"# save to file in format (HDF5 or netCDF)\n",
242+
"io.to_file(gdf, SRwidgets.file,\n",
243+
" format=SRwidgets.format,\n",
244+
" driver='pytables',\n",
245+
" parameters=parms,\n",
246+
" regions=m.regions,\n",
247+
" verbose=True)"
233248
],
234249
"outputs": [],
235250
"metadata": {}
236251
},
237252
{
238253
"cell_type": "markdown",
239254
"source": [
240-
"#### Read GeoDataFrame from HDF5\n",
241-
"Read the HDF5 back as a Geopandas GeoDataFrame for later use"
255+
"#### Read GeoDataFrame from input file\n",
256+
"- [pytables HDF5](https://www.pytables.org/)\n",
257+
"- [netCDF](https://www.unidata.ucar.edu/software/netcdf)"
242258
],
243259
"metadata": {}
244260
},
245261
{
246262
"cell_type": "code",
247263
"execution_count": null,
248264
"source": [
249-
"args = (submission_time,release)\n",
250-
"gdf = io.from_file(\"ATL06-SR_{0}_{1}.h5\".format(*args),format='hdf')"
265+
"display(SRwidgets.fileloader)"
266+
],
267+
"outputs": [],
268+
"metadata": {}
269+
},
270+
{
271+
"cell_type": "code",
272+
"execution_count": null,
273+
"source": [
274+
"# read from file in format (HDF5 or netCDF)\n",
275+
"gdf = io.from_file(SRwidgets.file,\n",
276+
" format=SRwidgets.format,\n",
277+
" driver='pytables')"
251278
],
252279
"outputs": [],
253280
"metadata": {}

postBuild

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
jupyter labextension install --clean @jupyter-widgets/jupyterlab-manager \
2+
jupyter-matplotlib jupyter-leaflet

requirements.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
requests
22
setuptools_scm
33
numpy
4+
ipykernel
5+
ipywidgets
6+
ipyleaflet
7+
tk
8+
matplotlib
9+
cartopy
10+
pandas
411
geopandas
12+
h5py
13+
pyproj
14+
scipy
15+
shapely

sliderule/icesat2.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,17 +278,22 @@ def __query_servers(max_workers):
278278
#
279279
# __emptyframe
280280
#
281-
def __emptyframe():
282-
return geopandas.pd.DataFrame()
281+
def __emptyframe(**kwargs):
282+
# set default keyword arguments
283+
kwargs['crs'] = "EPSG:4326"
284+
return geopandas.GeoDataFrame(crs=kwargs['crs'])
283285

284286
#
285287
# __todataframe
286288
#
287-
def __todataframe(columns, delta_time_key="delta_time", lon_key="lon", lat_key="lat", index_key="time"):
289+
def __todataframe(columns, delta_time_key="delta_time", lon_key="lon", lat_key="lat", **kwargs):
290+
# set default keyword arguments
291+
kwargs['index_key'] = "time"
292+
kwargs['crs'] = "EPSG:4326"
288293

289294
# Check Empty Columns
290295
if len(columns) <= 0:
291-
return __emptyframe()
296+
return __emptyframe(**kwargs)
292297

293298
# Generate Time Column
294299
delta_time = (columns[delta_time_key]*1e9).astype('timedelta64[ns]')
@@ -304,11 +309,11 @@ def __todataframe(columns, delta_time_key="delta_time", lon_key="lon", lat_key="
304309
df = geopandas.pd.DataFrame(columns)
305310

306311
# Build GeoDataFrame (default geometry is crs="EPSG:4326")
307-
gdf = geopandas.GeoDataFrame(df, geometry=geometry)
312+
gdf = geopandas.GeoDataFrame(df, geometry=geometry, crs=kwargs['crs'])
308313

309314
# Set index (default is Timestamp), can add `verify_integrity=True` to check for duplicates
310315
# Can do this during DataFrame creation, but this allows input argument for desired column
311-
gdf.set_index(index_key, inplace=True)
316+
gdf.set_index(kwargs['index_key'], inplace=True)
312317

313318
# Sort values for reproducible output despite async processing
314319
gdf.sort_index(inplace=True)

0 commit comments

Comments
 (0)