Learn R Programming

RCALI (version 0.3.7)

califlopp: Calculation of the Integrated Flow of Particles between Polygons

Description

Calculation of the flow of particles between polygons by two integration methods: integration by a cubature method and integration on a grid of points.

Usage

califlopp(file, dispf=c(1,2), param=NULL, resfile = NULL)

Value

Nothing. To store the results, set the argument resfile, then use the function

getRes or read.table, with option

skip=1

Arguments

file

Pathname of the polygons-file. See details.

dispf

The required dispersion functions. Vector of integers or vector of R functions. The maximum length of this vector is 5.

  • If vector of integers, the dispersion functions are then compiled. Five are provided. To modify them, see Details. By default, 1 is for dispersal of oilseed rape pollen, 2 for dispersal of oilseed rape seed (dispersals of oilseed rape are the ones defined in GeneSys - see References), 3 for the constant function, 4 for an anisotropic version of the dispersal of yellow rust of wheat defined in Soubeyrand and all, 5 for a discontinuous function.
    These functions are viewable in the C file src/functions.cc. To modify them, see Details.

  • If vector of functions, the dispersion functions are coded in R (more time consuming than compiled version). Two R dispersal functions are provided, fpollen and fseed, the functions used in Genesys. To specify your own function, see details.

param

Optional list of parameters. Valid components are input, output, verbose, warn.poly, warn.conv,delim, poly, send.and.receive, method, dz, dp. In addition, when method is “cub”: maxpts, reler, abser, tz. When method is “grid”: seed, step, nr. See details.

resfile

Optional pathname of a result-file. When set, the results are written on it. This file can be read by using function getRes or read.table. See details, as to the content of the file.

Side effect

This function creates a temporary file to store the parameters, usually in the directory tmp of the user. This file is destroyed at the end of execution.

Author

A. Bouvier

Details

The polygons-file

The coordinates of the polygons should be provided in an ASCII file, denoted here "polygons-file". The unit is the meter. The vertices should be ordered clockwise. The polygons can be closed or not, but without holes. The first line contains the number of polygons. The following lines depend of the input parameter:

input=1

Two lines per polygon: on the first one, an identifier (a positive integer), followed by the x-coordinates, on the second one, the same identifier followed by the y-coordinates. The function export.listpoly generates such a file from R structures

input=2

Three lines per polygon: on the first one, an identifier (a positive integer), followed by a name for the polygon and by the number of its vertices, on the second one, the x-coordinates, and on the third one, the y-coordinates.

The individual dispersion functions

The individual dispersion functions can either be compiled or R functions.

Compiled function:

Five compiled dispersal functions are provided (see argument dispf). To replace them by yours, you have to download the source of RCALI, modify and compile it.

Suppose that you have download the tar-archive in the directory MyDir. The steps to customize the dispersion functions are:

1/ Replace one or several functions in MyDir/RCALI/src/functions.cc by yours: The dispersion function has one argument, the current point, p, of class Point. You can use p.getX() and p.getY() to get the coordinates of the current point (in meters*SCALE, where SCALE is the rescaling parameter defined in the file src/calicinfig.h), p.dist0(), the distance of p from the origin (in meters*SCALE) and p.angle0(), the angle (in degrees, in \([-\pi, +\pi]\)) between the line (0,p) and the horizontal line.

2/ Create a directory MyDir/RCALI/libs, place you in MyDir/RCALI/src and type in:

R CMD SHLIB -o ../libs/RCALI.so  *.cc

to create the compiled shared library.

3/ To use in a R-session:


      source("MyDir/RCALI/R/sourceDir.R")
      sourceDir("MyDir/RCALI/R")
      dyn.load("MyDir/RCALI/libs/RCALI.so")
  

The help-files are viewable by opening in a browser MyDir/RCALI/inst/doc/html/00Index.html

You can also build the tar.gz file again, after modifications, and install it as a library by using the standard R commands R CMD build and R CMD INSTALL --html.

R function:

Two R dispersal functions are provided, fpollen and fseed, the functions used in Genesys.
You can define your own R dispersal function: it should have one vector argument, the localization of the current point, p. The first element of this vector is the distance of p from the origin (in meters) and the second one is the angle (in degrees, in \([-\pi, +\pi]\)) between the line (0,p) and the horizontal line (i.e, stating x and y are the coordinates of p, the angle is \(atan2(y,x)*\frac{180}{\pi}\))

The parameters

The argument param is a list which valid components are:

input

format of the polygons-file. 1 or 2 (see above). Default 2

output

output required on the screen: 0 nothing, 1: all results, 2: progression numbers, 3: the integrated flows and their means per squared meter. Default 1

verbose

TRUE, if output is required about polygons convexity and landscape translation. Default FALSE

warn.poly

TRUE, if output is required about polygons simplification. Default FALSE

warn.conv

TRUE, if output is required when cubature convergence is not reached. Default TRUE

delim

separator character between values in the polygons-file. Default: tabulate

send.and.receive

TRUE, if results are required from sending polygons to target polygons and from target polygons to sending polygons (case of anisotropic functions). Default FALSE

poly

required pairs of polygons. List of vectors of length 2, or two-columns matrix. If only one pair is required, it may be a vector of length 2. Default: all pairs of polygons.

method

string equal to cub for cubature method, grid for the grid method. Default: cub

dz

integer vector, whose length is greater or equal to the number of required dispersion functions. dz[i] is the distance in meters beyond which the ist dispersion function is considered as nul. Default in a standard configuration: 0,21,0,1000,0 for functions number 1 to 5, respectively.

dp

integer vector, whose length is greater or equal to the number of required dispersion functions. dp[i] is the distance in meters beyond which the ist dispersion function is calculated between centroids only. Default in a standard configuration: 100, 0, 0, 500, 0 for functions number 1 to 5, respectively.

In addition, when method is cub:

maxpts

maximal number of evaluation points required for each function. Vector of length equal to the number of required functions. Default in a standard configuration: 100000

reler

relative error required for each function. Vector of length equal to the number of required functions. Should be positive when method is cubature. Default in a standard configuration: 1.0e-3

abser

absolute error required for each function. Vector of length equal to the number of required functions. Should be positive when method is cubature. Default in a standard configuration: 1.0e-3

tz

integer vector, whose length is greater or equal to the number of required dispersion functions. Mode of triangulation for the cubature method. tz[i] should be 1, if, for the ist dispersion function, triangulation from (0,0) has to be done when (0,0) is included in the integration area and, 0 if not. 1 is recommended when the dispersion function is very "sharp" at the origin. Default in a standard configuration: 0,1,0,0,0 for functions number 1 to 5, respectively.

When method is grid:

seed

seed of the random generator.

step

step of the grid on the x-axis and on the y-axis in meter. Vector of length 2.

nr

maximal number of replications or grids.

The result-file

When the argument resfile is set, a file is created. On this file, the values are separated by tabulates.

Its contains, when the method is cub,

on the first line:

"npoly:", "input-file:", "nfunc:", "method:", each of these identifiers followed by the actual values.

on each of the following lines, the results for a couple of polygons:

the identifiers of both polygons; the integrated flow divided by the area of the second polygon, for each dispersal function; the areas of both polygons; then, for each dispersal function, the integrated flow, the lower and upper bounds of the confidence interval, the absolute error, and the number of evaluations.

Its contains, when the method is grid,

on the first line:

"npoly:", "input-file:", "nfunc:", "method:", "stepx:", "stepy:", each of these identifiers followed by the actual values.

on each of the following lines, the results for a couple of polygons:

the identifiers of both polygons; the integrated flow divided by the area of the second polygon, for each dispersal function; the areas of both polygons; then, for each dispersal function, the integrated flow, and the standard deviation.

This file can be read in a R-session by using the function getRes or read.table, with option skip=1.

References

- The CaliFloPP software: http://genome.jouy.inra.fr/logiciels/califlopp/
- Main reference paper: A. Bouvier, K. Kieu, K. Adamczyk, and H. Monod. Computation of integrated flow of particles between polygons. Environmental Modelling & Software, 24:843--849, 2009.
- N. Colbach, and all.Genesys: a model of the influence of cropping system on gene escape from herbicide tolerant rapeseed crops to rape volunteers. Agriculture, Ecosystems and Environnement, 83:235--270, 2001.

See Also

getRes

Examples

Run this code
# Grid method with compiled constant and seed dispersion functions:
param <- list(method="grid",  grid=list(step=c(50,50)))
if (FALSE) califlopp("MyPolygonsFile",dispf=c(3,1), param=param)

# Cubature method with a R dispersion function:
param <- list( output=1, input=2, dz=0, dp=100, tz=0)
if (FALSE) califlopp("MyPolygonsFile", dispf=fpollen, param=param)

Run the code above in your browser using DataLab