Skip to content

Commit

Permalink
enhancements for small_cell powder plotting
Browse files Browse the repository at this point in the history
  • Loading branch information
dwpaley committed Feb 6, 2025
1 parent 4285925 commit b909d12
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
20 changes: 14 additions & 6 deletions xfel/small_cell/command_line/powder_from_spots.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,20 @@
.help = Instead of counts, plot the likelihood that a d-spacing is observed \
together with a reference peak identified by filter.d_max and \
filter.d_min.
d_max = None
.type = float
.help = Max resolution of the peak to filter on
d_min = None
.type = float
.help = Min resolution of the peak to filter on
d_vals = None
.type = floats
.help = Resolution ranges (pairs dmax, dmin) to filter on
select_mode = *any all
.type = choice
.help = Any: select frames where any of the given d-spacings is present. \
All: select frames where all of the given d-spacings are present.
plot_mode = *ratio simple
.type = choice
.help = Ratio: y-value is the "correlation" between the reference d-vals \
and the given d-val. \
Simple: Plot a powder pattern conditioned on the presence of the \
reference peak(s).
}
output {
log = dials.powder_from_spots.log
Expand Down
28 changes: 19 additions & 9 deletions xfel/small_cell/powder_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ def _process_pixel(self, i_panel, s0, panel, xy, value):
res_inv = 1 / panel.get_resolution_at_pixel(s0, xy)
res = 1/res_inv
if self.params.filter.enable:
if self.params.filter.d_max > res > self.params.filter.d_min:
self.filter_counts += 1
for i, (dmax, dmin) in enumerate(zip(self.d_max_vals, self.d_min_vals)):
if dmax > res > dmin:
self.filter_counts[i] += 1
n_bins = self.params.n_bins
i_bin = int(
n_bins * (res_inv - d_max_inv ) / (d_min_inv - d_max_inv)
Expand Down Expand Up @@ -99,9 +100,13 @@ def calculate(self):
self.current_panelsums = [
np.zeros(params.n_bins) for _ in range(self.n_panels)
]
self.filter_counts = 0
if self.params.filter.d_max is not None:
assert self.params.filter.d_min is not None
if self.params.filter.enable:
assert self.params.filter.d_vals and len(self.params.filter.d_vals)%2==0
self.filter_counts = [0 for _ in range(len(self.params.filter.d_vals)//2)]
self.d_max_vals = self.params.filter.d_vals[::2]
self.d_min_vals = self.params.filter.d_vals[1::2]

if self.params.filter.enable:
self.use_current_expt = False
else:
self.use_current_expt = True
Expand Down Expand Up @@ -134,8 +139,10 @@ def calculate(self):
self._process_pixel(i_panel, s0, panel, (x,y), value)
for i in range(len(self.panelsums)):
self.panelsums[i] = self.panelsums[i] + self.current_panelsums[i]
if self.params.filter.enable:
use_current_expt = self.filter_counts >= 1
if self.params.filter.enable and self.params.filter.select_mode=='any':
use_current_expt = any(self.filter_counts)
elif self.params.filter.enable and self.params.filter.select_mode=='all':
use_current_expt = all(self.filter_counts)
else:
use_current_expt = True
if use_current_expt:
Expand Down Expand Up @@ -165,14 +172,17 @@ def plot(self):
for i_sums, sums in enumerate(self.panelsums):
yvalues = np.array(sums)
plt.plot(xvalues, yvalues+0.5*i_sums*offset)
elif params.filter.enable:
elif params.filter.enable and params.filter.plot_mode=="ratio":
for x in self.filtered_panelsums:
x /= self.filtered_expt_count
for x in self.antifiltered_panelsums:
x /= self.antifiltered_expt_count
yvalues = sum(self.filtered_panelsums) - sum(self.antifiltered_panelsums)
plt.plot(xvalues, yvalues)

elif params.filter.enable and params.filter.plot_mode=="simple":
# same as below, but keeping this separate for flexibility
yvalues = sum(self.filtered_panelsums)
plt.plot(xvalues, yvalues)
else:
yvalues = sum(self.filtered_panelsums)
plt.plot(xvalues, yvalues)
Expand Down

0 comments on commit b909d12

Please sign in to comment.