OscarLoader

class OscarLoader.OscarLoader(OSCAR_FILE: str)[source]

OscarLoader is a class for loading and processing OSCAR format data files.

This class extends the BaseLoader and provides functionality to load, filter, and process data from files in the OSCAR format. It supports different versions of the OSCAR format and allows for event-based data loading with optional filtering.

Attributes:
PATH_OSCAR_str

The path to the OSCAR data file.

oscar_format_str

The format of the OSCAR data file.

optional_arguments_dict

A dictionary of optional arguments passed to the load method.

event_end_lines_list

A list to store the end lines of events in the OSCAR data file.

num_events_int

The number of events in the OSCAR data file.

num_output_per_event_numpy.ndarray

An array containing the number of particles per event in the OSCAR data file.

Methods

__init__(OSCAR_FILE)

Initializes the OscarLoader with the provided OSCAR file path.

load(**kwargs)

Loads the OSCAR data with optional event ranges and filters.

set_oscar_format()

Determines and sets the format of the OSCAR data file.

oscar_format()

Returns the OSCAR format of the data file.

impact_parameter()

Returns the impact parameter of the events in the OSCAR data file.

event_end_lines()

Returns the event end lines in the OSCAR data file.

event_end_lines() List[str][source]

Returns the list of event end lines.

This method returns the list of strings that mark the end of events in the OSCAR data.

Returns:
List[str]

A list of strings that mark the end of events in the OSCAR data.

impact_parameter() List[float][source]

Returns the impact parameter of the events.

This method extracts the impact parameter of the collision from the end line of each surviving event in the OSCAR data file.

Returns:
List[float]

The impact parameter of the collisions.

load(**kwargs: Dict[str, Any]) Tuple[List[List[Particle]], int, ndarray, List[str]][source]

Loads the OSCAR data from the specified file.

This method accepts optional arguments that specify which events to load and any filters to apply. The ‘events’ argument can be either a tuple specifying a range of events or an integer specifying a single event. If the ‘events’ argument is provided and is not a tuple or an integer, or if any of the event numbers are negative, a ValueError is raised.

Parameters:
**kwargsdict, optional

A dictionary of optional arguments. The following keys are recognized:

  • ‘events’: Either a tuple of two integers specifying the range of events to load, or a single integer specifying a single event to load.

  • ‘filters’: A list of filters to apply to the data.

Returns:
tuple

A tuple containing the following elements:

  • A list of particles loaded from the OSCAR data.

  • The number of events in the OSCAR data.

  • The number of particles in each event in the OSCAR data.

Raises:
ValueError

If an unrecognized keyword argument is used in the constructor, or if the ‘events’ argument is not a tuple or an integer, or if any of the event numbers are negative.

oscar_format() str | None[source]

Returns the OSCAR format string.

This method returns the OSCAR format string that specifies the format of the OSCAR data being loaded.

Returns:
Optional[str]

The OSCAR format string, or None if the format is not set.

set_oscar_format() None[source]

Sets the number of events in the OSCAR data file.

This method reads the file in binary mode to search for the last line. This approach avoids the need to loop through the entire file, which can be time-consuming for large files. It then checks if the last line starts with a ‘#’ and contains the word ‘event’. If it does, it sets the number of events to the integer value in the third position of the last line. If the last line does not meet these conditions, it raises a TypeError.

Parameters:
None
Returns:
None
Raises:
TypeError

If the last line of the file does not start with a ‘#’ and contain the word ‘event’.