Skip to content

Commit 1d1bd37

Browse files
committed
debugging
1 parent 8da6795 commit 1d1bd37

File tree

6 files changed

+41
-32
lines changed

6 files changed

+41
-32
lines changed

cf/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@
275275

276276
from .constants import * # noqa: F403
277277
from .functions import * # noqa: F403
278-
from .maths import div_xy, relative_vorticity, histogram
278+
from .maths import curl_xy, div_xy, relative_vorticity, histogram
279279
from .examplefield import example_field, example_fields, example_domain
280280

281281
from .cfimplementation import CFImplementation, implementation

cf/field.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4758,9 +4758,10 @@ def laplacian_xy(
47584758
):
47594759
r"""Calculate the Laplacian in X-Y coordinates.
47604760

4761-
The horizontal Laplacian is calculated from a field that has
4762-
dimension coordinates of X and Y, in either Cartesian
4763-
(e.g. plane projection) or spherical polar coordinate systems.
4761+
The horizontal Laplacian of a scalar function is calculated
4762+
from a field that has dimension coordinates of X and Y, in
4763+
either Cartesian (e.g. plane projection) or spherical polar
4764+
coordinate systems.
47644765

47654766
The horizontal Laplacian in Cartesian coordinates is given by:
47664767

@@ -4822,8 +4823,8 @@ def laplacian_xy(
48224823
:Returns:
48234824

48244825
`Field` or `None`
4825-
The horizontal Laplacian of the field, or `None` if
4826-
the operation was in-place.
4826+
The horizontal Laplacian of the scalar field, or
4827+
`None` if the operation was in-place.
48274828

48284829
>>> f = cf.example_field(0)
48294830
>>> print(f)
@@ -13669,9 +13670,10 @@ def grad_xy(
1366913670
):
1367013671
r"""Calculate the (X, Y) gradient vector.
1367113672

13672-
The horizontal gradient vector is calculated from a field that
13673-
has dimension coordinates of X and Y, in either Cartesian
13674-
(e.g. plane projection) or spherical polar coordinate systems.
13673+
The horizontal gradient vector of a scalar function is
13674+
calculated from a field that has dimension coordinates of X
13675+
and Y, in either Cartesian (e.g. plane projection) or
13676+
spherical polar coordinate systems.
1367513677

1367613678
The horizontal gradient vector in Cartesian coordinates is
1367713679
given by:
@@ -13731,7 +13733,7 @@ def grad_xy(
1373113733
:Returns:
1373213734

1373313735
`FieldList`
13734-
The horizontal gradient vector of the field.
13736+
The horizontal gradient vector of the scalar field.
1373513737

1373613738
**Examples**
1373713739

cf/maths.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ def curl_xy(
409409
\frac{\partial (f_\phi \sin\theta)}{\partial \theta}
410410
-
411411
\frac{\partial f_\theta}{\partial \phi}
412-
/right)
412+
\right)
413413
414414
where *r* is radial distance to the origin, :math:`\theta` is the
415415
polar angle with respect to polar axis, and :math:`\phi` is the
@@ -767,20 +767,21 @@ def div_xy(
767767
sin_theta = theta.sin()
768768

769769
r = fx.radius(default=radius)
770-
r_sin_theta = sin_theta * r
770+
771+
# r_sin_theta = sin_theta * r
771772

772773
term1 = (
773774
fx.derivative(
774775
x_key, wrap=x_wrap, one_sided_at_boundary=one_sided_at_boundary
775776
)
776-
/ r_sin_theta
777+
# / r_sin_theta
777778
)
778779

779780
term2 = (fy * sin_theta).derivative(
780781
y_key, wrap=None, one_sided_at_boundary=one_sided_at_boundary
781-
) / r_sin_theta
782+
) # / r_sin_theta
782783

783-
d = term1 + term2
784+
d = (term1 + term2) / (sin_theta * r) # r_sin_theta
784785

785786
# Reset latitude and longitude coordinate units
786787
d.dimension_coordinate("X").Units = x_units

cf/test/test_Field.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2638,11 +2638,12 @@ def test_Field_grad_xy(self):
26382638
f = cf.example_field(0)
26392639

26402640
# Spherical polar coordinates
2641-
r = f.radius("earth")
2641+
radius = 2
2642+
r = f.radius(radius)
26422643
for wrap in (False, True, None):
2643-
for one_sided in (True, False):
2644+
for one_sided in (False, False):
26442645
x, y = f.grad_xy(
2645-
radius="earth",
2646+
radius=radius,
26462647
x_wrap=wrap,
26472648
one_sided_at_boundary=one_sided,
26482649
)
@@ -2661,8 +2662,9 @@ def test_Field_grad_xy(self):
26612662
f"{x0.data.array}, {x0.data.Units}, "
26622663
f"{(x.data == x0.data).array}"
26632664
)
2664-
self.assertTrue((x.data == x0.data).all(), message)
2665-
self.assertTrue((y.data == y0.data).all())
2665+
with cf.rtol(1e-10):
2666+
self.assertTrue((x.data == x0.data).all(), message)
2667+
self.assertTrue((y.data == y0.data).all())
26662668

26672669
# Check that x and y have the same metadata as f
26682670
# (except standard_name, long_name, and units).
@@ -2713,7 +2715,7 @@ def test_Field_laplacian_xy(self):
27132715
for wrap in (False, True, None):
27142716
for one_sided in (True, False):
27152717
lp = f.laplacian_xy(
2716-
radius="earth",
2718+
radius=2, # "earth",
27172719
x_wrap=wrap,
27182720
one_sided_at_boundary=one_sided,
27192721
)
@@ -2722,11 +2724,11 @@ def test_Field_laplacian_xy(self):
27222724

27232725
lp0 = cf.div_xy(
27242726
*f.grad_xy(
2725-
radius="earth",
2727+
radius=2, # "earth",
27262728
x_wrap=wrap,
27272729
one_sided_at_boundary=one_sided,
27282730
),
2729-
radius="earth",
2731+
radius=2, # "earth",
27302732
x_wrap=wrap,
27312733
one_sided_at_boundary=one_sided,
27322734
)
@@ -2738,7 +2740,8 @@ def test_Field_laplacian_xy(self):
27382740
f"{lp0.data.array}, {lp0.Units}"
27392741
f"{(lp.data == lp0.data).array}"
27402742
)
2741-
self.assertTrue(lp.equals(lp0, verbose=-1), message)
2743+
with cf.rtol(1e-10):
2744+
self.assertTrue(lp.equals(lp0), message)
27422745

27432746
# Cartesian coordinates
27442747
dim_x = f.dimension_coordinate("X")

cf/test/test_Maths.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,20 @@ def test_div_xy(self):
188188
f = cf.example_field(0)
189189

190190
# Spherical polar coordinates
191-
r = f.radius("earth")
191+
radius = 2 # 'earth'
192+
r = f.radius(radius)
192193
for wrap in (False, True, None):
193-
for one_sided in (True, False):
194+
for one_sided in (False, True):
194195
x, y = f.grad_xy(
195-
radius="earth",
196+
radius=radius,
196197
x_wrap=wrap,
197198
one_sided_at_boundary=one_sided,
198199
)
199200

200201
d = cf.div_xy(
201202
x,
202203
y,
203-
radius="earth",
204+
radius=radius,
204205
x_wrap=wrap,
205206
one_sided_at_boundary=one_sided,
206207
)
@@ -221,12 +222,13 @@ def test_div_xy(self):
221222

222223
# Check the data
223224
message = (
224-
f"{wrap}, {one_sided}, "
225-
f"{d.data.array}, {d.data.Units}, "
226-
f"{d0.data.array}, {d0.data.Units}"
225+
f"{wrap}, {one_sided}, \n"
226+
f"{d.data.array}, {d.data.Units}\n"
227+
f"{d0.data.array}, {d0.data.Units}\n"
227228
f"{(d.data == d0.data).array}"
228229
)
229-
self.assertTrue((d.data == d0.data).all(), message)
230+
with cf.rtol(1e-10):
231+
self.assertTrue((d.data == d0.data).all(), message)
230232

231233
del d.long_name
232234
d0.set_data(d.data)

docs/source/function.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Mathematical operations
4444
cf.atol
4545
cf.rtol
4646
cf.default_netCDF_fillvals
47+
cf.curl_xy
4748
cf.div_xy
4849
cf.histogram
4950
cf.relative_vorticity

0 commit comments

Comments
 (0)