py21cmfast.io.caching.OutputCache¶
- class py21cmfast.io.caching.OutputCache¶
An object that manages cache files from 21cmFAST simulations.
This object has a single attribute – the top-level directory of the cache. This directory can be anywhere on disk. A number of methods exist on the object to interact with the cache, including finding existing cache files for a particular OutputStruct, writing/reading an OutputStruct to/from the cache, and listing existing datasets.
The cache is meant for single-field OutputStruct objects, not “collections” of outputs in an evolved universe (like Coeval or Lightcone objects).
- find_existing(obj)¶
Try to find existing boxes which match the parameters of this instance.
- Parameters:
obj (OutputStruct) – The OutputStruct instance to search for.
- Returns:
Path – The path to an existing cached OutputStruct matching this instance, or None if no match is found.
- Parameters:
- Return type:
pathlib.Path | None
- get_filename(obj)¶
Generate a filename for a given OutputStruct object based on its properties.
This method constructs a unique filename using the object’s class name, redshift (if available), and hashes of its input parameters. The filename structure is determined by the _path_structures dictionary.
- Parameters:
obj (OutputStruct) – The OutputStruct object for which to generate a filename.
- Returns:
str – The generated filename for the given OutputStruct object.
- Parameters:
- Return type:
str
- get_path(obj)¶
Get the full path for a given OutputStruct object.
This method combines the cache directory with the filename generated for the given OutputStruct object to create a complete file path.
- Parameters:
obj (OutputStruct) – The OutputStruct object for which to generate the full path.
- Returns:
Path – The complete file path for the given OutputStruct object.
- Parameters:
- Return type:
pathlib.Path
- list_datasets(*, kind=None, inputs=None, all_seeds=True, redshift=None)¶
Return all datasets in the cache which match a given set of filters.
- Parameters:
kind (str, optional) – Filter by this kind (a class name of an OutputStruct).
inputs (InputParameters) – Filter by these input parameters
all_seeds – Set to False to only include the seed within inputs.
redshift – The redshift to search for.
- Returns:
files – list of paths pointing to files matching the filters.
- Parameters:
kind (str | None)
inputs (py21cmfast.wrapper.inputs.InputParameters | None)
all_seeds (bool)
redshift (float | None)
- Return type:
list[pathlib.Path]
- load(obj)¶
Load a cache-backed object from disk corresponding to a given object.
- Parameters:
- Return type:
- write(obj)¶
Write an OutputStruct object to the cache.
This method writes the given OutputStruct object to an HDF5 file in the cache, using the path determined by the object’s properties.
- Parameters:
obj (OutputStruct) – The OutputStruct object to be written to the cache.
- Parameters:
- Return type:
None
- direc: pathlib.Path¶