Skip to content

Commit

Permalink
small fixes from stitching reflectometry files
Browse files Browse the repository at this point in the history
  • Loading branch information
nvaytet committed Oct 8, 2020
1 parent 1374bd4 commit 556f0c0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
18 changes: 11 additions & 7 deletions src/dress/wfm/frames_peakfinding.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def frames_peakfinding(data=None,
plot=False,
verbose=False,
nbins=512,
exclude_left=None,
exclude_right=None,
bg_threshold=0.05,
peak_prominence=0.05,
gsmooth=2,
Expand Down Expand Up @@ -124,13 +126,13 @@ def frames_peakfinding(data=None,
bg_value = bg_raw + bg_threshold * (ymax - bg_raw)
# Find the leading and trailing edges; i.e. the leftmost and rightmost
# points that exceed the background value
i_start = 0
i_end = nx - 1
for i in range(nx):
i_start = exclude_left if exclude_left is not None else 0
i_end = exclude_right if exclude_right is not None else nx - 1
for i in range(i_start, nx):
if y[i] > bg_value:
i_start = i
break
for i in range(nx - 1, 1, -1):
for i in range(i_end, 1, -1):
if y[i] > bg_value:
i_end = i
break
Expand All @@ -143,9 +145,11 @@ def frames_peakfinding(data=None,
# Check for unwanted peaks:
# 1. If a peak is found inside the noise leading the signal, it will often
# have a zero left base
if exclude_left is None:
exclude_left = nbins // 10
to_be_removed = []
for p in range(len(peaks)):
if params["left_bases"][p] < nbins // 10:
if params["left_bases"][p] < exclude_left:
print("Removed peak number {} at x,y = {},{} because of a bad "
"left base".format(p, x[peaks[p]], y[peaks[p]]))
to_be_removed.append(p)
Expand Down Expand Up @@ -225,8 +229,8 @@ def frames_peakfinding(data=None,
fig.savefig(figname, bbox_inches="tight")

frames = {
"left_edge": np.array([f[0] for f in frame_boundaries]),
"right_edge": np.array([f[1] for f in frame_boundaries]),
"left_edges": np.array([f[0] for f in frame_boundaries]),
"right_edges": np.array([f[1] for f in frame_boundaries]),
"gaps": np.array(frame_gaps),
"shifts": np.array(frame_shifts)
}
Expand Down
2 changes: 1 addition & 1 deletion src/dress/wfm/stitch_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def stitch_events(events=None, frames=None, plot=False, nbins=5000):
if plot:
import matplotlib.pyplot as plt
# Histogram the events for plotting
y, edges = np.histogram(time_offset, bins=np.linspace(xmin, xmax, 513))
y, edges = np.histogram(time_offset, bins=np.linspace(xmin, xmax, 256))
x = 0.5 * (edges[:-1] + edges[1:])
fig, ax = plt.subplots(2, 1, figsize=(8, 8))
ax[0].plot(x, y, label="Raw data")
Expand Down
22 changes: 12 additions & 10 deletions src/dress/wfm/stitch_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ def stitch_files(files=None, entries=None, plot=False, frames=None):
files = files.split(",")
elif not isinstance(files, list):
files = [files]
print(frames)

v20setup = v20.setup()
v20frames = get_frames(instrument=v20setup)
# Compute WFM frame shifts and boundaries from V20 setup
if frames is None:
frames = get_frames(instrument=v20.setup())

for f in files:

Expand All @@ -100,11 +102,11 @@ def stitch_files(files=None, entries=None, plot=False, frames=None):
# Loop through entries and shift event tofs
with h5py.File(outfile, "r+") as outf:

# Compute WFM frame shifts and boundaries from V20 setup
if frames is None:
v20setup = v20.setup(filename=outf)
# v20setup = v20.setup()
v20frames = get_frames(instrument=v20setup)
# # Compute WFM frame shifts and boundaries from V20 setup
# if frames is None:
# # v20setup = v20.setup(filename=outf)
# # v20setup = v20.setup()
# # frames = get_frames(instrument=v20.setup(filename=outf))

for e in entries_:
print("==================")
Expand All @@ -114,11 +116,11 @@ def stitch_files(files=None, entries=None, plot=False, frames=None):
this_plot = (outfile + "-" + e + ".pdf").replace("/", "_")

if e.count("monitor") > 0:
frames = v20frames["monitor"]
frames_ = frames["monitor"]
else:
frames = v20frames["DENEX"]
frames_ = frames["DENEX"]

_stitch_file(file_handle=outf,
entry=e,
frames=frames,
frames=frames_,
plot=this_plot)

0 comments on commit 556f0c0

Please sign in to comment.