Skip to content

Commit e3183da

Browse files
authored
Merge pull request #722 from davidhassell/ugrid-weights
Fix bug when calculating UGRID cell areas when non-spatial coordinates span the discrete axis
2 parents b833352 + 14039e0 commit e3183da

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

Changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ version 3.17.0
33

44
**2024-??-??**
55

6+
* Fix occasional bug when calculating UGRID cell areas when
7+
non-spatial coordinates span the discrete axis
8+
(https://github.com/NCAS-CMS/cf-python/issues/721)
69
* New keyword parameter to `cf.Field.insert_dimension`:
710
``constructs`` (https://github.com/NCAS-CMS/cf-python/issues/719)
811
* Added the ``cell_measures`` and ``coordinates`` keyword arguments to

cf/weights.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,6 +1652,9 @@ def _geometry_ugrid_cells(cls, f, domain_axis, cell_type, auto=False):
16521652
)
16531653

16541654
for key, aux in auxiliary_coordinates_1d.items():
1655+
if str(aux.ctype) not in "XYZ":
1656+
continue
1657+
16551658
aux_axis = f.get_data_axes(key)[0]
16561659

16571660
ugrid = f.domain_topology(default=None, filter_by_axis=(aux_axis,))
@@ -1665,8 +1668,8 @@ def _geometry_ugrid_cells(cls, f, domain_axis, cell_type, auto=False):
16651668
):
16661669
continue
16671670

1668-
# Still here? Then this auxiliary coordinate has either UGRID
1669-
# or geometry cells.
1671+
# Still here? Then this X, Y, or Z auxiliary coordinate is
1672+
# for either UGRID or geometry cells.
16701673
if aux.X:
16711674
aux_X = aux.copy()
16721675
x_axis = aux_axis
@@ -1701,7 +1704,7 @@ def _geometry_ugrid_cells(cls, f, domain_axis, cell_type, auto=False):
17011704

17021705
raise ValueError(
17031706
"Can't create weights: X and Y cells span different domain "
1704-
"axes"
1707+
f"axes: {x_axis} != {y_axis}"
17051708
)
17061709

17071710
axis = x_axis

0 commit comments

Comments
 (0)