Created
February 11, 2015 18:54
-
-
Save ericdill/1470a9890c54cb3a29fa to your computer and use it in GitHub Desktop.
pvs.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"CSX-1 Scalars": | |
EpicsScaler: | |
pimte_tot1: | |
record: XF:23ID1-ES{Dif-Cam:PIMTE}Stats1:Total_RBV | |
numchan: 32 | |
EpicsSignal: | |
sclr_trig: | |
read_pv: XF:23ID1-ES{Sclr:1}.CNT | |
sclr_ch1: | |
read_pv: XF:23ID1-ES{Sclr:1}.S1 | |
sclr_ch2: | |
read_pv: XF:23ID1-ES{Sclr:1}.S2 | |
sclr_ch3: | |
read_pv: XF:23ID1-ES{Sclr:1}.S3 | |
sclr_ch4: | |
read_pv: XF:23ID1-ES{Sclr:1}.S4 | |
sclr_ch5: | |
read_pv: XF:23ID1-ES{Sclr:1}.S5 | |
sclr_ch6: | |
read_pv: XF:23ID1-ES{Sclr:1}.S6 | |
temp_a: | |
read_pv: XF:23ID1-ES{TCtrl:1-Chan:A}T-I | |
temp_b: | |
read_pv: XF:23ID1-ES{TCtrl:1-Chan:B}T-I | |
"Area detector beam instrumentation": | |
ProsilicaDetector: | |
fs1_cam: | |
prefix: XF:23IDA-BI:1{FS:1-Cam:1} | |
diag3_cam: | |
prefix: XF:23ID1-BI{Diag:3-Cam:1} | |
diag5_cam: | |
prefix: XF:23ID1-BI{Diag:5-Cam:1} | |
diag6_cam: | |
prefix: XF:23ID1-BI{Diag:6-Cam:1} | |
dif_beam_cam: | |
prefix: XF:23ID1-ES{Dif-Cam:Beam} | |
"Princeton CCD Camera": | |
EpicsSignal: | |
pimte_tot1: | |
read_pv: XF:23ID1-ES{Dif-Cam:PIMTE}Stats1:Total_RBV | |
pimte_tot2: | |
read_pv: XF:23ID1-ES{Dif-Cam:PIMTE}Stats2:Total_RBV | |
pimte_tot3: | |
read_pv: XF:23ID1-ES{Dif-Cam:PIMTE}Stats3:Total_RBV | |
pimte_tot4: | |
read_pv: XF:23ID1-ES{Dif-Cam:PIMTE}Stats4:Total_RBV | |
pimte_tot5: | |
read_pv: XF:23ID1-ES{Dif-Cam:PIMTE}Stats5:Total_RBV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# check that alias is a valid python identifier | |
import re | |
import tokenize | |
import keyword | |
import os | |
import yml | |
import ophyd | |
def is_valid_identifier(alias): | |
"""Check that the alias is a valid python identifier | |
Returns | |
------- | |
True if valid | |
False if not | |
""" | |
return re.match(tokenize.Name + '$', alias) and not keyword.iskeyword(alias) | |
yml_pvs = os.path.join(os.path.expanduser('~'), '.config', 'ophyd', 'pvs.yml') | |
with open(yml_pvs, 'r') as f: | |
config = yaml.load(f) | |
# loop over and ignore the top level 'namespacing' | |
for group_name, grouping in config.items(): | |
for cls_name, obj_info in grouping.items(): | |
# these are your different classes | |
cls = getattr(controls, cls_name) | |
for alias, info in obj_info.items(): | |
info['name'] = info.get('name', alias) | |
if not is_valid_identifier(alias): | |
raise ValueError('Alias {} is not a valid python object name' | |
''.format(alias)) | |
print('setting attribute {}'.format(alias)) | |
setattr(sys.modules['__main__'], alias, cls(**info)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment