spine.ana.base

Base class of all analysis scripts.

Classes

AnaBase([obj_type, run_mode, ...])

Parent class of all analysis scripts.

class spine.ana.base.AnaBase(obj_type=None, run_mode=None, truth_point_mode=None, truth_dep_mode=None, append=False, overwrite=False, log_dir=None, prefix=None, buffer_size=1)[source]

Parent class of all 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

req_keys

Data products needed to run the analysis script

Type:

List[str]

opt_keys

Optional data products which will be used only if they are provided

Type:

List[str]

units

Units in which the coordinates are expressed

Type:

str

Attributes:
dep_modes

Dictionary which makes the correspondance between the name of a true object deposition attribute with the underlying deposition array it points to.

keys

Dictionary of (key, necessity) pairs which determine which data keys are needed/optional for the post-processor to run.

name
point_modes

Dictionary which makes the correspondance between 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)

Apppend a CSV log file with a set of values.

close_writers()

Close all CSV writers and flush any remaining data.

flush_writers()

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()[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()[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)[source]

Adds a CSV writer to the list of writers for this script.

Parameters:

name (str) – Name of the writer

property keys

Dictionary of (key, necessity) pairs which determine which data keys are needed/optional for the post-processor to run.

Returns:

Dictionary of (key, necessity) pairs to be used

Return type:

Dict[str, bool]

property point_modes

Dictionary which makes the correspondance between 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

Dictionary which makes the correspondance between 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)[source]

Update the underlying set of keys and their necessity in place.

Parameters:

update_dict (Dict[str, bool]) – Dictionary of (key, necessity) pairs to update the keys with

get_base_dict(data)[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, **kwargs)[source]

Apppend a CSV log file with a set of values.

Parameters:
  • name (str) – Name of the writer

  • **kwargs (dict) – Dictionary of information to save to the writer

get_index(obj)[source]

Get a certain pre-defined index attribute of an object.

The TruthFragment, TruthParticle and TruthInteraction objects index are obtained using the truth_index_mode attribute of the class.

Parameters:
  • obj (Union[FragmentBase, ParticleBase, InteractionBase]) – Fragment, Particle or Interaction object

  • Results

  • -------

  • np.ndarray

    1. Object index

get_points(obj)[source]

Get a certain pre-defined point attribute of an object.

The TruthFragment, TruthParticle and TruthInteraction objects points are obtained using the truth_point_mode attribute of the class.

Parameters:
  • obj (Union[FragmentBase, ParticleBase, InteractionBase]) – Fragment, Particle or Interaction object

  • Results

  • -------

  • np.ndarray – (N, 3) Point coordinates

abstractmethod process(data)[source]

Place-holder method to be defined in each analysis script.

Parameters:

data (dict) – Filtered data dictionary for one entry