From 77430af92a865f69ff2da727fe28fedb60529c11 Mon Sep 17 00:00:00 2001 From: amsnyder <asnyder@usgs.gov> Date: Tue, 16 Jan 2024 11:01:05 -0600 Subject: [PATCH] add spatial step exploration to examples --- ..._collection_from_zarr_conus404-daily.ipynb | 82 ++++++++++++++++++- ...create_item_from_zarr_conus404-daily.ipynb | 82 ++++++++++++++++++- 2 files changed, 160 insertions(+), 4 deletions(-) diff --git a/workflows/examples/create_collection_from_zarr_conus404-daily.ipynb b/workflows/examples/create_collection_from_zarr_conus404-daily.ipynb index b79125ad..120e4947 100644 --- a/workflows/examples/create_collection_from_zarr_conus404-daily.ipynb +++ b/workflows/examples/create_collection_from_zarr_conus404-daily.ipynb @@ -553,6 +553,14 @@ "#### user review needed - looks at the steps pulled out and make sure they make sense" ] }, + { + "cell_type": "markdown", + "id": "9e2bbcc5-e45a-4b8c-9d60-601f345e8134", + "metadata": {}, + "source": [ + "**Time**" + ] + }, { "cell_type": "code", "execution_count": null, @@ -560,7 +568,7 @@ "metadata": {}, "outputs": [], "source": [ - "time_step = get_step(ds, dim_names_dict['T'])\n", + "time_step = pd.Timedelta(get_step(ds, dim_names_dict['T'])).isoformat()\n", "print(f'time step: {time_step}')" ] }, @@ -589,6 +597,14 @@ "# ds.isel(time=slice(ix-1,ix+3)).time" ] }, + { + "cell_type": "markdown", + "id": "9aa6c8ff-8d9b-40a7-a281-39b502bd5a3d", + "metadata": {}, + "source": [ + "**X/lon**" + ] + }, { "cell_type": "code", "execution_count": null, @@ -600,6 +616,41 @@ "print(f'x step: {x_step}')" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "fac4c9f2-a952-4c7f-aa32-862957372d6f", + "metadata": {}, + "outputs": [], + "source": [ + "# # debugging for spatial steps: get all step values and locations\n", + "# x_dim=dim_names_dict['X']\n", + "# x_step = get_step(ds, x_dim, debug=True, step_ix=1)\n", + "# print(f'\\nx dim name (for next cell): {x_dim}')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8d0b5a2d-dc58-4ad6-b890-859ce6bb08de", + "metadata": {}, + "outputs": [], + "source": [ + "# # debugging for spatial steps, cont:\n", + "# # please choose one of the index locations printed above\n", + "# # this will print the time steps adjacent to it\n", + "# ix = 5\n", + "# ds.isel(x=slice(ix-1,ix+3)).x" + ] + }, + { + "cell_type": "markdown", + "id": "21b5cca4-8bb4-498d-ae6b-6b8545fffe56", + "metadata": {}, + "source": [ + "**Y/lat**" + ] + }, { "cell_type": "code", "execution_count": null, @@ -611,6 +662,33 @@ "print(f'y step: {y_step}')" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "ece0fe37-b54c-4721-aa9b-33d2998d191b", + "metadata": {}, + "outputs": [], + "source": [ + "# # debugging for spatial steps: get all step values and locations\n", + "# y_dim=dim_names_dict['Y']\n", + "# y_step = get_step(ds, y_dim, debug=True, step_ix=1)\n", + "# print(f'\\nx dim name (for next cell): {x_dim}')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "abdafb8f-5217-4b82-91b6-eec8183c9128", + "metadata": {}, + "outputs": [], + "source": [ + "# # debugging for spatial steps, cont:\n", + "# # please choose one of the index locations printed above\n", + "# # this will print the time steps adjacent to it\n", + "# ix = 5\n", + "# ds.isel(y=slice(ix-1,ix+3)).y" + ] + }, { "cell_type": "markdown", "id": "00a5e041-081d-428d-ac2e-75d16de205e6", @@ -648,7 +726,7 @@ "\n", "# we do not recommend including redundant dimensions (do not include x,y if you have lon,lat)\n", "# note that the extent of each dimension should be pulled from the dataset\n", - "dims_dict = {dim_names_dict['T']: pystac.extensions.datacube.Dimension({'type': 'temporal', 'description': get_long_name(ds, dim_names_dict['T']), 'extent': [temporal_extent_lower.strftime('%Y-%m-%dT%XZ'), temporal_extent_upper.strftime('%Y-%m-%dT%XZ')], 'step': pd.Timedelta(time_step).isoformat()}),\n", + "dims_dict = {dim_names_dict['T']: pystac.extensions.datacube.Dimension({'type': 'temporal', 'description': get_long_name(ds, dim_names_dict['T']), 'extent': [temporal_extent_lower.strftime('%Y-%m-%dT%XZ'), temporal_extent_upper.strftime('%Y-%m-%dT%XZ')], 'step':time_step}),\n", " dim_names_dict['X']: pystac.extensions.datacube.Dimension({'type': 'spatial', 'axis': 'x', 'description': get_long_name(ds, dim_names_dict['X']), 'extent': [xy_bounds[0], xy_bounds[2]], 'step': x_step, 'reference_system': projjson}),\n", " dim_names_dict['Y']: pystac.extensions.datacube.Dimension({'type': 'spatial', 'axis': 'y', 'description': get_long_name(ds, dim_names_dict['Y']), 'extent': [xy_bounds[1], xy_bounds[3]], 'step': y_step, 'reference_system': projjson}),\n", " 'bottom_top_stag': pystac.extensions.datacube.Dimension({'type': 'spatial', 'axis': 'z', 'description': get_long_name(ds, 'bottom_top_stag')}),\n", diff --git a/workflows/examples/create_item_from_zarr_conus404-daily.ipynb b/workflows/examples/create_item_from_zarr_conus404-daily.ipynb index 3713cca8..c8d3f29b 100644 --- a/workflows/examples/create_item_from_zarr_conus404-daily.ipynb +++ b/workflows/examples/create_item_from_zarr_conus404-daily.ipynb @@ -563,6 +563,14 @@ "#### user review needed - looks at the steps pulled out and make sure they make sense" ] }, + { + "cell_type": "markdown", + "id": "18b8950f-030f-4f78-b9ac-799dc9263cb6", + "metadata": {}, + "source": [ + "**Time**" + ] + }, { "cell_type": "code", "execution_count": null, @@ -570,7 +578,7 @@ "metadata": {}, "outputs": [], "source": [ - "time_step = get_step(ds, dim_names_dict['T'])\n", + "time_step = pd.Timedelta(get_step(ds, dim_names_dict['T'])).isoformat()\n", "print(f'time step: {time_step}')" ] }, @@ -599,6 +607,14 @@ "# ds.isel(time=slice(ix-1,ix+3)).time" ] }, + { + "cell_type": "markdown", + "id": "c2898abe-ca26-4587-bc6d-531268547266", + "metadata": {}, + "source": [ + "**X/lon**" + ] + }, { "cell_type": "code", "execution_count": null, @@ -610,6 +626,41 @@ "print(f'x step: {x_step}')" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "2f29a57d-2203-4f49-9dea-c04c1362d685", + "metadata": {}, + "outputs": [], + "source": [ + "# # debugging for spatial steps: get all step values and locations\n", + "# x_dim=dim_names_dict['X']\n", + "# x_step = get_step(ds, x_dim, debug=True, step_ix=1)\n", + "# print(f'\\nx dim name (for next cell): {x_dim}')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "448714dd-4f57-4e74-99bc-c3b3de400231", + "metadata": {}, + "outputs": [], + "source": [ + "# # debugging for spatial steps, cont:\n", + "# # please choose one of the index locations printed above\n", + "# # this will print the time steps adjacent to it\n", + "# ix = 5\n", + "# ds.isel(x=slice(ix-1,ix+3)).x" + ] + }, + { + "cell_type": "markdown", + "id": "b40ef6ce-8830-4465-a960-f31357ac73ad", + "metadata": {}, + "source": [ + "**Y/lat**" + ] + }, { "cell_type": "code", "execution_count": null, @@ -621,6 +672,33 @@ "print(f'y step: {y_step}')" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "15975722-2f96-4a39-b904-c99cdf2921c3", + "metadata": {}, + "outputs": [], + "source": [ + "# # debugging for spatial steps: get all step values and locations\n", + "# y_dim=dim_names_dict['Y']\n", + "# y_step = get_step(ds, y_dim, debug=True, step_ix=1)\n", + "# print(f'\\nx dim name (for next cell): {x_dim}')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "142e62f0-412c-4e9b-a117-205c5a2c08af", + "metadata": {}, + "outputs": [], + "source": [ + "# # debugging for spatial steps, cont:\n", + "# # please choose one of the index locations printed above\n", + "# # this will print the time steps adjacent to it\n", + "# ix = 5\n", + "# ds.isel(y=slice(ix-1,ix+3)).y" + ] + }, { "cell_type": "markdown", "id": "00a5e041-081d-428d-ac2e-75d16de205e6", @@ -658,7 +736,7 @@ "\n", "# we do not recommend including redundant dimensions (do not include x,y if you have lon,lat)\n", "# note that the extent of each dimension should be pulled from the dataset\n", - "dims_dict = {dim_names_dict['T']: pystac.extensions.datacube.Dimension({'type': 'temporal', 'description': get_long_name(ds, dim_names_dict['T']), 'extent': [temporal_extent_lower.strftime('%Y-%m-%dT%XZ'), temporal_extent_upper.strftime('%Y-%m-%dT%XZ')], 'step': pd.Timedelta(time_step).isoformat()}),\n", + "dims_dict = {dim_names_dict['T']: pystac.extensions.datacube.Dimension({'type': 'temporal', 'description': get_long_name(ds, dim_names_dict['T']), 'extent': [temporal_extent_lower.strftime('%Y-%m-%dT%XZ'), temporal_extent_upper.strftime('%Y-%m-%dT%XZ')], 'step': time_step}),\n", " dim_names_dict['X']: pystac.extensions.datacube.Dimension({'type': 'spatial', 'axis': 'x', 'description': get_long_name(ds, dim_names_dict['X']), 'extent': [xy_bounds[0], xy_bounds[2]], 'step': x_step, 'reference_system': projjson}),\n", " dim_names_dict['Y']: pystac.extensions.datacube.Dimension({'type': 'spatial', 'axis': 'y', 'description': get_long_name(ds, dim_names_dict['Y']), 'extent': [xy_bounds[1], xy_bounds[3]], 'step': y_step, 'reference_system': projjson}),\n", " 'bottom_top_stag': pystac.extensions.datacube.Dimension({'type': 'spatial', 'axis': 'z', 'description': get_long_name(ds, 'bottom_top_stag')}),\n", -- GitLab