Skip to content

Commit ef4dc85

Browse files
authored
Merge pull request #35 from ICESat2-SlideRule/df_cleanup
icesat2: modifications to __todataframe
2 parents 70425b0 + 3942b22 commit ef4dc85

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

sliderule/icesat2.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def __emptyframe():
284284
#
285285
# __todataframe
286286
#
287-
def __todataframe(columns, delta_time_key="delta_time", lon_key="lon", lat_ley="lat"):
287+
def __todataframe(columns, delta_time_key="delta_time", lon_key="lon", lat_key="lat", index_key="time"):
288288

289289
# Check Empty Columns
290290
if len(columns) <= 0:
@@ -296,12 +296,21 @@ def __todataframe(columns, delta_time_key="delta_time", lon_key="lon", lat_ley="
296296
columns['time'] = geopandas.pd.to_datetime(atlas_sdp_epoch + delta_time)
297297

298298
# Generate Geometry Column
299-
geometry = geopandas.points_from_xy(columns[lon_key], columns[lat_ley])
299+
geometry = geopandas.points_from_xy(columns[lon_key], columns[lat_key])
300300
del columns[lon_key]
301-
del columns[lat_ley]
301+
del columns[lat_key]
302302

303-
# Build and Return GeoDataFrame (default geometry is crs="EPSG:4326")
303+
# Create Pandas DataFrame object
304304
df = geopandas.pd.DataFrame(columns)
305+
306+
# Set index (default is Timestamp), can add `verify_integrity=True` to check for duplicates
307+
# Can do this during DataFrame creation, but this allows input argument for desired column
308+
df.set_index(index_key, inplace=True)
309+
310+
# Sort values for reproducible output despite async processing
311+
df.sort_index(inplace=True)
312+
313+
# Build and Return GeoDataFrame (default geometry is crs="EPSG:4326")
305314
gdf = geopandas.GeoDataFrame(df, geometry=geometry)
306315
return gdf
307316

0 commit comments

Comments
 (0)