restructure 1
This commit is contained in:
@@ -0,0 +1 @@
|
||||
from .alvra import *
|
||||
Executable
+174
@@ -0,0 +1,174 @@
|
||||
|
||||
from .config import elog as _elog_info
|
||||
from ..utilities.elog import Elog as _Elog
|
||||
from ..utilities.elog import Screenshot as _Screenshot
|
||||
from ..utilities.config import loadConfig
|
||||
from epics import PV
|
||||
import sys,os
|
||||
|
||||
|
||||
from colorama import Fore as _color
|
||||
import traceback
|
||||
import datetime
|
||||
|
||||
elog = _Elog(_elog_info['url'],user='gac-alvra',screenshot_directory=_elog_info['screenshot_directory'])
|
||||
screenshot = _Screenshot(screenshot_directory=_elog_info['screenshot_directory'])
|
||||
#stationMessage = _stationMessage('ESA')
|
||||
|
||||
_smaractappends = []
|
||||
|
||||
########### configurations ########################
|
||||
currexp_file_path = '/sf/alvra/config/exp/current_experiment.json'
|
||||
if os.path.exists(currexp_file_path):
|
||||
exp_config = loadConfig(currexp_file_path)
|
||||
else:
|
||||
print('NB: Could not load experiment config in path %s .'%currexp_file_path)
|
||||
|
||||
########### GENERAL IMPLEMENTATIONS ##################
|
||||
from .config import aliases as _aliases
|
||||
def _attach_device(devDict,devId,args,kwargs):
|
||||
imp_p = devDict['eco_type'].split(sep='.')
|
||||
dev_alias = devDict['alias']
|
||||
dev_alias = dev_alias[0].lower() + dev_alias[1:]
|
||||
eco_type_name = imp_p[-1]
|
||||
istr = 'from ..'+'.'.join(imp_p[:-1])+' import '
|
||||
istr += '%s as _%s'%(eco_type_name,eco_type_name)
|
||||
#print(istr)
|
||||
print(('Configuring %s '%(dev_alias)).ljust(25), end='')
|
||||
print(('(%s)'%(devId)).ljust(25), end='')
|
||||
error = None
|
||||
try:
|
||||
exec(istr)
|
||||
tdev = eval('_%s(Id=\'%s\',*args,**kwargs)'%(eco_type_name,devId))
|
||||
tdev.name = dev_alias
|
||||
tdev._z_und = devDict['z_und']
|
||||
globals().update([(dev_alias,tdev)])
|
||||
print((_color.GREEN+'OK'+_color.RESET).rjust(5))
|
||||
except Exception as e:
|
||||
print((_color.RED+'FAILED'+_color.RESET).rjust(5))
|
||||
error = e
|
||||
return error
|
||||
|
||||
errors = []
|
||||
_composed = {}
|
||||
for device_Id in _aliases.keys():
|
||||
alias = _aliases[device_Id]
|
||||
if 'eco_type' in alias.keys() \
|
||||
and alias['eco_type']:
|
||||
if 'args' in alias.keys() \
|
||||
and alias['args']:
|
||||
args = alias['args']
|
||||
else:
|
||||
args = tuple()
|
||||
|
||||
if 'kwargs' in alias.keys() \
|
||||
and alias['kwargs']:
|
||||
kwargs = alias['kwargs']
|
||||
else:
|
||||
kwargs = dict()
|
||||
|
||||
e = _attach_device(alias,device_Id,args,kwargs)
|
||||
if e:
|
||||
errors.append((alias['alias'],e))
|
||||
else:
|
||||
_device = globals()[alias['alias'][0].lower()+alias['alias'][1:]]
|
||||
if hasattr(_device, '_smaractaxes'):
|
||||
_smaractappends.append(_device)
|
||||
else:
|
||||
if alias['eco_type'].endswith('SmarActRecord') \
|
||||
and 'device' in alias and 'axis' in alias:
|
||||
if alias['device'] not in _composed:
|
||||
_composed[alias['device']] = {}
|
||||
_composed[alias['device']][alias['axis']] = globals()[alias['alias']]
|
||||
|
||||
print('Integrating SmarAct devices:')
|
||||
|
||||
for _device in _smaractappends:
|
||||
print(" Appending %s: %s" \
|
||||
%(_device.name,', '.join(map(str, list(_device._smaractaxes.keys())))))
|
||||
for _axis in _device._smaractaxes.keys():
|
||||
setattr(_device, _axis, globals()[_device._smaractaxes[_axis]])
|
||||
|
||||
from ..devices_general.smaract import SmarActStage as _SmarActStage
|
||||
for _key in _composed.keys():
|
||||
print(' Composing %s: %s'%(_key,', '.join(map(str, list(_composed[_key].keys())))))
|
||||
globals()[_key] = _SmarActStage(_composed[_key], _key)
|
||||
|
||||
if len(errors)>0:
|
||||
print('Found errors when configuring %s'%[te[0] for te in errors])
|
||||
if input('Would you like to see error traces? (y/n)')=='y':
|
||||
for error in errors:
|
||||
print('---> Error when configuring %s'%error[0])
|
||||
traceback.print_tb(error[1].__traceback__)
|
||||
|
||||
|
||||
########### DAQ SECTION ########################
|
||||
# configuring bs daq
|
||||
|
||||
def parseChannelListFile(fina):
|
||||
out = []
|
||||
with open(fina,'r') as f:
|
||||
done = False
|
||||
while not done:
|
||||
d = f.readline()
|
||||
if not d:
|
||||
done=True
|
||||
if len(d)>0:
|
||||
if not d.isspace():
|
||||
if not d[0]=='#':
|
||||
out.append(d.strip())
|
||||
return out
|
||||
|
||||
|
||||
from ..acquisition.bs_data import BStools
|
||||
from ..acquisition import scan as _scan
|
||||
#from ..acquisition.ioxos_data import Ioxostools
|
||||
|
||||
channellist = dict(alvra_channel_list=
|
||||
parseChannelListFile('/sf/alvra/config/com/channel_lists/default_channel_list'))
|
||||
bsdaq = BStools(default_channel_list=channellist,default_file_path='%s')
|
||||
|
||||
#channellistioxos = dict(alvra_channel_list=
|
||||
# parseChannelListFile('/sf/alvra/config/com/channel_lists/default_channel_list_ioxos'))
|
||||
#ioxosdaq = Ioxostools(default_channel_list=channellistioxos,default_file_path='%s')
|
||||
|
||||
channellistPhotonDiag = dict(alvra_channel_list=
|
||||
parseChannelListFile('/sf/alvra/config/com/channel_lists/default_channel_list_PhotonDiag'))
|
||||
bsdaqPhotonDiag = BStools(default_channel_list=channellistPhotonDiag,default_file_path='%s')
|
||||
|
||||
from eco.devices_general.alvradetectors import DIAClient
|
||||
bsdaqJF = DIAClient('bsdaqJF', instrument="alvra", api_address = "http://sf-daq-alvra:10000", jf_name="JF_4.5M")
|
||||
|
||||
try:
|
||||
bsdaqJF.pgroup = int(exp_config['pgroup'][1:])
|
||||
except:
|
||||
print('Could not set p group in bsdaqJF !!')
|
||||
|
||||
checkerPV=PV('SARFE10-PBPG050:HAMP-INTENSITY-CAL')
|
||||
|
||||
def checker_function(limits):
|
||||
cv = checkerPV.get()
|
||||
if cv>limits[0] and cv<limits[1]:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
checker = {}
|
||||
checker['checker_call'] = checker_function
|
||||
checker['args'] = [[100,300]]
|
||||
checker['kwargs'] = {}
|
||||
checker['wait_time'] = 3
|
||||
|
||||
|
||||
#scansIoxos = _scan.Scans(data_base_dir='/sf/alvra/config/com/data/scan_data',scan_info_dir='/sf/alvra/config/com/data/scan_info',default_counters=[ioxosdaq])
|
||||
scansJF = _scan.Scans(data_base_dir='scan_data',scan_info_dir='/sf/alvra/data/%s/res/scan_info'%exp_config['pgroup'],default_counters=[bsdaqJF],checker=checker,scan_directories=True)
|
||||
scansBsreadLocal = _scan.Scans(data_base_dir='/sf/alvra/config/com/data/scan_data',scan_info_dir='/sf/alvra/config/com/data/scan_info',default_counters=[bsdaq])
|
||||
|
||||
scansPhotonDiag = _scan.Scans(data_base_dir='/sf/alvra/config/com/data/photon_diag/scan_data',scan_info_dir='/sf/alvra/config/com/data/photon_diag/scan_info',default_counters=[bsdaqPhotonDiag])
|
||||
|
||||
########### ADHOC IMPLEMENTED ########################
|
||||
from ..timing.alvralasertiming import Lxt as _Lxt
|
||||
lxt = _Lxt()
|
||||
|
||||
from ..xoptics.dcm import AlvraDCM_FEL
|
||||
monoFEL = AlvraDCM_FEL('SAROP11-ODCM105')
|
||||
Executable
+282
@@ -0,0 +1,282 @@
|
||||
elog = {'url': 'https://elog-gfa.psi.ch/Alvra',
|
||||
'screenshot_directory': '/sf/alvra/config/screenshots'}
|
||||
|
||||
aliases = {
|
||||
# Front-End components
|
||||
'SARFE10-OPSH044' : {
|
||||
'alias' : 'shutUnd',
|
||||
'z_und' : 44,
|
||||
'desc' : 'Photon shutter after Undulator'},
|
||||
'SARFE10-OAPU044' : {
|
||||
'alias' : 'slitUnd',
|
||||
'z_und' : 44,
|
||||
'desc' : 'Slit after Undulator',
|
||||
'eco_type' : 'xoptics.slits.SlitFourBlades'},
|
||||
'SARFE10-PBIG050' : {
|
||||
'alias' : 'gasMon',
|
||||
'z_und' : 50,
|
||||
'desc' : 'Gas Monitor Intensity (PBIG)'},
|
||||
'SARFE10-PBPS053' : {
|
||||
'alias' : 'pbpsUnd',
|
||||
'z_und' : 44,
|
||||
'desc' : 'Intensity position monitor after Undulator (PBPS)'},
|
||||
'SARFE10-OATT053' : {
|
||||
'alias' : 'attFE',
|
||||
'z_und' : 53,
|
||||
'desc' : 'Attenuator in Front End',
|
||||
'eco_type' : 'xoptics.attenuator_aramis.AttenuatorAramis'},
|
||||
'SARFE10-PPRM053' : {
|
||||
'alias' : 'screenFE',
|
||||
'z_und' : 53,
|
||||
'desc' : 'Profile monitor after single-shot spectrometer (PPRM)',
|
||||
'eco_type' : 'xdiagnostics.profile_monitors.Pprm'},
|
||||
'SARFE10-SBST060' : {
|
||||
'alias' : 'shutFE',
|
||||
'z_und' : 60,
|
||||
'desc' : 'Photon shutter in the end of Front End'},
|
||||
# Optics hutch components
|
||||
'SARFE10-PPRM064' : {
|
||||
'alias' : 'screenOP',
|
||||
'z_und' : 64,
|
||||
'desc' : 'Profile monitor after Front End',
|
||||
'eco_type' : 'xdiagnostics.profile_monitors.Pprm'},
|
||||
'SAROP11-OOMH064' : {
|
||||
'alias' : 'mirrorAlv1',
|
||||
'z_und' : 64,
|
||||
'desc' : 'First Alvra Horizontal offset mirror (OMH064)'},
|
||||
'SAROP11-PPRM066' : {
|
||||
'alias' : 'screenMirrAlv1',
|
||||
'z_und' : 66,
|
||||
'desc' : 'Profile monitor after Alvra Mirror 1 (PPRM)',
|
||||
'eco_type' : 'xdiagnostics.profile_monitors.Pprm'},
|
||||
'SAROP11-OOMH076' : {
|
||||
'alias' : 'mirrorAlv2',
|
||||
'z_und' : 76,
|
||||
'desc' : 'Second Alvra Horizontal offset mirror (OMH076)'},
|
||||
'SAROP11-PPRM078' : {
|
||||
'alias' : 'screenMirrAlv2',
|
||||
'z_und' : 78,
|
||||
'desc' : 'Profile monitor after Alvra Mirror 2 (PPRM)',
|
||||
'eco_type' : 'xdiagnostics.profile_monitors.Pprm'},
|
||||
'SAROP11-OAPU104' : {
|
||||
'alias' : 'slitSwitch',
|
||||
'z_und' : 104,
|
||||
'desc' : 'Slit in Optics hutch after Photon switchyard and before Alvra mono',
|
||||
'eco_type' : 'xoptics.slits.SlitBlades'},
|
||||
'SAROP11-ODCM105' : {
|
||||
'alias' : 'mono',
|
||||
'z_und' : 105,
|
||||
'desc' : 'Alvra DCM Monochromator',
|
||||
'eco_type' : 'xoptics.dcm.Double_Crystal_Mono'},
|
||||
# 'ALVRA' : {
|
||||
# 'alias' : 'mono_FEL',
|
||||
# 'z_und' : 105,
|
||||
# 'desc' : 'Joint mono-FEL energy device',
|
||||
# 'eco_type' : 'xoptics.dcm.alvra_mono_FEL'},
|
||||
# 'SAROP11-PSCR106' : {
|
||||
# 'alias' : 'ProfMono',
|
||||
# 'z_und' : 106,
|
||||
# 'desc' : 'Profile Monitor after Mono (PSCR)'},
|
||||
'SAROP11-OOMV108' : {
|
||||
'alias' : 'mirrorV1',
|
||||
'z_und' : 108,
|
||||
'desc' : 'Alvra Vertical offset Mirror 1 (OMV108)'},
|
||||
# 'SAROP11-PSCR109' : {
|
||||
# 'alias' : 'ProfMirrV1',
|
||||
# 'z_und' : 109,
|
||||
# 'desc' : 'Profile Monitor after Vertical Mirror 1 (PSCR)'},
|
||||
'SAROP11-OOMV109' : {
|
||||
'alias' : 'mirrorV2',
|
||||
'z_und' : 109,
|
||||
'desc' : 'Alvra Vertical offset Mirror 2 (OMV109)'},
|
||||
'SAROP11-PPRM110' : {
|
||||
'alias' : 'screenMirrorV2',
|
||||
'z_und' : 110,
|
||||
'desc' : 'Profile monitor after Vertical Mirror 2 (PPRM)',
|
||||
'eco_type' : 'xdiagnostics.profile_monitors.Pprm'},
|
||||
'SAROP11-OPPI110' : {
|
||||
'alias' : 'pulsePicker',
|
||||
'z_und' : 110,
|
||||
'desc' : 'X-ray pulse picker'},
|
||||
'SAROP11-SBST114' : {
|
||||
'alias' : 'shutOpt',
|
||||
'z_und' : 114,
|
||||
'desc' : 'Shutter after Optics hutch'},
|
||||
## Experimental hutch components
|
||||
'SAROP11-PBPS117' : {
|
||||
'alias' : 'pbpsOpt',
|
||||
'z_und' : 117,
|
||||
'desc' : 'Intensity/position monitor after Optics hutch (PBPS)',
|
||||
'eco_type' : 'xdiagnostics.intensity_monitors.SolidTargetDetectorPBPS',
|
||||
'kwargs' : {'VME_crate':'SAROP11-CVME-PBPS1','link':9} },
|
||||
'SAROP11-PPRM117' : {
|
||||
'alias' : 'screenOPEnd',
|
||||
'z_und' : 117,
|
||||
'desc' : 'Profile monitor after Optics hutch (PPRM)',
|
||||
'eco_type' : 'xdiagnostics.profile_monitors.Pprm'},
|
||||
'SAROP11-PALM118' : {
|
||||
'alias' : 'DelayPALM',
|
||||
'z_und' : 118,
|
||||
'desc' : 'Timing diagnostics THz streaking (PALM)'},
|
||||
'SAROP11-PSEN119' : {
|
||||
'alias' : 'DelayPSEN',
|
||||
'z_und' : 119,
|
||||
'desc' : 'Timing diagnostics spectral encoding (PSEN)'},
|
||||
'SAROP11-OATT120' : {
|
||||
'alias' : 'attExp',
|
||||
'z_und' : 120,
|
||||
'desc' : 'Attenuator Alvra',
|
||||
'eco_type' : 'xoptics.attenuator_aramis.AttenuatorAramis'},
|
||||
'SAROP11-OAPU120' : {
|
||||
'alias' : 'slitAttExp',
|
||||
'z_und' : 120,
|
||||
'desc' : 'Slits behind attenuator',
|
||||
'eco_type' : 'xoptics.slits.SlitPosWidth'},
|
||||
'SAROP11-OLAS120' : {
|
||||
'alias' : 'refLaser',
|
||||
'z_und' : 120,
|
||||
'desc' : 'Alvra beamline reference laser before KBs (OLAS)',
|
||||
'eco_type' : 'xoptics.reflaser.RefLaser_Aramis'},
|
||||
'SAROP11-PBPS122' : {
|
||||
'alias' : 'pbpsAtt',
|
||||
'z_und' : 122,
|
||||
'desc' : 'Intensity/Position monitor after Attenuator',
|
||||
'eco_type' : 'xdiagnostics.intensity_monitors.SolidTargetDetectorPBPS',
|
||||
'kwargs' : {'VME_crate':'SAROP11-CVME-PBPS1','link':9} },
|
||||
'SAROP11-PPRM122' : {
|
||||
'alias' : 'screenAtt',
|
||||
'z_und' : 122,
|
||||
'desc' : 'Profile monitor after Attenuator',
|
||||
'eco_type' : 'xdiagnostics.profile_monitors.Pprm'},
|
||||
'SAROP11-OKBV123' : {
|
||||
'alias' : 'kbVer',
|
||||
'z_und' : 123,
|
||||
'desc' : 'Alvra vertical KB mirror',
|
||||
'eco_type' : 'xoptics.KBver.KBver'},
|
||||
'SAROP11-OKBH124' : {
|
||||
'alias' : 'kbHor',
|
||||
'z_und' : 124,
|
||||
'desc' : 'Alvra horizontal KB mirror',
|
||||
'eco_type' : 'xoptics.KBhor.KBhor'},
|
||||
# 'SAROP11-PIPS125-1' : {
|
||||
# 'alias' : 'PIPS1',
|
||||
# 'z_und' : 127,
|
||||
# 'desc' : 'Diode digitizer for PIPS1',
|
||||
# 'eco_type' : 'devices_general.detectors.DiodeDigitizer',
|
||||
# 'kwargs' : {'VME_crate':'SAROP11-CVME-PBPS1','link':9} },
|
||||
# 'SAROP11-PIPS125-2' : {
|
||||
# 'alias' : 'PIPS1',
|
||||
# 'z_und' : 127,
|
||||
# 'desc' : 'Diode digitizer for PIPS2',
|
||||
# 'eco_type' : 'devices_general.detectors.DiodeDigitizer',
|
||||
# 'kwargs' : {'VME_crate':'SAROP11-CVME-PBPS1','link':9} },
|
||||
|
||||
'SARES11-XSAM125' : {
|
||||
'alias' : 'primeSample',
|
||||
'z_und' : 127,
|
||||
'desc' : 'Sample XYZ manipulator',
|
||||
'eco_type' : 'endstations.alvra_prime.huber'},
|
||||
'SARES11-XCRY125' : {
|
||||
'alias' : 'primeCryTrans',
|
||||
'z_und' : 127,
|
||||
'desc' : 'Prime von Hamos X-trans (Bragg)',
|
||||
'eco_type' : 'endstations.alvra_prime.vonHamosBragg'},
|
||||
'SARES11-XOTA125' : {
|
||||
'alias' : 'primeTable',
|
||||
'z_und' : 127,
|
||||
'desc' : 'Prime optical table',
|
||||
'eco_type' : 'endstations.alvra_prime.table'},
|
||||
'SARES11-XMI125' : {
|
||||
'alias' : 'primeMicroscope',
|
||||
'z_und' : 127,
|
||||
'desc' : 'Microscope focus and zoom',
|
||||
'eco_type' : 'endstations.alvra_prime.microscope'},
|
||||
|
||||
# 'SARES22-GPS' : {
|
||||
# 'alias' : 'Gps',
|
||||
# 'z_und' : 142,
|
||||
# 'desc' : 'General purpose station',
|
||||
# 'eco_type' : 'endstations.bernina_gps.GPS'},
|
||||
# 'SARES20-PROF142-M1' : {
|
||||
# 'alias' : 'Xeye',
|
||||
# 'z_und' : 142,
|
||||
# 'desc' : 'Mobile X-ray eye in Bernina hutch',
|
||||
# 'eco_type' : 'xdiagnostics.profile_monitors.Bernina_XEYE',
|
||||
# 'kwargs' : {'bshost':'sf-daqsync-01.psi.ch','bsport':11173},
|
||||
#
|
||||
# },
|
||||
# 'SLAAR21-LMOT' : {
|
||||
# 'alias' : 'LasExp',
|
||||
# 'z_und' : 127,
|
||||
# 'desc' : 'Experiment laser optics',
|
||||
# 'eco_type' : 'loptics.bernina_experiment.Laser_Exp'},
|
||||
'SLAAR01-TSPL-EPL' : {
|
||||
'alias' : 'phaseShifter',
|
||||
'z_und' : 127,
|
||||
'desc' : 'Experiment laser phase shifter (Globi)',
|
||||
'eco_type' : 'devices_general.alvratiming.PhaseShifterAramis'},
|
||||
'SLAAR11-LMOT' : {
|
||||
'alias' : 'laser',
|
||||
'z_und' : 122,
|
||||
'desc' : 'Experiment laser hardware',
|
||||
'eco_type' : 'loptics.alvra_experiment.Laser_Exp'},
|
||||
# 'SLAAR11-LMOT' : {
|
||||
# 'alias' : 'palm_eo',
|
||||
# 'z_und' : 119,
|
||||
# 'desc' : 'PALM EO-sampling delay line',
|
||||
# 'eco_type' : 'xdiagnostics.palm.eo'},
|
||||
# 'http://sf-daq-4:10000' : {
|
||||
# 'alias' : 'DetJF',
|
||||
# 'z_und' : 125,
|
||||
# 'desc' : '4.5M Jungfrau detector',
|
||||
# 'eco_type' : 'devices_general.alvradetectors.DIAClient'},
|
||||
'SARES11-V' : {
|
||||
'alias' : 'vacuum',
|
||||
'z_und' : 127,
|
||||
'desc' : 'Prime vacuum system',
|
||||
'eco_type' : 'endstations.alvra_prime.vacuum'},
|
||||
'SLAAR11-LTIM01-EVR0' : {
|
||||
'alias' : 'laserShutter',
|
||||
'z_und' : 122,
|
||||
'desc' : 'Laser Shutter',
|
||||
'eco_type' : 'loptics.alvra_laser_shutter.laser_shutter'},
|
||||
# = dict(
|
||||
# alias = ''
|
||||
# z_und =
|
||||
# desc = ''},
|
||||
'SARES11-CMOV-SMA691110' : {
|
||||
'alias' : '_prism_gonio',
|
||||
'z_und' : 127,
|
||||
'desc' : 'Prime laser prism gonio',
|
||||
'eco_type' : 'devices_general.smaract.SmarActRecord',
|
||||
'device' : 'prism',
|
||||
'axis' : 'gonio'},
|
||||
'SARES11-CMOV-SMA691111' : {
|
||||
'alias' : '_prism_trans',
|
||||
'z_und' : 127,
|
||||
'desc' : 'Prime laser prism trans',
|
||||
'eco_type' : 'devices_general.smaract.SmarActRecord',
|
||||
'device' : 'prism',
|
||||
'axis' : 'trans'},
|
||||
'SARES11-CMOV-SMA691112' : {
|
||||
'alias' : '_prism_rot',
|
||||
'z_und' : 127,
|
||||
'desc' : 'Prime laser prism rotation',
|
||||
'eco_type' : 'devices_general.smaract.SmarActRecord',
|
||||
'device' : 'prism', # a virtual stage for eco namespace
|
||||
'axis' : 'rot'}, # a axis of this virtual stage
|
||||
'SARES11-CMOV-SMA691113' : {
|
||||
'alias' : '_xmic_gon',
|
||||
'z_und' : 127,
|
||||
'desc' : 'Prime microscope mirror gonio',
|
||||
'eco_type' : 'devices_general.smaract.SmarActRecord'},
|
||||
# no 'device' becauses its appended to other stage in
|
||||
# ..endstations/alvra_prime.py
|
||||
'SARES11-CMOV-SMA691114' : {
|
||||
'alias' : '_xmic_rot',
|
||||
'z_und' : 127,
|
||||
'desc' : 'Prime microscope mirror rotation',
|
||||
'eco_type' : 'devices_general.smaract.SmarActRecord'}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
from .bernina import *
|
||||
Executable
+178
@@ -0,0 +1,178 @@
|
||||
|
||||
from .config import elog as _elog_info
|
||||
from ..utilities.elog import Elog as _Elog
|
||||
from ..utilities.elog import Screenshot as _Screenshot
|
||||
from ..utilities.config import loadConfig
|
||||
from epics import PV
|
||||
import sys,os
|
||||
|
||||
|
||||
from colorama import Fore as _color
|
||||
import traceback
|
||||
|
||||
elog = _Elog(_elog_info['url'],user='gac-bernina',screenshot_directory=_elog_info['screenshot_directory'])
|
||||
screenshot = _Screenshot(screenshot_directory=_elog_info['screenshot_directory'])
|
||||
|
||||
########### configurations ########################
|
||||
currexp_file_path = '/sf/bernina/config/exp/current_experiment.json'
|
||||
if os.path.exists(currexp_file_path):
|
||||
exp_config = loadConfig(currexp_file_path)
|
||||
else:
|
||||
print('NB: Could not load experiment config in path %s .'%currexp_file_path)
|
||||
|
||||
########### GENERAL IMPLEMENTATIONS ##################
|
||||
from .config import aliases as _aliases
|
||||
from ..utilities.utilities_instruments import initDeviceAliasList
|
||||
|
||||
dev = initDeviceAliasList(_aliases,lazy=True,verbose=True)
|
||||
|
||||
if 0:
|
||||
|
||||
def _attach_device(devDict,devId,args,kwargs):
|
||||
imp_p = devDict['eco_type'].split(sep='.')
|
||||
dev_alias = devDict['alias']
|
||||
dev_alias = dev_alias[0].lower() + dev_alias[1:]
|
||||
eco_type_name = imp_p[-1]
|
||||
istr = 'from ..'+'.'.join(imp_p[:-1])+' import '
|
||||
istr += '%s as _%s'%(eco_type_name,eco_type_name)
|
||||
#print(istr)
|
||||
print(('Configuring %s '%(dev_alias)).ljust(25), end='')
|
||||
print(('(%s)'%(devId)).ljust(25), end='')
|
||||
error = None
|
||||
try:
|
||||
exec(istr)
|
||||
tdev = eval('_%s(Id=\'%s\',*args,**kwargs)'%(eco_type_name,devId))
|
||||
tdev.name = dev_alias
|
||||
tdev._z_und = devDict['z_und']
|
||||
globals().update([(dev_alias,tdev)])
|
||||
print((_color.GREEN+'OK'+_color.RESET).rjust(5))
|
||||
except Exception as e:
|
||||
print((_color.RED+'FAILED'+_color.RESET).rjust(5))
|
||||
print(sys.exc_info())
|
||||
error = e
|
||||
return error
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
break
|
||||
errors = []
|
||||
for device_Id in _aliases.keys():
|
||||
if 'eco_type' in _aliases[device_Id].keys() \
|
||||
and _aliases[device_Id]['eco_type']:
|
||||
if 'args' in _aliases[device_Id].keys() \
|
||||
and _aliases[device_Id]['args']:
|
||||
args = _aliases[device_Id]['args']
|
||||
else:
|
||||
args = tuple()
|
||||
|
||||
if 'kwargs' in _aliases[device_Id].keys() \
|
||||
and _aliases[device_Id]['kwargs']:
|
||||
kwargs = _aliases[device_Id]['kwargs']
|
||||
else:
|
||||
kwargs = dict()
|
||||
|
||||
e = _attach_device(_aliases[device_Id],device_Id,args,kwargs)
|
||||
if e: errors.append((_aliases[device_Id]['alias'],e))
|
||||
|
||||
if len(errors)>0:
|
||||
print('Found errors when configuring %s'%[te[0] for te in errors])
|
||||
if input('Would you like to see error traces? (y/n)')=='y':
|
||||
for error in errors:
|
||||
print('---> Error when configuring %s'%error[0])
|
||||
traceback.print_tb(error[1].__traceback__)
|
||||
|
||||
|
||||
|
||||
########### DAQ SECTION ########################
|
||||
# configuring bs daq
|
||||
|
||||
def parseChannelListFile(fina):
|
||||
out = []
|
||||
with open(fina,'r') as f:
|
||||
done = False
|
||||
while not done:
|
||||
d = f.readline()
|
||||
if not d:
|
||||
done=True
|
||||
if len(d)>0:
|
||||
if not d.isspace():
|
||||
if not d[0]=='#':
|
||||
out.append(d.strip())
|
||||
return out
|
||||
|
||||
|
||||
from ..acquisition.bs_data import BStools
|
||||
from ..acquisition import scan as _scan
|
||||
from ..acquisition.ioxos_data import Ioxostools
|
||||
|
||||
channellist = dict(bernina_channel_list=
|
||||
parseChannelListFile('/sf/bernina/config/channel_lists/default_channel_list'))
|
||||
bsdaq = BStools(default_channel_list=channellist,default_file_path='%s')
|
||||
|
||||
channellistioxos = dict(bernina_channel_list=
|
||||
parseChannelListFile('/sf/bernina/config/channel_lists/default_channel_list_ioxos'))
|
||||
ioxosdaq = Ioxostools(default_channel_list=channellistioxos,default_file_path='%s')
|
||||
|
||||
|
||||
#from eco.devices_general.detectors import JF_BS_writer
|
||||
#bsdaqJF = JF_BS_writer('bsdaqJF') d
|
||||
from eco.devices_general.detectors import DIAClient
|
||||
bsdaqJF = DIAClient('bsdaqJF', instrument="bernina", api_address = "http://sf-daq-1:10000")
|
||||
|
||||
try:
|
||||
bsdaqJF.pgroup = int(exp_config['pgroup'][1:])
|
||||
except:
|
||||
print('Could not set p group in bsdaqJF !!')
|
||||
|
||||
checkerPV=PV('SARFE10-PBPG050:HAMP-INTENSITY-CAL')
|
||||
|
||||
def checker_function(limits):
|
||||
cv = checkerPV.get()
|
||||
if cv>limits[0] and cv<limits[1]:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
checker = {}
|
||||
checker['checker_call'] = checker_function
|
||||
checker['args'] = [[100,700]]
|
||||
checker['kwargs'] = {}
|
||||
checker['wait_time'] = 3
|
||||
|
||||
|
||||
scansIoxos = _scan.Scans(data_base_dir='/sf/bernina/config/com/data/scan_data',scan_info_dir='/sf/bernina/config/com/data/scan_info',default_counters=[ioxosdaq])
|
||||
scansJF = _scan.Scans(data_base_dir='scan_data',scan_info_dir='/sf/bernina/data/%s/res/scan_info'%exp_config['pgroup'],default_counters=[bsdaqJF],checker=checker,scan_directories=True)
|
||||
scansBsreadLocal = _scan.Scans(data_base_dir='/sf/bernina/config/com/data/scan_data',scan_info_dir='/sf/bernina/config/com/data/scan_info',default_counters=[bsdaq])
|
||||
|
||||
|
||||
|
||||
########### ADHOC IMPLEMENTED ########################
|
||||
bsdaqJF.gain_file = "/sf/bernina/data/p16582/res/gains_I0.h5"
|
||||
try:
|
||||
import glob
|
||||
path = '/sf/bernina/data/p17295/res/JF_pedestal/pedestal_*_res.h5'
|
||||
list_of_files = glob.glob('/sf/bernina/data/p17295/res/JF_pedestal/pedestal_*_res.h5')
|
||||
latest_file = max(list_of_files, key=os.path.getctime)
|
||||
bsdaqJF.pede_file = latest_file
|
||||
except (Exception, ArithmeticError) as e:
|
||||
template = "An exception of type {0} occurred when trying to load lates JF files from {2}. Arguments:\n{1!r}"
|
||||
message = template.format(type(e).__name__, e.args, path)
|
||||
print (message)
|
||||
from ..timing.lasertiming import Lxt as _Lxt
|
||||
|
||||
lxt = _Lxt()
|
||||
|
||||
|
||||
from ..xoptics.dcm import MonoEcolEnergy, EcolEnergy
|
||||
monoEcol = MonoEcolEnergy('SAROP21-ODCM098')
|
||||
ecol = EcolEnergy('dummy')
|
||||
|
||||
|
||||
|
||||
if 'eco_path' in list(exp_config.keys()):
|
||||
pass
|
||||
else:
|
||||
eco_path = '/sf/bernina/'+ exp_config['pgroup']
|
||||
Executable
+195
@@ -0,0 +1,195 @@
|
||||
elog = {'url': 'https://elog-gfa.psi.ch/Bernina',
|
||||
'screenshot_directory': '/sf/bernina/config/screenshots'}
|
||||
|
||||
aliases = {
|
||||
'SARFE10-OPSH044' : {
|
||||
'alias' : 'ShutUnd',
|
||||
'z_und' : 44,
|
||||
'desc' : 'Photon shutter after Undulator'},
|
||||
'SARFE10-OAPU044' : {
|
||||
'alias' : 'SlitUnd',
|
||||
'z_und' : 44,
|
||||
'desc' : 'Slit after Undulator',
|
||||
'eco_type' : 'xoptics.slits.SlitFourBlades'},
|
||||
'SARFE10-PBIG050' : {
|
||||
'alias' : 'GasMon',
|
||||
'z_und' : 50,
|
||||
'desc' : 'Gas Monitor Intensity'},
|
||||
'SARFE10-PBPS053' : {
|
||||
'alias' : 'MonUnd',
|
||||
'z_und' : 44,
|
||||
'desc' : 'Intensity position monitor after Undulator'},
|
||||
'SARFE10-OATT053' : {
|
||||
'alias' : 'AttFE',
|
||||
'z_und' : 53,
|
||||
'desc' : 'Attenuator in Front End',
|
||||
'eco_type' : 'xoptics.attenuator_aramis.AttenuatorAramis'},
|
||||
'SARFE10-SBST060' : {
|
||||
'alias' : 'ShutFE',
|
||||
'z_und' : 60,
|
||||
'desc' : 'Photon shutter in the end of Front End'},
|
||||
'SARFE10-PPRM064' : {
|
||||
'alias' : 'ProfFE',
|
||||
'z_und' : 64,
|
||||
'desc' : 'Profile monitor after Front End',
|
||||
'eco_type' : 'xdiagnostics.profile_monitors.Pprm'},
|
||||
'SAROP11-OOMH064' : {
|
||||
'alias' : 'MirrAlv1',
|
||||
'z_und' : 64,
|
||||
'desc' : 'Horizontal mirror Alvra 1'},
|
||||
'SAROP11-PPRM066' : {
|
||||
'alias' : 'ProfMirrAlv1',
|
||||
'z_und' : 66,
|
||||
'desc' : 'Profile monitor after Alvra Mirror 1',
|
||||
'eco_type' : 'xdiagnostics.profile_monitors.Pprm'},
|
||||
'SAROP21-OAPU092' : {
|
||||
'alias' : 'SlitSwitch',
|
||||
'z_und' : 92,
|
||||
'desc' : 'Slit in Optics hutch after Photon switchyard and before Bernina optics',
|
||||
'eco_type' : 'xoptics.slits.SlitBlades'},
|
||||
'SAROP21-OOMV092' : {
|
||||
'alias' : 'Mirr1',
|
||||
'z_und' : 92,
|
||||
'desc' : 'Vertical offset Mirror 1'},
|
||||
'SAROP21-PPRM094' : {
|
||||
'alias' : 'ProfMirr1',
|
||||
'z_und' : 94,
|
||||
'desc' : 'Profile monitor after Mirror 1',
|
||||
'eco_type' : 'xdiagnostics.profile_monitors.Pprm'},
|
||||
'SAROP21-OOMV096' : {
|
||||
'alias' : 'Mirr2',
|
||||
'z_und' : 96,
|
||||
'desc' : 'Vertical offset mirror 2'},
|
||||
'SAROP21-PSCR097' : {
|
||||
'alias' : 'ProfMirr2',
|
||||
'z_und' : 97,
|
||||
'desc' : 'Profile Monitor after Mirror 2'},
|
||||
'SAROP21-ODCM098' : {
|
||||
'alias' : 'Mono',
|
||||
'z_und' : 98,
|
||||
'desc' : 'DCM Monochromator',
|
||||
'eco_type' : 'xoptics.dcm.Double_Crystal_Mono'},
|
||||
'SAROP21-PPRM102' : {
|
||||
'alias' : 'ProfMono',
|
||||
'z_und' : 102,
|
||||
'desc' : 'Profile monitor after Monochromator',
|
||||
'eco_type' : 'xdiagnostics.profile_monitors.Pprm'},
|
||||
'SAROP21-OPPI103' : {
|
||||
'alias' : 'Pick',
|
||||
'z_und' : 103,
|
||||
'desc' : 'X-ray pulse picker'},
|
||||
'SAROP21-BST114' : {
|
||||
'alias' : 'ShutOpt',
|
||||
'z_und' : 114,
|
||||
'desc' : 'Shutter after Optics hutch'},
|
||||
'SAROP21-PBPS133' : {
|
||||
'alias' : 'MonOpt',
|
||||
'z_und' : 133,
|
||||
'desc' : 'Intensity/position monitor after Optics hutch',
|
||||
'eco_type' : 'xdiagnostics.intensity_monitors.SolidTargetDetectorPBPS',
|
||||
'kwargs' : {'VME_crate':'SAROP21-CVME-PBPS1','link':9} },
|
||||
'SAROP21-PPRM133' : {
|
||||
'alias' : 'ProfOpt',
|
||||
'z_und' : 133,
|
||||
'desc' : 'Profile monitor after Optics hutch',
|
||||
'eco_type' : 'xdiagnostics.profile_monitors.Pprm'},
|
||||
'SAROP21-PALM134' : {
|
||||
'alias' : 'TimTof',
|
||||
'z_und' : 134,
|
||||
'desc' : 'Timing diagnostics THz streaking/TOF'},
|
||||
'SAROP21-PSEN135' : {
|
||||
'alias' : 'TimRef',
|
||||
'z_und' : 135,
|
||||
'desc' : 'Timing diagnostics spectral encoding of ref. index change'},
|
||||
'SAROP21-OATT135' : {
|
||||
'alias' : 'Att',
|
||||
'z_und' : 135,
|
||||
'desc' : 'Attenuator Bernina',
|
||||
'eco_type' : 'xoptics.attenuator_aramis.AttenuatorAramis'},
|
||||
'SAROP21-OAPU136' : {
|
||||
'alias' : 'SlitAtt',
|
||||
'z_und' : 136,
|
||||
'desc' : 'Slits behind attenuator',
|
||||
'eco_type' : 'xoptics.slits.SlitPosWidth'},
|
||||
'SAROP21-OLAS136' : {
|
||||
'alias' : 'RefLaser',
|
||||
'z_und' : 136,
|
||||
'desc' : 'Bernina beamline reference laser before KBs',
|
||||
'eco_type' : 'xoptics.reflaser.RefLaser_Aramis'},
|
||||
'SAROP21-PBPS138' : {
|
||||
'alias' : 'MonAtt',
|
||||
'z_und' : 138,
|
||||
'desc' : 'Intensity/Position monitor after Attenuator',
|
||||
'eco_type' : 'xdiagnostics.intensity_monitors.SolidTargetDetectorPBPS',
|
||||
'kwargs' : {'VME_crate':'SAROP21-CVME-PBPS2','link':9} },
|
||||
'SAROP21-PDIO138' : {
|
||||
'alias' : 'DetDio',
|
||||
'z_und' : 138,
|
||||
'desc' : 'Diode digitizer for exp data',
|
||||
'eco_type' : 'devices_general.detectors.DiodeDigitizer',
|
||||
'kwargs' : {'VME_crate':'SAROP21-CVME-PBPS2','link':9} },
|
||||
'SAROP21-PPRM138' : {
|
||||
'alias' : 'ProfAtt',
|
||||
'z_und' : 138,
|
||||
'desc' : 'Profile monitor after Attenuator',
|
||||
'eco_type' : 'xdiagnostics.profile_monitors.Pprm'},
|
||||
'SAROP21-OKBV139' : {
|
||||
'alias' : 'KbVer',
|
||||
'z_und' : 139,
|
||||
'desc' : 'Vertically focusing Bernina KB mirror',
|
||||
'eco_type' : 'xoptics.KBver.KBver'},
|
||||
'SAROP21-OKBH140' : {
|
||||
'alias' : 'KbHor',
|
||||
'z_und' : 140,
|
||||
'desc' : 'Horizontally focusing Bernina KB mirror',
|
||||
'eco_type' : 'xoptics.KBhor.KBhor'},
|
||||
'SARES22-GPS' : {
|
||||
'alias' : 'Gps',
|
||||
'z_und' : 142,
|
||||
'desc' : 'General purpose station',
|
||||
'eco_type' : 'endstations.bernina_gps.GPS'},
|
||||
'SARES20-PROF142-M1' : {
|
||||
'alias' : 'Xeye',
|
||||
'z_und' : 142,
|
||||
'desc' : 'Mobile X-ray eye in Bernina hutch',
|
||||
'eco_type' : 'xdiagnostics.profile_monitors.Bernina_XEYE',
|
||||
'kwargs' : {'bshost':'sf-daqsync-01.psi.ch','bsport':11173},
|
||||
},
|
||||
'SLAAR02-TSPL-EPL' : {
|
||||
'alias' : 'PhaseShifter',
|
||||
'z_und' : 142,
|
||||
'desc' : 'Experiment laser phase shifter',
|
||||
'eco_type' : 'devices_general.timing.PhaseShifterAramis'},
|
||||
'http://sf-daq-1:10000' : {
|
||||
'alias' : 'DetJF',
|
||||
'z_und' : 142,
|
||||
'desc' : '1.5M Jungfrau detector',
|
||||
'eco_type' : 'devices_general.detectors.DIAClient'},
|
||||
'SLAAR21-LMOT' : {
|
||||
'alias' : 'Las',
|
||||
'z_und' : 142,
|
||||
'desc' : 'Experiment laser optics',
|
||||
'eco_type' : 'loptics.bernina_experiment.Laser_Exp'},
|
||||
'SLAAR21-LTIM01-EVR0' : {
|
||||
'alias' : 'LaserShutter',
|
||||
'z_und' : 142,
|
||||
'desc' : 'Laser Shutter',
|
||||
'eco_type' : 'loptics.laser_shutter.laser_shutter'}
|
||||
# 'SLAAR21-LMOT' : {
|
||||
# 'alias' : 'Palm',
|
||||
# 'z_und' : 142,
|
||||
# 'desc' : 'Streaking arrival time monitor',
|
||||
# 'eco_type' : 'timing.palm.Palm'},
|
||||
# 'SLAAR21-LMOT' : {
|
||||
# 'alias' : 'Psen',
|
||||
# 'z_und' : 142,
|
||||
# 'desc' : 'Streaking arrival time monitor',
|
||||
# 'eco_type' : 'timing.psen.Psen'}
|
||||
|
||||
# = dict(
|
||||
# alias = ''
|
||||
# z_und =
|
||||
# desc = ''},
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
import traceback
|
||||
from colorama import Fore as _color
|
||||
|
||||
try:
|
||||
from lazy_object_proxy import Proxy as LazyProxy
|
||||
except:
|
||||
print('Could not find package lazy-object-proxy for lazy initialisation of devices!')
|
||||
pass
|
||||
|
||||
def init_device(devDict,devId,args,kwargs,verbose=True):
|
||||
imp_p = devDict['eco_type'].split(sep='.')
|
||||
dev_alias = devDict['alias']
|
||||
dev_alias = dev_alias[0].lower() + dev_alias[1:]
|
||||
eco_type_name = imp_p[-1]
|
||||
istr = 'from ..'+'.'.join(imp_p[:-1])+' import '
|
||||
istr += '%s as _%s'%(eco_type_name,eco_type_name)
|
||||
#print(istr)
|
||||
if verbose:
|
||||
print(('Configuring %s '%(dev_alias)).ljust(25), end='')
|
||||
print(('(%s)'%(devId)).ljust(25), end='')
|
||||
error = None
|
||||
try:
|
||||
exec(istr)
|
||||
tdev = eval('_%s(Id=\'%s\',*args,**kwargs)'%(eco_type_name,devId))
|
||||
tdev.name = dev_alias
|
||||
tdev._z_und = devDict['z_und']
|
||||
if verbose:
|
||||
print((_color.GREEN+'OK'+_color.RESET).rjust(5))
|
||||
return tdev
|
||||
except Exception as expt:
|
||||
#tb = traceback.format_exc()
|
||||
if verbose:
|
||||
print((_color.RED+'FAILED'+_color.RESET).rjust(5))
|
||||
#print(sys.exc_info())
|
||||
raise expt
|
||||
|
||||
|
||||
def initDeviceAliasList(aliases,lazy=False,verbose=True):
|
||||
devices = []
|
||||
problems = []
|
||||
for device_Id in aliases.keys():
|
||||
alias = aliases[device_Id]['alias']
|
||||
alias = alias[0].lower() + alias[1:]
|
||||
if 'eco_type' in aliases[device_Id].keys() \
|
||||
and aliases[device_Id]['eco_type']:
|
||||
if 'args' in aliases[device_Id].keys() \
|
||||
and aliases[device_Id]['args']:
|
||||
args = aliases[device_Id]['args']
|
||||
else:
|
||||
args = tuple()
|
||||
|
||||
if 'kwargs' in aliases[device_Id].keys() \
|
||||
and aliases[device_Id]['kwargs']:
|
||||
kwargs = aliases[device_Id]['kwargs']
|
||||
else:
|
||||
kwargs = dict()
|
||||
try:
|
||||
if lazy:
|
||||
dev = LazyProxy(lambda:init_device(aliases[device_Id],device_Id,args,kwargs,verbose=verbose))
|
||||
else:
|
||||
dev = init_device(aliases[device_Id],device_Id,args,kwargs,verbose=verbose)
|
||||
devices.append((device_Id,alias,dev))
|
||||
except:
|
||||
problems.append((device_Id,alias,traceback.format_exc()))
|
||||
return devices, problems
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
from . import materials
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,90 @@
|
||||
import xrayutilities as xu
|
||||
from . import consts as _consts
|
||||
from scipy.constants import torr,bar,k,N_A,R
|
||||
import numpy as np
|
||||
|
||||
# This module holds relevant materials of the
|
||||
# xrayutilities materials class,
|
||||
|
||||
class MaterialCollection:
|
||||
""" Dummy class collections of materials (dict-like)."""
|
||||
def __init__(self, **entries):
|
||||
self.__dict__.update(entries)
|
||||
def __setitem__(self,key,value):
|
||||
self.__dict__.update({key:value})
|
||||
|
||||
_amorphous = dict()
|
||||
_crystal = dict()
|
||||
_gas = dict()
|
||||
|
||||
amorphous = MaterialCollection()
|
||||
crystal = MaterialCollection()
|
||||
gas = MaterialCollection()
|
||||
|
||||
def _get_transmission(self,d,E='config'):
|
||||
""" calculate the transmittion after thickness d (in m) of material at energy E (in eV)."""
|
||||
return np.exp(-d*1e6/self.absorption_length(E))
|
||||
|
||||
xu.materials.Material.transmission = _get_transmission
|
||||
|
||||
|
||||
crystal['Si'] = xu.materials.Si
|
||||
crystal['Ge'] = xu.materials.Ge
|
||||
crystal['GaAs'] = xu.materials.GaAs
|
||||
crystal['Al'] = xu.materials.Al
|
||||
crystal['Diamond'] = xu.materials.C
|
||||
crystal['Be'] = xu.materials.material.Crystal("Be", \
|
||||
xu.materials.spacegrouplattice.SGLattice(\
|
||||
194, 2.2858, 3.5843, atoms=[xu.materials.elements.Be, ], \
|
||||
pos=['2c', ]))
|
||||
|
||||
amorphous['B4C'] = xu.materials.material.Amorphous('B4C',2520,[('B',4),('C',1)])
|
||||
amorphous['Mo'] = xu.materials.material.Amorphous('Mo',10220,[('Mo',1)])
|
||||
amorphous['polyimide'] = xu.materials.material.Amorphous('polyimide',1430,[('C',22),('H',10),('N',2),('O',5)])
|
||||
amorphous['mylar'] = xu.materials.material.Amorphous('mylar',1400,[('C',10),('H',8),('O',4)])
|
||||
amorphous['polycarbonate'] = xu.materials.material.Amorphous('polycarbonate',1200,[('C',16),('H',14),('O',3)])
|
||||
amorphous['Si3N4'] = xu.materials.material.Amorphous('Silicon nitride',3440,[('Si',3),('N',4)])
|
||||
amorphous['air'] = xu.materials.material.Amorphous('air',1000,[('N',1.562),('O',.42),('C',.0003),('Ar',.0094)])
|
||||
|
||||
|
||||
# more useful values and constants
|
||||
#elementName = DummyClassDict(_consts.elementName)
|
||||
#meltPoint = DummyClassDict(_consts.meltPoint)
|
||||
#density = DummyClassDict(_consts.Density)
|
||||
|
||||
class Gas(xu.materials.material.Amorphous):
|
||||
def __init__(self,name, pressure=bar, temperature=295, molecule_size=1, atoms=None, cij=None):
|
||||
"""pressure in Pascal, temperature in Kelvin"""
|
||||
self.pressure = pressure
|
||||
self.temperature = temperature
|
||||
self.molecule_size = molecule_size
|
||||
super(Gas,self).__init__(name,0,atoms=atoms,cij=cij)
|
||||
|
||||
|
||||
def _getdensity(self):
|
||||
"""
|
||||
calculates the mass density of an material from the atomic composition and the average molecule size (ideal gas).
|
||||
|
||||
Returns
|
||||
-------
|
||||
mass density in kg/m^3
|
||||
"""
|
||||
num_dens = self.pressure/k/self.temperature
|
||||
return self._get_composition_mass()*num_dens*self.molecule_size
|
||||
density = property(_getdensity)
|
||||
|
||||
def _get_composition_mass(self):
|
||||
w = 0
|
||||
for atom,occ in self.base:
|
||||
w += atom.weight * occ
|
||||
return w
|
||||
|
||||
gas['air'] = Gas('air',molecule_size=1.9917,atoms=[('N',1.562),('O',.42),('C',.0003),('Ar',.0094)])
|
||||
gas['He'] = Gas('He',molecule_size=1,atoms=[('He',1)])
|
||||
gas['N'] = Gas('He',molecule_size=2,atoms=[('N',1)])
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import xrayutilities as xu
|
||||
import xraylib as xl
|
||||
import numpy as np
|
||||
from . import materials
|
||||
|
||||
def getKBMirrorLayer():
|
||||
subst = xu.simpack.Layer(materials.crystal.Si, np.inf)
|
||||
highZ = xu.simpack.Layer(materials.amorphous.Mo,200)
|
||||
lowZ = xu.simpack.Layer(materials.amorphous.B4C,150)
|
||||
return subst+highZ+lowZ
|
||||
|
||||
def calcReflectivity(mirror=getKBMirrorLayer(),energys=np.linspace(2000,12000,200),
|
||||
alphais=np.linspace(0,3,200),sample_width=500,**kwargs):
|
||||
Refl = []
|
||||
for E in energys:
|
||||
m = xu.simpack.SpecularReflectivityModel(mirror,energy=E,**kwargs)
|
||||
Refl.append(m.simulate(alphais))
|
||||
|
||||
return np.asarray(Refl),energys,alphais
|
||||
|
||||
def absorptionEdge(element,edge=None):
|
||||
if type(element) is str:
|
||||
element = xl.SymbolToAtomicNumber(element)
|
||||
shells = ['K','L1','L2','L3','M1','M2','M3','M4','M5']
|
||||
if edge is not None:
|
||||
shell_ind = shells.index(edge)
|
||||
return xl.EdgeEnergy(element,shell_ind)
|
||||
else:
|
||||
shell_inds = range(8)
|
||||
print('Absorption edges %s'%xl.AtomicNumberToSymbol(element))
|
||||
for shell_ind in shell_inds:
|
||||
print(' '\
|
||||
+shells[shell_ind].ljust(3)\
|
||||
+' = %7.1f eV'%(xl.EdgeEnergy(element,shell_ind)*1000))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
import numpy as np
|
||||
from scipy import constants
|
||||
import xraylib as xl
|
||||
|
||||
|
||||
def cartesian(arrays, out=None):
|
||||
"""
|
||||
Generate a cartesian product of input arrays.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
arrays : list of array-like
|
||||
1-D arrays to form the cartesian product of.
|
||||
out : ndarray
|
||||
Array to place the cartesian product in.
|
||||
|
||||
Returns
|
||||
-------
|
||||
out : ndarray
|
||||
2-D array of shape (M, len(arrays)) containing cartesian products
|
||||
formed of input arrays.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> cartesian(([1, 2, 3], [4, 5], [6, 7]))
|
||||
array([[1, 4, 6],
|
||||
[1, 4, 7],
|
||||
[1, 5, 6],
|
||||
[1, 5, 7],
|
||||
[2, 4, 6],
|
||||
[2, 4, 7],
|
||||
[2, 5, 6],
|
||||
[2, 5, 7],
|
||||
[3, 4, 6],
|
||||
[3, 4, 7],
|
||||
[3, 5, 6],
|
||||
[3, 5, 7]])
|
||||
|
||||
"""
|
||||
|
||||
arrays = [np.asarray(x) for x in arrays]
|
||||
dtype = arrays[0].dtype
|
||||
|
||||
n = np.prod([x.size for x in arrays])
|
||||
if out is None:
|
||||
out = np.zeros([n, len(arrays)], dtype=dtype)
|
||||
|
||||
m = n / arrays[0].size
|
||||
out[:,0] = np.repeat(arrays[0], m)
|
||||
if arrays[1:]:
|
||||
cartesian(arrays[1:], out=out[0:m,1:])
|
||||
for j in range(1, arrays[0].size):
|
||||
out[j*m:(j+1)*m,1:] = out[0:m,1:]
|
||||
return out
|
||||
|
||||
def E2lam(energy):
|
||||
"""energy in eV, lambda in Ångstrøm"""
|
||||
return constants.h*constants.c/constants.e / energy *1e10
|
||||
|
||||
def QE2theta(Q,energy):
|
||||
"""Q in Å**(-1), energy in eV, theta in radians"""
|
||||
return np.arcsin(E2lam(energy)/4/np.pi*Q)
|
||||
|
||||
|
||||
def absorptionEdge(element,edge=None):
|
||||
if type(element) is str:
|
||||
element = xl.SymbolToAtomicNumber(element)
|
||||
shells = ['K','L1','L2','L3','M1','M2','M3','M4','M5']
|
||||
if edge is not None:
|
||||
shell_ind = shells.index(edge)
|
||||
return xl.EdgeEnergy(element,shell_ind)
|
||||
else:
|
||||
shell_inds = range(8)
|
||||
print('Absorption edges %s'%xl.AtomicNumberToSymbol(element))
|
||||
for shell_ind in shell_inds:
|
||||
print(' '\
|
||||
+shells[shell_ind].ljust(3)\
|
||||
+' = %7.1f eV'%(xl.EdgeEnergy(element,shell_ind)*1000))
|
||||
Reference in New Issue
Block a user