sectionate 0.3.4__tar.gz → 0.4.0rc2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. {sectionate-0.3.4 → sectionate-0.4.0rc2}/.github/workflows/ci.yml +5 -0
  2. {sectionate-0.3.4 → sectionate-0.4.0rc2}/.gitignore +7 -0
  3. sectionate-0.4.0rc2/CLAUDE.md +151 -0
  4. {sectionate-0.3.4 → sectionate-0.4.0rc2}/PKG-INFO +2 -2
  5. {sectionate-0.3.4 → sectionate-0.4.0rc2}/conda/meta.yaml +1 -1
  6. {sectionate-0.3.4 → sectionate-0.4.0rc2}/docs/environment.yml +1 -0
  7. {sectionate-0.3.4 → sectionate-0.4.0rc2}/docs/source/index.rst +1 -1
  8. {sectionate-0.3.4 → sectionate-0.4.0rc2}/docs/source/installation.rst +1 -1
  9. {sectionate-0.3.4 → sectionate-0.4.0rc2}/pyproject.toml +1 -1
  10. {sectionate-0.3.4 → sectionate-0.4.0rc2}/sectionate/_version.py +2 -2
  11. sectionate-0.4.0rc2/sectionate/gridutils.py +1323 -0
  12. sectionate-0.4.0rc2/sectionate/section.py +982 -0
  13. sectionate-0.4.0rc2/sectionate/tests/test_convergent_transport.py +342 -0
  14. sectionate-0.4.0rc2/sectionate/tests/test_cube_left_grid.py +612 -0
  15. sectionate-0.4.0rc2/sectionate/tests/test_ecco_llc90.py +99 -0
  16. sectionate-0.4.0rc2/sectionate/tests/test_left_grid.py +251 -0
  17. sectionate-0.4.0rc2/sectionate/tests/test_section.py +229 -0
  18. {sectionate-0.3.4 → sectionate-0.4.0rc2}/sectionate/tests/test_section_class.py +24 -1
  19. sectionate-0.4.0rc2/sectionate/tests/test_section_cornercases.py +97 -0
  20. sectionate-0.4.0rc2/sectionate/tests/test_section_fold.py +113 -0
  21. sectionate-0.4.0rc2/sectionate/tests/test_section_multitile.py +590 -0
  22. sectionate-0.4.0rc2/sectionate/tests/test_section_reversibility.py +91 -0
  23. {sectionate-0.3.4 → sectionate-0.4.0rc2}/sectionate/tests/test_utils.py +1 -1
  24. {sectionate-0.3.4 → sectionate-0.4.0rc2}/sectionate/tracers.py +17 -11
  25. sectionate-0.4.0rc2/sectionate/transports.py +811 -0
  26. {sectionate-0.3.4 → sectionate-0.4.0rc2}/sectionate/utils.py +6 -1
  27. sectionate-0.3.4/sectionate/gridutils.py +0 -99
  28. sectionate-0.3.4/sectionate/section.py +0 -786
  29. sectionate-0.3.4/sectionate/tests/test_convergent_transport.py +0 -120
  30. sectionate-0.3.4/sectionate/tests/test_section.py +0 -92
  31. sectionate-0.3.4/sectionate/tests/test_section_cornercases.py +0 -63
  32. sectionate-0.3.4/sectionate/transports.py +0 -505
  33. {sectionate-0.3.4 → sectionate-0.4.0rc2}/.github/workflows/publish-to-pypi.yml +0 -0
  34. {sectionate-0.3.4 → sectionate-0.4.0rc2}/.readthedocs.yaml +0 -0
  35. {sectionate-0.3.4 → sectionate-0.4.0rc2}/LICENSE +0 -0
  36. {sectionate-0.3.4 → sectionate-0.4.0rc2}/README.md +0 -0
  37. {sectionate-0.3.4 → sectionate-0.4.0rc2}/binder/environment.yml +0 -0
  38. {sectionate-0.3.4 → sectionate-0.4.0rc2}/ci/environment.yml +0 -0
  39. {sectionate-0.3.4 → sectionate-0.4.0rc2}/docs/Makefile +0 -0
  40. {sectionate-0.3.4 → sectionate-0.4.0rc2}/docs/make.bat +0 -0
  41. {sectionate-0.3.4 → sectionate-0.4.0rc2}/docs/source/_static/.gitkeep +0 -0
  42. {sectionate-0.3.4 → sectionate-0.4.0rc2}/docs/source/_static/custom.css +0 -0
  43. {sectionate-0.3.4 → sectionate-0.4.0rc2}/docs/source/_templates/.gitkeep +0 -0
  44. {sectionate-0.3.4 → sectionate-0.4.0rc2}/docs/source/conf.py +0 -0
  45. {sectionate-0.3.4 → sectionate-0.4.0rc2}/sectionate/__init__.py +0 -0
  46. {sectionate-0.3.4 → sectionate-0.4.0rc2}/sectionate/catalog/Atlantic_transport_arrays.json +0 -0
  47. {sectionate-0.3.4 → sectionate-0.4.0rc2}/sectionate/version.py +0 -0
@@ -45,6 +45,11 @@ jobs:
45
45
  - name: Set up conda environment
46
46
  run: |
47
47
  mamba env update -f ci/environment.yml
48
+ # The topology-driven multi-tile section/transport and bipolar north-fold
49
+ # tests need xgcm >= 0.10.1, which introduces the fold boundary
50
+ # (padding={"Y": {"fold": ...}}, formerly xgcm#711), the face_connections
51
+ # halo-padding fix (xgcm#712), and the other_component vector-pad fix
52
+ # (xgcm#749). It is a plain PyPI dependency, pulled in by `pip install -e .`.
48
53
  python -m pip install -e .
49
54
  - name: Conda list information
50
55
  run: |
@@ -103,5 +103,12 @@ venv.bak/
103
103
  # mypy
104
104
  .mypy_cache/
105
105
 
106
+ # Local example data cache (fetched from Zenodo / PO.DAAC at runtime)
107
+ data/*.nc
108
+
109
+ # Build artifacts and OS cruft
110
+ *.tar.gz
111
+ .DS_Store
112
+
106
113
  # Version file generated from the git tag by hatch-vcs at build time.
107
114
  sectionate/_version.py
@@ -0,0 +1,151 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Project Overview
6
+
7
+ Sectionate is a Python package for sampling grid-consistent hydrographic sections from structured ocean model outputs (e.g. MOM6). It traces paths along C-grid velocity faces between geographic waypoints and computes transports/tracer values along those sections. Only structured grids are supported.
8
+
9
+ ## Development Setup
10
+
11
+ **One conda environment per branch/worktree, named `docs_env_sectionate_<branch-or-worktree-name>`.**
12
+ Branches diverge in their dependencies — the xgcm floor in particular — so a single
13
+ shared environment silently tests the wrong versions. Create it from
14
+ `docs/environment.yml`, overriding the baked-in `name:` with `-n`:
15
+
16
+ ```bash
17
+ ENV="docs_env_sectionate_$(git rev-parse --abbrev-ref HEAD)"
18
+ conda env create -f docs/environment.yml -n "$ENV"
19
+ conda activate "$ENV"
20
+ pip install -e . # resolves the branch's own runtime deps from pyproject.toml
21
+ python -m ipykernel install --user --name "$ENV" --display-name "$ENV"
22
+ ```
23
+
24
+ `docs/environment.yml` pins none of the runtime dependencies; `pip install -e .` is
25
+ what resolves them, so install in that order and re-run it after any dependency
26
+ change in `pyproject.toml`. Reuse the env across runs on the same branch; remove it
27
+ with `conda env remove -n "$ENV"` once the branch or worktree is gone.
28
+ (`ci/environment.yml` is the minimal CI environment — pytest only, no plotting or
29
+ notebook stack. It is not sufficient for the notebooks.)
30
+
31
+ The environment must carry **xgcm >= 0.10.1**, which
32
+ introduces the bipolar north fold (`padding={"Y": {"fold": ...}}`, formerly #711),
33
+ the face-connection padding fix (#712), and the bare-`DataArray` `other_component`
34
+ vector-pad fix (#749). It is a plain PyPI release, so `pip install -e .` pulls it in
35
+ automatically (sectionate requires `xgcm>=0.10.1`). The ECCO example (notebook 5)
36
+ pulls its data subset from Zenodo (concept DOI `10.5281/zenodo.21051424`) via stdlib
37
+ `urllib` with MD5 checks — no `earthaccess`/Earthdata login needed.
38
+
39
+ A correctly set up environment runs the full suite with **0 skips**. Skips mean one of
40
+ two things: fold and multi-tile tests `skip` on `xgcm < 0.10.1`, and the ECCO LLC90 and
41
+ MOM6-fold tests `skip` when their example data is absent from `data/`. In a fresh
42
+ worktree the latter is the usual cause — `data/` holds ~1.4 GB of downloaded input that
43
+ each checkout otherwise re-fetches. Symlink it from a checkout that already has it
44
+ rather than downloading again (`data/*.nc` is gitignored, but `MOM5_global_example_grid.nc`
45
+ is tracked, so link the individual files, not the directory):
46
+
47
+ ```bash
48
+ cd data && for f in /path/to/other/checkout/data/*.nc; do
49
+ b=$(basename "$f"); [ -e "$b" ] || ln -s "$f" "$b"
50
+ done
51
+ ```
52
+
53
+ ## Commands
54
+
55
+ - **Run all tests:** `pytest`
56
+ - **Run a single test:** `pytest sectionate/tests/test_section.py::test_find_closest_grid_point`
57
+ - **Build docs:** `cd docs && make html` (requires `docs/environment.yml` environment)
58
+
59
+ ## Definition of Done (always, before committing or pushing)
60
+
61
+ Before committing **or pushing** any change to this repository, always do all of the
62
+ following — use parallel agents where it is faster. Both of the first two steps, every
63
+ time: not one or the other, and not only the notebooks that look related to the change.
64
+ A change that passes `pytest` but breaks a notebook is still a broken change, because
65
+ the notebooks are the rendered documentation.
66
+
67
+ Run them in this branch's own `docs_env_sectionate_<branch-or-worktree-name>` environment
68
+ (see *Development Setup*), not in whatever env happens to be active.
69
+
70
+ 1. **Run the full test suite** (`pytest`) and confirm it passes with **0 skips**.
71
+ 2. **Re-execute the example notebooks** in `examples/` and confirm they run cleanly:
72
+ ```bash
73
+ cd examples && jupyter nbconvert --to notebook --execute --inplace \
74
+ --ExecutePreprocessor.timeout=1800 \
75
+ --ExecutePreprocessor.kernel_name=python3 *.ipynb
76
+ ```
77
+ Run from `examples/` — the notebooks resolve data paths relative to it. `--inplace`
78
+ refreshes the committed outputs, which is intended; review the resulting diff.
79
+ `kernel_name=python3` uses the active env's kernel, so the per-branch env name need
80
+ not match the `kernelspec` recorded in each notebook.
81
+ 3. **Scan the repo for inconsistencies / outdated information** introduced by the change —
82
+ including docstrings, `README.md`, files under `docs/`, the example notebooks, and this
83
+ `CLAUDE.md` — and update them so docs and code stay in sync.
84
+
85
+ ## Keeping pull requests in sync
86
+
87
+ When pushing a new commit to a branch that already has an open PR, also update that PR's
88
+ top-comment description so it stays consistent with the most recent commit:
89
+
90
+ - Revise the summary / "Changes" prose to reflect what the latest commit actually did.
91
+ - Update any task/status checklist — check off completed items (`- [ ]` → `- [x]`) and add
92
+ new ones as needed.
93
+ - Edit it in place with `gh pr edit <number> --repo <owner>/<repo> --body-file <file>` (find
94
+ the PR for the current branch with `gh pr view --json number,url`).
95
+
96
+ ## AI Usage Policy
97
+
98
+ AI-assisted contributions to sectionate are welcome, but the person running the AI is
99
+ responsible for every change. This project follows the
100
+ [xgcm AI Usage Policy](https://github.com/hdrake/xgcm/blob/add-Claude.md/docs/contributor_guide.md),
101
+ which in turn adapts [xarray's](https://docs.xarray.dev/en/stable/contribute/ai-policy.html).
102
+ It applies to every change regardless of whether it was written by hand, with AI
103
+ assistance, or generated entirely by an AI tool. The essentials:
104
+
105
+ - **You own the diff.** Before opening or updating a PR, you must have read and understood
106
+ every line and be able to explain why each change is correct — the same bar as a
107
+ hand-written PR. Keep changes small, single-purpose, and free of unrelated edits.
108
+ - **Disclose AI assistance openly.** Add a `Co-Authored-By:` trailer to AI-assisted commits
109
+ and note on any PR or comment that was drafted with AI.
110
+ - **Communicate in your own words.** PR descriptions, issue comments, and review responses
111
+ must be your own; do not paste AI-generated text as a comment. Using AI to polish your own
112
+ writing (grammar, phrasing) is fine as long as it introduces no inaccuracies.
113
+ - **Every code change ships with tests** and, per the *Definition of Done* above, a green
114
+ suite and re-executed notebooks.
115
+ - **Discuss large AI-assisted contributions first.** For a substantial refactor, new
116
+ subsystem, or migration, open an issue to agree scope before generating the diff — a large
117
+ diff is fast to produce and slow to review.
118
+
119
+ ## Architecture
120
+
121
+ The package is organized around a pipeline: define sections → map to grid → compute transports/tracers.
122
+
123
+ ### Core Modules
124
+
125
+ - **`section.py`** — Section definition and grid path algorithms. `Section` holds named waypoint coordinates; `GriddedSection` extends it with grid index information. `grid_section()` is the main entry point that maps geographic waypoints to grid vorticity-point indices `(i_c, j_c)` by walking the grid between waypoints along the `curve` requested (`"great circle"`, the default geodesic, or `"latitude circle"`); each segment must span less than 180°. The walk is deterministic and direction-independent: it admits neighbors strictly closer to the endpoint plus any seam twin of the current cell (so periodic/fold-seam crossings do not depend on floating-point rounding), and breaks ties by index. Grid topology is inferred entirely from `xgcm.Grid` metadata — each axis' `boundary` (periodic wrap, fill/extend wall, or a single-tile bipolar north fold `{"Y": {"fold": ...}}`) and `face_connections` for multi-tile grids — so there is no `topology` keyword. The pathfinder consumes topology-aware neighbor maps built by `gridutils.build_neighbor_maps`.
126
+
127
+ - **`transports.py`** — Transport computation along sections. `uvindices_from_qindices()` converts vorticity-point indices to U/V velocity-point indices using a per-position corner offset (`gridutils.corner_offset`) covering all three C-grid staggerings: 'outer', 'right', and 'left' (see "Corner staggering" below). `convergent_transport()` is the main function: it lazily computes signed normal transports with configurable orientation (positive inward to the polygon defined by the section).
128
+
129
+ - **`tracers.py`** — `extract_tracer()` interpolates tracer data to U/V points along a section path for cross-section plotting.
130
+
131
+ - **`gridutils.py`** — Grid introspection utilities: `corner_position()` returns the shared vorticity corner position (`"outer"`, `"right"`, or `"left"`) and `corner_offset()` the corresponding velocity index shift used throughout transports/tracers; `check_outer()` is a thin wrapper (True iff `"outer"`). (Package source names positions only by these xgcm labels; their correspondence to MOM6/MITgcm/ECCO conventions is documented under "Corner staggering" below and in the example notebooks.) `coord_dict()` and `get_geo_corners()` extract coordinate/dimension names from `xgcm.Grid` metadata; `build_neighbor_maps()` builds the topology-aware neighbor maps the pathfinder consumes. For single-tile grids these come from xgcm halo padding; for every multi-tile grid they are projected from **`outer_topology(grid)`** (cached `_OuterTopology`), which reconstructs each face's full 'outer' (shared-corner) lattice, resolves every extended corner slot to the native corner storing that physical point (topological matching of the surrounding tracer cells — including a diagonal-cell recovery for normal-seam face corners and a 3-cell fingerprint for 3-tile junctions with native storage — with a small coordinate fallback only for the polar-cut corners no cell fingerprint can determine), and merges slots into physical corner *nodes* — so rotated/reversed seams, cube-vertex/tile junctions, boundary folds (e.g. LLC's south rows), and the polar grid cut are ordinary graph nodes, each resolved to its canonical native `(face, j, i)` (a physical corner may be stored once, on no face, or more than once). `_OuterTopology.padded_transports(u, v)` extends native transports to the outer lattice by reading each missing edge slot's *stored* twin through the node graph — a topology-exact, xgcm-independent alternative to `xgcm.pad(..., other_component=...)` (cell convergence built from `padded_transports` sums to exactly zero globally on ECCO LLC90). Even a correct vector pad (xgcm#749 fixes the bare-DataArray path; the dict form was always exact) cannot supply a halo for edges stored on *no* face, so `padded_transports` remains the exact path on grids with cuts/caps. Points stored on **no** face (a cubed-sphere stores `6N²` corners for `6N²+2` points; LLC90's 4th Arctic-cap vertex; the unstored lip of its 65°E/115°W polar grid cut under Antarctica) become edge-less nodes: sections and traced boundaries cannot pass through them and raise an error rather than return invalid indices.
132
+
133
+ - **`utils.py`** — Section catalog I/O. Sections can be loaded by name from JSON catalog files in `sectionate/catalog/`. Also provides `save_gridded_section()`/`load_gridded_section()` for persisting gridded sections.
134
+
135
+ ### Key Concepts
136
+
137
+ - **Vorticity points (q-points):** Sections are defined as paths through vorticity-point indices `(i_c, j_c)`. Consecutive q-points define velocity faces (either U or V).
138
+ - **Corner staggering (three positions):** Vorticity sits at one of three xgcm positions: `"outer"` (MOM6 symmetric, M+1×N+1), `"right"` (MOM6 non-symmetric, M×N), or `"left"` (MITgcm/ECCO, incl. the lat-lon-cap, M×N). All three are native; they differ only by a per-position velocity index offset (`gridutils.corner_offset`: outer→0, right→+1, left→0). `"left"` indexes like `"outer"`; it differs only in array length and in that the *high* corner row/column is absent (so a section exactly on the north/east domain wall clips one row inside).
139
+ - **Sign conventions:** For a *closed* section, `convergent_transport()` determines orientation (clockwise/counterclockwise) using stereographic projection and signed polygon area, then applies sign corrections so positive transport means "inward" (toward the enclosed polygon). For an *open* section there is no enclosing polygon, so `positive_in` is undefined; it instead uses the **left-of-transect** convention — `positive_in=True` makes positive transport point to the left of the section as traversed from the first to the last waypoint — and emits a `UserWarning`. `is_section_counterclockwise()` is only consulted in the closed case.
140
+ - **xgcm.Grid dependency:** The package relies heavily on `xgcm.Grid` for grid metadata (axis boundaries, coordinate positions, dataset access via `grid._ds`).
141
+
142
+ ## Version
143
+
144
+ **The git tag is the version.** There is no version string checked into the tree:
145
+ `hatch-vcs` derives it from the tag at build time and writes the gitignored
146
+ `sectionate/_version.py`, which ships inside the sdist and wheel. `sectionate/version.py`
147
+ is only a shim over that generated file — never add a version literal back to it. A
148
+ `0.0.0+unknown` from it means the package was imported without being built or installed,
149
+ not that a number is missing. Any checkout that installs the package needs its tags: a
150
+ shallow clone resolves a `.devN` version instead of the release line, which is why CI and
151
+ Read the Docs both fetch with full depth. See the Releasing section of `README.md`.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sectionate
3
- Version: 0.3.4
3
+ Version: 0.4.0rc2
4
4
  Summary: A package to sample grid-consistent sections from ocean model outputs
5
5
  Project-URL: Homepage, https://github.com/MOM6-community/sectionate
6
6
  Project-URL: Bugs/Issues/Features, https://github.com/MOM6-community/sectionate/issues
@@ -16,7 +16,7 @@ Requires-Dist: numba
16
16
  Requires-Dist: numpy
17
17
  Requires-Dist: scipy
18
18
  Requires-Dist: xarray
19
- Requires-Dist: xgcm==0.9.*
19
+ Requires-Dist: xgcm>=0.10.1
20
20
  Description-Content-Type: text/markdown
21
21
 
22
22
  # sectionate
@@ -32,7 +32,7 @@ requirements:
32
32
  - numpy
33
33
  - scipy
34
34
  - xarray
35
- - xgcm >=0.9.0
35
+ - xgcm >=0.10.1
36
36
 
37
37
  test:
38
38
  requires:
@@ -13,5 +13,6 @@ dependencies:
13
13
  - pytest
14
14
  - sphinx
15
15
  - nbsphinx
16
+ - pandoc
16
17
  - ipykernel
17
18
  - pip
@@ -10,4 +10,4 @@ sectionate: a package to sample grid-consistent sections from structured ocean m
10
10
  examples/2_OSNAP_transports_CM4p25
11
11
  examples/3_Labrador_convergence_CM4p25
12
12
  examples/4_sections_on_global_tripolar_grid
13
- examples/5_MOC_transports_CM4p25
13
+ examples/5_MOC_transports_ECCOv4r4
@@ -5,7 +5,7 @@ Requirements
5
5
  ^^^^^^^^^^^^
6
6
 
7
7
  sectionate is compatible with python 3 (>= version 3.11). It requires xgcm
8
- (>= version 0.9.0).
8
+ (>= version 0.10.1).
9
9
 
10
10
  Installation from Conda Forge
11
11
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -19,7 +19,7 @@ dependencies = [
19
19
  "numpy",
20
20
  "scipy",
21
21
  "xarray",
22
- "xgcm == 0.9.*",
22
+ "xgcm >= 0.10.1",
23
23
  ]
24
24
 
25
25
  [project.urls]
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '0.3.4'
22
- __version_tuple__ = version_tuple = (0, 3, 4)
21
+ __version__ = version = '0.4.0rc2'
22
+ __version_tuple__ = version_tuple = (0, 4, 0, 'rc2')
23
23
 
24
24
  __commit_id__ = commit_id = None