def __init__(self, file_path, *, gain_file="", pedestal_file=""):
        with h5py.File(file_path, "r") as h5f:
            detector_name = h5f["/general/detector_name"][()].decode()
            self.handler = JFDataHandler(detector_name)

            if "module_map" in h5f[f"/data/{detector_name}"]:
                # Pick only the first row (module_map of the first frame), because it is not
                # expected that module_map ever changes during a run. In fact, it is forseen in the
                # future that this data will be saved as a single row for the whole run.
                module_map = h5f[f"/data/{detector_name}/module_map"][0, :]
            else:
                module_map = None

            self.handler.module_map = module_map

            # TODO: Here we use daq_rec only of the first pulse within an hdf5 file, however its
            # value can be different for later pulses and this needs to be taken care of.
            daq_rec = h5f[f"/data/{detector_name}/daq_rec"][0]
            self.handler.highgain = daq_rec & 0b1

        # Gain file
        if not gain_file:
            gain_file = locate_gain_file(file_path)

        self.handler.gain_file = gain_file

        # Pedestal file (with a pixel mask)
        if not pedestal_file:
            pedestal_file = locate_pedestal_file(file_path)

        self.handler.pedestal_file = pedestal_file
Exemplo n.º 2
0
    def __init__(
        self,
        file_path,
        *,
        gain_file="",
        pedestal_file="",
        conversion=True,
        mask=True,
        gap_pixels=True,
        double_pixels="keep",
        geometry=True,
        parallel=True,
    ):
        self.file_path = Path(file_path)

        self.file = h5py.File(self.file_path, "r")
        self.handler = JFDataHandler(
            self.file["general/detector_name"][()].decode())

        self._conversion = conversion
        self._mask = mask
        self._gap_pixels = gap_pixels
        self._double_pixels = double_pixels
        self._geometry = geometry
        self._parallel = parallel

        # No need for any further setup if the file is already processed
        if self._processed:
            return

        # Gain file
        if not gain_file:
            gain_file = locate_gain_file(file_path)

        self.handler.gain_file = gain_file

        # Pedestal file (with a pixel mask)
        if not pedestal_file:
            pedestal_file = locate_pedestal_file(file_path)

        self.handler.pedestal_file = pedestal_file

        if "module_map" in self.file[f"data/{self.detector_name}"]:
            # Pick only the first row (module_map of the first frame), because it is not expected
            # that module_map ever changes during a run. In fact, it is forseen in the future that
            # this data will be saved as a single row for the whole run.
            module_map = self.file[f"data/{self.detector_name}/module_map"][
                0, :]
        else:
            module_map = None

        self.handler.module_map = module_map

        # TODO: Here we use daq_rec only of the first pulse within an hdf5 file, however its
        # value can be different for later pulses and this needs to be taken care of. Currently,
        # _allow_n_images decorator applies a function in a loop, making it impossible to change
        # highgain for separate images in a 3D stack.
        daq_rec = self.file[f"data/{self.detector_name}/daq_rec"][0]

        self.handler.highgain = daq_rec & 0b1
Exemplo n.º 3
0
    def __init__(
        self,
        file_path,
        gain_file="",
        pedestal_file="",
        conversion=True,
        mask=True,
        gap_pixels=True,
        geometry=True,
        parallel=True,
    ):
        """Create a new Jungfrau file wrapper.

        Args:
            file_path (str): Path to Jungfrau file
            gain_file (str, optional): Path to gain file. Auto-locate if empty. Defaults to ''.
            pedestal_file (str, optional): Path to pedestal file. Auto-locate if empty.
                Defaults to ''.
            conversion (bool, optional): Apply gain conversion and pedestal correction.
                Defaults to True.
            mask (bool, optional): Perform masking of bad pixels (assign them to 0).
                Defaults to True.
            gap_pixels (bool, optional): Add gap pixels between detector chips.
                Defaults to True.
            geometry (bool, optional): Apply geometry correction. Defaults to True.
            parallel (bool, optional): Use parallelized processing. Defaults to True.
        """
        self.file_path = Path(file_path)

        self.file = h5py.File(self.file_path, "r")
        self.handler = JFDataHandler(self.file["/general/detector_name"][()].decode())

        self._conversion = conversion
        self._mask = mask
        self._gap_pixels = gap_pixels
        self._geometry = geometry
        self._parallel = parallel

        # Gain file
        if not gain_file:
            gain_file = locate_gain_file(file_path)

        self.handler.gain_file = gain_file

        # Pedestal file (with a pixel mask)
        if not pedestal_file:
            pedestal_file = locate_pedestal_file(file_path)

        self.handler.pedestal_file = pedestal_file

        if "module_map" in self.file[f"/data/{self.detector_name}"]:
            # Pick only the first row (module_map of the first frame), because it is not expected
            # that module_map ever changes during a run. In fact, it is forseen in the future that
            # this data will be saved as a single row for the whole run.
            module_map = self.file[f"/data/{self.detector_name}/module_map"][0, :]
        else:
            module_map = None

        self.handler.module_map = module_map

        # TODO: Here we use daq_rec only of the first pulse within an hdf5 file, however its
        # value can be different for later pulses and this needs to be taken care of. Currently,
        # _allow_n_images decorator applies a function in a loop, making it impossible to change
        # highgain for separate images in a 3D stack.
        daq_rec = self.file[f"/data/{self.detector_name}/daq_rec"][0]

        self.handler.highgain = daq_rec & 0b1