dunedn.utils package
Submodules
dunedn.utils.ask_edit_card module
This module handle interactive user changes to the runcard.
- exception dunedn.utils.ask_edit_card.TimeOutError[source]
Bases:
ExceptionException class for time-out error.
- dunedn.utils.ask_edit_card.ask_edit_card(logger: Logger, output: Path)[source]
Asks interactively to edit the runcard.
Receives the input from the user and opens an editor in the terminal as a subprocess. Default editor is nano, otherwise the QUAKE_EDITOR environment variable allows for custom choice.
- Parameters
logger (logger) – The logger instance.
output (Path) – The output folder.
- dunedn.utils.ask_edit_card.ask_question(logger: Logger, question: str, default: str, timeout: float = 10) str[source]
Asks question to user.
The user has only
timeoutseconds to answer, then thedefaultis returned.- Parameters
logger (Logger) – The logger instance.
question (str) – The question to ask.
default (str) – The default answer.
timeout (float) – Time limit to answer in seconds.
- Returns
The user answer to the question.
- Return type
str
- dunedn.utils.ask_edit_card.question_instance(logger: Logger, question: str) str[source]
Asks for user input and checks if the answer is valid
- Parameters
logger (Logger) – The logger instance.
question (str) – The question to ask.
- Returns
The user answer to the question.
- Return type
str
- dunedn.utils.ask_edit_card.timed_input(logger: Logger, question: str, default: str, timeout: Optional[float] = None, noerror: bool = True, fct: Optional[Callable] = None) str[source]
Poses a question with a maximal time to answer, take default otherwise.
- Parameters
logger (Logger) – The logger instance.
question (str) – The question to ask.
default (str) – The default answer.
timeout (float) – Time limit to answer in seconds.
noerror (bool) – Wether to raise error on TimeOutError exception.
fct (Callable) – The callable effectively asking the question.
- Returns
The user answer to the question.
- Return type
str
dunedn.utils.utils module
This module contains utility functions of general interest.
- dunedn.utils.utils.add_info_columns(evt: ndarray) ndarray[source]
Adds event identifier and channel number columns to event.
Events come with additional information placed in the two first comlumns of the 2D array. These must be removed to make the computation as they are not informative. When saving back the event, the information must be added again.
- Parameters
evt (np.ndarray) – The event w/o additional information, of shape=(nb channels, nb tdc ticks).
- Returns
- Return type
The event w additional information, of shape=(nb channels, 2 + nb tdc ticks).
- dunedn.utils.utils.check(check_instance: Any, check_list: list[Any])[source]
Checks that check_list contains check_instance object. If not, raises NotImplementedError.
- Parameters
check_instance (Any) – Object to check.
check_list (list[Any]) – Available options.
- Raises
NotImplementedError – If
check_instanceis not incheck_list.
- dunedn.utils.utils.check_in_folder(folder: Path, should_force: bool)[source]
Creates the query folder.
The
should_forceparameters controls the function behavior in casefolderexists. If true, it overwrites the existent directory, otherwise exits.- Parameters
folder (Path) – The directory to be checked.
should_force (bool) – Wether to replace the already existing directory.
- Raises
FileExistsError – If output folder exists and
should_forceis False.
- dunedn.utils.utils.confusion_matrix(hit, no_hit, t=0.5)[source]
Return confusion matrix elements from arrays of scores and threshold value.
- Parameters
hit – np.array, scores of real hits
no_hit – np.array, scores of real no-hits
t – float, threshold
- Returns
tp, fp, fn, tn
- dunedn.utils.utils.get_configcard_path(fname)[source]
Retrieves the configcard path.
Deprecated since version 2.0.0: this function is not used anymore.
If the supplied path is not a valid file, looks recursively into directories from DUNEDN_SEARCH_PATH environment variable to find the first match.
- Parameters
fname (Path) – Path to configcard yaml file.
- Returns
- Return type
Path, the retrieved configcard path
- Raises
FileNotFoundError, if fname is not found. –
- dunedn.utils.utils.get_cpu_info() dict[source]
Parses
lscpucommand to dictionary.- Returns
cpu_info – The parsed command output.
- Return type
dict
- dunedn.utils.utils.get_nb_cpu_cores() int[source]
Returns the number of available cpus for the current process.
- Returns
nb_cpus – The number of available cpus for the current process.
- Return type
int
- dunedn.utils.utils.initialize_output_folder(output: Path, should_force: bool)[source]
Creates the output directory structure.
- Parameters
output (Path) – The output directory.
should_force (bool) – Wether to replace the already existing output directory.
- dunedn.utils.utils.load_runcard(runcard_file: Path) dict[source]
Load runcard from yaml file.
- Parameters
runcard_file (Path) – The yaml to dump the dictionary.
- Returns
runcard – The loaded settings dictionary.
- Return type
dict
Note
The pathlib.Path objects are automatically loaded if they are encoded with the following syntax:
` path: !Path 'path/to/file' `
- dunedn.utils.utils.median_subtraction(planes: ndarray) ndarray[source]
Computes median subtraction to input planes.
- Parameters
planes (np.ndarray) – The data to be normalized, of shape=(N,C,H,W).
- Returns
output – The median subtracted data, of shape=(N,C,H,W).
- Return type
np.ndarray
- dunedn.utils.utils.moving_average(scalars: list[float], weight: float) list[float][source]
Computes the moving avarage from a list of scalar quantities.
- Parameters
scalars (list[float]) – List of scalar quantities to be smoothed.
weight (float) – The weighting factor in the (0,1) range. Higher values provide more smoothing power.
- Returns
smoothed – The list of smoothed scalar quantities.
- Return type
list[float]
- dunedn.utils.utils.save_runcard(fname: Path, setup: dict)[source]
Save runcard to yaml file.
- Parameters
fname (Path) – The yaml output file.
setup (Path) – The settings dictionary to be dumped.
Note
pathlib.PosixPath objects are automatically loaded.
- dunedn.utils.utils.smooth(smoothed: list[float], scalars: list[float], weight: float) list[float][source]
Computes the next element of the moving average.
In-place appending of the next element of the moving average to
smoothed.- Parameters
smoothed (list[float]) – The list of smoothed scalar quantities.
scalars (list[float]) – The list of scalar quantities to be smoothed.
weight (float) – The weighting factor in the (0,1) range.
- Returns
smoothed – The extended list of computed smoothed scalar quantities.
- Return type
list[float]
- Raises
AssertionError – If
scalarsdoes not have one element more thatsmoothed.