Skip to content

Commit

Permalink
Fixed a bug, added an example, and start of tests for Rectangular grid.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisBarker-NOAA committed Mar 8, 2025
1 parent 8b6282c commit a36410d
Show file tree
Hide file tree
Showing 12 changed files with 654 additions and 9,606 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ To run a shell to do dev work:
pixi shell -e dev
```

If you want to run the examples (notebooks and al that):

```bash
pixi shell -e all
```

That will set up a conda environment with all the develop dependencies.

To run a shell in which you can run the examples:
Expand Down Expand Up @@ -131,4 +137,4 @@ If you need the development tools, you can also install:
conda install --file conda_requirements_dev.txt
```

(requirements should all be on the conda-forge channel)
(requirements should all be on the conda-forge channel)
1 change: 1 addition & 0 deletions docs/examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
AMSEAS-subset.nc
194 changes: 194 additions & 0 deletions docs/examples/RegularGridTHREDDS.ipynb
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
}
2,391 changes: 89 additions & 2,302 deletions docs/examples/regular_grid_2d.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit a36410d

Please sign in to comment.