Skip to content

Commit 28a5508

Browse files
committed
o Fix formatting
1 parent fcd8293 commit 28a5508

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

test/core/test_divergence.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def test_divergence_output_format(self, gridpath, datasetpath):
1414
# Create two components for vector field (using same data for simplicity in test)
1515
u_component = uxds['t2m']
1616
v_component = uxds['t2m']
17-
17+
1818
div_da = u_component.divergence(v_component)
1919

2020
assert isinstance(div_da, ux.UxDataArray)
@@ -27,14 +27,14 @@ def test_divergence_input_validation(self, gridpath, datasetpath):
2727
uxds = ux.open_dataset(gridpath("ugrid", "quad-hexagon", "grid.nc"), datasetpath("ugrid", "quad-hexagon", "data.nc"))
2828

2929
u_component = uxds['t2m']
30-
30+
3131
# Test with non-UxDataArray
3232
with pytest.raises(TypeError, match="other must be a UxDataArray"):
3333
u_component.divergence(np.array([1, 2, 3]))
34-
34+
3535
# Test with different grids (create a simple test case)
3636
# This would require creating another grid, so we'll skip for now
37-
37+
3838
# Test with different dimensions
3939
# This would require creating data with different dims, so we'll skip for now
4040

@@ -48,7 +48,7 @@ def test_divergence_basic(self, gridpath, datasetpath):
4848
# Use the same field for both components (not physically meaningful but tests the method)
4949
u_component = uxds['bottomDepth']
5050
v_component = uxds['bottomDepth']
51-
51+
5252
div_field = u_component.divergence(v_component)
5353

5454
# Check that we get finite values where expected
@@ -64,20 +64,20 @@ def test_divergence_constant_field(self, gridpath, datasetpath):
6464
gridpath("mpas", "dyamond-30km", "gradient_grid_subset.nc"),
6565
datasetpath("mpas", "dyamond-30km", "gradient_data_subset.nc")
6666
)
67-
67+
6868
# Create constant fields
6969
constant_u = uxds['face_lat'] * 0 + 1.0 # Constant field = 1
7070
constant_v = uxds['face_lat'] * 0 + 1.0 # Constant field = 1
71-
71+
7272
div_field = constant_u.divergence(constant_v)
73-
73+
7474
# Divergence of constant field should be close to zero for interior faces
7575
# Boundary faces may have NaN values (which is expected)
7676
finite_values = div_field.values[np.isfinite(div_field.values)]
77-
77+
7878
# Check that we have some finite values (interior faces)
7979
assert len(finite_values) > 0, "No finite divergence values found"
80-
80+
8181
# Divergence of constant field should be close to zero for finite values
8282
assert np.abs(finite_values).max() < 1e-10, f"Max divergence: {np.abs(finite_values).max()}"
8383

@@ -87,19 +87,19 @@ def test_divergence_linear_field(self, gridpath, datasetpath):
8787
gridpath("mpas", "dyamond-30km", "gradient_grid_subset.nc"),
8888
datasetpath("mpas", "dyamond-30km", "gradient_data_subset.nc")
8989
)
90-
90+
9191
# Create linear fields: u = x, v = y (in spherical coordinates: u = lon, v = lat)
9292
u_component = uxds['face_lon'] # Linear in longitude
9393
v_component = uxds['face_lat'] # Linear in latitude
94-
94+
9595
div_field = u_component.divergence(v_component)
96-
96+
9797
# Check that we have some finite values (interior faces)
9898
finite_mask = np.isfinite(div_field.values)
9999
finite_values = div_field.values[finite_mask]
100-
100+
101101
assert len(finite_values) > 0, "No finite divergence values found"
102-
102+
103103
# For linear fields, divergence should be finite where computable
104104
# Boundary faces may have NaN values (which is expected)
105105
assert not np.isnan(finite_values).any(), "Found NaN in finite values"
@@ -110,26 +110,26 @@ def test_divergence_radial_field(self, gridpath, datasetpath):
110110
gridpath("mpas", "dyamond-30km", "gradient_grid_subset.nc"),
111111
datasetpath("mpas", "dyamond-30km", "gradient_data_subset.nc")
112112
)
113-
113+
114114
# Create a radial field pointing outward from center
115115
# Use the inverse gaussian as a proxy for radial distance
116116
radial_distance = uxds['inverse_gaussian']
117-
117+
118118
# Create components proportional to position (simplified radial field)
119119
u_component = radial_distance * uxds['face_lon']
120120
v_component = radial_distance * uxds['face_lat']
121-
121+
122122
div_field = u_component.divergence(v_component)
123-
123+
124124
# Check that we have some finite values (interior faces)
125125
finite_mask = np.isfinite(div_field.values)
126126
finite_values = div_field.values[finite_mask]
127-
127+
128128
assert len(finite_values) > 0, "No finite divergence values found"
129-
129+
130130
# Boundary faces may have NaN values (which is expected)
131131
assert not np.isnan(finite_values).any(), "Found NaN in finite values"
132-
132+
133133
# Most finite values should be positive for an expanding field
134134
positive_values = finite_values > 0
135135
assert positive_values.sum() > len(finite_values) * 0.3 # At least 30% positive
@@ -140,28 +140,28 @@ def test_divergence_curl_identity(self, gridpath, datasetpath):
140140
gridpath("mpas", "dyamond-30km", "gradient_grid_subset.nc"),
141141
datasetpath("mpas", "dyamond-30km", "gradient_data_subset.nc")
142142
)
143-
143+
144144
# Create a scalar potential field
145145
potential = uxds['gaussian']
146-
146+
147147
# Compute gradient to get a conservative vector field
148148
grad = potential.gradient()
149149
u_component = grad['zonal_gradient']
150150
v_component = grad['meridional_gradient']
151-
151+
152152
# Compute divergence of this gradient (should be the Laplacian)
153153
div_grad = u_component.divergence(v_component)
154-
154+
155155
# Check that we have some finite values (interior faces)
156156
finite_mask = np.isfinite(div_grad.values)
157157
finite_values = div_grad.values[finite_mask]
158-
158+
159159
assert len(finite_values) > 0, "No finite divergence values found"
160-
160+
161161
# This tests the Laplacian computation via div(grad)
162162
# Boundary faces may have NaN values (which is expected)
163163
assert not np.isnan(finite_values).any(), "Found NaN in finite values"
164-
164+
165165
# The Laplacian of a Gaussian should have both positive and negative values
166166
assert (finite_values > 0).any(), "No positive Laplacian values found"
167-
assert (finite_values < 0).any(), "No negative Laplacian values found"
167+
assert (finite_values < 0).any(), "No negative Laplacian values found"

0 commit comments

Comments
 (0)