pheromone_dispersion package
Submodules
pheromone_dispersion.advection_operator module
- class pheromone_dispersion.advection_operator.Advection(*args: Any, **kwargs: Any)[source]
Bases:
LinearOperatorClass containing the convection term linear operator of the PDE Subclass of the scipy.sparse.linalg.LinearOperator class, see https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.linalg.LinearOperator.html
- __init__(U, msh)[source]
Instanciation of the class.
- input:
U: object of the class Velocity
msh: object of the class MeshRect2D
- attributes:
U: object of the class Velocity
minus_U: object of the class Velocity, the opposite sign velocity field
msh: object of the class MeshRect2D
shape: tuple of integers, shape of the matrix of the linear operator
dtype: data type object, data type of the element of the matrix of the linear operator
- _matmat(x_out)[source]
Compute the image (matrix-matrix product) of the advection linear operator for a given (matrix of) concentration
- input:
- x_out:
numpy array of (shape msh.x.size*msh.y.size, msh.x.size*msh.y.size), contains the concentration of pheromones raveled into a vector to match the format of the LinearOperator class
- output:
numpy array of shape (msh.x.size*msh.y.size, msh.x.size*msh.y.size), the image of the convection linear operator for the given concentration
- _matvec(x_out)[source]
Compute the image (matrix-vector product) of the convection linear operator for a given vector of concentration
- input:
- x_out:
numpy array of shape (msh.x.size*msh.y.size, ), contains the concentration of pheromones raveled into a vector to match the format of the LinearOperator class
- output:
numpy array of shape (msh.x.size*msh.y.size, ), the image of the convection linear operator for the given concentration
- _rmatvec(x_out)[source]
Compute the image (matrix-vector product) of the flux part of the adjoint of the convection linear operator for a given vector of concentration. This flux part of the adjoint operator is the adjoint operator if the velocity field has a divergence equal to 0
- input:
- x_out:
numpy array of shape (msh.x.size*msh.y.size, ), contains the concentration of pheromones raveled into a vector to match the format of the LinearOperator class
- output:
numpy array of shape (msh.x.size*msh.y.size, ), the image of adjoint the convection linear operator for a given concentration
- class pheromone_dispersion.advection_operator.AdvectionAdjoint(*args: Any, **kwargs: Any)[source]
Bases:
LinearOperatorClass containing the adjoint convection term linear operator of the PDE This class and it method _matvec are redundant with the _rmatvec function of the class Advection but this class is meant for the implicit scheme of the adjoint model Subclass of the scipy.sparse.linalg.LinearOperator class, see https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.linalg.LinearOperator.html
- __init__(U, msh)[source]
Instanciation of the class.
- input:
U: object of the class Velocity
msh: object of the class MeshRect2D
- attributes:
U: object of the class Velocity
minus_U: object of the class Velocity, the opposite sign velocity field
msh: object of the class MeshRect2D
shape: tuple of integers, shape of the matrix of the linear operator
dtype: data type object, data type of the element of the matrix of the linear operator
- _matmat(x_out)[source]
Compute the image (matrix-matrix product) of the adjoint advection linear operator for a given (matrix of) concentration
- input:
- x_out:
numpy array of (shape msh.x.size*msh.y.size, msh.x.size*msh.y.size), contains the concentration of pheromones raveled into a vector to match the format of the LinearOperator class
- output:
numpy array of shape (msh.x.size*msh.y.size, msh.x.size*msh.y.size), the image of the convection linear operator for the given concentration
- _matvec(x_out)[source]
Compute the image (matrix-vector product) of the adjoint of the convection linear operator for a given vector of concentration
- input:
- x_out:
numpy array of shape (msh.x.size*msh.y.size, ), contains the concentration of pheromones raveled into a vector to match the format of the LinearOperator class
- output:
numpy array of shape (msh.x.size*msh.y.size, ), the image of the convection linear operator for the given concentration
- pheromone_dispersion.advection_operator.sum_advection_flux_given_U(U, x, msh)[source]
compute the sum over a cell of the flux of the advection term for a given velocity field
- TO BE DONE:
change the BC, for now: no income, change for: a given income
- input:
U: object of the class Velocity
- x:
numpy array of shape (msh.x.size, msh.y.size), contains the concentration of pheromones
msh: object of the class MeshRect2D
- output:
sum_faces: the sum over a cell of the flux
pheromone_dispersion.cli module
Module that contains the command line app.
Why does this file exist, and why not put this in __main__?
You might be tempted to import things from __main__ later, but that will cause problems: the code will get executed twice:
When you run python -mpherosensor python will execute
__main__.pyas a script. That means there won’t be anypherosensor.__main__insys.modules.When you import __main__ it will get executed again (as a module) because there’s no
pherosensor.__main__insys.modules.Also see (1) from http://click.pocoo.org/5/setuptools/#setuptools-integration
- pheromone_dispersion.cli.main(argv=['/home/docs/checkouts/readthedocs.org/user_builds/pherosensor-toolbox/envs/v0.1.1/lib/python3.12/site-packages/sphinx/__main__.py', '-T', '-b', 'html', '-d', '_build/doctrees', '-D', 'language=en', '.', '/home/docs/checkouts/readthedocs.org/user_builds/pherosensor-toolbox/checkouts/v0.1.1/_readthedocs//html'])[source]
- Parameters:
argv (list) – List of arguments
- Returns:
A return code
- Return type:
int
Does stuff.
pheromone_dispersion.convection_diffusion_2D module
- class pheromone_dispersion.convection_diffusion_2D.DiffusionConvectionReaction2DEquation(U, K, coeff_depot, S, msh, time_discretization='semi-implicit', tol_inversion=1e-14)[source]
Bases:
objectClass containing the 2D diffusion-convection-reaction PDE and its solvers
- __init__(U, K, coeff_depot, S, msh, time_discretization='semi-implicit', tol_inversion=1e-14)[source]
Instanciation of the class.
- input:
msh: object of the class MeshRect2D
U: object of the class Velocity
K: object of the class DiffusionTensor
coeff_depot: array of shape (msh.y, msh.x) containing the deposition coefficient
S: object of the class Source, contains the source term
- time_discretization:
string, describes the type of time discretization by default is ‘semi-implicit’, can also be ‘implicit’
- attributes:
msh: object of the class MeshRect2D
A: object of the class Advection, contains the convection linear operator
D: oject of the class Diffusion, contains the diffusion linear operator
R: object of the class Reaction, contains the reaction linear operator
ID: object of the class Id, contains the identity operator
S: object of the class Source, contains the source term
time_discretization: string, describes the type of time discretization
- TO DO:
Add exceptions in case the matrix are computed/initialized
- at_current_time(tc, i=None)[source]
Update the linear operators of the PDE (attributes A, D and S of the class) at a given time.
- input:
tc: the current time
- set_source(value, t=None)[source]
Update the source term with the values provided as input
- input:
value: numpy array of shape (t.size, msh.y.size, msh.x.size), the new values of the source term
t: numpy array of shape (t.size,), the vector containing the associated times, by default None if the source is stationnary
- solver(save_all=False, path_save='./save/', display_flag=True)[source]
solve the PDE on the whole time window
- input:
- save_all:
boolean, False by default, the matrix of the concentration at every time step and the vector of time are saved in numpy arrays if True
path_save: string, ‘./save/’ by default, contains the path of the directory in which the ouputs are saved
display_flag: boolean, True by default, print the evolution in time of the solver if True
- output:
c: numpy array of shape (msh.t_array.size, msh.y.size, msh.x.size), contains the concentration at all time steps
- solver_est_at_obs_times(obs, display_flag=True)[source]
solve the PDE on the whole time window and store the resulting estimations of the concentration at the observations times
- TO DO:
check that the function works
- input:
- obs:
object of the class Obs, contains the observations and the observations times at which we aim to estimate the concentration
- do:
solve the PDE on the whole time window but only store the resulting estimations at the observations times in the atrtibutes c_est of obs
- solver_one_time_step(c)[source]
solve the PDE for one time step inverse the linear system (I + dt (- D + R)).c^{n+1} = c^n + dt (- A.c^n + S)
- input:
c: numpy array of shape (msh.y.size, msh.x.size), contains the concentration of pheromones at the previous time step
- output:
numpy array of shape (msh.y.size, msh.x.size), resulting concentration at the current time step
- solver_save_all(path_save='./save/', display_flag=True, save_rate=1000)[source]
solve the PDE on the whole time window
- input:
- save_all:
boolean, False by default, the matrix of the concentration at every time step and the vector of time are saved in numpy arrays if True
path_save: string, ‘./save/’ by default, contains the path of the directory in which the ouputs are saved
display_flag: boolean, True by default, print the evolution in time of the solver if True
- output:
c: numpy array of shape (msh.t_array.size, msh.y.size, msh.x.size), contains the concentration at all time steps
pheromone_dispersion.deposition_coeff module
- pheromone_dispersion.deposition_coeff.deposition_coeff_from_land_occupation_data(path_data, file_name_data, land_occupation_to_deposition_coeff, msh)[source]
read the land occupation data, search the land occupation at the cells of the mesh and return the associated deposition coefficient map
- input:
paht_data: str, path to the folder that contains the land occupation data
file_name_data: str, name of the file that contains the land occupation data
land_occupation_to_deposition_coeff: dictionary, contains the deposition coefficient wrt the land occupation
msh: object of the class MeshRect2D
- output:
- deposition_coeff:
array of shape (msh.y.size, msh.x.size), contains the value of the deposition coefficient at the cells of the mesh
- TO ADD:
take into account the case None
exception to check the points are indeed in one of the polygon
exception to check the format of the df is as expected
exception to check the land occupation data and the dictionary coincide together
pheromone_dispersion.diffusion_operator module
- class pheromone_dispersion.diffusion_operator.Diffusion(*args: Any, **kwargs: Any)[source]
Bases:
LinearOperatorClass containing the diffusion term linear operator of the PDE Subclass of the scipy.sparse.linalg.LinearOperator class, see https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.linalg.LinearOperator.html
- __init__(K, msh)[source]
Instanciation of the class.
- input:
K: object of the class DiffusionTensor
msh: object of the class MeshRect2D
- attributes:
msh: object of the class MeshRect2D
K: object of the class DiffusionTensor
shape: tuple of integers, shape of the matrix of the linear operator
dtype: data type object, data type of the element of the matrix of the linear operator
- _matmat(x_out)[source]
Compute the image (matrix-matrix product) of the diffusion linear operator for a given (matrix of) concentration
- TO DO:
the gradient at msh.y[0] and msh.y[-1] at the vertical interfaces and at msh.x[0] and msh.x[-1] at the horizontal interfaces are not well taken into account phantom cells should be added that satisfies the boundary conditions for now, the solver works for diagonal diffusion tensor, i.e. for unidirectional wind field or for isotropic diffusion tensor (K_u=K_u_t)
- input:
- x_out:
numpy array of (shape msh.x.size*msh.y.size, msh.x.size*msh.y.size), contains the concentration of pheromones raveled into a vector to match the format of the LinearOperator class
- output:
numpy array of shape (msh.x.size*msh.y.size, msh.x.size*msh.y.size), the image of the convection linear operator for the given concentration
- _matvec(x_out)[source]
Compute the image (matrix-vector product) of the diffusion linear operator for a given (vector of) concentration
- TO DO:
the gradient at msh.y[0] and msh.y[-1] at the vertical interfaces and at msh.x[0] and msh.x[-1] at the horizontal interfaces are not well taken into account phantom cells should be added that satisfies the boundary conditions for now, the solver works for diagonal diffusion tensor, i.e. for unidirectional wind field or for isotropic diffusion tensor (K_u=K_u_t)
- input:
- x_out:
numpy array of (shape msh.x.size*msh.y.size, ), contains the concentration of pheromones raveled into a vector to match the format of the LinearOperator class
- output:
numpy array of shape (msh.x.size*msh.y.size, ), the image of the convection linear operator for the given concentration
pheromone_dispersion.diffusion_tensor module
- class pheromone_dispersion.diffusion_tensor.DiffusionTensor(U, K_u, K_u_t)[source]
Bases:
objectClass containing the anisotropic and inhomogeneous diffusion tensor
- __init__(U, K_u, K_u_t)[source]
Instanciation of the class.
- TO BE DONE:
add exceptions to make sure that all the inputs have the right type
- input:
U: object of the class Velocity
K_u: float, the diffusion coefficient in the wind direction
K_u_t: float, the diffusion coefficient in the crosswind direction
- attributes:
U: object of the class Velocity
- at_vertical_interface:
numpy array of shape (msh.y, msh.x_vertical_interface, 2, 2), contains the diffusion tensor at each vertical interfaces
- at_horizontal_interface:
numpy array of shape (msh.y_horizontal_interface, msh.x, 2, 2), contains the diffusion tensor at each horizontal interfaces
K_u: float, the diffusion coefficient in the wind direction
K_u_t: float, the diffusion coefficient in the crosswind direction
pheromone_dispersion.gaussian_plume module
- class pheromone_dispersion.gaussian_plume.Gaussian_plume_1source(Xs, K, u, Q, w_set, w_dep)[source]
Bases:
object
- class pheromone_dispersion.gaussian_plume.Gaussian_plume_multisources(Xs, K, u, Q, w_set, w_dep)[source]
Bases:
object
pheromone_dispersion.geom module
- class pheromone_dispersion.geom.Mesh2D[source]
Bases:
objectClass containing the generic 2D cartesian mesh TO BE IMPLEMENTED IF NEEDED
- class pheromone_dispersion.geom.MeshRect2D(L_x, L_y, dx, dy, T_final, X_0=None)[source]
Bases:
objectClass containing a 2D rectangular cartesian mesh
- __init__(L_x, L_y, dx, dy, T_final, X_0=None)[source]
Instanciation of the class.
- TO BE DONE:
add exceptions to make sure that all the inputs are float
- input:
L_x: float, length of the domain along the x-axis
L_y: float, length of the domain along the y-axis
dx: float, space step along the x-axis
dy: float, space step along the y-axis
T_final: float, final time of the modeling time window
X_0: coordinates of the origin of the mesh, is None if the orgin is (0, 0)
- attributes:
L_x: float, length of the domain along the x-axis
L_y: float, length of the domain along the y-axis
dx: float, space step along the x-axis
dy: float, space step along the y-axis
- x:
numpy array of shape (L_x//dx, ), contains the x-coordinates of the center of the cells of the mesh
- y:
numpy array of shape (L_y//dy, ), contains the y-coordinates of the center of the cells of the mesh
- x_vertical_interface:
numpy array of shape (L_x//dx+1, ), contains the x-coordinates of the vertical interfaces between the cells of the mesh
- y_horizontal_interface:
numpy array of shape (L_y//dy+1, ), contains the y-coordinates of the horizontal interfaces between the cells of the mesh
mass_cell: float, contains the measure of a control volume
t: float, the current time of the modeling, initialized to 0
T_final: float, the final time of the modeling time window
X_0: coordinates of the origin of the mesh, is None if the orgin is (0, 0)
- calc_dt_explicit_solver(U, mult_param=1.0, dt_max=0.1)[source]
Make sure that the time step satisfies the CFL condition dt < 1 / (max(||U||) / (dx + dy))
- TO BE DONE:
add exceptions to make sure that all the inputs are float
- input:
U: object of the class Velocity
mult_param: multiplicative parameter that allows to enhance time accuracy by decreasing the time step (with mult_param<1)
dt_max: float, maximum time step
- do:
store in the attribute dt the time step that satisfies the CFL condition and is smaller than the maximal time step 0.1
- calc_dt_implicit_solver(dt)[source]
Make sure that the time step satisfies the CFL condition dt < 1 / (max(||U||) / (dx + dy))
- TO BE DONE:
add exceptions to make sure that all the inputs are float
- input:
U: object of the class Velocity
mult_param: multiplicative parameter that allows to enhance time accuracy by decreasing the time step (with mult_param<1)
dt_max: float, maximum time step
- do:
store in the attribute dt the time step that satisfies the CFL condition and is smaller than the maximal time step 0.1
pheromone_dispersion.identity_operator module
- class pheromone_dispersion.identity_operator.Id(*args: Any, **kwargs: Any)[source]
Bases:
LinearOperatorClass containing the identity operator of the PDE Subclass of the scipy.sparse.linalg.LinearOperator class, see https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.linalg.LinearOperator.html
- __init__(msh)[source]
Instanciation of the class.
- input:
msh: object of the class MeshRect2D
- attributes:
shape: tuple of integers, shape of the matrix of the linear operator
dtype: data type object, data type of the element of the matrix of the linear operator
- _matvec(x_out)[source]
Compute the image (matrix-vector product) of the reaction linear operator for a given (vector of) concentration
- TO BE DONE:
Better implementation or already implemented in scipy?
- input:
- x_out:
numpy array of shape (shape msh.x.size*msh.y.size, ), contains the concentration of pheromones raveled into a vector to match the format of the LinearOperator class
- output:
numpy array of shape (msh.x.size*msh.y.size, ), the image of the identity operator for the given concentration
pheromone_dispersion.reaction_operator module
- class pheromone_dispersion.reaction_operator.Reaction(*args: Any, **kwargs: Any)[source]
Bases:
LinearOperatorClass containing the reaction term linear operator of the PDE Subclass of the scipy.sparse.linalg.LinearOperator class, see https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.linalg.LinearOperator.html
- __init__(reaction_coeff, msh)[source]
Instanciation of the class.
- input:
msh: object of the class MeshRect2D
reaction_coeff: array of shape (msh.y, msh.x), containing the reaction coefficient
- attributes:
msh: object of the class MeshRect2D
reaction_coeff: array of shape (msh.y, msh.x)
shape: tuple of integers, shape of the matrix of the linear operator
dtype: data type object, data type of the element of the matrix of the linear operator
- _matmat(x_out)[source]
Compute the image (matrix-matrix product) of the reaction linear operator for a given (matrix of) concentration
- input:
- x_out:
numpy array of (shape msh.x.size*msh.y.size, msh.x.size*msh.y.size), contains the concentration of pheromones raveled into a vector to match the format of the LinearOperator class
- output:
numpy array of shape (msh.x.size*msh.y.size, msh.x.size*msh.y.size), the image of the convection linear operator for the given concentration
- _matvec(x_out)[source]
Compute the image (matrix-vector product) of the reaction linear operator for a given (vector of) concentration
- input:
- x_out:
numpy array of shape (msh.x.size*msh.y.size, ), contains the concentration of pheromones raveled into a vector to match the format of the LinearOperator class
- output:
numpy array of shape (msh.x.size*msh.y.size, ), the image of the convection linear operator for the given concentration
pheromone_dispersion.source_term module
- class pheromone_dispersion.source_term.Source(msh, value, t=None)[source]
Bases:
objectClass containing the source term of the PDE Subclass of the scipy.sparse.linalg.LinearOperator class, see https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.linalg.LinearOperator.html
- __init__(msh, value, t=None)[source]
Instanciation of the class.
- input:
msh: object of the class MeshRect2D
value: numpy array of shape (t.size, msh.y.size, msh.x.size,), contains the matrix the coefficient of the source term
t: numpy array, the vector containing the times at which the source is given, if None, the source is supposed steady
- attributes:
t: numpy array, the vector containing the times at which the source is given, if None, the source is supposed steady
- value:
numpy array of shape (t.size, mesh.y.size, mesh.x.size,), contains the discharge of pheromones in the air by the source of emissions
- time_interpolation:
object of the class scipy.interpolate.interp1D, aims at computing the source term given the current time using the linear interpolation of the data
pheromone_dispersion.velocity module
- class pheromone_dispersion.velocity.Velocity(msh, U_at_vertical_interface, U_at_horizontal_interface, t=None)[source]
Bases:
objectClass containing the velocity field
- __init__(msh, U_at_vertical_interface, U_at_horizontal_interface, t=None)[source]
Instanciation of the class.
- TO BE DONE:
adapt to some more realistic input (e.g. velocity field inside the cells …)
- input:
msh: object of the class MeshRect2D
- U_at_vertical_interface:
numpy array of shape (t.size, mesh.y.size, mesh.vx.size, 2), contains the velocity field on the vertical interfaces of the cells
- U_at_horizontal_interface:
numpy array of shape (t.size, mesh.vy.size, mesh.x.size, 2), contains the velocity field on the horizontal interfaces of the cells
t: numpy array, the vector containing the times at which the velocity is given, if None, the velocity is supposed steady
- attributes:
- at_vertical_interface:
numpy array of shape (mesh.y, mesh.vx, 2), contains the velocity field on the vertical interfaces of the cells
- at_horizontal_interface:
numpy array of shape (mesh.vy, mesh.x, 2), contains the velocity field on the horizontal interfaces of the cells
div: array of shape (mesh.y.size, mesh.x.size), contains the divergence of U at the center of the cells at the current time
t: numpy array, the vector containing the times at which the velocity is given, if None, the velocity is supposed steady
- time_interpolation_at_vertical_interface:
object of the class scipy.interpolate.interp1D, aims at computing the velocity at the vertical interfaces given a time using the linear interpolation of the data
- time_interpolation_at_horizontal_interface:
object of the class scipy.interpolate.interp1D, aims at computing the velocity at the horizontal interfaces given a time using the linear interpolation of the data
- time_interpolation_div:
object of the class scipy.interpolate.interp1D, aims at computing the divergence of the velocity given a time using the linear interpolation of the data
cell_above_upwind: array of boolean, is True if the cell above is the upwind cell for the y-component of the wind velocity
cell_under_upwind: array of boolean, is True if the cell under is the upwind cell for the y-component of the wind velocity
cell_right_upwind: array of boolean, is True if the right cell is the upwind cell for the x-component of the wind velocity
cell_left_upwind: array of boolean, is True if the left cell under is the upwind cell for the x-component of the wind velocity
max_U_horizontal_U: float, L^infinity norm of the horizontal component of the velocity field
max_U_vertical_U: float, L^infinity norm of the vertical component of the velocity field
- at_current_time(tc)[source]
Update the attributes div, at_vertical_interface and at_horizontal_interface of the class at a given time using linear interpolation and re-compute the attributes cell_above_upwind, cell_under_upwind, cell_right_upwind and cell_left_upwind
- input:
tc: float, the current time
- pheromone_dispersion.velocity.velocity_field_from_meteo_data(path_data, file_name_data, msh)[source]
read the meteorological wind velocity data and return a object of the Velocity class containing the linear interpolation of these data on the mesh
- input:
path_data: str, path to the folder that contains the meteorological data
file_name_data: str, name of the file that contains the meteorological data
msh: object of the class MeshRect2D
- output:
Velocity object
- TO DO :
- add exceptions to check path and file names,
to check the data have the expected format, to check the msh, to check that the mesh is covered by the data