spine.ana.base
Base class of all analysis scripts.
Classes
|
Parent class for CSV-writing analysis scripts. |
- class spine.ana.base.AnaBase(obj_type: str | Sequence[str] | None = None, run_mode: str | None = None, truth_point_mode: str | None = None, truth_index_mode: str | None = None, truth_dep_mode: str | None = None, append: bool = False, overwrite: bool = False, log_dir: str | None = None, prefix: str | None = None, buffer_size: int = 1)[source]
Parent class for CSV-writing analysis scripts.
This base class performs the following functions: - Ensures that the necessary methods exist - Checks that the script is provided the necessary information - Writes the output of the analysis to CSV
- name
Name of the analysis script (to call it from a configuration file)
- Type:
str
- keys
Data products needed or optionally consumed by the analysis script
- Type:
dict
- units
Units in which the coordinates are expressed
- Type:
str
- Attributes:
dep_modesDictionary which maps the name of a true object deposition attribute with the underlying deposition array it points to.
keysDictionary of (key, necessity) pairs which determine which data keys are needed or optional for the analysis script to run.
- name
point_modesDictionary which maps the name of a true object point attribute with the underlying point tensor it points to.
Methods
__call__(data[, entry])Runs the analysis script on one entry.
append(name, **kwargs)Append a row to a CSV log file.
Close all CSV writers and flush any remaining data.
Flush all CSV writer buffers without closing the files.
get_base_dict(data)Builds the entry information dictionary.
get_index(obj)Get a certain pre-defined index attribute of an object.
get_points(obj)Get a certain pre-defined point attribute of an object.
initialize_writer(name)Adds a CSV writer to the list of writers for this script.
process(data)Place-holder method to be defined in each analysis script.
update_keys(update_dict)Update the underlying set of keys and their necessity in place.
- name = None
- aliases = ()
- units = 'cm'
- close_writers() None[source]
Close all CSV writers and flush any remaining data.
This should be called when the analysis is complete to ensure all data is written and files are properly closed.
- flush_writers() None[source]
Flush all CSV writer buffers without closing the files.
This forces any buffered data to be written to disk. Useful for ensuring data persistence at checkpoints.
- initialize_writer(name: str) None[source]
Adds a CSV writer to the list of writers for this script.
- Parameters:
name (str) – Name of the writer
- property keys: dict[str, bool]
Dictionary of (key, necessity) pairs which determine which data keys are needed or optional for the analysis script to run.
- Returns:
Dictionary of (key, necessity) pairs to be used
- Return type:
dict[str, bool]
- property point_modes: dict[str, str]
Dictionary which maps the name of a true object point attribute with the underlying point tensor it points to.
- Returns:
Dictionary of (attribute, key) mapping for point coordinates
- Return type:
dict[str, str]
- property dep_modes: dict[str, str]
Dictionary which maps the name of a true object deposition attribute with the underlying deposition array it points to.
- Returns:
Dictionary of (attribute, key) mapping for point depositions
- Return type:
dict[str, str]
- update_keys(update_dict: Mapping[str, bool]) None[source]
Update the underlying set of keys and their necessity in place.
- Parameters:
update_dict (Mapping[str, bool]) – Dictionary of (key, necessity) pairs to update the keys with
- get_base_dict(data: Mapping[str, Any]) dict[str, Any][source]
Builds the entry information dictionary.
- Parameters:
data (dict) – Dictionary of data products
- Returns:
Dictionary of information for this entry
- Return type:
dict
- append(name: str, **kwargs: Any) None[source]
Append a row to a CSV log file.
- Parameters:
name (str) – Name of the writer
**kwargs (dict) – Dictionary of information to save to the writer
- get_index(obj: Any) Any[source]
Get a certain pre-defined index attribute of an object.
The
TruthFragment,TruthParticleandTruthInteractionobjects index are obtained using the truth_index_mode attribute of the class.- Parameters:
obj (FragmentBase or ParticleBase or InteractionBase) – Fragment, Particle or Interaction object
Results
-------
np.ndarray –
Object index
- get_points(obj: Any) Any[source]
Get a certain pre-defined point attribute of an object.
The
TruthFragment,TruthParticleandTruthInteractionobjects points are obtained using the truth_point_mode attribute of the class.- Parameters:
obj (FragmentBase or ParticleBase or InteractionBase) – Fragment, Particle or Interaction object
Results
-------
np.ndarray – (N, 3) Point coordinates