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

WIP: Trexafs #44

Open
wants to merge 82 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
a3fd419
Add time-resolved exafs scans
Jul 27, 2022
56f0aec
Changed user information
Jul 27, 2022
a4f8953
WIP Debugging at beamline
Jul 27, 2022
62ba69e
V7 Changes
Aug 1, 2022
faa032b
After our coding session
Aug 3, 2022
e89db6c
V8 before we fix things
Aug 5, 2022
721101d
Added AND and DIV classes to Zebra
Aug 5, 2022
b58a982
Added stage sigs to zebra
Aug 5, 2022
a3beb28
Make laser controls work
Aug 5, 2022
024a8d7
Change zebra staging delay back to 10 ms
Aug 6, 2022
e346fce
WIP: End of day commit
Aug 6, 2022
c3682fb
Got the scaler and xs to work!
Aug 6, 2022
2d68f5f
Added debugging statements for setting up Merlin
Aug 8, 2022
3a53a7d
Added triggering for merlin and flyer complete/collect
Aug 9, 2022
da23b51
Cleaned with small edits
emusterman Aug 10, 2022
81e8caa
Minor edits after meeting review
emusterman Aug 10, 2022
a382dc0
Got the X3X and scaler saving data and visible in DB
Aug 11, 2022
737430c
Add function to save all scaler points
Aug 11, 2022
48240b0
Remove checking for ME4/XS4
Aug 11, 2022
da7a1ca
Change set to actually write file path
Aug 11, 2022
66c992d
Single time-series is working with xs, merlin, scaler
Aug 11, 2022
d5eb1df
Always move z first. Added dets to md
Aug 12, 2022
320d4bb
Add time-resolved exafs scans
Jul 27, 2022
64e5cf9
Changed user information
Jul 27, 2022
478de25
WIP Debugging at beamline
Jul 27, 2022
3e741df
V7 Changes
Aug 1, 2022
cdb8868
After our coding session
Aug 3, 2022
5ffcf3f
V8 before we fix things
Aug 5, 2022
b85def2
Added AND and DIV classes to Zebra
Aug 5, 2022
b1a92a0
Added stage sigs to zebra
Aug 5, 2022
6dff981
Make laser controls work
Aug 5, 2022
51e6ac6
WIP: End of day commit
Aug 6, 2022
1744fbb
Got the scaler and xs to work!
Aug 6, 2022
b9c4c4c
Added debugging statements for setting up Merlin
Aug 8, 2022
48d59e3
Added triggering for merlin and flyer complete/collect
Aug 9, 2022
3ac274c
Cleaned with small edits
emusterman Aug 10, 2022
9a4a3be
Minor edits after meeting review
emusterman Aug 10, 2022
d33b11e
Got the X3X and scaler saving data and visible in DB
Aug 11, 2022
aaeaa92
Add function to save all scaler points
Aug 11, 2022
6be2297
Remove checking for ME4/XS4
Aug 11, 2022
50e0203
Change set to actually write file path
Aug 11, 2022
a61359f
Single time-series is working with xs, merlin, scaler
Aug 11, 2022
3670ce7
Always move z first. Added dets to md
Aug 12, 2022
cdfbc6b
Merge branch 'trexafs' of https://github.com/NSLS-II-SRX/profile_coll…
Aug 12, 2022
a9c9b5f
updates from beamtime
Aug 18, 2022
c4266a6
logging set to info
emusterman Aug 18, 2022
622714a
saving knife edge raw data
emusterman Aug 18, 2022
6ea48a2
added text to knife edge plots
emusterman Aug 18, 2022
80a6c73
updated text, forced opacity
emusterman Aug 18, 2022
388ce29
Can align along just one direction now
emusterman Aug 18, 2022
0bcea47
better meta data and TODO list
emusterman Aug 18, 2022
868d524
delay time added after laser on
emusterman Aug 18, 2022
a319981
mild cleaning
emusterman Aug 18, 2022
917fbe6
added both beam plot for alignment
emusterman Aug 19, 2022
b7818e1
vlm stage move can be disabled during beam alignment
emusterman Aug 19, 2022
d6cae01
beam alignment move more verbose
emusterman Aug 19, 2022
edf4146
edge function added, testing needed
emusterman Aug 19, 2022
e8fa041
fixed some plotting issues
emusterman Aug 22, 2022
da2d745
new edge function with variable slopes
emusterman Aug 22, 2022
2430ce2
lazer testing updates
Aug 26, 2022
ffe6ed2
updates from Sep 1 testing
Sep 1, 2022
5f741af
updates from Sep. 2 testing
Sep 2, 2022
3de6712
Sept 6th beamline testing
Sep 6, 2022
cf04843
Changes after testing
Sep 19, 2022
61a61ed
Can now fit 1 or 2 edges
emusterman Sep 20, 2022
31bc9ee
removed range check TODO, not needed
emusterman Sep 20, 2022
1779caa
Fixed errors in plot_beam_alignment
emusterman Sep 20, 2022
4d4cb26
added beam alignments plot
emusterman Oct 25, 2022
0d2f939
Generated z-coords for point arrays
emusterman Oct 25, 2022
f2f8b44
Added conditionals to gen_pos for z-coords
emusterman Oct 25, 2022
73050fc
Added z-coordinate moves and checks
emusterman Oct 25, 2022
a31facf
Time delay before data collection added to batch plan
emusterman Oct 25, 2022
ec29bae
A bit of cleanup
emusterman Oct 25, 2022
a49fe15
Added logscan_detailed to time series
emusterman Oct 25, 2022
c39589a
Merge remote-tracking branch 'origin' into trexafs
Oct 26, 2022
534fc8e
Merge branch 'master' of https://github.com/NSLS-II-SRX/profile_colle…
Nov 10, 2022
9740aec
Fixes from beamline testing
Nov 10, 2022
6abe4b9
more changes
Nov 10, 2022
a52a11c
Better implement merlin and dexela into fly scans
Dec 2, 2022
15de2c0
Changes from Nov 2022 beamtime
Dec 2, 2022
786db9f
Merge with master
Feb 28, 2023
756cfc2
Changes from end of run March 2023
Mar 3, 2023
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
52 changes: 52 additions & 0 deletions startup/30-scaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,58 @@ def export_sis_data(ion, filepath, zebra):
f.close()


def export_sis_data_laser(ion, filepath, zebra):
N = ion.nuse_all.get()
t = ion.mca1.get(timeout=5.0)
i = ion.mca2.get(timeout=5.0)
im = ion.mca3.get(timeout=5.0)
it = ion.mca4.get(timeout=5.0)
while len(t) == 0 and len(t) != len(i):
t = ion.mca1.get(timeout=5.0)
i = ion.mca2.get(timeout=5.0)
im = ion.mca3.get(timeout=5.0)
it = ion.mca4.get(timeout=5.0)

if len(i) != N:
print(f'Scaler did not receive collect enough points.')
## Try one more time
t = ion.mca1.get(timeout=5.0)
i = ion.mca2.get(timeout=5.0)
im = ion.mca3.get(timeout=5.0)
it = ion.mca4.get(timeout=5.0)
if len(i) != N:
print(f'Nope. Only received {len(i)}/{N} points.')

correct_length = N
# correct_length = zebra.pc.data.num_down.get()
# Only consider even points
with h5py.File(filepath, "w") as f:
if len(t) != correct_length:
correction_factor = correct_length - len(t)
print(f"Adding {correction_factor} points to scaler!")
print(f"t is not the correct length. {t} != {correct_length}")
correction_list = [1e10 for _ in range(0, int(correction_factor))]
new_t = [k for k in t] + correction_list
new_i = [k for k in i] + correction_list
new_im = [k for k in im] + correction_list
new_it = [k for k in it] + correction_list
else:
correction_factor = 0
new_t = t
new_i = i
new_im = im
new_it = it
dset0 = f.create_dataset("time", (correct_length,), dtype="f")
dset0[...] = np.array(new_t)
dset1 = f.create_dataset("i0", (correct_length,), dtype="f")
dset1[...] = np.array(new_i)
dset2 = f.create_dataset("im", (correct_length,), dtype="f")
dset2[...] = np.array(new_im)
dset3 = f.create_dataset("it", (correct_length,), dtype="f")
dset3[...] = np.array(new_it)
f.close()


class SISHDF5Handler(HandlerBase):
HANDLER_NAME = "SIS_HDF51"

Expand Down
4 changes: 4 additions & 0 deletions startup/31-xspress3.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ class SrxXspress3Detector(SRXXspressTrigger, Xspress3Detector):
# replace HDF5:FileCreateDir with HDF1:FileCreateDir
create_dir = Cpt(EpicsSignal, "HDF5:FileCreateDir")

# deadtime correction on/off attribute, added by YY
# dt_correction = Cpt(EpicsSignal, "det1:CTRL_DTC")


hdf5 = Cpt(
Xspress3FileStoreFlyable,
"HDF5:",
Expand Down
109 changes: 72 additions & 37 deletions startup/32-zebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def unstage(self):
super().unstage()


class SRXZebraOR(Device):
class SRXZebraANDOR(Device):
# I really appreciate the different indexing for input source
# Thank you for that
use1 = Cpt(EpicsSignal, '_ENA:B0')
Expand All @@ -206,28 +206,44 @@ def unstage(self):
super().unstage()


class SRXZebraAND(Device):
# I really appreciate the different indexing for input source
# Thank you for that
use1 = Cpt(EpicsSignal, '_ENA:B0')
use2 = Cpt(EpicsSignal, '_ENA:B1')
use3 = Cpt(EpicsSignal, '_ENA:B2')
use4 = Cpt(EpicsSignal, '_ENA:B3')
input_source1 = Cpt(EpicsSignal, '_INP1')
input_source2 = Cpt(EpicsSignal, '_INP2')
input_source3 = Cpt(EpicsSignal, '_INP3')
input_source4 = Cpt(EpicsSignal, '_INP4')
invert1 = Cpt(EpicsSignal, '_INV:B0')
invert2 = Cpt(EpicsSignal, '_INV:B1')
invert3 = Cpt(EpicsSignal, '_INV:B2')
invert4 = Cpt(EpicsSignal, '_INV:B3')
class SRXZebraDIV(Device):
input_source = Cpt(EpicsSignal, 'INP')
div = Cpt(EpicsSignal, 'DIV')
first_pulse = FC(EpicsSignal, '{self._zebra_prefix}DIV_FIRST:{self._div_addr}')
trigger_on = FC(EpicsSignal, '{self._zebra_prefix}POLARITY:{self._edge_addr}')

_edge_addrs = {1: 'B8',
2: 'B9',
3: 'BA',
4: 'BB',
}
_div_addrs = {1: 'B0',
2: 'B1',
3: 'B2',
4: 'B3',
}

def stage(self):
super().stage()

def unstage(self):
super().unstage()

def __init__(self, prefix, *, index=None, parent=None,
configuration_attrs=None, read_attrs=None, **kwargs):
if read_attrs is None:
read_attrs = ['input_source', 'div', 'first_pulse', 'trigger_on']
if configuration_attrs is None:
configuration_attrs = []

zebra = parent
self.index = index
self._zebra_prefix = zebra.prefix
self._edge_addr = self._edge_addrs[index]
self._div_addr = self._div_addrs[index]

super().__init__(prefix, configuration_attrs=configuration_attrs,
read_attrs=read_attrs, parent=parent, **kwargs)


class ZebraPulse(Device):
Expand All @@ -240,8 +256,7 @@ class ZebraPulse(Device):
time_units = Cpt(EpicsSignalWithRBV, 'PRE', string=True)
output = Cpt(EpicsSignal, 'OUT')

input_edge = FC(EpicsSignal,
'{self._zebra_prefix}POLARITY:{self._edge_addr}')
input_edge = FC(EpicsSignal, '{self._zebra_prefix}POLARITY:{self._edge_addr}')

_edge_addrs = {1: 'BC',
2: 'BD',
Expand Down Expand Up @@ -278,18 +293,22 @@ class SRXZebra(Zebra):
"""

pc = Cpt(ZebraPositionCapture, "")
or1 = Cpt(SRXZebraOR, "OR1") # XF:05IDD-ES:1{Dev:Zebra2}:OR1_INV:B0
or2 = Cpt(SRXZebraOR, "OR2")
or3 = Cpt(SRXZebraOR, "OR3")
or4 = Cpt(SRXZebraOR, "OR4")
and1 = Cpt(SRXZebraAND, "AND1") # XF:05IDD-ES:1{Dev:Zebra2}:AND1_ENA:B0
and2 = Cpt(SRXZebraAND, "AND2")
and3 = Cpt(SRXZebraAND, "AND3")
and4 = Cpt(SRXZebraAND, "AND4")
and1 = Cpt(SRXZebraANDOR, "AND1")
and2 = Cpt(SRXZebraANDOR, "AND2")
and3 = Cpt(SRXZebraANDOR, "AND3")
and4 = Cpt(SRXZebraANDOR, "AND4")
or1 = Cpt(SRXZebraANDOR, "OR1") # XF:05IDD-ES:1{Dev:Zebra2}:OR1_INV:B0
or2 = Cpt(SRXZebraANDOR, "OR2")
or3 = Cpt(SRXZebraANDOR, "OR3")
or4 = Cpt(SRXZebraANDOR, "OR4")
pulse1 = Cpt(ZebraPulse, "PULSE1_", index=1) # XF:05IDD-ES:1{Dev:Zebra2}:PULSE1_INP
pulse2 = Cpt(ZebraPulse, "PULSE2_", index=2)
pulse3 = Cpt(ZebraPulse, "PULSE3_", index=3)
pulse4 = Cpt(ZebraPulse, "PULSE4_", index=4)
div1 = Cpt(SRXZebraDIV, "DIV1_", index=1)
div2 = Cpt(SRXZebraDIV, "DIV2_", index=2)
div3 = Cpt(SRXZebraDIV, "DIV3_", index=3)
div4 = Cpt(SRXZebraDIV, "DIV4_", index=4)

def stage(self):
super().stage()
Expand Down Expand Up @@ -386,7 +405,7 @@ def set_flyer_zebra_stage_sigs(flyer, method):
# flyer.stage_sigs[flyer._encoder.pulse1.delay] = 0.2
# flyer.stage_sigs[flyer._encoder.pulse1.width] = 0.1
# flyer.stage_sigs[flyer._encoder.pulse1.time_units] = 0
flyer.stage_sigs[flyer._encoder.pulse2.input_addr] = 30
flyer.stage_sigs[flyer._encoder.pulse2.input_addr] = 31
flyer.stage_sigs[flyer._encoder.pulse2.input_edge] = 0 # 0 = rising, 1 = falling
flyer.stage_sigs[flyer._encoder.pulse2.delay] = 0
flyer.stage_sigs[flyer._encoder.pulse2.width] = 0.1
Expand Down Expand Up @@ -438,11 +457,11 @@ def set_flyer_zebra_stage_sigs(flyer, method):
# flyer.stage_sigs[flyer._encoder.pulse1.delay] = 0.2
# flyer.stage_sigs[flyer._encoder.pulse1.width] = 0.1
# flyer.stage_sigs[flyer._encoder.pulse1.time_units] = 0
# flyer.stage_sigs[flyer._encoder.pulse2.input_addr] = 30
# flyer.stage_sigs[flyer._encoder.pulse2.input_edge] = 0 # 0 = rising, 1 = falling
# flyer.stage_sigs[flyer._encoder.pulse2.delay] = 0
# flyer.stage_sigs[flyer._encoder.pulse2.width] = 0.1
# flyer.stage_sigs[flyer._encoder.pulse2.time_units] = 0
flyer.stage_sigs[flyer._encoder.pulse2.input_addr] = 30
flyer.stage_sigs[flyer._encoder.pulse2.input_edge] = 0 # 0 = rising, 1 = falling
flyer.stage_sigs[flyer._encoder.pulse2.delay] = 0
flyer.stage_sigs[flyer._encoder.pulse2.width] = 0.45
flyer.stage_sigs[flyer._encoder.pulse2.time_units] = 1
flyer.stage_sigs[flyer._encoder.pulse3.input_addr] = 31
flyer.stage_sigs[flyer._encoder.pulse3.input_edge] = 0 # 0 = rising, 1 = falling
flyer.stage_sigs[flyer._encoder.pulse3.delay] = 0.0
Expand Down Expand Up @@ -826,10 +845,11 @@ def complete(self):
ttime.sleep(0.01)
if (ttime.monotonic() - t0) > 60:
print(f"{self.name} is behaving badly!")
self._encoder.pc.disarm.put(1)
ttime.sleep(0.100)
if self._encoder.pc.data_in_progress.get() == 1:
raise TimeoutError
#self._encoder.pc.disarm.put(1)
#ttime.sleep(0.100)
#if self._encoder.pc.data_in_progress.get() == 1:
#raise TimeoutError
break

# ttime.sleep(.1)
self._mode = "complete"
Expand Down Expand Up @@ -920,7 +940,12 @@ def get_sis_data():

if amk_debug_flag:
t_sisdata = tic()
get_sis_data()
if 'laser' in self.name:
export_sis_data_laser(
self._sis, self.__write_filepath_sis, self._encoder
)
else:
get_sis_data()
if amk_debug_flag:
toc(t_sisdata, str='Get SIS data')

Expand Down Expand Up @@ -1096,19 +1121,29 @@ def resume(self):

def export_nano_zebra_data(zebra, filepath, fastaxis):
j = 0
flag_bad_zebra = False
while zebra.pc.data_in_progress.get() == 1:
print("Waiting for zebra...")
ttime.sleep(0.1)
j += 1
if j > 10:
print("THE ZEBRA IS BEHAVING BADLY CARRYING ON")
flag_bad_zebra = True
zebra.pc.reset_block_state.put(1)
break

time_d = zebra.pc.data.time.get()
enc1_d = zebra.pc.data.enc1.get()
enc2_d = zebra.pc.data.enc2.get()
enc3_d = zebra.pc.data.enc3.get()

# Drop the first point if Zebra is behaving badly
if flag_bad_zebra:
time_d = time_d[1:]
enc1_d = enc1_d[1:]
enc2_d = enc2_d[1:]
enc3_d = enc3_d[1:]

px = zebra.pc.pulse_step.get()
if fastaxis == 'NANOHOR':
# Add half pixelsize to correct encoder
Expand Down
Loading