expelliarmus.wizard.wizard#

Module Contents#

Classes#

Wizard

Wizard allows to cast powerful spells, such as reading entire files to NumPy arrays or chunks of these, or cutting binary files to a certain duration.

class expelliarmus.wizard.wizard.Wizard(encoding: str, fpath: Optional[Union[str, pathlib.Path]] = None, chunk_size: Optional[int] = 8192, time_window: Optional[int] = 10, buff_size: Optional[int] = _DEFAULT_BUFF_SIZE)[source]#

Wizard allows to cast powerful spells, such as reading entire files to NumPy arrays or chunks of these, or cutting binary files to a certain duration.

Parameters
  • encoding (str) – the encoding of the file, to be chosen among DAT, EVT2 and EVT3.

  • fpath (Optional[Union[str, pathlib.Path]]) – the file to be read, either in chunks or fully.

  • buff_size (Optional[int]) – the size of the buffer used to read the binary file.

  • chunk_size (Optional[int]) – the chunk lenght when reading files in chunks.

  • time_window (Optional[int]) – the time window length in microseconds when reading files in time chunks.

property encoding: str[source]#

The encoding of the files handles by Wizard.

Returns

the encoding.

Return type

str

property fpath: pathlib.Path[source]#

Wizard input file path.

Returns

the file path.

Return type

pathlib.Path

property buff_size: int[source]#

The buffer size used by Wizard to read the binary files.

Returns

the buffer size.

Return type

int

property chunk_size: int[source]#

The length of each chunk provided by Wizard when reading files in chunks.

Returns

the chunk size.

Return type

int

property time_window: int[source]#

The time window lenght, expressed in microseconds.

Returns

the time window length.

Return type

int

set_file(fpath: Union[str, pathlib.Path]) None[source]#

Function that sets the input file.

Parameters

fpath (Union[str, pathlib.Path]) – the path to the file.

Return type

None

set_chunk_size(chunk_size: int, do_reset: bool = True) None[source]#

Function to sets the size of the chunks to be read. WARNING: due to the vectorized events in event files, the chunks can be longer that ‘chunk_size’ (at most ‘chunk_size+12’).

Parameters
  • fpath – path to the input file.

  • chunk_size (int) – size of the chunks ot be read.

  • do_reset (bool) – whether or not to reset the wizard after setting the chunk size.

Return type

None

set_encoding(encoding: Union[str, pathlib.Path]) None[source]#

Sets the encoding proprierty of the class.

Parameters

encoding (Union[str, pathlib.Path]) – the encoding of the file.

Return type

None

set_buff_size(buff_size: int) None[source]#

Sets te buffer size used to read the binary file.

Parameters

buff_size (int) – the buffer size specified.

Return type

None

set_time_window(time_window: int, do_reset: bool = True) None[source]#

Sets the time window length.

Parameters
  • time_window (int) – the time window specified [us].

  • do_reset (bool) – whether or not to reset the wizard after setting the time window.

Return type

None

reset() None[source]#

Function used to reset the generator, so that the file can be read from the beginning.

Return type

None

cut(fpath_out: Union[str, pathlib.Path], new_duration: int, fpath_in: Optional[Union[str, pathlib.Path]] = None) int[source]#

Cuts the duration of the recording contained in ‘fpath_in’ to ‘new_duration’ and saves the result to ‘fpath_out’.

Parameters
  • fpath_in (Optional[Union[str, pathlib.Path]]) – path to input file.

  • fpath_out (Union[str, pathlib.Path]) – path to output file.

  • new_duration (int) – the desired duration, expressed in microseconds.

Returns

the number of events encoded in the output file.

Return type

int

read(fpath: Optional[Union[str, pathlib.Path]] = None) numpy.ndarray[source]#

Reads a binary file to a structured NumPy of events.

Parameters

fpath (Optional[Union[str, pathlib.Path]]) – path to the input file.

Returns

the structured NumPy array.

Return type

numpy.ndarray

save(fpath: Union[str, pathlib.Path], arr: numpy.ndarray) None[source]#

Compresses the provided to the chosen encoding format.

Parameters
  • fpath (Union[str, pathlib.Path]) – path to output file.

  • arr (numpy.ndarray) – the NumPy array to be saved.

Returns

the number of events encoded in the output file.

Return type

None

read_chunk() numpy.ndarray[source]#

Generator used to read the file in chunks.

Returns

structured NumPy array of events.

Return type

numpy.ndarray

read_time_window() numpy.ndarray[source]#

Generator used to read the file in time windows.

Returns

structured NumPy array of events.

Return type

numpy.ndarray