Source code for datapipe_testbench.inputdataset
"""
InputDataset class that wrap everything you need to define related to input files necessary to process a benchmark.
"""
from dataclasses import asdict, dataclass, fields
from pathlib import Path
from typing import get_args
[docs]
@dataclass(slots=True)
class InputDataset:
"""An inputDataset defines common inputs that can be used by Benchmarks."""
name: str
dl0: Path | None = None
dl1: Path | None = None
dl1_images: Path | None = None
dl2: Path | None = None
dl2_signal: Path | None = None
dl2_background: Path | None = None
dl3_irf: Path | None = None
dl3_benchmark: Path | None = None
def __post_init__(self):
"""Ensure all strings are converted to Paths where necessary."""
for field in fields(self):
value = getattr(self, field.name)
if value and (field.type is Path or Path in get_args(field.type)):
setattr(self, field.name, Path(value))
[docs]
def to_dict(self) -> dict:
"""Represent as a dict."""
# have to convert Paths back to strings, since later they are compared
# after being read from metadata.
thedict = dict()
for key, value in asdict(self).items():
if isinstance(value, Path):
value = str(value)
thedict[key] = value
return thedict
[docs]
@classmethod
def from_dict(cls, input_dict):
"""Create instance from input dictionary (from serialisation).
Parameters
----------
input_dict :
cls :
dict input_dict :
Input dictionary with all necessary information for a valid constructor.
Returns
-------
InputDataset
Instance corresponding to the input dictionary.
"""
obj = cls(**input_dict)
return obj
def __eq__(self, other):
"""Compare 2 InputData obj by comparing their dict."""
return self.to_dict() == other.to_dict()
@property
def dtypes(self):
"""Return list of field names."""
return self.__dataclass_fields__.keys()