xopto.mcbase.mcutil.cache module¶
- class LutCache(lutsize: int = 2000, verbose: bool = False, cachefile: Optional[str] = None)[source]¶
Bases:
xopto.mcbase.mcutil.cache.ObjCache
Initializes a lookup table-based Monte Carlo scattering phase function cache (
LutPhaseFunction
objects). This object internally saves all created instances of lookup table-based scattering phase functions and runs computations only if the requested scattering phase function cannot be found in the cache.- Parameters
lutsize (int) – The lookup table size.
verbose (bool) – Print information to stdout isf set to True.
cachefile (str or file) – File location or a binary file like object from which to load LutCache.
- get(pftype: Type[xopto.pf.pfbase.PfBase], pfargs: tuple, lutsize: Optional[int] = None) → object[source]¶
Prepare a new lookup table-based scattering phase function. Computations are made only if the requested scattering phase function is not found in the cache. This method can be used to pre-populate the cache with scattering phase functions.
- Parameters
pftype (Type[xopto.pf.PfBase]) – Any type of a scattering phase function that inherits from the
xopto.pf.PfBase
class.pfargs (tuple) – Parameters passed to the scattering phase function constructor.
lutsize (int) – Size of the lookup table passed to the py:meth:xopto.mcbase.pf.lut.LutEx. If None, the value passed to the constructor is used.
- Returns
lut_pf – Created or from cache loaded lookup table scattering phase function.
- Return type
LutPhaseFunction
- insert(lut: xopto.mcbase.mcpf.lut.LutEx, pftype: Type[xopto.pf.pfbase.PfBase], pfargs: tuple, lutsize: Optional[int] = None) → object[source]¶
Inserts an existing lookup table-based scattering phase function into the cache.
- Parameters
lut (LutEx) – Instance of
LutEx
created with the specified scattering phase function type, arguments and lookup table size.pftype (Type[xopto.pf.PfBase]) – Any type of a scattering phase function that inherits from the
xopto.pf.PfBase
class.pfargs (tuple) – Parameters passed to the scattering phase function constructor.
lutsize (int) – Size of the lookup table passed to the py:meth:xopto.mcbase.pf.lut.LutEx. If None, the value passed to the constructor is used.
- Returns
inserted – Return True if the scattering phase function was inserted into the cache and False if existing scattering phase function was found in the lookup table.
- Return type
bool
- static load(cachefile: str, **kwargs) → xopto.mcbase.mcutil.cache.LutCache[source]¶
Load LutCache object from a file.
- Parameters
cachefile (str, file) – File location or a file like object.
kwargs (dict) – Keyword arguments are passed to the LutCache constructor.
- Returns
cache – ObjCache instance initialized with data from the specified file.
- Return type
- class ObjCache(cachefile: Optional[str] = None, verbose: bool = False)[source]¶
Bases:
object
ObjCache constructor.
- Parameters
cachefile (str, file) – File location or a binary file like object.
verbose (bool) – Print information to stdout.
- contains(obj_type: type, *args) → bool[source]¶
Checks if the specified object is in the cache.
- Parameters
obj_type (object type or callable) – Any python class or callable.
args (list) – Parameters passed to the object constructor or callable.
- Returns
found – Returns True if the specified object is found in the cache.
- Return type
bool
- get(obj_type: type, *args) → object[source]¶
Request an object of type obj_type and constructor arguments args from the cache. Object is created if one is not found in the cache.
- Parameters
obj_type (object type or callable) – Any python class or callable.
args (list) – Parameters passed to the object constructor or callable.
- Returns
obj – An object created as
obj_type(*args)
or an existing object from cache.- Return type
object
- insert(value: object, obj_type: type, *args)[source]¶
Inserts the specified object into the cache if an existing entry is not found.
- Parameters
value (object) – Value that is attained by calling
obj_type(*args)
obj_type (object type or callable) – Any python class or callable.
args (list) – Parameters passed to the object constructor or callable.
- Returns
found – Returns True if the specified object was added to the cache or False if an existing object has been found in the cache.
- Return type
bool
- static load(cachefile, **kwargs) → xopto.mcbase.mcutil.cache.ObjCache[source]¶
Load ObjCache object from a file.
- Parameters
cachefile (str, file) – File location or a file like object.
kwargs (dict) – Keyword arguments are passed to the
ObjCache()
constructor.
- Returns
cache – ObjCache instance initialized with data from the specified file.
- Return type