Skip to content

Commit 752c1e2

Browse files
fixed bug with LLL/LL and ASF_V/ASF_S
1 parent 829f278 commit 752c1e2

6 files changed

+233
-126
lines changed

fluidsf/calculate_structure_function.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,53 +97,53 @@ def calculate_structure_function( # noqa: D417, C901
9797
SF_dict = {}
9898

9999
for direction in ["x", "y"]:
100-
if any("ASF_V" in t for t in sf_type):
100+
if "ASF_V" in sf_type:
101101
SF_dict["SF_advection_velocity_" + direction] = np.nanmean(
102102
(inputs["adv_x_" + direction + "_shift"] - adv_x)
103103
* (inputs["u_" + direction + "_shift"] - u)
104104
+ (inputs["adv_y_" + direction + "_shift"] - adv_y)
105105
* (inputs["v_" + direction + "_shift"] - v)
106106
)
107-
if any("ASF_S" in t for t in sf_type):
107+
if "ASF_S" in sf_type:
108108
SF_dict["SF_advection_scalar_" + direction] = np.nanmean(
109109
(inputs["adv_scalar_" + direction + "_shift"] - adv_scalar)
110110
* (inputs["scalar_" + direction + "_shift"] - scalar)
111111
)
112112
if direction == "x":
113-
if any("LL" in t for t in sf_type):
113+
if "LL" in sf_type:
114114
SF_dict["SF_LL_" + direction] = np.nanmean(
115115
(inputs["u_" + direction + "_shift"] - u) ** 2
116116
)
117-
if any("LLL" in t for t in sf_type):
117+
if "LLL" in sf_type:
118118
SF_dict["SF_LLL_" + direction] = np.nanmean(
119119
(inputs["u_" + direction + "_shift"] - u) ** 3
120120
)
121-
if any("LTT" in t for t in sf_type):
121+
if "LTT" in sf_type:
122122
SF_dict["SF_LTT_" + direction] = np.nanmean(
123123
(inputs["u_" + direction + "_shift"] - u)
124124
* (inputs["v_" + direction + "_shift"] - v) ** 2
125125
)
126-
if any("LSS" in t for t in sf_type):
126+
if "LSS" in sf_type:
127127
SF_dict["SF_LSS_" + direction] = np.nanmean(
128128
(inputs["u_" + direction + "_shift"] - u)
129129
* (inputs["scalar_" + direction + "_shift"] - scalar) ** 2
130130
)
131131

132132
elif direction == "y":
133-
if any("LL" in t for t in sf_type):
133+
if "LL" in sf_type:
134134
SF_dict["SF_LL_" + direction] = np.nanmean(
135135
(inputs["v_" + direction + "_shift"] - v) ** 2
136136
)
137-
if any("LLL" in t for t in sf_type):
137+
if "LLL" in sf_type:
138138
SF_dict["SF_LLL_" + direction] = np.nanmean(
139139
(inputs["v_" + direction + "_shift"] - v) ** 3
140140
)
141-
if any("LTT" in t for t in sf_type):
141+
if "LTT" in sf_type:
142142
SF_dict["SF_LTT_" + direction] = np.nanmean(
143143
(inputs["v_" + direction + "_shift"] - v)
144144
* (inputs["u_" + direction + "_shift"] - u) ** 2
145145
)
146-
if any("LSS" in t for t in sf_type):
146+
if "LSS" in sf_type:
147147
SF_dict["SF_LSS_" + direction] = np.nanmean(
148148
(inputs["v_" + direction + "_shift"] - v)
149149
* (inputs["scalar_" + direction + "_shift"] - scalar) ** 2

fluidsf/calculate_structure_function_3d.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def calculate_structure_function_3d( # noqa: D417, C901
121121
SF_dict = {}
122122

123123
for direction in ["x", "y", "z"]:
124-
if any("ASF_V" in t for t in sf_type):
124+
if "ASF_V" in sf_type:
125125
SF_dict["SF_advection_velocity_" + direction] = np.nanmean(
126126
(inputs["adv_x_" + direction + "_shift"] - adv_x)
127127
* (inputs["u_" + direction + "_shift"] - u)
@@ -130,67 +130,67 @@ def calculate_structure_function_3d( # noqa: D417, C901
130130
+ (inputs["adv_z_" + direction + "_shift"] - adv_z)
131131
* (inputs["w_" + direction + "_shift"] - w)
132132
)
133-
if any("ASF_S" in t for t in sf_type):
133+
if "ASF_S" in sf_type:
134134
SF_dict["SF_advection_scalar_" + direction] = np.nanmean(
135135
(inputs["adv_scalar_" + direction + "_shift"] - adv_scalar)
136136
* (inputs["scalar_" + direction + "_shift"] - scalar)
137137
)
138138

139139
if direction == "x":
140-
if any("LL" in t for t in sf_type):
140+
if "LL" in sf_type:
141141
SF_dict["SF_LL_" + direction] = np.nanmean(
142142
(inputs["u_" + direction + "_shift"] - u) ** 2
143143
)
144-
if any("LLL" in t for t in sf_type):
144+
if "LLL" in sf_type:
145145
SF_dict["SF_LLL_" + direction] = np.nanmean(
146146
(inputs["u_" + direction + "_shift"] - u) ** 3
147147
)
148-
if any("LTT" in t for t in sf_type):
148+
if "LTT" in sf_type:
149149
SF_dict["SF_LTT_" + direction] = np.nanmean(
150150
(inputs["u_" + direction + "_shift"] - u)
151151
* (inputs["v_" + direction + "_shift"] - v) ** 2
152152
)
153-
if any("LSS" in t for t in sf_type):
153+
if "LSS" in sf_type:
154154
SF_dict["SF_LSS_" + direction] = np.nanmean(
155155
(inputs["u_" + direction + "_shift"] - u)
156156
* (inputs["scalar_" + direction + "_shift"] - scalar) ** 2
157157
)
158158

159159
elif direction == "y":
160-
if any("LL" in t for t in sf_type):
160+
if "LL" in sf_type:
161161
SF_dict["SF_LL_" + direction] = np.nanmean(
162162
(inputs["v_" + direction + "_shift"] - v) ** 2
163163
)
164-
if any("LLL" in t for t in sf_type):
164+
if "LLL" in sf_type:
165165
SF_dict["SF_LLL_" + direction] = np.nanmean(
166166
(inputs["v_" + direction + "_shift"] - v) ** 3
167167
)
168-
if any("LTT" in t for t in sf_type):
168+
if "LTT" in sf_type:
169169
SF_dict["SF_LTT_" + direction] = np.nanmean(
170170
(inputs["v_" + direction + "_shift"] - v)
171171
* (inputs["u_" + direction + "_shift"] - u) ** 2
172172
)
173-
if any("LSS" in t for t in sf_type):
173+
if "LSS" in sf_type:
174174
SF_dict["SF_LSS_" + direction] = np.nanmean(
175175
(inputs["v_" + direction + "_shift"] - v)
176176
* (inputs["scalar_" + direction + "_shift"] - scalar) ** 2
177177
)
178178

179179
elif direction == "z":
180-
if any("LL" in t for t in sf_type):
180+
if "LL" in sf_type:
181181
SF_dict["SF_LL_" + direction] = np.nanmean(
182182
(inputs["w_" + direction + "_shift"] - w) ** 2
183183
)
184-
if any("LLL" in t for t in sf_type):
184+
if "LLL" in sf_type:
185185
SF_dict["SF_LLL_" + direction] = np.nanmean(
186186
(inputs["w_" + direction + "_shift"] - w) ** 3
187187
)
188-
if any("LTT" in t for t in sf_type):
188+
if "LTT" in sf_type:
189189
SF_dict["SF_LTT_" + direction] = np.nanmean(
190190
(inputs["w_" + direction + "_shift"] - w)
191191
* (inputs["u_" + direction + "_shift"] - u) ** 2
192192
)
193-
if any("LSS" in t for t in sf_type):
193+
if "LSS" in sf_type:
194194
SF_dict["SF_LSS_" + direction] = np.nanmean(
195195
(inputs["w_" + direction + "_shift"] - w)
196196
* (inputs["scalar_" + direction + "_shift"] - scalar) ** 2

fluidsf/generate_sf_maps_2d.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,21 @@ def generate_sf_maps_2d( # noqa: C901, D417
8080
x_separations = np.zeros([len(x_shifts), len(y_shifts)])
8181
y_separations = np.zeros([len(x_shifts), len(y_shifts)])
8282

83-
if any("ASF_V" in t for t in sf_type):
83+
if "ASF_V" in sf_type:
8484
SF_adv = np.zeros([len(x_shifts), len(y_shifts)])
8585
adv_x, adv_y = calculate_advection(u, v, x, y, dx, dy, grid_type)
86-
if any("ASF_S" in t for t in sf_type):
86+
if "ASF_S" in sf_type:
8787
SF_scalar_adv = np.zeros([len(x_shifts), len(y_shifts)])
8888
adv_scalar = calculate_advection(u, v, x, y, dx, dy, grid_type, scalar)
89-
if any("LL" in t for t in sf_type):
89+
if "LL" in sf_type:
9090
SF_LL = np.zeros([len(x_shifts), len(y_shifts)])
91-
if any("TT" in t for t in sf_type):
91+
if "TT" in sf_type:
9292
SF_TT = np.zeros([len(x_shifts), len(y_shifts)])
93-
if any("LLL" in t for t in sf_type):
93+
if "LLL" in sf_type:
9494
SF_LLL = np.zeros([len(x_shifts), len(y_shifts)])
95-
if any("LTT" in t for t in sf_type):
95+
if "LTT" in sf_type:
9696
SF_LTT = np.zeros([len(x_shifts), len(y_shifts)])
97-
if any("LSS" in t for t in sf_type):
97+
if "LSS" in sf_type:
9898
SF_LSS = np.zeros([len(x_shifts), len(y_shifts)])
9999

100100
# Iterate over separations right and down
@@ -130,21 +130,21 @@ def generate_sf_maps_2d( # noqa: C901, D417
130130
x_separations[x_shift, y_shift + int(len(y) / 2)] = x_separation
131131
y_separations[x_shift, y_shift + int(len(y) / 2)] = y_separation
132132

133-
if any("ASF_V" in t for t in sf_type):
133+
if "ASF_V" in sf_type:
134134
SF_adv[x_shift, y_shift + int(len(y) / 2)] = SF_dicts[
135135
"SF_advection_velocity_xy"
136136
]
137-
if any("ASF_S" in t for t in sf_type):
137+
if "ASF_S" in sf_type:
138138
SF_scalar_adv[x_shift, y_shift + int(len(y) / 2)] = SF_dicts[
139139
"SF_advection_velocity_xy"
140140
]
141-
if any("LL" in t for t in sf_type):
141+
if "LL" in sf_type:
142142
SF_LL[x_shift, y_shift + int(len(y) / 2)] = SF_dicts["SF_LL_xy"]
143-
if any("LLL" in t for t in sf_type):
143+
if "LLL" in sf_type:
144144
SF_LLL[x_shift, y_shift + int(len(y) / 2)] = SF_dicts["SF_LLL_xy"]
145-
if any("LTT" in t for t in sf_type):
145+
if "LTT" in sf_type:
146146
SF_LTT[x_shift, y_shift + int(len(y) / 2)] = SF_dicts["SF_LTT_xy"]
147-
if any("LSS" in t for t in sf_type):
147+
if "LSS" in sf_type:
148148
SF_LSS[x_shift, y_shift + int(len(y) / 2)] = SF_dicts["SF_LSS_xy"]
149149

150150
# When saving data, roll y-axis so that y-values go from most negative to most

fluidsf/generate_structure_functions.py

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -192,28 +192,38 @@ def generate_structure_functions( # noqa: C901, D417
192192
yd = np.zeros(len(sep_y) + 1)
193193

194194
# Calculate advection if requested
195-
if any("ASF_V" in t for t in sf_type):
195+
if "ASF_V" in sf_type:
196196
SF_adv_x = np.zeros(len(sep_x) + 1)
197197
SF_adv_y = np.zeros(len(sep_y) + 1)
198198
adv_x, adv_y = calculate_advection(
199-
u, v, x, y, lats, lons, dx, dy, grid_type, scalar, sphere_circumference
199+
u,
200+
v,
201+
x,
202+
y,
203+
lats,
204+
lons,
205+
dx,
206+
dy,
207+
grid_type,
208+
scalar=None,
209+
sphere_circumference=sphere_circumference,
200210
)
201-
if any("ASF_S" in t for t in sf_type):
211+
if "ASF_S" in sf_type:
202212
SF_x_scalar = np.zeros(len(sep_x) + 1)
203213
SF_y_scalar = np.zeros(len(sep_y) + 1)
204214
adv_scalar = calculate_advection(
205215
u, v, x, y, lats, lons, dx, dy, grid_type, scalar, sphere_circumference
206216
)
207-
if any("LL" in t for t in sf_type):
217+
if "LL" in sf_type:
208218
SF_x_LL = np.zeros(len(sep_x) + 1)
209219
SF_y_LL = np.zeros(len(sep_y) + 1)
210-
if any("LLL" in t for t in sf_type):
220+
if "LLL" in sf_type:
211221
SF_x_LLL = np.zeros(len(sep_x) + 1)
212222
SF_y_LLL = np.zeros(len(sep_y) + 1)
213-
if any("LTT" in t for t in sf_type):
223+
if "LTT" in sf_type:
214224
SF_x_LTT = np.zeros(len(sep_x) + 1)
215225
SF_y_LTT = np.zeros(len(sep_y) + 1)
216-
if any("LSS" in t for t in sf_type):
226+
if "LSS" in sf_type:
217227
SF_x_LSS = np.zeros(len(sep_x) + 1)
218228
SF_y_LSS = np.zeros(len(sep_y) + 1)
219229

@@ -246,17 +256,17 @@ def generate_structure_functions( # noqa: C901, D417
246256
boundary,
247257
)
248258

249-
if any("ASF_V" in t for t in sf_type):
259+
if "ASF_V" in sf_type:
250260
SF_adv_x[x_shift] = SF_dicts["SF_advection_velocity_x"]
251-
if any("LL" in t for t in sf_type):
261+
if "LL" in sf_type:
252262
SF_x_LL[x_shift] = SF_dicts["SF_LL_x"]
253-
if any("LLL" in t for t in sf_type):
263+
if "LLL" in sf_type:
254264
SF_x_LLL[x_shift] = SF_dicts["SF_LLL_x"]
255-
if any("LTT" in t for t in sf_type):
265+
if "LTT" in sf_type:
256266
SF_x_LTT[x_shift] = SF_dicts["SF_LTT_x"]
257-
if any("ASF_S" in t for t in sf_type):
267+
if "ASF_S" in sf_type:
258268
SF_x_scalar[x_shift] = SF_dicts["SF_advection_scalar_x"]
259-
if any("LSS" in t for t in sf_type):
269+
if "LSS" in sf_type:
260270
SF_x_LSS[x_shift] = SF_dicts["SF_LSS_x"]
261271

262272
# Calculate separation distances in x
@@ -304,17 +314,17 @@ def generate_structure_functions( # noqa: C901, D417
304314
boundary,
305315
)
306316

307-
if any("ASF_V" in t for t in sf_type):
317+
if "ASF_V" in sf_type:
308318
SF_adv_y[y_shift] = SF_dicts["SF_advection_velocity_y"]
309-
if any("LL" in t for t in sf_type):
319+
if "LL" in sf_type:
310320
SF_y_LL[y_shift] = SF_dicts["SF_LL_y"]
311-
if any("LLL" in t for t in sf_type):
321+
if "LLL" in sf_type:
312322
SF_y_LLL[y_shift] = SF_dicts["SF_LLL_y"]
313-
if any("LTT" in t for t in sf_type):
323+
if "LTT" in sf_type:
314324
SF_y_LTT[y_shift] = SF_dicts["SF_LTT_y"]
315-
if any("ASF_S" in t for t in sf_type):
325+
if "ASF_S" in sf_type:
316326
SF_y_scalar[y_shift] = SF_dicts["SF_advection_scalar_y"]
317-
if any("LSS" in t for t in sf_type):
327+
if "LSS" in sf_type:
318328
SF_y_LSS[y_shift] = SF_dicts["SF_LSS_y"]
319329

320330
# Calculate separation distances in y
@@ -340,22 +350,22 @@ def generate_structure_functions( # noqa: C901, D417
340350

341351
# Bin the data if requested or if grid_type is latlon
342352
if nbins is not None:
343-
if any("ASF_V" in t for t in sf_type):
353+
if "ASF_V" in sf_type:
344354
xd_bin, SF_adv_x = bin_data(xd, SF_adv_x, nbins, grid_type)
345355
yd_bin, SF_adv_y = bin_data(yd, SF_adv_y, nbins, grid_type)
346-
if any("ASF_S" in t for t in sf_type):
356+
if "ASF_S" in sf_type:
347357
xd_bin, SF_x_scalar = bin_data(xd, SF_x_scalar, nbins, grid_type)
348358
yd_bin, SF_y_scalar = bin_data(yd, SF_y_scalar, nbins, grid_type)
349-
if any("LL" in t for t in sf_type):
359+
if "LL" in sf_type:
350360
xd_bin, SF_x_LL = bin_data(xd, SF_x_LL, nbins, grid_type)
351361
yd_bin, SF_y_LL = bin_data(yd, SF_y_LL, nbins, grid_type)
352-
if any("LLL" in t for t in sf_type):
362+
if "LLL" in sf_type:
353363
xd_bin, SF_x_LLL = bin_data(xd, SF_x_LLL, nbins, grid_type)
354364
yd_bin, SF_y_LLL = bin_data(yd, SF_y_LLL, nbins, grid_type)
355-
if any("LTT" in t for t in sf_type):
365+
if "LTT" in sf_type:
356366
xd_bin, SF_x_LTT = bin_data(xd, SF_x_LTT, nbins, grid_type)
357367
yd_bin, SF_y_LTT = bin_data(yd, SF_y_LTT, nbins, grid_type)
358-
if any("LSS" in t for t in sf_type):
368+
if "LSS" in sf_type:
359369
xd_bin, SF_x_LSS = bin_data(xd, SF_x_LSS, nbins, grid_type)
360370
yd_bin, SF_y_LSS = bin_data(yd, SF_y_LSS, nbins, grid_type)
361371
xd = xd_bin

0 commit comments

Comments
 (0)