-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed a bug, added an example, and start of tests for Rectangular grid.
- Loading branch information
1 parent
8b6282c
commit a36410d
Showing
12 changed files
with
654 additions
and
9,606 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
AMSEAS-subset.nc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "e601719e-1253-4140-aa64-274c5a36f724", | ||
"metadata": {}, | ||
"source": [ | ||
"# subsetting a regular grid from an TDS source\n", | ||
"\n", | ||
"In this case, the Navy American Seas (AMSEAS) model, as provided by NCEI:\n", | ||
"\n", | ||
"https://www.ncei.noaa.gov/thredds-coastal/catalog/ncom_amseas_agg/catalog.html\n", | ||
"\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "caa476fd-2375-4a22-8981-5869bbff3eb5", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import xarray as xr\n", | ||
"import xarray_subset_grid\n", | ||
"from xarray_subset_grid.utils import format_bytes\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "f01dd841-7c89-47ba-8c16-a154bdee1b80", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# EXAMPLE (very small) subset:\n", | ||
"bbox = (268.0, 29.0, 269, 29.75)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"id": "f22007b0-f540-45a8-b974-e41c321cad0a", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# create an xarray dataset from the OpenDAP url\n", | ||
"ds = xr.open_dataset('https://www.ncei.noaa.gov/thredds-coastal/dodsC/ncom_amseas_agg/AmSeas_Dec_17_2020_to_Current_best.ncd')\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"id": "4f93c32b-bc4d-4e1e-af4c-dfa890729a20", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Dataset is: 10.0 TB\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(f\"Dataset is: {format_bytes(ds.nbytes)}\")\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"id": "5f4fde4a-39bf-491c-a57c-acc2f3216ffa", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# downscale in time (would be nice to make this smart, but for now:\n", | ||
"# 3 hour timesteps, last 12 timesteps is 3 days\n", | ||
"ds = ds.isel(time=slice(-12, None))\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"id": "ce852bd3-0485-4d59-9310-e35c2d8e0ce5", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Dataset is: 9.9 GB\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(f\"Dataset is: {format_bytes(ds.nbytes)}\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"id": "215d1a33-7bb6-47b5-9343-1e8ff6267103", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"ds_ss = ds.xsg.subset_bbox(bbox)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"id": "ee346b9f-8b5c-4f57-8c63-944c3a11febf", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Dataset is: 6.4 MB\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(f\"Dataset is: {format_bytes(ds_ss.nbytes)}\")\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"id": "f6487d58-5479-4c86-a927-0accc7f11209", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Save out the subset as a netcdf file.\n", | ||
"\n", | ||
"ds_ss.to_netcdf(\"AMSEAS-subset.nc\")\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "2536e8c5-5531-499a-a799-873be65fcd2f", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "549bda29-a996-49d0-be1d-89e8a30b18e2", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "66aa16b1-832e-4882-b974-526553f36bd9", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "240d4dc1-8a2b-4696-8cd1-eb1ee78c6ef8", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.12.7" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.