Skip to content

Add Basin 16: Arctic Ocean north of 80N - #118

Open
chengz2 wants to merge 6 commits into
NCAR:mainfrom
chengz2:arctic_80N
Open

chengz2 wants to merge 6 commits into
NCAR:mainfrom
chengz2:arctic_80N

Conversation

@chengz2

@chengz2 chengz2 commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

Also use genBasinMasks to specify basin code in compute_basin_reduction.py and drift.py.

@chengz2

chengz2 commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator Author

nb_templates/climo.ipynb still reads basin code using

basin_code = xr.open_dataset('/glade/work/gmarques/cesm/tx2_3/basin_masks/basin_masks_tx2_3v2_20250318.nc')['basin_masks']

This needs to be updated.

@chengz2

chengz2 commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator Author

Can we just save the basin code generated from genBasinMasks, so that the notebooks don't have to call genBasinMasks again.

nb_templates/climo.ipynb still reads basin code using

basin_code = xr.open_dataset('/glade/work/gmarques/cesm/tx2_3/basin_masks/basin_masks_tx2_3v2_20250318.nc')['basin_masks']

This needs to be updated.

@chengz2
chengz2 force-pushed the arctic_80N branch 2 times, most recently from e85ba04 to bed7489 Compare September 21, 2026 19:25
@chengz2

chengz2 commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator Author

Maritime and SouthernOcean60S do not exist in genBasinMasks, removed from nb_templates/ts.ipynb

@gustavo-marques

Copy link
Copy Markdown
Collaborator

Please add the SouthernOcean60S, as it is a critical region for CESM3 development.

@chengz2

chengz2 commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator Author

Please add the SouthernOcean60S, as it is a critical region for CESM3 development.

Added back.

@chengz2
chengz2 marked this pull request as ready for review September 22, 2026 18:47
@gustavo-marques

Copy link
Copy Markdown
Collaborator

For regional applications, it would be useful to be able to provide the path to a "basin_code" to the script, e.g.:

drift.py -basin path-to-basin-file.nc
If this is not provided, then the script uses:

basin_code = genBasinMasks(grd.geolon.values, grd.geolat.values, depth, xda=True)
It might also be good to override the default name of the NetCDF file generated when "-basin" is specified.

@chengz2

chengz2 commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator Author

For regional applications, it would be useful to be able to provide the path to a "basin_code" to the script, e.g.:

drift.py -basin path-to-basin-file.nc If this is not provided, then the script uses:

basin_code = genBasinMasks(grd.geolon.values, grd.geolat.values, depth, xda=True) It might also be good to override the default name of the NetCDF file generated when "-basin" is specified.

Should I add it to all scripts that use genBasinMasks? And nb_notebooks/climo.ipynb?

@gustavo-marques

Copy link
Copy Markdown
Collaborator

Yes, please. You might need to add it to the Papermill arguments innb_notebooks/climo.ipynb

@chengz2

chengz2 commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator Author

Yes, please. You might need to add it to the Papermill arguments innb_notebooks/climo.ipynb

In some scripts, not all basins are used, e.g.,

  #select a few basins, namely, Global, MedSea,BalticSea,HudsonBay Arctic,
  # Pacific, Atlantic, Indian, Southern, LabSea and BaffinBay
  basins = basin_code.isel(region=[0,4,5,6,7,8,9,10,11,12,13])

Should I add another flag for that, or just use all regions? Either way, I think it should be consistent across all scripts.

@chengz2
chengz2 force-pushed the arctic_80N branch 2 times, most recently from 3ec2ba0 to e145c1f Compare September 24, 2026 20:24
@chengz2

chengz2 commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator Author

For regional applications, it would be useful to be able to provide the path to a "basin_code" to the script, e.g.:

drift.py -basin path-to-basin-file.nc If this is not provided, then the script uses:

basin_code = genBasinMasks(grd.geolon.values, grd.geolat.values, depth, xda=True) It might also be good to override the default name of the NetCDF file generated when "-basin" is specified.

Also, would it be better to implement this optional path through diag_config.yml instead of as a CLI flag?

@chengz2 chengz2 added the enhancement New feature or request label Sep 29, 2026
@mnlevy1981
mnlevy1981 requested a review from AidanJanney October 5, 2026 16:44
@gustavo-marques

Copy link
Copy Markdown
Collaborator

Here is a workflow for reviewing all the basin masks generated:
https://ncar.github.io/tx2_3/basin_masks/basin_masks.html

chengz2 and others added 6 commits October 5, 2026 14:27
* Add Basin 16: Arctic Ocean north of 80N

* Switch to genBasinMasks for comnpute_basin_reductions.py and drift.py
* Add Basin 16: Arctic Ocean north of 80N to nb_templates/ts.ipynb

* Remove Maritime and SouthernOcean60S from nb_templates/ts.ipynb

* Switch to genBasinMasks for nb_templates/climo.ipynb
Add SouthernOcean60S back
Adds a -b/--basin CLI flag to drift.py, TS_levels.py, moc.py,
moc_sigma2.py, diff_rms.py, stats.py, compute_basin_reductions.py,
poleward_heat_transport.py, and create_climatology.py, letting
users read pre-computed basin masks from a netCDF file. This is
done through the additional argument, basin_from_file, passed to
genBasinMasks().

moc.py and poleward_heat_transport.py now derive their composite
Atlantic/Indo-Pacific masks by specifying region name instead of
numeric basin codes.

Removed the unused genBasinMasks import from aaiw_pv.py.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Set xda=True by default, since codes 12-17 are overlapping sub-regions
and can only be represented when xda=True.

Also updated docs/source/examples.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
genBasinMasks assumed plain numpy arrays internally, but some callers
(e.g. nb_templates/climo.ipynb, which passes grd.geolon/grd.geolat/depth
from an xarray-format grid without .values) pass xarray DataArrays
instead. xarray disallows 2-dimensional boolean array indexing through
plain [] syntax, so the NaN-removal line and every code[tmp>0] = N
basin assignment raised "IndexError: 2-dimensional boolean indexing is
not supported" as soon as x/y/depth were xarray-backed.

Fix by normalizing x, y, depth to plain numpy via np.asarray() at the
top of the function, before any boolean-mask logic runs. Verified
against a synthetic grid with both xarray and plain numpy inputs,
xda=True and xda=False.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@chengz2

chengz2 commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator Author

Here is a workflow for reviewing all the basin masks generated: https://ncar.github.io/tx2_3/basin_masks/basin_masks.html

Checked. Arctic80N and SouthernOcean60S cover the basins as intended.

@chengz2

chengz2 commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator Author

Should we keep the drift.py -basin path-to-basin-file.nc CLI flag, or implement something similar in diag_config.yml, or both?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants