Skip to content

Commit

Permalink
Correctly use instrument name in format class
Browse files Browse the repository at this point in the history
  • Loading branch information
jbeilstenedmands committed Feb 23, 2024
1 parent 2f6edf3 commit 0081506
Showing 1 changed file with 18 additions and 48 deletions.
66 changes: 18 additions & 48 deletions src/dxtbx/format/FormatHDF5ESRFJungfrau4M.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ def understand(image_file):
if "instrument" not in h5_handle[key]:
return False

Check warning on line 26 in src/dxtbx/format/FormatHDF5ESRFJungfrau4M.py

View check run for this annotation

Codecov / codecov/patch

src/dxtbx/format/FormatHDF5ESRFJungfrau4M.py#L26

Added line #L26 was not covered by tests
# instrument name is of form jungfrau4m_rr[X]_smx where X is empty, 4 or another number
if not h5_handle[key]["instrument"].startswith("jungfrau4m_rr"):
instrument = list(h5_handle[key]["instrument"].keys())[0]
if not instrument.startswith("jungfrau4m_rr"):
return False
if not h5_handle[key]["instrument"].endswith("smx"):
if not instrument.endswith("smx"):
return False
return True

Check warning on line 33 in src/dxtbx/format/FormatHDF5ESRFJungfrau4M.py

View check run for this annotation

Codecov / codecov/patch

src/dxtbx/format/FormatHDF5ESRFJungfrau4M.py#L32-L33

Added lines #L32 - L33 were not covered by tests

Expand All @@ -36,62 +37,31 @@ def _start(self):
image_file = self.get_image_file()
self._h5_handle = h5py.File(image_file, "r")
self.key = list(self._h5_handle.keys())[0]
self.n_images = self._h5_handle[self.key]["instrument"]["jungfrau4m_rr_smx"][
"data"
].shape[0]
self.adus_per_photon = self._h5_handle[self.key]["instrument"][
"jungfrau4m_rr_smx"
]["detector_information"]["adus_per_photon"]
self.image_size = tuple(
self._h5_handle[self.key]["instrument"]["jungfrau4m_rr_smx"]["data"].shape[
1:
]
)
wavelength = self._h5_handle[self.key]["instrument"]["jungfrau4m_rr_smx"][
"beam"
]["incident_wavelength"][()]
self.instrument_name = list(self._h5_handle[self.key]["instrument"].keys())[0]
instrument = self._h5_handle[self.key]["instrument"][self.instrument_name]
self.n_images = instrument["data"].shape[0]
self.adus_per_photon = instrument["detector_information"]["adus_per_photon"]
self.image_size = tuple(instrument["data"].shape[1:])
wavelength = instrument["beam"]["incident_wavelength"][()]
x_pixel_size = (

Check warning on line 46 in src/dxtbx/format/FormatHDF5ESRFJungfrau4M.py

View check run for this annotation

Codecov / codecov/patch

src/dxtbx/format/FormatHDF5ESRFJungfrau4M.py#L36-L46

Added lines #L36 - L46 were not covered by tests
self._h5_handle[self.key]["instrument"]["jungfrau4m_rr_smx"][
"detector_information"
]["x_pixel_size"][()]
* 1000
instrument["detector_information"]["x_pixel_size"][()] * 1000
) # convert m to mm
y_pixel_size = (

Check warning on line 49 in src/dxtbx/format/FormatHDF5ESRFJungfrau4M.py

View check run for this annotation

Codecov / codecov/patch

src/dxtbx/format/FormatHDF5ESRFJungfrau4M.py#L49

Added line #L49 was not covered by tests
self._h5_handle[self.key]["instrument"]["jungfrau4m_rr_smx"][
"detector_information"
]["y_pixel_size"][()]
* 1000
instrument["detector_information"]["y_pixel_size"][()] * 1000
) # convert m to mm
distance = (

Check warning on line 52 in src/dxtbx/format/FormatHDF5ESRFJungfrau4M.py

View check run for this annotation

Codecov / codecov/patch

src/dxtbx/format/FormatHDF5ESRFJungfrau4M.py#L52

Added line #L52 was not covered by tests
self._h5_handle[self.key]["instrument"]["jungfrau4m_rr_smx"][
"detector_information"
]["detector_distance"][()]
* 1000
instrument["detector_information"]["detector_distance"][()] * 1000
) # convert m to mm
beam_center_x = self._h5_handle[self.key]["instrument"]["jungfrau4m_rr_smx"][
"detector_information"
]["beam_center_x"][
()
] # in px
beam_center_y = self._h5_handle[self.key]["instrument"]["jungfrau4m_rr_smx"][
"detector_information"
]["beam_center_y"][
()
] # in px
beam_center_x = instrument["detector_information"]["beam_center_x"][()] # in px
beam_center_y = instrument["detector_information"]["beam_center_y"][()] # in px

Check warning on line 56 in src/dxtbx/format/FormatHDF5ESRFJungfrau4M.py

View check run for this annotation

Codecov / codecov/patch

src/dxtbx/format/FormatHDF5ESRFJungfrau4M.py#L55-L56

Added lines #L55 - L56 were not covered by tests

beam_center_x *= x_pixel_size
beam_center_y *= y_pixel_size
trusted_range = (

Check warning on line 60 in src/dxtbx/format/FormatHDF5ESRFJungfrau4M.py

View check run for this annotation

Codecov / codecov/patch

src/dxtbx/format/FormatHDF5ESRFJungfrau4M.py#L58-L60

Added lines #L58 - L60 were not covered by tests
self._h5_handle[self.key]["instrument"]["jungfrau4m_rr_smx"][
"detector_information"
]["underload_value"][()],
self._h5_handle[self.key]["instrument"]["jungfrau4m_rr_smx"][
"detector_information"
]["saturation_value"][()],
instrument["detector_information"]["underload_value"][()],
instrument["detector_information"]["saturation_value"][()],
)
exposure_time = self._h5_handle[self.key]["instrument"]["jungfrau4m_rr_smx"][
"acquisition"
]["exposure_time"][()]
exposure_time = instrument["acquisition"]["exposure_time"][()]

Check warning on line 64 in src/dxtbx/format/FormatHDF5ESRFJungfrau4M.py

View check run for this annotation

Codecov / codecov/patch

src/dxtbx/format/FormatHDF5ESRFJungfrau4M.py#L64

Added line #L64 was not covered by tests

self._detector_model = self._detector_factory.simple(

Check warning on line 66 in src/dxtbx/format/FormatHDF5ESRFJungfrau4M.py

View check run for this annotation

Codecov / codecov/patch

src/dxtbx/format/FormatHDF5ESRFJungfrau4M.py#L66

Added line #L66 was not covered by tests
sensor="UNKNOWN",
Expand Down Expand Up @@ -147,7 +117,7 @@ def get_detector(self, index=None):

def get_static_mask(self):
if FormatHDF5ESRFJungfrau4M._cached_mask is None:
mask = self._h5_handle[self.key]["instrument"]["jungfrau4m_rr_smx"][
mask = self._h5_handle[self.key]["instrument"][self.instrument_name][

Check warning on line 120 in src/dxtbx/format/FormatHDF5ESRFJungfrau4M.py

View check run for this annotation

Codecov / codecov/patch

src/dxtbx/format/FormatHDF5ESRFJungfrau4M.py#L120

Added line #L120 was not covered by tests
"detector_information"
]["pixel_mask"]
mask = flumpy.from_numpy(mask[()])
Expand Down

0 comments on commit 0081506

Please sign in to comment.