kdsource Python API
kdsource.kdsource module
kdsource.plist module
kdsource.geom module
Module for Geometry and Metric objects
- class kdsource.geom.Metric(partvars, varnames, units, volunits)
Bases:
object- __init__(partvars, varnames, units, volunits)
Abstract object defining metrics for a subset of variables.
The main function of a Metric is definig a transformation from a subset of particle variables to certain parametrized variables, which can be more suitable for applying KDE.
See geom._metrics for available metrics.
- Parameters:
- partvars: list of int
Indices of the particle variables to parametrize (see varnames global list).
- varnames: list of str
Names of parametrized variables.
- units: list of str
Units of each parametrized variable.
- volunits: str
Units of the product of variables to parametrize.
- transform(parts)
Transform particle variables to parametrized variables.
- inverse_transform(vecs)
Transform parametrized variables to particle variables.
- jac(parts)
Jacobian of transformation.
- mean(parts=None, vecs=None, weights=None)
Mean of particle variables.
Mean is computed in parametrized space, and transformed back to particle variables.
- Parameters:
- parts: array-like, optional
Array of particle variables.
- vecs: array-like, optional
Array of parametrized variables. If set, overrides parts.
- weights: array-like, optional
Array of particle statistic weights.
- std(parts=None, vecs=None, weights=None)
Standard deviation of particle variables.
Standard deviation is computed in parametrized space, and transformed back to particle variables.
- Parameters:
- parts: array-like, optional
Array of particle variables.
- vecs: array-like, optional
Array of parametrized variables. If set, overrides parts.
- weights: array-like, optional
Array of particle statistic weights.
- save(mtree)
Save Metric parameters into XML tree.
- static load(mtree)
Load parameters from XML tree and build Metric.
- __dict__ = mappingproxy({'__module__': 'kdsource.geom', '__init__': <function Metric.__init__>, 'transform': <function Metric.transform>, 'inverse_transform': <function Metric.inverse_transform>, 'jac': <function Metric.jac>, 'mean': <function Metric.mean>, 'std': <function Metric.std>, 'save': <function Metric.save>, 'load': <staticmethod object>, '__dict__': <attribute '__dict__' of 'Metric' objects>, '__weakref__': <attribute '__weakref__' of 'Metric' objects>, '__doc__': None, '__annotations__': {}})
- __module__ = 'kdsource.geom'
- __weakref__
list of weak references to the object (if defined)
- class kdsource.geom.Geometry(metrics, trasl=None, rot=None)
Bases:
Metric- __init__(metrics, trasl=None, rot=None)
Object defining particle variables treatment (metrics).
The main function of a Geometry is definig a transformation from particle variables to certain parametrized variables, which can be more suitable for applying KDE.
- Parameters:
- metrics: list
List of metrics for each subset of variables. They must cover all particle variables (energy, position, direction and time).
- trasl: array-like, optional
Spatial traslation for source. Default is no traslation.
- rot: numpy.ndarray or scipy.spatial.transform.Rotation, optional
Spatial rotation for source. Can be a scipy Rotation object, or any array-like which can be used to generate a scipy Rotation object (rotation vector, quaternion or rotation matrix). Rotation is applied after traslation in transform, and before traslation in inverse_transform. Default is no rotation.
- transform(parts)
Transform particle variables to parametrized variables.
- inverse_transform(vecs)
Transform parametrized variables to particle variables.
- jac(parts)
Jacobian of transformation.
- mean(parts=None, vecs=None, weights=None)
Mean of particle variables.
Mean is computed in parametrized space, and transformed back to particle variables.
- Parameters:
- parts: array-like, optional
Array of particle variables.
- vecs: array-like, optional
Array of parametrized variables. If set, overrides parts.
- weights: array-like, optional
Array of particle statistic weights.
- std(parts=None, vecs=None, weights=None)
Standard deviation of particle variables.
Standard deviation is computed in parametrized space, and transformed back to particle variables.
- Parameters:
- parts: array-like, optional
Array of particle variables.
- vecs: array-like, optional
Array of parametrized variables. If set, overrides parts.
- weights: array-like, optional
Array of particle statistic weights.
- save(gtree)
Save Geometry parameters into XML tree.
- static load(gtree)
Load parameters from XML tree and build Geometry.
- __module__ = 'kdsource.geom'
- class kdsource.geom.Energy
Bases:
Metric- __init__()
Simple metric for energy, with no transformation.
- load()
Build Energy.
- __module__ = 'kdsource.geom'
- class kdsource.geom.Lethargy(E0=10)
Bases:
Metric- __init__(E0=10)
Lethargy metric for energy.
- Lethargy is defined as:
u = log(E0 / ekin)
- Parameters:
- E0: float
Reference energy. Typically, it is the highest energy in the system.
- transform(ekins)
Transform energy to lethargy.
- inverse_transform(us)
Transform lethargy to energy.
- jac(ekins)
Jacobian of lethargy transformation.
- save(mtree)
Save Lethargy parameters into XML tree.
- static load(mtree)
Load parameters from XML tree and build Lethargy.
- __module__ = 'kdsource.geom'
- class kdsource.geom.Time
Bases:
Metric- __init__()
Simple metric for time, with no transformation.
- load()
Build Time.
- __module__ = 'kdsource.geom'
- class kdsource.geom.Decade
Bases:
Metric- __init__()
Decade metric for time.
- Decade is defined as:
d = log(t)
- transform(ts)
Transform time to decade.
- inverse_transform(ds)
Transform deacde to time.
- jac(ts)
Jacobian of lethargy transformation.
- static load(mtree)
Build Decade.
- __module__ = 'kdsource.geom'
- class kdsource.geom.Vol(xmin=-inf, xmax=inf, ymin=-inf, ymax=inf, zmin=-inf, zmax=inf)
Bases:
Metric- __init__(xmin=-inf, xmax=inf, ymin=-inf, ymax=inf, zmin=-inf, zmax=inf)
Simple metric for 3D position, with no transformation.
Each spatial variable (x, y, z) is delimited between a min and max value. By default these are -infinity and infinity, respectively. All positions in the particle list should be inside these limits.
Axis system of reference can be changed by means of the ‘trasl’ and ‘rot’ arguments of the Geometry object.
- save(mtree)
Save Vol parameters into XML tree.
- static load(mtree)
Load parameters from XML tree and build Vol.
- __module__ = 'kdsource.geom'
- class kdsource.geom.SurfXY(xmin=-inf, xmax=inf, ymin=-inf, ymax=inf, z=0)
Bases:
Metric- __init__(xmin=-inf, xmax=inf, ymin=-inf, ymax=inf, z=0)
Simple metric for 2D position, with no transformation.
Spatial variables x and y are delimited between a min and max value. By default these are -infinity and infinity, respectively. All positions in the particle list should be inside these limits.
z has the fixed value given as argument.
Axis system of reference can be changed by means of the ‘trasl’ and ‘rot’ arguments of the Geometry object.
- transform(poss)
Transform volume position (x,y,z) to flat position (x,y).
- inverse_transform(poss)
Transform flat position (x,y) to volume position (x,y,z).
- save(mtree)
Save SurfXY parameters into XML tree.
- static load(mtree)
Load parameters from XML tree and build SurfXY.
- __module__ = 'kdsource.geom'
- class kdsource.geom.SurfR(rho_min=0, rho_max=inf, psi_min=-3.141592653589793, psi_max=3.141592653589793, z=0)
Bases:
Metric- __init__(rho_min=0, rho_max=inf, psi_min=-3.141592653589793, psi_max=3.141592653589793, z=0)
Polar parametrization for position. Polar variables are defined as follows:
rho: radius, in [cm] psi: azimuthal angle, starting from x direction, in [deg].
Spatial variable rho is delimited between a min and max value. By default these are zero and infinity, respectively. All positions in the particle list should be inside these limits. z has the fixed value given as argument.
- transform(poss)
Transform volume position (x,y,z) to circular flat position (rho,psi).
- inverse_transform(poss)
Transform polar flat position (rho,psi) to volume position (x,y,z).
- save(mtree)
Save SurfCirc parameters into XML tree.
- jac(poss)
Jacobian of polar transformation.
- static load(mtree)
Load parameters from XML tree and build SurfCirc.
- __module__ = 'kdsource.geom'
- class kdsource.geom.SurfR2(rho_min=0, rho_max=inf, psi_min=-3.141592653589793, psi_max=3.141592653589793, z=0)
Bases:
Metric- __init__(rho_min=0, rho_max=inf, psi_min=-3.141592653589793, psi_max=3.141592653589793, z=0)
Pseudo-polar parametrization for position. Polar variables are defined as follows:
rho2: radius squared, in [cm²] psi: azimuthal angle, starting from x direction, in [deg].
Spatial variable rho2 is delimited between a min and max value. By default these are zero and infinity, respectively. All positions in the particle list should be inside these limits. z has the fixed value given as argument.
- transform(poss)
Transform volume position (x,y,z) to circular flat position (rho2,psi).
- inverse_transform(poss)
Transform polar flat position (rho2,psi) to volume position (x,y,z).
- save(mtree)
Save SurfCirc parameters into XML tree.
- jac(poss)
Jacobian of polar transformation.
- static load(mtree)
Load parameters from XML tree and build SurfCirc.
- __module__ = 'kdsource.geom'
- class kdsource.geom.SurfCircle(rho_min=0, rho_max=inf, psi_min=-3.141592653589793, psi_max=3.141592653589793, z=0)
Bases:
Metric- __init__(rho_min=0, rho_max=inf, psi_min=-3.141592653589793, psi_max=3.141592653589793, z=0)
Simple metric for 2D position, with no transformation.
Spatial variables x and y are delimited between a min and max value for the radius (rho) and the angle (psi), in polar coordinates. By default these are 0 and infinity for rho, and -pi and pi for psi, respectively. All positions in the particle list should be inside these limits.
z has the fixed value given as argument.
Axis system of reference can be changed by means of the ‘trasl’ and ‘rot’ arguments of the Geometry object.
- transform(poss)
Transform volume position (x,y,z) to flat position (x,y).
- inverse_transform(poss)
Transform flat position (x,y) to volume position (x,y,z).
- save(mtree)
Save SurfXY parameters into XML tree.
- static load(mtree)
Load parameters from XML tree and build SurfXY.
- __module__ = 'kdsource.geom'
- class kdsource.geom.Guide(xwidth, yheight, zmax=inf, rcurv=None)
Bases:
Metric- __init__(xwidth, yheight, zmax=inf, rcurv=None)
Guide metric for position and direction.
Position is parametrized with following variables:
z: distance along guide, following curvature (if any).
t: transversal direction along mirrors, starting at (x+,y-) corner, towards (x+,y+) corner.
Direction is parametrized with following variables:
mu: cosine of angle between particle direction and mirror normal.
phi: azimuthal angle, starting from z direction, in [deg].
Axis system of reference can be changed by means of the ‘trasl’ and ‘rot’ arguments of the Geometry object.
- Parameters:
- xwidth: float
Guide width.
- yheight: float
Guide height.
- zmax: float
Guide length.
- rcurv: float
Curvature radius, defined as follows. Default is no curvature.
rcurv > 0 for curvature towards negative x
rcurv < 0 for curvature towards negative x
rcurv = 0 or rcurv = infinity for no curvature
- transform(posdirs)
Transform position and direction to guide variables.
- inverse_transform(posdirs)
Transform guide variables to position and direction.
- save(mtree)
Save Guide parameters into XML tree.
- static load(mtree)
Load parameters from XML tree and build Guide.
- __module__ = 'kdsource.geom'
- class kdsource.geom.Isotrop(keep_xdir=False, keep_ydir=False, keep_zdir=False)
Bases:
Metric- __init__(keep_xdir=False, keep_ydir=False, keep_zdir=False)
Simple metric for direction, with no transformation.
Distance is measured as the euclidean distance between 3D unitary direction vectors.
Axis orientation can be changed by means of the rot’ argument of the Geometry object.
- Parameters:
- keep_xdir: bool
If True, when using the source for sampling new particles, perturbation will not change dirx sign.
- keep_ydir: bool
If True, when using the source for sampling new particles, perturbation will not change diry sign.
- keep_zdir: bool
If True, when using the source for sampling new particles, perturbation will not change dirz sign.
- mean(dirs=None, vecs=None, weights=None)
Mean of directions.
Mean is computed as the euclidean mean of direction vectors, normalized to 1.
- Parameters:
- dirs: array-like, optional
Array of directions.
- vecs: array-like, optional
Array of parametrized directions. If set, overrides dirs.
- weights: array-like, optional
Array of particle statistic weights.
- std(dirs=None, vecs=None, weights=None)
Standard deviation of directions.
Standard deviation is computed as the euclidean standard deviation of direction vectors minus its mean (computed with mean method).
- Parameters:
- dirs: array-like, optional
Array of directions.
- vecs: array-like, optional
Array of parametrized directions. If set, overrides dirs.
- weights: array-like, optional
Array of particle statistic weights.
- save(mtree)
Save Guide parameters into XML tree.
- static load(mtree)
Load parameters from XML tree and build Isotrop.
- __module__ = 'kdsource.geom'
- class kdsource.geom.Polar
Bases:
Metric- __init__()
Polar parametrization for direction.
- Polar angles are defined as follows:
theta: angle between direction and z, in [deg]. phi: azimuthal angle, starting from x direction, in [deg].
Axis orientation can be changed by means of the rot’ argument of the Geometry object.
- transform(dirs)
Transform directions to polar angles.
- inverse_transform(tps)
Transform polar angles to directions.
- jac(dirs)
Jacobian of polar transformation.
- static load(mtree)
Build Polar.
- __module__ = 'kdsource.geom'
- class kdsource.geom.PolarMu
Bases:
Metric- __init__()
Polar parametrization for direction, with mu = cos(theta).
- Polar parameters are defined as follows:
mu: cosine of angle between direction and z, in [deg]. phi: azimuthal angle, starting from x direction, in [deg].
Axis orientation can be changed by means of the rot’ argument of the Geometry object.
- transform(dirs)
Transform directions to polar parameters.
- inverse_transform(tps)
Transform polar parameters to directions.
- static load(mtree)
Build PolarMu.
- __module__ = 'kdsource.geom'
- kdsource.geom.GeomFlat(xmin=-inf, xmax=inf, ymin=-inf, ymax=inf, z=0, E0=10, keep_zdir=True, trasl=None, rot=None)
Build flat neutron source.
Energy metric is Lethargy, position metric is SurfXY and direction metric is Isotrop.
See Metric’s and Geometry constructors for parameters docs.
- kdsource.geom.GeomFlatTemp(xmin=-inf, xmax=inf, ymin=-inf, ymax=inf, z=0, E0=10, keep_zdir=True, trasl=None, rot=None)
Build flat neutron source with time treatment.
Energy metric is Lethargy, position metric is SurfXY, direction metric is Isotrop, and time metric is Decade.
See Metric’s and Geometry constructors for parameters docs.
- kdsource.geom.GeomGuide(xwidth, yheight, zmax=inf, rcurv=None, E0=10, trasl=None, rot=None)
Build neutron source for leaks thru guide mirrors.
Energy metric is Lethargy, position and direction metric is Guide.
See Metric’s and Geometry constructors for parameters docs.
- kdsource.geom.GeomActiv(xmin=-inf, xmax=inf, ymin=-inf, ymax=inf, zmin=-inf, zmax=inf, trasl=None, rot=None)
Build photon volumetric activation source.
Energy metric is Energy, position metric is Vol and direction metric is Isotrop.
See Metric’s and Geometry constructors for parameters docs.