Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Along track views of height change over time #99

Merged
merged 4 commits into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions atl11_play.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"import hvplot.pandas\n",
"import hvplot.xarray\n",
"\n",
"# import intake\n",
"import intake\n",
"import geopandas as gpd\n",
"import numpy as np\n",
"import pandas as pd\n",
Expand Down Expand Up @@ -123,6 +123,15 @@
},
"outputs": [],
"source": [
"# Xarray open_dataset preprocessor to add fields based on input filename.\n",
"# Adapted from the intake.open_netcdf._add_path_to_ds function.\n",
"add_path_to_ds = lambda ds: ds.assign_coords(\n",
" coords=intake.source.utils.reverse_format(\n",
" format_string=\"ATL11.001z123/ATL11_{referencegroundtrack:04d}1x_{mincycle:02d}{maxcycle:02d}_{}_v{}.zarr\",\n",
" resolved_string=ds.encoding[\"source\"],\n",
" )\n",
")\n",
"\n",
"# Load dataset from all Zarr stores\n",
"# Aligning chunks spatially along cycle_number (i.e. time)\n",
"ds: xr.Dataset = xr.open_mfdataset(\n",
Expand All @@ -132,6 +141,7 @@
" combine=\"nested\",\n",
" concat_dim=\"ref_pt\",\n",
" parallel=\"True\",\n",
" preprocess=add_path_to_ds,\n",
" backend_kwargs={\"consolidated\": True},\n",
")\n",
"# ds = ds.unify_chunks().compute()\n",
Expand Down Expand Up @@ -306,11 +316,9 @@
"source": [
"# Save to Zarr/NetCDF formats for distribution\n",
"ds_subset.to_zarr(\n",
" store=f\"ATLXI/ds_subset_{placename}.zarr\", mode=\"w\", consolidated=True,\n",
" store=f\"ATLXI/ds_subset_{placename}.zarr\", mode=\"w\", consolidated=True\n",
")\n",
"ds_subset.to_netcdf(\n",
" path=f\"ATLXI/ds_subset_{placename}.nc\", engine=\"h5netcdf\",\n",
")"
"ds_subset.to_netcdf(path=f\"ATLXI/ds_subset_{placename}.nc\", engine=\"h5netcdf\")"
]
},
{
Expand All @@ -324,7 +332,7 @@
" data=ds_subset.sel(cycle_number=7)[[*essential_columns]],\n",
" label=\"Cycle_7\",\n",
" kdims=[\"x\", \"y\"],\n",
" vdims=[\"utc_time\", \"h_corr\", \"cycle_number\"],\n",
" vdims=[\"utc_time\", \"h_corr\", \"cycle_number\", \"referencegroundtrack\"],\n",
" datatype=[\"xarray\"],\n",
")\n",
"df_subset = points_subset.dframe()"
Expand All @@ -343,10 +351,12 @@
" title=f\"Elevation (metres) at Cycle 7\",\n",
" x=\"x\",\n",
" y=\"y\",\n",
" c=\"h_corr\",\n",
" cmap=\"Blues\",\n",
" rasterize=True,\n",
" c=\"referencegroundtrack\",\n",
" cmap=\"Set3\",\n",
" # rasterize=True,\n",
" hover=True,\n",
" datashade=True,\n",
" dynspread=True,\n",
")"
]
},
Expand Down Expand Up @@ -726,13 +736,13 @@
" grid=agg_grid,\n",
" region=region.bounds(),\n",
" projection=f\"x1:{scale}\",\n",
" frame=[\"afg\", f'WSne+t\"ICESat-2 Ice Surface Change over {region.name}\"',],\n",
" frame=[\"afg\", f'WSne+t\"ICESat-2 Ice Surface Change over {region.name}\"'],\n",
" Q=True,\n",
")\n",
"for subglacial_lake in subglacial_lakes:\n",
" fig.plot(data=subglacial_lake, L=True, pen=\"thinnest\")\n",
"fig.colorbar(\n",
" position=\"JCR+e\", frame=[\"af\", 'x+l\"Elevation Change from Cycle 5 to 6\"', \"y+lm\"],\n",
" position=\"JCR+e\", frame=[\"af\", 'x+l\"Elevation Change from Cycle 5 to 6\"', \"y+lm\"]\n",
")\n",
"fig.savefig(f\"figures/plot_atl11_dh56_{placename}.png\")\n",
"fig.show(width=600)"
Expand Down Expand Up @@ -854,7 +864,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.2"
"version": "3.8.3"
}
},
"nbformat": 4,
Expand Down
34 changes: 22 additions & 12 deletions atl11_play.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# extension: .py
# format_name: hydrogen
# format_version: '1.3'
# jupytext_version: 1.4.2
# jupytext_version: 1.5.0
# kernelspec:
# display_name: deepicedrain
# language: python
Expand Down Expand Up @@ -34,7 +34,7 @@
import hvplot.pandas
import hvplot.xarray

# import intake
import intake
import geopandas as gpd
import numpy as np
import pandas as pd
Expand Down Expand Up @@ -63,6 +63,15 @@
print(f"{len(stores)} reference ground track Zarr stores")

# %%
# Xarray open_dataset preprocessor to add fields based on input filename.
# Adapted from the intake.open_netcdf._add_path_to_ds function.
add_path_to_ds = lambda ds: ds.assign_coords(
coords=intake.source.utils.reverse_format(
format_string="ATL11.001z123/ATL11_{referencegroundtrack:04d}1x_{mincycle:02d}{maxcycle:02d}_{}_v{}.zarr",
resolved_string=ds.encoding["source"],
)
)

# Load dataset from all Zarr stores
# Aligning chunks spatially along cycle_number (i.e. time)
ds: xr.Dataset = xr.open_mfdataset(
Expand All @@ -72,6 +81,7 @@
combine="nested",
concat_dim="ref_pt",
parallel="True",
preprocess=add_path_to_ds,
backend_kwargs={"consolidated": True},
)
# ds = ds.unify_chunks().compute()
Expand Down Expand Up @@ -178,19 +188,17 @@
# %%
# Save to Zarr/NetCDF formats for distribution
ds_subset.to_zarr(
store=f"ATLXI/ds_subset_{placename}.zarr", mode="w", consolidated=True,
)
ds_subset.to_netcdf(
path=f"ATLXI/ds_subset_{placename}.nc", engine="h5netcdf",
store=f"ATLXI/ds_subset_{placename}.zarr", mode="w", consolidated=True
)
ds_subset.to_netcdf(path=f"ATLXI/ds_subset_{placename}.nc", engine="h5netcdf")

# %%
# Look at Cycle Number 7 only for plotting
points_subset = hv.Points(
data=ds_subset.sel(cycle_number=7)[[*essential_columns]],
label="Cycle_7",
kdims=["x", "y"],
vdims=["utc_time", "h_corr", "cycle_number"],
vdims=["utc_time", "h_corr", "cycle_number", "referencegroundtrack"],
datatype=["xarray"],
)
df_subset = points_subset.dframe()
Expand All @@ -201,10 +209,12 @@
title=f"Elevation (metres) at Cycle 7",
x="x",
y="y",
c="h_corr",
cmap="Blues",
rasterize=True,
c="referencegroundtrack",
cmap="Set3",
# rasterize=True,
hover=True,
datashade=True,
dynspread=True,
)


Expand Down Expand Up @@ -359,13 +369,13 @@
grid=agg_grid,
region=region.bounds(),
projection=f"x1:{scale}",
frame=["afg", f'WSne+t"ICESat-2 Ice Surface Change over {region.name}"',],
frame=["afg", f'WSne+t"ICESat-2 Ice Surface Change over {region.name}"'],
Q=True,
)
for subglacial_lake in subglacial_lakes:
fig.plot(data=subglacial_lake, L=True, pen="thinnest")
fig.colorbar(
position="JCR+e", frame=["af", 'x+l"Elevation Change from Cycle 5 to 6"', "y+lm"],
position="JCR+e", frame=["af", 'x+l"Elevation Change from Cycle 5 to 6"', "y+lm"]
)
fig.savefig(f"figures/plot_atl11_dh56_{placename}.png")
fig.show(width=600)
Expand Down
Loading