Skip to content

Commit d38d864

Browse files
Merge pull request #10 from cassidymwagner/main
Merging updates from main
2 parents 4c02b34 + 60ed4dc commit d38d864

8 files changed

+304
-135
lines changed

.github/workflows/draft-pdf.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
tags:
6+
- "v*"
7+
pull_request:
8+
branches:
9+
- main
10+
jobs:
11+
paper:
12+
runs-on: ubuntu-latest
13+
name: Paper Draft
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
- name: Build draft PDF
18+
uses: openjournals/openjournals-draft-action@master
19+
with:
20+
journal: joss
21+
# This should be the path to the paper within your repo.
22+
paper-path: paper/paper.md
23+
- name: Upload
24+
uses: actions/upload-artifact@v1
25+
with:
26+
name: paper
27+
# This is the output path where Pandoc will write the compiled
28+
# PDF. Note, this should be the same directory as the input
29+
# paper.md
30+
path: paper/paper.pdf

oceans_sf/calculate_advection.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,7 @@ def calculate_advection( # noqa: D417
4444
northward_advection) if scalar is not provided, otherwise returns an ndarray
4545
of scalar advection.
4646
"""
47-
if grid_type == "latlon":
48-
xcoords = dx.cumsum()
49-
ycoords = dy.cumsum()
50-
51-
if scalar is not None:
52-
dsdy, dsdx = np.gradient(scalar, xcoords, ycoords, axis=(0, 1))
53-
else:
54-
dudy, dudx = np.gradient(u, xcoords, ycoords, axis=(0, 1))
55-
dvdy, dvdx = np.gradient(v, xcoords, ycoords, axis=(0, 1))
56-
57-
else:
47+
if grid_type == "uniform":
5848
dx = np.abs(x[0] - x[1])
5949
dy = np.abs(y[0] - y[1])
6050

@@ -64,6 +54,16 @@ def calculate_advection( # noqa: D417
6454
dudy, dudx = np.gradient(u, dx, dy, axis=(0, 1))
6555
dvdy, dvdx = np.gradient(v, dx, dy, axis=(0, 1))
6656

57+
else:
58+
xcoords = dx.cumsum()
59+
ycoords = dy.cumsum()
60+
61+
if scalar is not None:
62+
dsdy, dsdx = np.gradient(scalar, xcoords, ycoords, axis=(0, 1))
63+
else:
64+
dudy, dudx = np.gradient(u, xcoords, ycoords, axis=(0, 1))
65+
dvdy, dvdx = np.gradient(v, xcoords, ycoords, axis=(0, 1))
66+
6767
if scalar is not None:
6868
advection = u * dsdx + v * dsdy
6969
else:

oceans_sf/calculate_structure_function.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from .shift_array2d import shift_array2d
44

55

6-
def calculate_structure_function( # noqa: D417
6+
def calculate_structure_function( # noqa: D417, C901
77
u,
88
v,
99
adv_e,
@@ -14,7 +14,7 @@ def calculate_structure_function( # noqa: D417
1414
scalar=None,
1515
adv_scalar=None,
1616
traditional_type=None,
17-
boundary="Periodic",
17+
boundary="periodic-all",
1818
):
1919
"""
2020
Calculate structure function, either advective or traditional.
@@ -50,7 +50,9 @@ def calculate_structure_function( # noqa: D417
5050
Accepted types are: "LL", "LLL", "LTT", "LSS". If None,
5151
no traditional structure functions are calculated. Defaults to None.
5252
boundary: str, optional
53-
Boundary condition for shifting arrays. Defaults to "Periodic".
53+
Boundary condition for shifting arrays. Accepted strings
54+
are "periodic-x", "periodic-y", and "periodic-all".
55+
Defaults to "periodic-all".
5456
5557
Returns
5658
-------

oceans_sf/generate_structure_functions.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def generate_structure_functions( # noqa: C901, D417
1919
traditional_type=None,
2020
dx=None,
2121
dy=None,
22-
boundary="Periodic",
22+
boundary="periodic-all",
2323
even="True",
2424
grid_type="uniform",
2525
nbins=10,
@@ -56,7 +56,8 @@ def generate_structure_functions( # noqa: C901, D417
5656
dy: float, optional
5757
Grid spacing in the y-direction. Defaults to None.
5858
boundary: str, optional
59-
Boundary condition of the data. Defaults to "Periodic".
59+
Boundary condition of the data. Accepted strings are "periodic-x",
60+
"periodic-y", and "periodic-all". Defaults to "periodic-all".
6061
even: bool, optional
6162
Flag indicating if the grid is evenly spaced. Defaults to True.
6263
grid_type:str, optional
@@ -90,10 +91,16 @@ def generate_structure_functions( # noqa: C901, D417
9091

9192
# Define a list of separation distances to iterate over.
9293
# Periodic is half the length since the calculation will wrap the data.
93-
if boundary == "Periodic":
94+
if boundary == "periodic-all":
9495
sep_z = range(1, int(len(x) / 2))
9596
sep_m = range(1, int(len(y) / 2))
96-
else:
97+
elif boundary == "periodic-x":
98+
sep_z = range(1, int(len(x) / 2))
99+
sep_m = range(1, int(len(y) - 1))
100+
elif boundary == "periodic-y":
101+
sep_z = range(1, int(len(x) - 1))
102+
sep_m = range(1, int(len(y) / 2))
103+
elif boundary is None:
97104
sep_z = range(1, int(len(x) - 1))
98105
sep_m = range(1, int(len(y) - 1))
99106

@@ -129,7 +136,10 @@ def generate_structure_functions( # noqa: C901, D417
129136
# Iterate over separations right and down
130137
for down in sep_m:
131138
right = 1
132-
yroll = shift_array1d(y, shift_by=down, boundary=boundary)
139+
if boundary == "periodic-all" or boundary == "periodic-y":
140+
yroll = shift_array1d(y, shift_by=down, boundary="Periodic")
141+
else:
142+
yroll = shift_array1d(y, shift_by=down, boundary=None)
133143

134144
SF_dicts = calculate_structure_function(
135145
u,
@@ -167,7 +177,10 @@ def generate_structure_functions( # noqa: C901, D417
167177

168178
for right in sep_z:
169179
down = 1
170-
xroll = shift_array1d(x, shift_by=right, boundary=boundary)
180+
if boundary == "periodic-all" or boundary == "periodic-x":
181+
xroll = shift_array1d(x, shift_by=right, boundary="Periodic")
182+
else:
183+
xroll = shift_array1d(x, shift_by=right, boundary=None)
171184

172185
SF_dicts = calculate_structure_function(
173186
u,

oceans_sf/shift_array2d.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
def shift_array2d( # noqa: D417
5-
input_array, shift_right=1, shift_down=1, boundary="Periodic"
5+
input_array, shift_right=1, shift_down=1, boundary="periodic-all"
66
):
77
"""
88
Shifts 2D array right and down by the specified integer amounts and returns
@@ -22,8 +22,9 @@ def shift_array2d( # noqa: D417
2222
conditions. Defaults to 1.
2323
boundary: str, optional
2424
Boundary condition for input array. Periodic boundary conditions will wrap
25-
the array, otherwise the array will be padded with NaNs. Defaults to
26-
"Periodic".
25+
the array, otherwise the array will be padded with NaNs. Accepted strings
26+
are "periodic-x", "periodic-y", and "periodic-all".
27+
Defaults to "periodic-all".
2728
2829
Returns
2930
-------
@@ -35,13 +36,26 @@ def shift_array2d( # noqa: D417
3536
shifted_right_array = np.full(np.shape(input_array), np.nan)
3637
shifted_down_array = np.full(np.shape(input_array), np.nan)
3738

38-
if boundary == "Periodic":
39+
if boundary == "periodic-all":
3940
shifted_right_array[:, :shift_right] = input_array[:, -shift_right:]
4041
shifted_right_array[:, shift_right:] = input_array[:, :-shift_right]
4142

4243
shifted_down_array[:shift_down, :] = input_array[-shift_down:, :]
4344
shifted_down_array[shift_down:, :] = input_array[:-shift_down, :]
44-
else:
45+
46+
elif boundary == "periodic-x":
47+
shifted_right_array[:, :shift_right] = input_array[:, -shift_right:]
48+
shifted_right_array[:, shift_right:] = input_array[:, :-shift_right]
49+
50+
shifted_down_array[shift_down:, :] = input_array[:-shift_down, :]
51+
52+
elif boundary == "periodic-y":
53+
shifted_right_array[:, shift_right:] = input_array[:, :-shift_right]
54+
55+
shifted_down_array[:shift_down, :] = input_array[-shift_down:, :]
56+
shifted_down_array[shift_down:, :] = input_array[:-shift_down, :]
57+
58+
elif boundary is None:
4559
shifted_right_array[:, shift_right:] = input_array[:, :-shift_right]
4660
shifted_down_array[shift_down:, :] = input_array[:-shift_down, :]
4761

tests/test_calculate_structure_function.py

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
@pytest.mark.parametrize(
1010
"u, v, adv_e, adv_n, down, right, skip_velocity_sf, scalar, "
11-
"adv_scalar, traditional_order, boundary, expected_result",
11+
"adv_scalar, traditional_type, boundary, expected_result",
1212
[
1313
# Test 1: velocity and scalar no traditional
1414
(
@@ -21,8 +21,8 @@
2121
False, # skip_velocity_sf
2222
np.array([[1, 2], [3, 4]]), # scalar
2323
np.array([[3, -2], [-3, 12]]), # adv_scalar
24-
0, # traditional_order
25-
"Periodic", # boundary
24+
None, # traditional_type
25+
"periodic-all", # boundary
2626
{
2727
"SF_velocity_right": 88,
2828
"SF_velocity_down": 138,
@@ -42,17 +42,15 @@
4242
False,
4343
np.array([[1, 2], [3, 4]]),
4444
np.array([[3, -2], [-3, 12]]),
45-
2,
46-
"Periodic",
45+
["LL"],
46+
"periodic-all",
4747
{
4848
"SF_velocity_right": 88,
49-
"SF_trad_velocity_right": 1,
49+
"SF_LL_right": 1,
5050
"SF_scalar_right": 5,
51-
"SF_trad_scalar_right": 1,
5251
"SF_velocity_down": 138,
53-
"SF_trad_velocity_down": 4,
52+
"SF_LL_down": 4,
5453
"SF_scalar_down": 8,
55-
"SF_trad_scalar_down": 4,
5654
},
5755
),
5856
# Test 3: all but skip velocity and no traditional
@@ -66,8 +64,8 @@
6664
True,
6765
np.array([[1, 2], [3, 4]]),
6866
np.array([[3, -2], [-3, 12]]),
69-
0,
70-
"Periodic",
67+
None,
68+
"periodic-all",
7169
{
7270
"SF_scalar_right": 5,
7371
"SF_scalar_down": 8,
@@ -84,8 +82,8 @@
8482
False,
8583
None,
8684
None,
87-
0,
88-
"Periodic",
85+
None,
86+
"periodic-all",
8987
{
9088
"SF_velocity_right": 88,
9189
"SF_velocity_down": 138,
@@ -102,7 +100,7 @@
102100
False,
103101
np.array([[1, 2], [3, 4]]),
104102
np.array([[3, -2], [-3, 12]]),
105-
0,
103+
None,
106104
None,
107105
{
108106
"SF_velocity_right": 88,
@@ -122,17 +120,15 @@
122120
False,
123121
np.array([[1, 2], [3, 4]]),
124122
np.array([[3, -2], [-3, 12]]),
125-
2,
123+
["LL"],
126124
None,
127125
{
128126
"SF_velocity_right": 88,
129-
"SF_trad_velocity_right": 1,
127+
"SF_LL_right": 1,
130128
"SF_scalar_right": 5,
131-
"SF_trad_scalar_right": 1,
132129
"SF_velocity_down": 138,
133-
"SF_trad_velocity_down": 4,
130+
"SF_LL_down": 4,
134131
"SF_scalar_down": 8,
135-
"SF_trad_scalar_down": 4,
136132
},
137133
),
138134
# Test 7: all but skip velocity and no traditional non-periodic
@@ -146,7 +142,7 @@
146142
True,
147143
np.array([[1, 2], [3, 4]]),
148144
np.array([[3, -2], [-3, 12]]),
149-
0,
145+
None,
150146
None,
151147
{
152148
"SF_scalar_right": 5,
@@ -164,7 +160,7 @@
164160
False,
165161
None,
166162
None,
167-
0,
163+
None,
168164
None,
169165
{
170166
"SF_velocity_right": 88,
@@ -183,7 +179,7 @@ def test_calculate_structure_function_parameterized(
183179
skip_velocity_sf,
184180
scalar,
185181
adv_scalar,
186-
traditional_order,
182+
traditional_type,
187183
boundary,
188184
expected_result,
189185
):
@@ -198,7 +194,7 @@ def test_calculate_structure_function_parameterized(
198194
skip_velocity_sf,
199195
scalar,
200196
adv_scalar,
201-
traditional_order,
197+
traditional_type,
202198
boundary,
203199
)
204200

0 commit comments

Comments
 (0)