Skip to content

Commit

Permalink
Fixed flattened images not being scaled correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
toastisme committed Jul 30, 2024
1 parent 4656078 commit 773e4a2
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/dxtbx/format/FormatISISSXD.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ def get_raw_data(self, index: int, use_loaded_data=True) -> Tuple[flex.int]:

return tuple(raw_data)

def get_flattened_data(self, scale_data: bool = True) -> Tuple[flex.int]:
def get_flattened_data(
self, image_range: None | Tuple = None, scale_data: bool = True
) -> Tuple[flex.int]:
"""
Image data summed along the time-of-flight direction
"""
Expand All @@ -337,15 +339,27 @@ def get_flattened_data(self, scale_data: bool = True) -> Tuple[flex.int]:
panel_data = self._nxs_file["raw_data_1/detector_1/counts"][

Check warning on line 339 in src/dxtbx/format/FormatISISSXD.py

View check run for this annotation

Codecov / codecov/patch

src/dxtbx/format/FormatISISSXD.py#L337-L339

Added lines #L337 - L339 were not covered by tests
0, start_idx:end_idx, :
]
panel_max_val = np.max(panel_data)
if max_val is None or max_val < panel_max_val:
max_val = panel_max_val
panel_data = np.reshape(

Check warning on line 342 in src/dxtbx/format/FormatISISSXD.py

View check run for this annotation

Codecov / codecov/patch

src/dxtbx/format/FormatISISSXD.py#L342

Added line #L342 was not covered by tests
panel_data, (panel_size[0], panel_size[1], num_tof_bins)
)
panel_data = np.flipud(np.sum(panel_data, axis=2))
if image_range is not None:
assert (

Check warning on line 346 in src/dxtbx/format/FormatISISSXD.py

View check run for this annotation

Codecov / codecov/patch

src/dxtbx/format/FormatISISSXD.py#L346

Added line #L346 was not covered by tests
len(image_range) == 2
), "expected image_range to be only two values"
assert (

Check warning on line 349 in src/dxtbx/format/FormatISISSXD.py

View check run for this annotation

Codecov / codecov/patch

src/dxtbx/format/FormatISISSXD.py#L349

Added line #L349 was not covered by tests
image_range[0] >= 0 and image_range[0] < image_range[1]
), "image_range[0] out of range"
assert image_range[1] <= num_tof_bins, "image_range[1] out of range"
panel_data = np.flipud(

Check warning on line 353 in src/dxtbx/format/FormatISISSXD.py

View check run for this annotation

Codecov / codecov/patch

src/dxtbx/format/FormatISISSXD.py#L352-L353

Added lines #L352 - L353 were not covered by tests
np.sum(panel_data[:, :, image_range[0] : image_range[1]], axis=2)
)
else:
panel_data = np.flipud(np.sum(panel_data, axis=2))

Check warning on line 357 in src/dxtbx/format/FormatISISSXD.py

View check run for this annotation

Codecov / codecov/patch

src/dxtbx/format/FormatISISSXD.py#L357

Added line #L357 was not covered by tests
if panel_idx == 0 and self._panel_0_flipped():
panel_data = np.flipud(panel_data)
panel_max_val = np.max(panel_data)

Check warning on line 360 in src/dxtbx/format/FormatISISSXD.py

View check run for this annotation

Codecov / codecov/patch

src/dxtbx/format/FormatISISSXD.py#L359-L360

Added lines #L359 - L360 were not covered by tests
if max_val is None or max_val < panel_max_val:
max_val = panel_max_val
raw_data.append(panel_data)

Check warning on line 363 in src/dxtbx/format/FormatISISSXD.py

View check run for this annotation

Codecov / codecov/patch

src/dxtbx/format/FormatISISSXD.py#L362-L363

Added lines #L362 - L363 were not covered by tests

if scale_data:
Expand Down

0 comments on commit 773e4a2

Please sign in to comment.