Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions docs/documentation/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ Documentation and Tutorials

Parcels has several documentation and tutorial Jupyter notebooks and scripts which go through various aspects of Parcels. Static versions of the notebooks are available below via the gallery in the site, with the interactive notebooks being available either completely online at the following `Binder link <https://mybinder.org/v2/gh/OceanParcels/parcels/main?labpath=docs%2Fexamples%2Fparcels_tutorial.ipynb>`_. Following the gallery of notebooks is a list of scripts which provide additional examples to users. You can work with the example notebooks and scripts locally by downloading :download:`parcels_tutorials.zip </_downloads/parcels_tutorials.zip>` and running with your own Parcels installation.

.. warning::
In v3.1.0 we updated kernels in the tutorials to use ``parcels.ParcelsRandom`` instead of ``from parcels import ParcelsRandom``. Due to our C-conversion code, using ``parcels.ParcelsRandom`` only works with v3.1.0+. When browsing/downloading the tutorials, it's important that you are using the documentation corresponding to the version of Parcels that you have installed. You can find which parcels version you have installed by doing ``import parcels`` followed by ``print(parcels.__version__)``. If you don't want to use the latest version of Parcels, you can browse prior versions of the documentation by using the version switcher in the bottom right of this page.

.. nbgallery::
:caption: Overview
:name: tutorial-overview
Expand Down
5 changes: 3 additions & 2 deletions docs/examples/example_brownian.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import random
from datetime import timedelta

import numpy as np
Expand Down Expand Up @@ -27,11 +28,11 @@ def test_brownian_example(mesh, npart=3000):
)

# Set random seed
parcels.ParcelsRandom.seed(123456)
random.seed(123456)

runtime = timedelta(days=1)

parcels.ParcelsRandom.seed(1234)
random.seed(1234)
pset = parcels.ParticleSet(
fieldset=fieldset,
pclass=parcels.ScipyParticle,
Expand Down
169 changes: 85 additions & 84 deletions docs/examples/tutorial_delaystart.ipynb

Large diffs are not rendered by default.

60 changes: 38 additions & 22 deletions docs/examples/tutorial_diffusion.ipynb

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions docs/reference/misc.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
Miscellaneous
=============

parcels.rng module
------------------

.. automodule:: parcels.rng
:members:
:undoc-members:

parcels.tools.statuscodes module
--------------------------------

Expand Down
1 change: 0 additions & 1 deletion parcels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

__version__ = version

import parcels.rng as ParcelsRandom # noqa: F401
from parcels.application_kernels import *
from parcels.field import *
from parcels.fieldset import *
Expand Down
15 changes: 7 additions & 8 deletions parcels/application_kernels/advectiondiffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"""

import math

import parcels
import random

__all__ = ["AdvectionDiffusionEM", "AdvectionDiffusionM1", "DiffusionUniformKh"]

Expand All @@ -26,8 +25,8 @@
mean and a standard deviation of sqrt(dt).
"""
# Wiener increment with zero mean and std of sqrt(dt)
dWx = parcels.rng.normalvariate(0, math.sqrt(math.fabs(particle.dt)))
dWy = parcels.rng.normalvariate(0, math.sqrt(math.fabs(particle.dt)))
dWx = random.normalvariate(0, math.sqrt(math.fabs(particle.dt)))
dWy = random.normalvariate(0, math.sqrt(math.fabs(particle.dt)))

Check warning on line 29 in parcels/application_kernels/advectiondiffusion.py

View check run for this annotation

Codecov / codecov/patch

parcels/application_kernels/advectiondiffusion.py#L28-L29

Added lines #L28 - L29 were not covered by tests

Kxp1 = fieldset.Kh_zonal[time, particle.depth, particle.lat, particle.lon + fieldset.dres]
Kxm1 = fieldset.Kh_zonal[time, particle.depth, particle.lat, particle.lon - fieldset.dres]
Expand Down Expand Up @@ -61,8 +60,8 @@
mean and a standard deviation of sqrt(dt).
"""
# Wiener increment with zero mean and std of sqrt(dt)
dWx = parcels.rng.normalvariate(0, math.sqrt(math.fabs(particle.dt)))
dWy = parcels.rng.normalvariate(0, math.sqrt(math.fabs(particle.dt)))
dWx = random.normalvariate(0, math.sqrt(math.fabs(particle.dt)))
dWy = random.normalvariate(0, math.sqrt(math.fabs(particle.dt)))

Check warning on line 64 in parcels/application_kernels/advectiondiffusion.py

View check run for this annotation

Codecov / codecov/patch

parcels/application_kernels/advectiondiffusion.py#L63-L64

Added lines #L63 - L64 were not covered by tests

u, v = fieldset.UV[time, particle.depth, particle.lat, particle.lon]

Expand Down Expand Up @@ -102,8 +101,8 @@
mean and a standard deviation of sqrt(dt).
"""
# Wiener increment with zero mean and std of sqrt(dt)
dWx = parcels.rng.normalvariate(0, math.sqrt(math.fabs(particle.dt)))
dWy = parcels.rng.normalvariate(0, math.sqrt(math.fabs(particle.dt)))
dWx = random.normalvariate(0, math.sqrt(math.fabs(particle.dt)))
dWy = random.normalvariate(0, math.sqrt(math.fabs(particle.dt)))

Check warning on line 105 in parcels/application_kernels/advectiondiffusion.py

View check run for this annotation

Codecov / codecov/patch

parcels/application_kernels/advectiondiffusion.py#L104-L105

Added lines #L104 - L105 were not covered by tests

bx = math.sqrt(2 * fieldset.Kh_zonal[particle])
by = math.sqrt(2 * fieldset.Kh_meridional[particle])
Expand Down
8 changes: 1 addition & 7 deletions parcels/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

import numpy as np

import parcels.rng as ParcelsRandom # noqa: F401
from parcels import rng # noqa: F401
from parcels.application_kernels.advection import (
AdvectionAnalytical,
AdvectionRK4_3D,
Expand Down Expand Up @@ -137,9 +135,7 @@
self.funcvars = None
self.funccode = funccode or inspect.getsource(pyfunc.__code__)
self.funccode = ( # Remove parcels. prefix (see #1608)
self.funccode.replace("parcels.rng", "rng")
.replace("parcels.ParcelsRandom", "ParcelsRandom")
.replace("parcels.StatusCode", "StatusCode")
self.funccode.replace("parcels.StatusCode", "StatusCode")

Check warning on line 138 in parcels/kernel.py

View check run for this annotation

Codecov / codecov/patch

parcels/kernel.py#L138

Added line #L138 was not covered by tests
)

# Parse AST if it is not provided explicitly
Expand All @@ -152,8 +148,6 @@
try:
user_ctx = stack[-1][0].f_globals
user_ctx["math"] = globals()["math"]
user_ctx["ParcelsRandom"] = globals()["ParcelsRandom"]
user_ctx["rng"] = globals()["rng"]
user_ctx["random"] = globals()["random"]
user_ctx["StatusCode"] = globals()["StatusCode"]
except:
Expand Down
194 changes: 0 additions & 194 deletions parcels/rng.py

This file was deleted.

16 changes: 8 additions & 8 deletions tests/test_diffusion.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import random
from datetime import timedelta

import numpy as np
Expand All @@ -9,7 +10,6 @@
AdvectionDiffusionM1,
DiffusionUniformKh,
Field,
ParcelsRandom,
ParticleSet,
RectilinearZGrid,
ScipyParticle,
Expand All @@ -33,7 +33,7 @@ def test_fieldKh_Brownian(mesh):
npart = 1000
runtime = timedelta(days=1)

ParcelsRandom.seed(1234)
random.seed(1234)
pset = ParticleSet(fieldset=fieldset, pclass=ScipyParticle, lon=np.zeros(npart), lat=np.zeros(npart))
pset.execute(pset.Kernel(DiffusionUniformKh), runtime=runtime, dt=timedelta(hours=1))

Expand All @@ -43,7 +43,7 @@ def test_fieldKh_Brownian(mesh):
lats = pset.lat
lons = pset.lon

tol = 200 * mesh_conversion # effectively 200 m errors
tol = 500 * mesh_conversion # effectively 500 m errors
assert np.allclose(np.std(lats), expected_std_lat, atol=tol)
assert np.allclose(np.std(lons), expected_std_lon, atol=tol)
assert np.allclose(np.mean(lons), 0, atol=tol)
Expand Down Expand Up @@ -71,7 +71,7 @@ def test_fieldKh_SpatiallyVaryingDiffusion(mesh, kernel):
npart = 100
runtime = timedelta(days=1)

ParcelsRandom.seed(1636)
random.seed(1636)
pset = ParticleSet(fieldset=fieldset, pclass=ScipyParticle, lon=np.zeros(npart), lat=np.zeros(npart))
pset.execute(pset.Kernel(kernel), runtime=runtime, dt=timedelta(hours=1))

Expand All @@ -92,15 +92,15 @@ def test_randomexponential(lambd):
fieldset.lambd = lambd

# Set random seed
ParcelsRandom.seed(1234)
random.seed(1234)

pset = ParticleSet(
fieldset=fieldset, pclass=ScipyParticle, lon=np.zeros(npart), lat=np.zeros(npart), depth=np.zeros(npart)
)

def vertical_randomexponential(particle, fieldset, time): # pragma: no cover
# Kernel for random exponential variable in depth direction
particle.depth = ParcelsRandom.expovariate(fieldset.lambd)
particle.depth = random.expovariate(fieldset.lambd)

pset.execute(vertical_randomexponential, runtime=1, dt=1)

Expand All @@ -120,15 +120,15 @@ def test_randomvonmises(mu, kappa):
fieldset.kappa = kappa

# Set random seed
ParcelsRandom.seed(1234)
random.seed(1234)

AngleParticle = ScipyParticle.add_variable("angle")
pset = ParticleSet(
fieldset=fieldset, pclass=AngleParticle, lon=np.zeros(npart), lat=np.zeros(npart), depth=np.zeros(npart)
)

def vonmises(particle, fieldset, time): # pragma: no cover
particle.angle = ParcelsRandom.vonmisesvariate(fieldset.mu, fieldset.kappa)
particle.angle = random.vonmisesvariate(fieldset.mu, fieldset.kappa)

pset.execute(vonmises, runtime=1, dt=1)

Expand Down
Loading
Loading