Skip to content

Commit ed36fdd

Browse files
Merge branch 'master' into summedvectorfield_eval_implementation
2 parents cf6f1f2 + 85a45b0 commit ed36fdd

29 files changed

Lines changed: 318 additions & 161 deletions

parcels/compilation/codecompiler.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,10 @@ def _create_compile_process_(self, cmd, src, log):
237237
Source/Destination file: %s
238238
Log file: %s
239239
240-
Log output: %s""" % (" ".join(cmd), src, logfile.name, logfile2.read())
240+
Log output: %s
241+
If you are on macOS, it might help to type 'export CC=gcc'
242+
243+
""" % (" ".join(cmd), src, logfile.name, logfile2.read())
241244
raise RuntimeError(err)
242245
return True
243246

parcels/compilation/codegenerator.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,10 @@ def visit_Attribute(self, node):
331331
raise NotImplementedError("Cannot convert numpy functions in kernels to C-code.\n"
332332
"Either use functions from the math library or run Parcels in Scipy mode.\n"
333333
"For more information, see http://oceanparcels.org/faq.html#kernelwriting")
334+
elif node.value.id in ['random']:
335+
raise NotImplementedError("Cannot convert random functions in kernels to C-code.\n"
336+
"Use `import parcels.rng as ParcelsRandom` and then ParcelsRandom.random(), ParcelsRandom.uniform() etc.\n"
337+
"For more information, see http://oceanparcels.org/faq.html#kernelwriting")
334338
else:
335339
raise NotImplementedError("Cannot convert '%s' used in kernel to C-code" % node.value.id)
336340

@@ -692,9 +696,9 @@ def visit_If(self, node):
692696

693697
def visit_Compare(self, node):
694698
self.visit(node.left)
695-
assert(len(node.ops) == 1)
699+
assert (len(node.ops) == 1)
696700
self.visit(node.ops[0])
697-
assert(len(node.comparators) == 1)
701+
assert (len(node.comparators) == 1)
698702
self.visit(node.comparators[0])
699703
node.ccode = "%s %s %s" % (node.left.ccode, node.ops[0].ccode,
700704
node.comparators[0].ccode)

parcels/examples/documentation_indexing.ipynb

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@
6565
{
6666
"cell_type": "code",
6767
"execution_count": 2,
68-
"metadata": {},
68+
"metadata": {
69+
"tags": [
70+
"raises-exception"
71+
]
72+
},
6973
"outputs": [
7074
{
7175
"ename": "ValueError",
@@ -123,19 +127,7 @@
123127
"cell_type": "code",
124128
"execution_count": 4,
125129
"metadata": {},
126-
"outputs": [
127-
{
128-
"name": "stderr",
129-
"output_type": "stream",
130-
"text": [
131-
"WARNING: File NemoNorthSeaORCA025-N006_data/coordinates.nc could not be decoded properly by xarray (version 0.15.1).\n",
132-
" It will be opened with no decoding. Filling values might be wrongly parsed.\n",
133-
"WARNING: Casting lon data to np.float32\n",
134-
"WARNING: Casting lat data to np.float32\n",
135-
"WARNING: Trying to initialize a shared grid with different chunking sizes - action prohibited. Replacing requested field_chunksize with grid's master chunksize.\n"
136-
]
137-
}
138-
],
130+
"outputs": [],
139131
"source": [
140132
"mesh_mask = data_path + 'coordinates.nc'\n",
141133
"\n",
@@ -147,7 +139,14 @@
147139
" 'V': {'lon': 'glamf', 'lat': 'gphif', 'depth': 'depthw', 'time': 'time_counter'},\n",
148140
" 'W': {'lon': 'glamf', 'lat': 'gphif', 'depth': 'depthw', 'time': 'time_counter'}}\n",
149141
"\n",
150-
"fieldsetC = FieldSet.from_nemo(filenames, variables, dimensions)"
142+
"fieldsetC = FieldSet.from_nemo(filenames, variables, dimensions, netcdf_decodewarning=False)"
143+
]
144+
},
145+
{
146+
"cell_type": "markdown",
147+
"metadata": {},
148+
"source": [
149+
"Note by the way, that we used `netcdf_decodewarning=False` in the `FieldSet.from_nemo()` call above. This is to silence an expected warning because the time dimension in the `coordinates.nc` file can't be decoded by `xarray`."
151150
]
152151
},
153152
{
@@ -221,7 +220,7 @@
221220
],
222221
"metadata": {
223222
"kernelspec": {
224-
"display_name": "Python 3",
223+
"display_name": "Python 3 (ipykernel)",
225224
"language": "python",
226225
"name": "python3"
227226
},
@@ -235,7 +234,7 @@
235234
"name": "python",
236235
"nbconvert_exporter": "python",
237236
"pygments_lexer": "ipython3",
238-
"version": "3.8.5"
237+
"version": "3.8.13"
239238
}
240239
},
241240
"nbformat": 4,

parcels/examples/documentation_unstuck_Agrid.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"cell_type": "markdown",
1212
"metadata": {},
1313
"source": [
14-
"In [another notebook](https://ndViewer.jupyter.org/github/OceanParcels/parcels/blob/master/parcels/examples/documentation_stuck_particles.ipynb), we have shown how particles may end up getting stuck on land, especially in A gridded velocity fields. Here we show how you can work around this problem and how large the effects of the solutions on the trajectories are.\n",
14+
"In [another notebook](https://nbviewer.jupyter.org/github/OceanParcels/parcels/blob/master/parcels/examples/documentation_stuck_particles.ipynb), we have shown how particles may end up getting stuck on land, especially in A gridded velocity fields. Here we show how you can work around this problem and how large the effects of the solutions on the trajectories are.\n",
1515
"\n",
1616
"Common solutions are:\n",
1717
"1. [Delete the particles](#1.-Particle-deletion)\n",
@@ -28,7 +28,7 @@
2828
"1. Flag particles within a specific distance to the shore\n",
2929
"2. Flag particles in any gridcell that has a shore edge\n",
3030
"\n",
31-
"As argued in the [previous notebook](https://ndViewer.jupyter.org/github/OceanParcels/parcels/blob/master/parcels/examples/documentation_stuck_particles.ipynb), it is important to accurately plot the grid discretization, in order to understand the motion of particles near the boundary. The velocity fields can best be depicted using points or arrows that define the velocity at a single position. Four of these nodes then form gridcells that can be shown using tiles, for example with `matplotlib.pyplot.pcolormesh`."
31+
"As argued in the [previous notebook](https://nbviewer.jupyter.org/github/OceanParcels/parcels/blob/master/parcels/examples/documentation_stuck_particles.ipynb), it is important to accurately plot the grid discretization, in order to understand the motion of particles near the boundary. The velocity fields can best be depicted using points or arrows that define the velocity at a single position. Four of these nodes then form gridcells that can be shown using tiles, for example with `matplotlib.pyplot.pcolormesh`."
3232
]
3333
},
3434
{

parcels/examples/example_dask_chunk_OCMs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ def test_globcurrent_2D(mode, chunk_mode):
281281
elif chunk_mode == 'failsafe': # chunking time but not lat
282282
assert (len(field_set.U.grid.load_chunk) != 1)
283283
assert (len(field_set.V.grid.load_chunk) != 1)
284-
assert(abs(pset[0].lon - 23.8) < 1)
285-
assert(abs(pset[0].lat - -35.3) < 1)
284+
assert abs(pset[0].lon - 23.8) < 1
285+
assert abs(pset[0].lat - -35.3) < 1
286286

287287

288288
@pytest.mark.parametrize('mode', ['jit'])
@@ -382,8 +382,8 @@ def test_ofam_3D(mode, chunk_mode):
382382
matching_fields = (field_set.U.grid.chunk_info == field_set.V.grid.chunk_info)
383383
matching_uniformblocks = (len(field_set.U.grid.load_chunk) == (1 * int(math.ceil(1.0/60.0)) * int(math.ceil(601.0/50.0)) * int(math.ceil(2001.0/100.0))))
384384
assert (matching_uniformblocks or (matching_fields and matching_numblocks))
385-
assert(abs(pset[0].lon - 173) < 1)
386-
assert(abs(pset[0].lat - 11) < 1)
385+
assert abs(pset[0].lon - 173) < 1
386+
assert abs(pset[0].lat - 11) < 1
387387

388388

389389
@pytest.mark.parametrize('mode', ['jit'])

parcels/examples/example_globcurrent.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ def set_globcurrent_fieldset(filename=None, indices=None, deferred_load=True, us
3939
@pytest.mark.parametrize('use_xarray', [True, False])
4040
def test_globcurrent_fieldset(use_xarray):
4141
fieldset = set_globcurrent_fieldset(use_xarray=use_xarray)
42-
assert(fieldset.U.lon.size == 81)
43-
assert(fieldset.U.lat.size == 41)
44-
assert(fieldset.V.lon.size == 81)
45-
assert(fieldset.V.lat.size == 41)
42+
assert fieldset.U.lon.size == 81
43+
assert fieldset.U.lat.size == 41
44+
assert fieldset.V.lon.size == 81
45+
assert fieldset.V.lat.size == 41
4646

4747
if not use_xarray:
4848
indices = {'lon': [5], 'lat': range(20, 30)}
@@ -88,8 +88,8 @@ def test_globcurrent_particles(mode, use_xarray):
8888

8989
pset.execute(AdvectionRK4, runtime=delta(days=1), dt=delta(minutes=5))
9090

91-
assert(abs(pset[0].lon - 23.8) < 1)
92-
assert(abs(pset[0].lat - -35.3) < 1)
91+
assert abs(pset[0].lon - 23.8) < 1
92+
assert abs(pset[0].lat - -35.3) < 1
9393

9494

9595
@pytest.mark.parametrize('mode', ['scipy', 'jit'])

parcels/examples/example_moving_eddies.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ def test_moving_eddies_fieldset(mode, mesh, tmpdir):
157157
assert (pset[0].lon < 2.2e5 and 1.1e5 < pset[0].lat < 1.2e5)
158158
assert (pset[1].lon < 2.2e5 and 3.7e5 < pset[1].lat < 3.8e5)
159159
else:
160-
assert(pset[0].lon < 2.0 and 46.2 < pset[0].lat < 46.25)
161-
assert(pset[1].lon < 2.0 and 48.8 < pset[1].lat < 48.85)
160+
assert (pset[0].lon < 2.0 and 46.2 < pset[0].lat < 46.25)
161+
assert (pset[1].lon < 2.0 and 48.8 < pset[1].lat < 48.85)
162162

163163

164164
def fieldsetfile(mesh, tmpdir):

parcels/examples/example_ofam.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def set_ofam_fieldset(deferred_load=True, use_xarray=False):
3333
def test_ofam_fieldset_fillvalues(use_xarray):
3434
fieldset = set_ofam_fieldset(deferred_load=False, use_xarray=use_xarray)
3535
# V.data[0, 0, 150] is a landpoint, that makes NetCDF4 generate a masked array, instead of an ndarray
36-
assert(fieldset.V.data[0, 0, 150] == 0)
36+
assert fieldset.V.data[0, 0, 150] == 0
3737

3838

3939
@pytest.mark.parametrize('dt', [delta(minutes=-5), delta(minutes=5)])
@@ -66,5 +66,5 @@ def test_ofam_particles(mode, use_xarray):
6666

6767
pset.execute(AdvectionRK4, runtime=delta(days=10), dt=delta(minutes=5))
6868

69-
assert(abs(pset[0].lon - 173) < 1)
70-
assert(abs(pset[0].lat - 11) < 1)
69+
assert abs(pset[0].lon - 173) < 1
70+
assert abs(pset[0].lat - 11) < 1

parcels/examples/example_peninsula.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ def test_peninsula_fieldset(mode, mesh, tmpdir):
145145
pset = peninsula_example(fieldset, outfile, 5, mode=mode, degree=1)
146146
# Test advection accuracy by comparing streamline values
147147
err_adv = np.abs(pset.p_start - pset.p)
148-
assert(err_adv <= 1.e-3).all()
148+
assert (err_adv <= 1.e-3).all()
149149
# Test Field sampling accuracy by comparing kernel against Field sampling
150150
err_smpl = np.array([abs(pset.p[i] - pset.fieldset.P[0., pset.depth[i], pset.lat[i], pset.lon[i]]) for i in range(pset.size)])
151-
assert(err_smpl <= 1.e-3).all()
151+
assert (err_smpl <= 1.e-3).all()
152152

153153

154154
@pytest.mark.parametrize('mode', ['scipy']) # Analytical Advection only implemented in Scipy mode
@@ -161,7 +161,7 @@ def test_peninsula_fieldset_AnalyticalAdvection(mode, mesh, tmpdir):
161161
method=AdvectionAnalytical)
162162
# Test advection accuracy by comparing streamline values
163163
err_adv = np.array([abs(p.p_start - p.p) for p in pset])
164-
assert(err_adv <= 1.e-1).all()
164+
assert (err_adv <= 1.e-1).all()
165165

166166

167167
def fieldsetfile(mesh, tmpdir):
@@ -182,10 +182,10 @@ def test_peninsula_file(mode, mesh, tmpdir):
182182
pset = peninsula_example(fieldset, outfile, 5, mode=mode, degree=1)
183183
# Test advection accuracy by comparing streamline values
184184
err_adv = np.abs(pset.p_start - pset.p)
185-
assert(err_adv <= 1.e-3).all()
185+
assert (err_adv <= 1.e-3).all()
186186
# Test Field sampling accuracy by comparing kernel against Field sampling
187187
err_smpl = np.array([abs(pset.p[i] - pset.fieldset.P[0., pset.depth[i], pset.lat[i], pset.lon[i]]) for i in range(pset.size)])
188-
assert(err_smpl <= 1.e-3).all()
188+
assert (err_smpl <= 1.e-3).all()
189189

190190

191191
if __name__ == "__main__":

parcels/examples/example_radial_rotation.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ def radial_rotation_fieldset(xdim=200, ydim=200): # Define 2D flat, square fiel
3131
for j in range(lat.size):
3232

3333
r = np.sqrt((lon[i]-x0)**2 + (lat[j]-y0)**2) # Define radial displacement.
34-
assert(r >= 0.)
35-
assert(r <= np.sqrt(x0**2 + y0**2))
34+
assert r >= 0.
35+
assert r <= np.sqrt(x0**2 + y0**2)
3636

3737
theta = math.atan2((lat[j]-y0), (lon[i]-x0)) # Define the polar angle.
38-
assert(abs(theta) <= np.pi)
38+
assert abs(theta) <= np.pi
3939

4040
U[j, i] = r * math.sin(theta) * omega
4141
V[j, i] = -r * math.cos(theta) * omega
@@ -75,10 +75,10 @@ def test_rotation_example(mode, tmpdir):
7575
fieldset = radial_rotation_fieldset()
7676
outfile = tmpdir.join("RadialParticle")
7777
pset = rotation_example(fieldset, outfile, mode=mode)
78-
assert(pset[0].lon == 30. and pset[0].lat == 30.) # Particle at centre of Field remains stationary.
78+
assert (pset[0].lon == 30. and pset[0].lat == 30.) # Particle at centre of Field remains stationary.
7979
vals = true_values(pset.time[1])
80-
assert(np.allclose(pset[1].lon, vals[0], 1e-5)) # Check advected values against calculated values.
81-
assert(np.allclose(pset[1].lat, vals[1], 1e-5))
80+
assert np.allclose(pset[1].lon, vals[0], 1e-5) # Check advected values against calculated values.
81+
assert np.allclose(pset[1].lat, vals[1], 1e-5)
8282

8383

8484
if __name__ == "__main__":

0 commit comments

Comments
 (0)