Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hit indices #709

Merged
merged 5 commits into from
Apr 18, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions src/dxtbx/format/FormatXTC.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import functools
import sys
import time
from itertools import groupby

import numpy as np
import serialtbx.detector.xtc
Expand Down Expand Up @@ -32,11 +33,15 @@
psana = None

locator_str = """
hits_file = None
.type = str
.help = path to a file where each line is 2 numbers separated by a space, a run index, and an event index in the XTC stream
experiment = None
.type = str
.help = Experiment identifier, e.g. mfxo1916
run = None
.type = ints
.type = int
.multiple = True
.help = Run number or a list of runs to process
mode = idx
.type = str
Expand Down Expand Up @@ -147,6 +152,7 @@

self._ds = FormatXTC._get_datasource(image_file, self.params)
self._evr = None
self._load_hit_indices()

Check warning on line 155 in src/dxtbx/format/FormatXTC.py

View check run for this annotation

Codecov / codecov/patch

src/dxtbx/format/FormatXTC.py#L155

Added line #L155 was not covered by tests
self.populate_events()

self._cached_psana_detectors = {}
Expand All @@ -162,6 +168,17 @@
else:
self._spectrum_pedestal = None

def _load_hit_indices(self):
self._hit_inds = None

Check warning on line 172 in src/dxtbx/format/FormatXTC.py

View check run for this annotation

Codecov / codecov/patch

src/dxtbx/format/FormatXTC.py#L172

Added line #L172 was not covered by tests
if self.params.hits_file is not None:
assert self.params.mode == "idx"
hits = np.loadtxt(self.params.hits_file, int)
hits = list(map(tuple, hits))

Check warning on line 176 in src/dxtbx/format/FormatXTC.py

View check run for this annotation

Codecov / codecov/patch

src/dxtbx/format/FormatXTC.py#L174-L176

Added lines #L174 - L176 were not covered by tests
key = lambda x: x[0]
gb = groupby(sorted(hits, key=key), key=key)

Check warning on line 178 in src/dxtbx/format/FormatXTC.py

View check run for this annotation

Codecov / codecov/patch

src/dxtbx/format/FormatXTC.py#L178

Added line #L178 was not covered by tests
# dictionary where key is run number, and vals are indices of hits
self._hit_inds = {r:[ind for _,ind in group] for r,group in gb}

@staticmethod
def understand(image_file):
"""Extracts the datasource and detector_address from the image_file and then feeds it to PSANA
Expand Down Expand Up @@ -229,18 +246,27 @@
self.run_mapping = {}

if self.params.mode == "idx":
for run in self._psana_runs.values():
for run_num, run in self._psana_runs.items():
times = run.times()
if self._hit_inds is not None and run_num not in self._hit_inds:
continue

Check warning on line 252 in src/dxtbx/format/FormatXTC.py

View check run for this annotation

Codecov / codecov/patch

src/dxtbx/format/FormatXTC.py#L252

Added line #L252 was not covered by tests
if self._hit_inds is not None and run_num in self._hit_inds:
temp = []

Check warning on line 254 in src/dxtbx/format/FormatXTC.py

View check run for this annotation

Codecov / codecov/patch

src/dxtbx/format/FormatXTC.py#L254

Added line #L254 was not covered by tests
for i_hit in self._hit_inds[run_num]:
temp.append( times[i_hit] )
times = tuple(temp)

Check warning on line 257 in src/dxtbx/format/FormatXTC.py

View check run for this annotation

Codecov / codecov/patch

src/dxtbx/format/FormatXTC.py#L256-L257

Added lines #L256 - L257 were not covered by tests
if (
self.params.filter.required_present_codes
or self.params.filter.required_absent_codes
) and self.params.filter.pre_filter:
times = [t for t in times if self.filter_event(run.event(t))]
self.run_mapping[run.run()] = (

self.run_mapping[run_num] = (

Check warning on line 264 in src/dxtbx/format/FormatXTC.py

View check run for this annotation

Codecov / codecov/patch

src/dxtbx/format/FormatXTC.py#L264

Added line #L264 was not covered by tests
len(self.times),
len(self.times) + len(times),
run,
)

self.times.extend(times)
self.n_images = len(self.times)

Expand Down
Loading