units are now saved with the run_table, also added metadata sending to dimas sf_daq
This commit is contained in:
@@ -41,7 +41,7 @@ class Daq:
|
||||
self.name = name
|
||||
self._default_file_path = None
|
||||
|
||||
def acquire(self, file_name=None, Npulses=100):
|
||||
def acquire(self, file_name=None, Npulses=100, acq_pars = {}):
|
||||
print(file_name, Npulses)
|
||||
acquisition = Acquisition(
|
||||
acquire=None, acquisition_kwargs={"Npulses": Npulses},
|
||||
@@ -55,6 +55,7 @@ class Daq:
|
||||
channels_JF=self.channels["channels_JF"].get_current_value(),
|
||||
channels_BS=self.channels["channels_BS"].get_current_value(),
|
||||
channels_BSCAM=self.channels["channels_BSCAM"].get_current_value(),
|
||||
**acq_pars,
|
||||
)
|
||||
acquisition.acquisition_kwargs.update({"file_names": file_names})
|
||||
for key, val in acquisition.acquisition_kwargs.items():
|
||||
@@ -87,7 +88,6 @@ class Daq:
|
||||
label=None,
|
||||
wait=True,
|
||||
wait_cycle_sleep=0.01,
|
||||
**kwargs,
|
||||
):
|
||||
if not stop_id:
|
||||
stop_id = int(self.pulse_id.get_current_value())
|
||||
@@ -96,7 +96,6 @@ class Daq:
|
||||
|
||||
acq_pars = self.running.pop(acq_ix)
|
||||
acq_pars["stop_id"] = stop_id
|
||||
acq_pars.update(kwargs)
|
||||
label = acq_pars.pop("label")
|
||||
if wait:
|
||||
while int(self.pulse_id.get_current_value()) < stop_id:
|
||||
@@ -116,6 +115,7 @@ class Daq:
|
||||
pgroup=None,
|
||||
pgroup_base_path="/sf/bernina/data/{:s}/raw",
|
||||
filename_format="run_{:06d}",
|
||||
**kwargs,
|
||||
):
|
||||
if not pgroup:
|
||||
pgroup = self.pgroup
|
||||
@@ -127,6 +127,8 @@ class Daq:
|
||||
directory_base = Path(pgroup_base_path.format(pgroup)) / directory_relative
|
||||
files_extensions = []
|
||||
parameters = {"start_pulseid": start_id, "stop_pulseid": stop_id}
|
||||
parameters.update(kwargs)
|
||||
print(parameters)
|
||||
if channels_CA:
|
||||
parameters["pv_list"] = channels_CA
|
||||
files_extensions.append("CADUMP")
|
||||
|
||||
+25
-1
@@ -76,6 +76,7 @@ class Scan:
|
||||
f"scan_motor_{n}": adj.name,
|
||||
f"from_motor_{n}": self.values_todo[0][n],
|
||||
f"to_motor_{n}": self.values_todo[-1][n],
|
||||
f"id_motor_{n}": adj.Id,
|
||||
}
|
||||
)
|
||||
metadata.update(
|
||||
@@ -154,13 +155,36 @@ class Scan:
|
||||
for tm in ms:
|
||||
tm.wait()
|
||||
readbacks_step = []
|
||||
adjs_name = []
|
||||
adjs_offset = []
|
||||
adjs_id = []
|
||||
|
||||
for adj in self.adjustables:
|
||||
readbacks_step.append(adj.get_current_value())
|
||||
try:
|
||||
adjs_name.append(adj.name)
|
||||
if hasattr(adj, '_motor'):
|
||||
adjs_offset.append(adj._motor.OFF)
|
||||
if hasattr(adj, 'Id'):
|
||||
adjs_id.append(adj.Id)
|
||||
except:
|
||||
print("acquiring metadata failed")
|
||||
pass
|
||||
|
||||
if verbose:
|
||||
print("Moved variables, now starting acquisition")
|
||||
acs = []
|
||||
for ctr in self.counterCallers:
|
||||
acq = ctr.acquire(file_name=fina, Npulses=self.pulses_per_step)
|
||||
if ctr.__module__ == 'eco.acquisition.daq_client':
|
||||
acq_pars = {
|
||||
"motors_value": values_step,
|
||||
"motors_readback_value": readbacks_step,
|
||||
"motors_name": adjs_name,
|
||||
"motors_pv_name": adjs_id,
|
||||
}
|
||||
acq = ctr.acquire(file_name=fina, Npulses=self.pulses_per_step, acq_pars=acq_pars)
|
||||
else:
|
||||
acq = ctr.acquire(file_name=fina, Npulses=self.pulses_per_step)
|
||||
acs.append(acq)
|
||||
filenames = []
|
||||
for ta in acs:
|
||||
|
||||
@@ -690,10 +690,10 @@ components = [
|
||||
},
|
||||
{
|
||||
"args": [],
|
||||
"name": "tht",
|
||||
"name": "ocb",
|
||||
"z_und": 142,
|
||||
"desc": "High field THz Table",
|
||||
"type": "eco.endstations.bernina_sample_environments:High_field_thz_table",
|
||||
"desc": "LiNbO3 crystal breadboard",
|
||||
"type": "eco.endstations.bernina_sample_environments:LiNbO3_crystal_breadboard",
|
||||
"kwargs": {"Id": "SARES23"},
|
||||
},
|
||||
{
|
||||
@@ -701,7 +701,7 @@ components = [
|
||||
"name": "eos",
|
||||
"z_und": 142,
|
||||
"desc": "electro optic sampling stages",
|
||||
"type": "eco.endstations.bernina_sample_environments:electro_optic_sampling",
|
||||
"type": "eco.endstations.bernina_sample_environments:Electro_optic_sampling",
|
||||
"kwargs": {
|
||||
"Id": "SARES23",
|
||||
"pgroup": config["pgroup"],
|
||||
|
||||
@@ -140,7 +140,7 @@ class High_field_thz_chamber:
|
||||
return self.get_adjustable_positions_str()
|
||||
|
||||
|
||||
class High_field_thz_table:
|
||||
class Organic_crystal_breadboard:
|
||||
def __init__(self, name=None, Id=None, alias_namespace=None):
|
||||
self.Id = Id
|
||||
self.name = name
|
||||
@@ -150,48 +150,48 @@ class High_field_thz_table:
|
||||
"mirr2_x": {
|
||||
"id": "-ESB1",
|
||||
"pv_descr": "Motor3:1 THz mirror x ",
|
||||
"type": 2,
|
||||
"sensor": 1,
|
||||
"type": 1,
|
||||
"sensor": 0,
|
||||
"speed": 250,
|
||||
"home_direction": "back",
|
||||
},
|
||||
"mirr2_rz": {
|
||||
"id": "-ESB2",
|
||||
"pv_descr": "Motor3:2 THz mirror rz ",
|
||||
"type": 1,
|
||||
"sensor": 0,
|
||||
"type": 2,
|
||||
"sensor": 1,
|
||||
"speed": 250,
|
||||
"home_direction": "back",
|
||||
},
|
||||
"mirr2_ry": {
|
||||
"id": "-ESB3",
|
||||
"pv_descr": "Motor3:3 THz mirror ry ",
|
||||
"type": 1,
|
||||
"sensor": 0,
|
||||
"type": 2,
|
||||
"sensor": 1,
|
||||
"speed": 250,
|
||||
"home_direction": "back",
|
||||
},
|
||||
"mirr2_z": {
|
||||
"id": "-ESB4",
|
||||
"pv_descr": "Motor4:1 THz mirror z",
|
||||
"type": 2,
|
||||
"sensor": 1,
|
||||
"type": 1,
|
||||
"sensor": 0,
|
||||
"speed": 250,
|
||||
"home_direction": "back",
|
||||
},
|
||||
"par2_x": {
|
||||
"id": "-ESB5",
|
||||
"pv_descr": "Motor4:2 THz parabola2 x",
|
||||
"type": 2,
|
||||
"sensor": 1,
|
||||
"type": 1,
|
||||
"sensor": 0,
|
||||
"speed": 250,
|
||||
"home_direction": "back",
|
||||
},
|
||||
"mirr1_x": {
|
||||
"id": "-ESB7",
|
||||
"pv_descr": "Motor5:1 near IR mirror x",
|
||||
"type": 2,
|
||||
"sensor": 1,
|
||||
"type": 1,
|
||||
"sensor": 0,
|
||||
"speed": 250,
|
||||
"home_direction": "back",
|
||||
},
|
||||
@@ -213,7 +213,7 @@ class High_field_thz_table:
|
||||
},
|
||||
}
|
||||
|
||||
### in vacuum smaract motors ###
|
||||
### smaract motors ###
|
||||
for name, config in self.motor_configuration.items():
|
||||
addSmarActRecordToSelf(self, Id=Id + config["id"], name=name)
|
||||
|
||||
@@ -289,7 +289,7 @@ class High_field_thz_table:
|
||||
mot.put("FRM_BACK.PROC", 1)
|
||||
|
||||
def get_adjustable_positions_str(self):
|
||||
ostr = "*****THz table motor positions******\n"
|
||||
ostr = "*****Organic Crystal Breadboard positions******\n"
|
||||
|
||||
for tkey, item in self.__dict__.items():
|
||||
if hasattr(item, "get_current_value"):
|
||||
@@ -301,7 +301,79 @@ class High_field_thz_table:
|
||||
return self.get_adjustable_positions_str()
|
||||
|
||||
|
||||
class electro_optic_sampling:
|
||||
|
||||
class LiNbO3_crystal_breadboard:
|
||||
def __init__(self, name=None, Id=None, alias_namespace=None):
|
||||
self.Id = Id
|
||||
self.name = name
|
||||
self.alias = Alias(name)
|
||||
|
||||
self.motor_configuration = {
|
||||
"rz": {
|
||||
"id": "-ESB7",
|
||||
"pv_descr": "Motor5:1 THz mirror rz ",
|
||||
"type": 2,
|
||||
"sensor": 1,
|
||||
"speed": 250,
|
||||
"home_direction": "back",
|
||||
},
|
||||
"ry": {
|
||||
"id": "-ESB8",
|
||||
"pv_descr": "Motor5:2 THz mirror ry ",
|
||||
"type": 2,
|
||||
"sensor": 1,
|
||||
"speed": 250,
|
||||
"home_direction": "back",
|
||||
},
|
||||
"z": {
|
||||
"id": "-ESB9",
|
||||
"pv_descr": "Motor5:3 THz mirror z ",
|
||||
"type": 1,
|
||||
"sensor": 0,
|
||||
"speed": 250,
|
||||
"home_direction": "back",
|
||||
},
|
||||
"x": {
|
||||
"id": "-ESB15",
|
||||
"pv_descr": "Motor7:3 THz mirror x",
|
||||
"type": 1,
|
||||
"sensor": 0,
|
||||
"speed": 250,
|
||||
"home_direction": "back",
|
||||
},
|
||||
}
|
||||
|
||||
### in vacuum smaract motors ###
|
||||
for name, config in self.motor_configuration.items():
|
||||
addSmarActRecordToSelf(self, Id=Id + config["id"], name=name)
|
||||
|
||||
|
||||
def set_stage_config(self):
|
||||
for name, config in self.motor_configuration.items():
|
||||
mot = self.__dict__[name]._device
|
||||
mot.put("NAME", config["pv_descr"])
|
||||
mot.put("STAGE_TYPE", config["type"])
|
||||
mot.put("SET_SENSOR_TYPE", config["sensor"])
|
||||
mot.put("CL_MAX_FREQ", config["speed"])
|
||||
sleep(0.5)
|
||||
mot.put("CALIBRATE.PROC", 1)
|
||||
|
||||
|
||||
def get_adjustable_positions_str(self):
|
||||
ostr = "*****LiNbO3 crystal breadboard positions******\n"
|
||||
|
||||
for tkey, item in self.__dict__.items():
|
||||
if hasattr(item, "get_current_value"):
|
||||
pos = item.get_current_value()
|
||||
ostr += " " + tkey.ljust(17) + " : % 14g\n" % pos
|
||||
return ostr
|
||||
|
||||
def __repr__(self):
|
||||
return self.get_adjustable_positions_str()
|
||||
|
||||
|
||||
|
||||
class Electro_optic_sampling:
|
||||
def __init__(
|
||||
self, name=None, Id=None, alias_namespace=None, pgroup=None, diode_channels=None
|
||||
):
|
||||
@@ -461,7 +533,7 @@ class electro_optic_sampling:
|
||||
diff = dat1-dat2
|
||||
elif what == "diff/sum":
|
||||
diff = (dat1 - dat2) / (dat1 + dat2)
|
||||
if "delay_thz" in x_motor:
|
||||
if "delay" in x_motor:
|
||||
freq, ampl = self.calcFFT(x, diff.T)
|
||||
|
||||
else:
|
||||
@@ -516,6 +588,7 @@ class electro_optic_sampling:
|
||||
|
||||
def calcFFT(self, x, y, norm=True, lim=[0.1, 15]):
|
||||
# lim: min and max in THz for normalization and plotting
|
||||
x = abs(x)
|
||||
N = x.size
|
||||
T = x[N - 1] - x[0]
|
||||
te = x[1] - x[0]
|
||||
|
||||
@@ -163,8 +163,8 @@ class Laser_Exp:
|
||||
|
||||
# Waveplate and Delay stage
|
||||
try:
|
||||
addMotorRecordToSelf(self, self.Id + "-M534:MOT", name="wp_bsen")
|
||||
addMotorRecordToSelf(self, self.Id + "-M533:MOT", name="wp_eos")
|
||||
addMotorRecordToSelf(self, self.Id + "-M534:MOT", name="wp_eos")
|
||||
addMotorRecordToSelf(self, self.Id + "-M533:MOT", name="wp_bsen")
|
||||
except:
|
||||
print("No wp found")
|
||||
|
||||
@@ -251,15 +251,19 @@ class Laser_Exp:
|
||||
print(expt)
|
||||
|
||||
## IR beam pointing mirrors
|
||||
#try:
|
||||
# addPvRecordToSelf(self, pvsetname="SLAAR21-LMNP-ESBIR13:DRIVE", pvreadbackname ="SLAAR21-LMNP-ESBIR13:MOTRBV", accuracy= 10, name='IR_mirr1_ry')
|
||||
# addPvRecordToSelf(self, pvsetname="SLAAR21-LMNP-ESBIR14:DRIVE", pvreadbackname ="SLAAR21-LMNP-ESBIR14:MOTRBV", accuracy= 10, name='IR_mirr1_rx')
|
||||
#except:
|
||||
# print("Issue intializing picomotor IR beam pointing mirrors")
|
||||
# pass
|
||||
try:
|
||||
addPvRecordToSelf(self, pvsetname="SLAAR21-LMNP-ESBIR13:DRIVE", pvreadbackname ="SLAAR21-LMNP-ESBIR13:MOTRBV", accuracy= 10, name='IR_mirr1_ry')
|
||||
addPvRecordToSelf(self, pvsetname="SLAAR21-LMNP-ESBIR14:DRIVE", pvreadbackname ="SLAAR21-LMNP-ESBIR14:MOTRBV", accuracy= 10, name='IR_mirr1_rx')
|
||||
except:
|
||||
print("Issue intializing picomotor IR beam pointing mirrors")
|
||||
pass
|
||||
try:
|
||||
addSmarActRecordToSelf(self, Id='SARES23-LIC12', name='IR_mirr2_rx')
|
||||
addSmarActRecordToSelf(self, Id='SARES23-LIC8', name='IR_mirr2_ry')
|
||||
addSmarActRecordToSelf(self, Id='SARES23-ESB4', name='IR_mirr1_rx')
|
||||
addSmarActRecordToSelf(self, Id='SARES23-LIC7', name='IR_mirr1_ry')
|
||||
|
||||
addSmarActRecordToSelf(self, Id='SARES23-ESB1', name='IR_mirr2_ry')
|
||||
addSmarActRecordToSelf(self, Id='SARES23-ESB2', name='IR_mirr2_rz')
|
||||
addSmarActRecordToSelf(self, Id='SARES23-ESB3', name='IR_mirr2_z')
|
||||
except:
|
||||
print("Issue intializing SmarAct IR beam pointing mirrors")
|
||||
pass
|
||||
|
||||
@@ -15,7 +15,7 @@ from datetime import datetime
|
||||
import xlwt
|
||||
import openpyxl
|
||||
from ..devices_general.pv_adjustable import PvRecord
|
||||
|
||||
from epics import caget
|
||||
|
||||
class Run_Table():
|
||||
def __init__(self, pgroup=None,spreadsheet_key=None, devices=None, alias_namespace=None, channels_ca={'pulse_id': 'SLAAR11-LTIM01-EVR0:RX-PULSEID'}, name=None):
|
||||
@@ -33,8 +33,10 @@ class Run_Table():
|
||||
self.name=name
|
||||
self.alias_df = DataFrame()
|
||||
self.adj_df = DataFrame()
|
||||
self.unit_df = DataFrame()
|
||||
self.alias_file_name = f'/sf/bernina/data/{pgroup}/res/runtables/{pgroup}_alias_runtable'
|
||||
self.adj_file_name = f'/sf/bernina/data/{pgroup}/res/runtables/{pgroup}_adjustable_runtable'
|
||||
self.unit_file_name = f'/sf/bernina/data/{pgroup}/res/runtables/{pgroup}_unit_runtable'
|
||||
self._channels_ca = channels_ca
|
||||
|
||||
### credentials and settings for uploading to gspread ###
|
||||
@@ -49,6 +51,7 @@ class Run_Table():
|
||||
### dicts holding adjustables and bad (not connected) adjustables ###
|
||||
self.adjustables = {}
|
||||
self.bad_adjustables={}
|
||||
self.units = {}
|
||||
pd.options.display.max_rows = 999
|
||||
self.load()
|
||||
|
||||
@@ -103,16 +106,19 @@ class Run_Table():
|
||||
print(f"Tried to change permissions to 775")
|
||||
self.alias_df.to_pickle(self.alias_file_name+'.pkl')
|
||||
self.adj_df.to_pickle(self.adj_file_name+'.pkl')
|
||||
#self.alias_df.to_hdf(self.alias_file_name+'.h5', key='data')
|
||||
#self.adj_df.to_hdf(self.adj_file_name+'.h5', key='data')
|
||||
self.unit_df.to_pickle(self.unit_file_name+'.pkl')
|
||||
self.alias_df.to_excel(self.alias_file_name+'.xlsx')
|
||||
self.adj_df.to_excel(self.adj_file_name+'.xlsx')
|
||||
self.unit_df.to_excel(self.unit_file_name+'.xlsx')
|
||||
|
||||
|
||||
def load(self):
|
||||
if os.path.exists(self.alias_file_name+'.pkl'):
|
||||
self.alias_df = pd.read_pickle(self.alias_file_name+'.pkl')
|
||||
if os.path.exists(self.adj_file_name+'.pkl'):
|
||||
self.adj_df = pd.read_pickle(self.adj_file_name+'.pkl')
|
||||
if os.path.exists(self.unit_file_name+'.pkl'):
|
||||
self.alias_df = pd.read_pickle(self.alias_file_name+'.pkl')
|
||||
|
||||
|
||||
def append_run(self, runno, metadata={'type': 'ascan',
|
||||
@@ -138,6 +144,10 @@ class Run_Table():
|
||||
values = np.array([val for adjs in dat.values() for val in adjs.values()])
|
||||
run_df = DataFrame([values], columns=multiindex, index=[runno])
|
||||
self.adj_df = self.adj_df.append(run_df)
|
||||
multiindex_u = pd.MultiIndex.from_tuples([(dev, adj) for dev in self.units.keys() for adj in self.units[dev].keys()], names=names)
|
||||
values_u = np.array([val for adjs in self.units.values() for val in adjs.values()])
|
||||
self.unit_df = DataFrame([values_u], columns=multiindex_u, index=['units'])
|
||||
|
||||
self.save()
|
||||
|
||||
def append_pos(self, name=''):
|
||||
@@ -161,6 +171,9 @@ class Run_Table():
|
||||
values = np.array([val for adjs in dat.values() for val in adjs.values()])
|
||||
pos_df = DataFrame([values], columns=multiindex, index=[f'p{posno}'])
|
||||
self.adj_df = self.adj_df.append(pos_df)
|
||||
multiindex_u = pd.MultiIndex.from_tuples([(dev, adj) for dev in self.units.keys() for adj in self.units[dev].keys()], names=names)
|
||||
values_u = np.array([val for adjs in self.units.values() for val in adjs.values()])
|
||||
self.unit_df = DataFrame([values_u], columns=multiindex_u, index=['units'])
|
||||
self.save()
|
||||
|
||||
def upload_rt(self, worksheet='runtable', keys=None, df=None):
|
||||
@@ -257,6 +270,9 @@ class Run_Table():
|
||||
else:
|
||||
name = device.name
|
||||
self.adjustables[name] = {key: value for key, value in device.__dict__.items() if hasattr(value, 'get_current_value')}
|
||||
self.adjustables[name] = {key+'_offset': PvRecord(pvsetname = value.Id+'.OFF') for key, value in device.__dict__.items() if hasattr(value, '_motor')}
|
||||
self.units[name] = {key: caget(value.Id+'.EGU') for key, value in device.__dict__.items() if hasattr(value, '_motor')}
|
||||
|
||||
if hasattr(device, 'get_current_value'):
|
||||
self.adjustables[name]['_'.join([name, 'self'])]=device
|
||||
|
||||
@@ -302,7 +318,7 @@ class Run_Table():
|
||||
if len(good_dev_adj)>0:
|
||||
good_adj[device]=good_dev_adj
|
||||
if len(bad_dev_adj)>0:
|
||||
bad_dev_adj[device]=bad_dev
|
||||
bad_adj[device]=bad_dev_adj
|
||||
self.good_adjustables = good_adj
|
||||
self.bad_adjustables = bad_adj
|
||||
|
||||
|
||||
@@ -72,11 +72,11 @@ class Bsen:
|
||||
|
||||
self.motor_configuration = {
|
||||
"transl": {
|
||||
"id": "-LIC9",
|
||||
"pv_descr": " ",
|
||||
"id": "-ESB17",
|
||||
"pv_descr":"Motor8:2 BSEN_transl",
|
||||
"type": 2,
|
||||
"sensor": 1,
|
||||
"speed": 250,
|
||||
"speed": 400,
|
||||
"home_direction": "back",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class KBhor:
|
||||
addPvRecordToSelf(self, pvsetname=Id + ":CURV_SP", pvreadbackname =Id + ":CURV", accuracy= 0.002, name='curv')
|
||||
addPvRecordToSelf(self, pvsetname=Id + ":ASYMMETRY_SP", pvreadbackname =Id + ":ASYMMETRY", accuracy= 0.002, name='asym')
|
||||
|
||||
self.mode = PV(Id[:11] + ":MODE").enum_strs[PV(Id[:11] + ":MODE").value]
|
||||
#self.mode = PV(Id[:11] + ":MODE").enum_strs[PV(Id[:11] + ":MODE").value]
|
||||
|
||||
#### actual motors ###
|
||||
addMotorRecordToSelf(self, Id=Id + ":TY1", name='_Y1')
|
||||
|
||||
@@ -45,7 +45,7 @@ class KBver:
|
||||
addPvRecordToSelf(self, pvsetname=Id + ":CURV_SP", pvreadbackname =Id + ":CURV", accuracy= 0.002, name='curv')
|
||||
addPvRecordToSelf(self, pvsetname=Id + ":ASYMMETRY_SP", pvreadbackname =Id + ":ASYMMETRY", accuracy= 0.002, name='asym')
|
||||
|
||||
self.mode = PV(Id[:11] + ":MODE").enum_strs[PV(Id[:11] + ":MODE").value]
|
||||
#self.mode = PV(Id[:11] + ":MODE").enum_strs[PV(Id[:11] + ":MODE").value]
|
||||
|
||||
#### actual motors ###
|
||||
addMotorRecordToSelf(self, Id=Id + ":TY1", name='_Y1')
|
||||
|
||||
Reference in New Issue
Block a user