Skip to content

Commit f3f210b

Browse files
Merge pull request #7 from cassidymwagner/sep_dist_debug
Separation distance bug fix
2 parents dfec5b6 + 6759f0c commit f3f210b

File tree

3 files changed

+90
-25
lines changed

3 files changed

+90
-25
lines changed

oceans_sf/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55

66
from .bin_data import bin_data
7+
from .calculate_advection import calculate_advection
78
from .calculate_separation_distances import calculate_separation_distances
89
from .calculate_structure_function import (
910
calculate_structure_function,

oceans_sf/generate_structure_functions.py

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def generate_structure_functions( # noqa: C901, D417
2525
nbins=10,
2626
):
2727
"""
28+
TEST
2829
Full method for generating structure functions for 2D data, either advective or
2930
traditional structure functions. Supports velocity-based and scalar-based structure
3031
functions. Defaults to calculating the velocity-based advective structure functions
@@ -113,8 +114,8 @@ def generate_structure_functions( # noqa: C901, D417
113114
SF_m_trad_scalar = np.zeros(len(sep_m) + 1)
114115

115116
# Iterate over separations right and down
116-
for down, right in zip(sep_m, sep_z): # noqa: B905
117-
xroll = shift_array1d(x, shift_by=right, boundary=boundary)
117+
for down in sep_m:
118+
right = 1
118119
yroll = shift_array1d(y, shift_by=down, boundary=boundary)
119120

120121
SF_dicts = calculate_structure_function(
@@ -131,27 +132,50 @@ def generate_structure_functions( # noqa: C901, D417
131132
boundary,
132133
)
133134

134-
# Maybe don't do this and just let the dict have Nones in it,
135-
# probably a lot easier and less silly
136135
if skip_velocity_sf is False:
137-
SF_z[right] = SF_dicts["SF_velocity_right"]
138136
SF_m[down] = SF_dicts["SF_velocity_down"]
139137
if traditional_order > 0:
140-
SF_z_trad_velocity[right] = SF_dicts["SF_trad_velocity_right"]
141138
SF_m_trad_velocity[down] = SF_dicts["SF_trad_velocity_down"]
142139
if scalar is not None:
143-
SF_z_scalar[right] = SF_dicts["SF_scalar_right"]
144140
SF_m_scalar[down] = SF_dicts["SF_scalar_down"]
145141
if traditional_order > 0:
146-
SF_z_trad_scalar[right] = SF_dicts["SF_trad_scalar_right"]
147142
SF_m_trad_scalar[down] = SF_dicts["SF_trad_scalar_down"]
148143

149-
# Calculate separation distances in x and y
150-
xd[right], tmp = calculate_separation_distances(
151-
x[right], y[right], xroll[right], yroll[right], grid_type
152-
)
144+
# Calculate separation distances in y
153145
tmp, yd[down] = calculate_separation_distances(
154-
x[down], y[down], xroll[down], yroll[down], grid_type
146+
x[right], y[down], x[right], yroll[down], grid_type
147+
)
148+
149+
for right in sep_z:
150+
down = 1
151+
xroll = shift_array1d(x, shift_by=right, boundary=boundary)
152+
153+
SF_dicts = calculate_structure_function(
154+
u,
155+
v,
156+
adv_E,
157+
adv_N,
158+
down,
159+
right,
160+
skip_velocity_sf,
161+
scalar,
162+
adv_scalar,
163+
traditional_order,
164+
boundary,
165+
)
166+
167+
if skip_velocity_sf is False:
168+
SF_z[right] = SF_dicts["SF_velocity_right"]
169+
if traditional_order > 0:
170+
SF_z_trad_velocity[right] = SF_dicts["SF_trad_velocity_right"]
171+
if scalar is not None:
172+
SF_z_scalar[right] = SF_dicts["SF_scalar_right"]
173+
if traditional_order > 0:
174+
SF_z_trad_scalar[right] = SF_dicts["SF_trad_scalar_right"]
175+
176+
# Calculate separation distances in x
177+
xd[right], tmp = calculate_separation_distances(
178+
x[right], y[down], xroll[right], y[down], grid_type
155179
)
156180

157181
# Bin the data if the grid is uneven

tests/test_generate_structure_functions.py

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,13 @@
197197
[
198198
0.0,
199199
111127.34496561,
200-
222085.35856591,
201-
332772.46924562,
202-
443087.12759851,
203-
552927.80866002,
204-
662193.01584979,
205-
770781.28701475,
206-
878591.20301767,
200+
222254.67962213,
201+
333381.99365421,
202+
444509.27673393,
203+
555636.51851453,
204+
666763.70862407,
205+
777890.83665907,
206+
889017.89217812,
207207
]
208208
),
209209
}, # expected_dict
@@ -257,9 +257,9 @@
257257
[
258258
0.0,
259259
111127.34496561,
260-
222085.35856591,
261-
332772.46924562,
262-
443087.12759851,
260+
222254.67962213,
261+
333381.99365421,
262+
444509.27673393,
263263
]
264264
),
265265
}, # expected_dict
@@ -304,7 +304,7 @@
304304
"y-diffs": np.array([1, 4, 7]),
305305
}, # expected_dict
306306
),
307-
# Test 5: all with no boundary and latlon grid and binning
307+
# Test 6: all with no boundary and latlon grid and binning
308308
(
309309
np.array(
310310
[[i + 1 for i in range(j * 10, (j + 1) * 10)] for j in range(10)]
@@ -344,10 +344,50 @@
344344
[111195.08372419, 444780.33489677, 778365.58606934]
345345
),
346346
"y-diffs": np.array(
347-
[111070.90117717, 442929.13516805, 770521.83529407]
347+
[111127.34152924, 444509.26296756, 777890.81248708]
348348
),
349349
}, # expected_dict
350350
),
351+
# Test 7: all with no boundary and uneven x vs y
352+
(
353+
np.array(
354+
[[i + 1 for i in range(j * 5, (j + 1) * 5)] for j in range(10)]
355+
), # u
356+
np.array([[i + 1 for i in range(j * 5, (j + 1) * 5)] for j in range(10)])
357+
* 2, # v
358+
np.linspace(1, 5, 5), # x
359+
np.linspace(1, 10, 10), # y
360+
False, # skip_velocity_sf
361+
np.array([[i + 1 for i in range(j * 5, (j + 1) * 5)] for j in range(10)])
362+
* 3, # scalar
363+
3, # traditional_order
364+
None, # dx
365+
None, # dy
366+
None, # boundary
367+
False, # even
368+
"uniform", # grid_type
369+
5, # nbins
370+
{
371+
"SF_advection_velocity_zonal": np.array([0, 55, 220, 495]),
372+
"SF_advection_velocity_meridional": np.array(
373+
[687.5, 8937.5, 22000, 41937.5, 77687.5]
374+
),
375+
"SF_advection_scalar_zonal": np.array([0, 99, 396, 891]),
376+
"SF_advection_scalar_meridional": np.array(
377+
[1237.5, 16087.5, 39600.0, 75487.5, 139837.5]
378+
),
379+
"SF_traditional_velocity_zonal": np.array([0, -1, -8, -27]),
380+
"SF_traditional_velocity_meridional": np.array(
381+
[-62.5, -2187.5, -8000.0, -21312.5, -53437.5]
382+
),
383+
"SF_traditional_scalar_zonal": np.array([0, -27, -216, -729]),
384+
"SF_traditional_scalar_meridional": np.array(
385+
[-1687.5, -59062.5, -216000.0, -575437.5, -1442812.5]
386+
),
387+
"x-diffs": np.linspace(0, 3, 4),
388+
"y-diffs": np.array([0.5, 2.5, 4, 5.5, 7.5]),
389+
}, # expected_dict
390+
),
351391
],
352392
)
353393
def test_generate_structure_functions_parameterized(

0 commit comments

Comments
 (0)