xopto.mcbase.mcutil.lut module¶
- class CollectionLut(sensitivity: numpy.ndarray, costheta: Optional[numpy.ndarray] = None, n: int = 1000)[source]¶
Bases:
xopto.mcbase.mcutil.lut.LinearLut
A lookup table of detector sensitivity (collection efficiency) as a function of the angle of incidence. Azimuthal symmetry of the collection sensitivity is assumed.
- Parameters
sensitivity (np.ndarray or str) – Detector sensitivity (efficiency) as a function of the angle of incidence. If the value is a str, an instance is loaded from the file represented by the string.
costheta (np.ndarray) – Angle of incidence cosines at which the detector sensitivities are defined. If None, a vector of uniformly distributed values from 0 to 1 is used.
n (int) – The size of lookup table that will be used in Monte Carlo simulations.
- class EmissionLut(radiance: numpy.ndarray, costheta: Optional[numpy.ndarray] = None, n: int = 2000, npts: int = 10000, meth: str = 'simps')[source]¶
Bases:
xopto.mcbase.mcutil.lut.LinearLut
Constructs a lookup table for numerical sampling of the emission angles of a source with the given angular emission characteristics. Azimuthal symmetry of the emission characteristics is assumed.
The constructed lookup table should be sampled by a uniform random variable
from [0, 1] and linear interpolation that will yield the emission angle cosine (costheta): .. math:
f_{i} = r*n i_1 = int(fp_index) i_2 = min(i_1 + 1, n - 1) delta = f_i - i_1 costheta = lut[i_1]*(1.0 - delta) + lut[i_2 + 1]*delta
- Parameters
radiance (np.ndarray, EmissionLut or str) – Relative source radiance as a function of the angle of incidence cosines given in the costheta array. If the value is an instance of EmissionLut, a new weak copy of the instance is created. If the value is a str, an instance is loaded from the file represented by the string.
costheta (np.ndarray) – Cosines of the angle of incidence at which the values in the radiance array are defined. If None, a uniformly distributed vector of values from 0 to 1 is used.
n (int) – Size of the lookup table that can be used to numerically sample the emission angles.
npts (int) – Number of uniformly distributed control points from min(costheta) to max(costheta) used for simpson approximation of the radiance CDF.
meth (str) – Method that is used to compute the radiance CDF. Use “simps” for Simpson or “quad” for adaptive-step integration.
- class LinearLut(lut_data: numpy.ndarray, first: float = 0.0, last: float = 1.0)[source]¶
Bases:
xopto.mcbase.mcobject.McObject
Creates a linear lookup table instance. Samples in the lookup table are uniformly spread between the positions of the first and last lookup table element that are passed to the constructor.
- Parameters
lut_data (LinearLut, np.ndarray vector or str) – If a numpy array, lookup table data as an array or array-like object. If a str, a filename from which to load the instance. If a LinearLut, a weak copy is created.
first (float) – Position of the first element/entry in the lookup table.
last (float) – Position of the last element/entry in the lookup table.
- cl_pack(mc: xopto.mcbase.mcobject.McObject, target: Optional[xopto.cl.cltypes.Structure] = None) → xopto.cl.cltypes.Structure[source]¶
Fills the ctypes structure (target) with the data required by the Monte Carlo simulator.
- Parameters
mc (McObject) – Simulator instance.
target (cltypes.Struct) – Ctypes structure to be filled with the lut parameters.
- Returns
lut – Filled ctypes structured received as an input arguments.
- Return type
cltypes.Struct
- static cl_type(mc: xopto.mcbase.mcobject.McObject) → xopto.cl.cltypes.Structure[source]¶
Create a Structure type that represents LinearLut in the OpenCL kernel.
- Parameters
mc (mcobject.McObject) – Simulator instance.
- Returns
struct – OpenCL structure type that is used to represents a LinearLut instance in the OpenCL kernel.
The returned structure type implements the following fields:
- first: mc_fp_t
The value of the independent variable for the first element in the lookup table.
- inv_span: mc_fp_t
Inverse of the span of the independent variable (the span is defined as the difference between the value of the independent variable of the last and first element in the lookup table).
- n: mc_size_t
The number of elements in the lookup table.
- offset: mc_size_t
Offset/index of the first element in the lookup table from the start of the linear array that holds data of all the lookup tables.
- Return type
- property data: numpy.ndarray¶
Lookup table data as a flat numpy array.
- property first: float¶
Position of the first point in the lookup table.
- static fromdict(data: dict) → xopto.mcbase.mcutil.lut.LinearLut[source]¶
Create a linear lookup table instance from a dictionary.
- Parameters
data (dict) – Dictionary created by the
LinearLut.todict()
method.
- static fromfile(filename: str) → xopto.mcbase.mcutil.lut.LinearLut[source]¶
Load LinearLut instance from a npz file.
- Parameters
filename (str) – Data file.
- Returns
lut – A new LinearLut instance created from the file.
- Return type
- property last: float¶
Position of the last point in the lookup table.
- property span: Tuple[float, float]¶
Distance between the positions of the first and last point in the lookup table.
- class LutEntry(manager: xopto.mcbase.mcutil.lut.LutManager, data: numpy.ndarray, offset: int)[source]¶
Bases:
object
Lookup table entry.
- Parameters
manager (LutManager) – Manager of this lookup table entry.
data (np.ndarray) – Lookup table data as a numpy array.
offset (int) – Offset of the first element of this lookup table in the common lookup table buffer.
- property data: xopto.mcbase.mcutil.lut.LutManager¶
Data array of the entry.
- property manager: xopto.mcbase.mcutil.lut.LutManager¶
Lookup table manager that manages this entry.
- property offset: int¶
Offset of the first element of this lookup table entry from the beginning of the data buffer.
- class LutManager(dtype)[source]¶
Bases:
object
Manages the data of multiple lookup tables. The lookup tables can be easily packed into a single contiguous array that is passed to an OpenCL kernel.
Creates a new instance of the lookup table manager.
- Parameters
dtype (np.dtype) – Data type of the array that will contain all the managed lookup table arrays.
- append(lut: numpy.ndarray, force: bool = False) → Tuple[xopto.mcbase.mcutil.lut.LutEntry, bool][source]¶
Appends a new lookup table to the list of managed lookup tables and returns the offset from the first element of the contiguous array of all managed lookup tables.
A lookup table is appended only if an existing lookup table with the same values is not found in the list of managed lookup tables.
- Parameters
lut (np.ndarray vector) – A new lookup table to append to the list of managed lookup tables. The new lookup table is appended only if the same lookup table i not found in the list of existing lookup tables.
force (bool) – If True, the lookup table is appended without comparing its content to the list of existing managed lookup tables. This improves the performance but can grow the total size of the contiguous data array due to duplicate lookup tables in the managed list.
- Returns
lut (LutEntry) – Lookup table entry representing the given data.
added (bool) – True if a lookup table entry with the same data was not found among the existing managed lookup table entries. If the value of the force argument is True, this value is always returned as True.
- property dtype: numpy.dtype¶
Lookup table data type.
- offset(lut: numpy.ndarray) → int[source]¶
Get the offset of the first element in the lookup table.
- Parameters
lut (np.ndarray) – Lookup table array as passed to the append method.
- Returns
offset – Offset of the first element or None if the lookup table is not found.
- Return type
int
- pack_into(target: Optional[numpy.ndarray] = None, dtype: Optional[numpy.dtype] = None) → numpy.ndarray[source]¶
Move the lookup tables into a contiguous numpy array. If target is None, a new target array is created using the data type specified in dtype. If the target array is too small to fit all the data, a new target of the same data type is allocated.
- Parameters
target (np.ndarray) – A contiguous numpy array that will hold the lookup tables on return. One of the input arguments target and dtype must not be None!
dtype (np.dtype) – This data type overloads the data type passed to the constructor.
- Returns
data – A contiguous numpy array with all the lookup tables.
- Return type
np.ndarray
- class LutManagers[source]¶
Bases:
object
Manages multiple lookup table managers of type
LutManager
.- manager(dtype: numpy.dtype) → xopto.mcbase.mcutil.lut.LutManager[source]¶
Return lookup table manager for the given data type. Lookup table managers are created on the first demand/use.
- Parameters
dtype (np.dtype) – Numpy data type of the lookup table manager.
- Returns
allocator – Lookup table manager.
- Return type
Note
Lookup table managers can be retrieved by the [] operator that takes the numpy data type of the lookup table manager.
- class RestrictedLutManagers(dtypes: List[numpy.dtype])[source]¶
Bases:
xopto.mcbase.mcutil.lut.LutManagers
Manages multiple lookup table managers of type
LutManager
. The range of data types is restricted to list of dtypes.- Parameters
dtypes (list or tuple) – List of data types as numpy.dtype that will be supported by the instance.
- manager(dtype: numpy.dtype) → xopto.mcbase.mcutil.lut.LutManager[source]¶
Return lookup table manager for the given data type. Lookup table managers are created on the first demand/use.
- Parameters
dtype (np.dtype) – Numpy data type of the lookup table manager.
- Returns
allocator – Lookup table manager.
- Return type
Note
Lookup table managers can be retrieved by the [] operator that takes the numpy data type of the lookup table manager.