Skip to content

Commit ed1ce9d

Browse files
committed
Making files flake8 compliant
1 parent f7aca6e commit ed1ce9d

3 files changed

Lines changed: 45 additions & 30 deletions

File tree

tests/test_constructors.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def make_simple_fieldset():
1111
mesh='spherical')
1212
return fieldset
1313

14+
1415
def make_standard_simulation_settings():
1516
simulation_settings = {'startdate': datetime.strptime('2020-01-04-00:00:00', '%Y-%m-%d-%H:%M:%S'),
1617
'runtime': timedelta(days=2),
@@ -19,6 +20,7 @@ def make_standard_simulation_settings():
1920
}
2021
return simulation_settings
2122

23+
2224
def make_standard_plastictype_settings():
2325
plastictype_settings = {'wind_coefficient' : 0.01, # Percentage of wind to apply to particles
2426
'plastic_diameter' : 0.01, # Plastic particle diameter (m)
@@ -37,6 +39,7 @@ def test_create_hydrodynamic_fieldset():
3739

3840
assert isinstance(fieldset, parcels.FieldSet)
3941

42+
4043
# Test the create_fieldset() function
4144
@pytest.mark.parametrize('use_3D', [True, False])
4245
@pytest.mark.parametrize('use_biofouling', [True, False])
@@ -49,17 +52,18 @@ def test_create_fieldset(use_3D, use_biofouling, use_stokes, use_wind, use_mixin
4952
settings = pp.utils.download_plasticparcels_dataset('NEMO0083', settings, 'input_data')
5053

5154
settings['simulation'] = make_standard_simulation_settings()
52-
55+
5356
settings['use_3D'] = use_3D
5457
settings['use_biofouling'] = use_biofouling
5558
settings['use_stokes'] = use_stokes
5659
settings['use_wind'] = use_wind
5760
settings['use_mixing'] = use_mixing
58-
61+
5962
fieldset = pp.constructors.create_fieldset(settings)
6063

6164
assert isinstance(fieldset, parcels.FieldSet)
6265

66+
6367
# Test three different initialisation maps
6468
@pytest.mark.parametrize('initialisation_map', ['coastal', 'fisheries', 'rivers'])
6569
def test_create_particleset_from_map(initialisation_map):
@@ -68,18 +72,19 @@ def test_create_particleset_from_map(initialisation_map):
6872
settings = pp.utils.download_plasticparcels_dataset('NEMO0083', settings, 'input_data')
6973

7074
settings['simulation'] = make_standard_simulation_settings()
71-
75+
7276
settings['plastictype'] = make_standard_plastictype_settings()
73-
77+
7478
settings['release'] = {'initialisation_type': initialisation_map,
7579
'country': 'Italy',
7680
}
77-
81+
7882
fieldset = make_simple_fieldset()
7983
pset = pp.constructors.create_particleset_from_map(fieldset, settings)
8084

8185
assert isinstance(pset, parcels.ParticleSet)
8286

87+
8388
# Test the two global concentration release map types
8489
@pytest.mark.parametrize('concentration_type', ['Beach', 'Ocean'])
8590
def test_create_particleset_from_map_concentrations(concentration_type):
@@ -88,18 +93,19 @@ def test_create_particleset_from_map_concentrations(concentration_type):
8893
settings = pp.utils.download_plasticparcels_dataset('NEMO0083', settings, 'input_data')
8994

9095
settings['simulation'] = make_standard_simulation_settings()
91-
96+
9297
settings['plastictype'] = make_standard_plastictype_settings()
93-
98+
9499
settings['release'] = {'initialisation_type': 'global_concentrations',
95100
'concentration_type': concentration_type,
96101
}
97-
102+
98103
fieldset = make_simple_fieldset()
99104
pset = pp.constructors.create_particleset_from_map(fieldset, settings)
100105

101106
assert isinstance(pset, parcels.ParticleSet)
102107

108+
103109
# Test three different initialisation maps
104110
@pytest.mark.parametrize('use_3D', [True, False])
105111
@pytest.mark.parametrize('use_biofouling', [True, False])
@@ -118,7 +124,7 @@ def test_create_kernel(use_3D, use_biofouling, use_stokes, use_wind, use_mixing)
118124
settings['use_stokes'] = use_stokes
119125
settings['use_wind'] = use_wind
120126
settings['use_mixing'] = use_mixing
121-
127+
122128
fieldset = pp.constructors.create_fieldset(settings)
123129
kernels = pp.constructors.create_kernel(fieldset)
124130

@@ -133,18 +139,18 @@ def test_create_kernel(use_3D, use_biofouling, use_stokes, use_wind, use_mixing)
133139
assert pp.kernels.Biofouling in kernels
134140
elif use_3D and not use_biofouling:
135141
assert pp.kernels.SettlingVelocity in kernels
136-
142+
137143
if use_mixing:
138144
assert pp.kernels.VerticalMixing in kernels
139145

140146
if use_stokes:
141147
assert pp.kernels.StokesDrift in kernels
142148
assert pp.kernels.unbeaching in kernels
143-
149+
144150
if use_wind:
145151
assert pp.kernels.WindageDrift in kernels
146152
assert pp.kernels.unbeaching in kernels
147-
153+
148154
assert pp.kernels.deleteParticle in kernels
149155
assert pp.kernels.periodicBC in kernels
150-
assert pp.kernels.PolyTEOS10_bsq in kernels
156+
assert pp.kernels.PolyTEOS10_bsq in kernels

tests/test_kernels.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def make_standard_simulation_settings():
1414
}
1515
return simulation_settings
1616

17+
1718
def make_standard_plastictype_settings():
1819
#Use tiny wind percentage because test data set is not large and wind speeds are quick!
1920
plastictype_settings = {'wind_coefficient' : 0.0001, # Percentage of wind to apply to particles
@@ -22,6 +23,7 @@ def make_standard_plastictype_settings():
2223
}
2324
return plastictype_settings
2425

26+
2527
def make_standard_particleset(fieldset, settings):
2628
# Generate a particleset that has particles in the test domain
2729
settings['release'] = {'initialisation_type': 'fisheries', 'country': 'Malta'}
@@ -30,9 +32,10 @@ def make_standard_particleset(fieldset, settings):
3032
# Only keep particles in the test domain
3133
keep_particles = (pset.lon >17) & (pset.lon <20) & (pset.lat < 36) & (pset.lat > 34)
3234
pset.remove_booleanvector(~keep_particles)
33-
35+
3436
return pset
3537

38+
3639
@pytest.mark.parametrize('use_3D', [True, False])
3740
def test_advection_only(use_3D):
3841
settings_file = 'tests/test_data/test_settings.json'
@@ -41,7 +44,7 @@ def test_advection_only(use_3D):
4144

4245
settings['simulation'] = make_standard_simulation_settings()
4346
settings['plastictype'] = make_standard_plastictype_settings()
44-
47+
4548
# Turn on/off 3D advection
4649
settings['use_3D'] = use_3D
4750

@@ -67,14 +70,15 @@ def test_advection_only(use_3D):
6770
# Assert that the particles move from their initial location
6871
assert (np.sum(np.abs(pset.lon - start_lons)) > 0.) & (np.sum(np.abs(pset.lat - start_lats)) > 0.)
6972

73+
7074
def test_settling_velocity():
7175
settings_file = 'tests/test_data/test_settings.json'
7276
settings = pp.utils.load_settings(settings_file)
7377
settings = pp.utils.download_plasticparcels_dataset('NEMO0083', settings, 'input_data')
7478

7579
settings['simulation'] = make_standard_simulation_settings()
7680
settings['plastictype'] = make_standard_plastictype_settings()
77-
81+
7882
# Turn on 3D advection
7983
settings['use_3D'] = True
8084

@@ -85,7 +89,7 @@ def test_settling_velocity():
8589
settings['use_mixing'] = False
8690

8791
fieldset = pp.constructors.create_fieldset(settings)
88-
92+
8993
kernels = pp.constructors.create_kernel(fieldset)
9094

9195
pset = make_standard_particleset(fieldset, settings)
@@ -99,14 +103,15 @@ def test_settling_velocity():
99103
# Assert that the particles move from their initial location
100104
assert (np.sum(np.abs(pset.lon - start_lons)) > 0.) & (np.sum(np.abs(pset.lat - start_lats)) > 0.) & (np.sum(np.abs(pset.depth - start_depths)) > 0.)
101105

106+
102107
def test_biofouling():
103108
settings_file = 'tests/test_data/test_settings.json'
104109
settings = pp.utils.load_settings(settings_file)
105110
settings = pp.utils.download_plasticparcels_dataset('NEMO0083', settings, 'input_data')
106111

107112
settings['simulation'] = make_standard_simulation_settings()
108113
settings['plastictype'] = make_standard_plastictype_settings()
109-
114+
110115
# Turn on biofouling
111116
settings['use_biofouling'] = True
112117

@@ -117,7 +122,7 @@ def test_biofouling():
117122
settings['use_mixing'] = False
118123

119124
fieldset = pp.constructors.create_fieldset(settings)
120-
125+
121126
kernels = [pp.kernels.PolyTEOS10_bsq, pp.kernels.Biofouling,
122127
pp.kernels.checkThroughBathymetry, pp.kernels.checkErrorThroughSurface,
123128
pp.kernels.deleteParticle]
@@ -131,25 +136,26 @@ def test_biofouling():
131136
# Assert that the particles move from their initial location
132137
assert (np.sum(np.abs(pset.depth - start_depths)) > 0.)
133138

139+
134140
def test_Stokes():
135141
settings_file = 'tests/test_data/test_settings.json'
136142
settings = pp.utils.load_settings(settings_file)
137143
settings = pp.utils.download_plasticparcels_dataset('NEMO0083', settings, 'input_data')
138144

139145
settings['simulation'] = make_standard_simulation_settings()
140146
settings['plastictype'] = make_standard_plastictype_settings()
141-
147+
142148
# Turn on Stokes Drift
143149
settings['use_stokes'] = True
144-
150+
145151
# Turn off all other processes
146152
settings['use_3D'] = False
147153
settings['use_biofouling'] = False
148154
settings['use_wind'] = False
149155
settings['use_mixing'] = False
150156

151157
fieldset = pp.constructors.create_fieldset(settings)
152-
158+
153159
kernels = [pp.kernels.StokesDrift, pp.kernels.deleteParticle]
154160

155161
pset = make_standard_particleset(fieldset, settings)
@@ -162,29 +168,30 @@ def test_Stokes():
162168
# Assert that the particles move from their initial location
163169
assert (np.sum(np.abs(pset.lon - start_lons)) > 0.) & (np.sum(np.abs(pset.lat - start_lats)) > 0.)
164170

171+
165172
def test_wind():
166173
settings_file = 'tests/test_data/test_settings.json'
167174
settings = pp.utils.load_settings(settings_file)
168175
settings = pp.utils.download_plasticparcels_dataset('NEMO0083', settings, 'input_data')
169176

170177
settings['simulation'] = make_standard_simulation_settings()
171178
settings['plastictype'] = make_standard_plastictype_settings()
172-
179+
173180
# Turn on Stokes Drift
174181
settings['use_wind'] = True
175-
182+
176183
# Turn off all other processes
177184
settings['use_3D'] = False
178185
settings['use_biofouling'] = False
179186
settings['use_stokes'] = False
180187
settings['use_mixing'] = False
181188

182189
fieldset = pp.constructors.create_fieldset(settings)
183-
190+
184191
kernels = [pp.kernels.WindageDrift, pp.kernels.unbeaching, pp.kernels.periodicBC, pp.kernels.deleteParticle]
185192

186193
pset = make_standard_particleset(fieldset, settings)
187-
194+
188195
start_lons = pset.lon.copy()
189196
start_lats = pset.lat.copy()
190197

@@ -193,17 +200,18 @@ def test_wind():
193200
# Assert that the particles move from their initial location
194201
assert (np.sum(np.abs(pset.lon - start_lons)) > 0.) & (np.sum(np.abs(pset.lat - start_lats)) > 0.)
195202

203+
196204
def test_mixing():
197205
settings_file = 'tests/test_data/test_settings.json'
198206
settings = pp.utils.load_settings(settings_file)
199207
settings = pp.utils.download_plasticparcels_dataset('NEMO0083', settings, 'input_data')
200208

201209
settings['simulation'] = make_standard_simulation_settings()
202210
settings['plastictype'] = make_standard_plastictype_settings()
203-
211+
204212
settings['use_3D'] = True
205213
settings['use_mixing'] = True
206-
214+
207215
# Turn off all other processes
208216
settings['use_wind'] = False
209217
settings['use_biofouling'] = False
@@ -212,7 +220,7 @@ def test_mixing():
212220
fieldset = pp.constructors.create_fieldset(settings)
213221
kernels = [parcels.application_kernels.AdvectionRK4_3D, pp.kernels.checkThroughBathymetry,
214222
pp.kernels.checkErrorThroughSurface, pp.kernels.deleteParticle]
215-
223+
216224
kernels_mixing = [parcels.application_kernels.AdvectionRK4_3D, pp.kernels.VerticalMixing,
217225
pp.kernels.checkThroughBathymetry, pp.kernels.checkErrorThroughSurface,
218226
pp.kernels.deleteParticle]

tests/test_settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import plasticparcels as pp
22

3+
34
def test_settings():
45
settings = pp.utils.load_settings('tests/test_data/test_settings.json')
56
assert settings is not None
@@ -8,4 +9,4 @@ def test_settings():
89
def test_download_script(tmpdir):
910
settings = pp.utils.load_settings('tests/test_data/test_settings.json')
1011
pp.utils.download_plasticparcels_dataset("NEMO0083", settings=settings, data_home=tmpdir)
11-
assert True
12+
assert True

0 commit comments

Comments
 (0)