Commit 1e3b4d06 authored by Jameson Graef Rollins's avatar Jameson Graef Rollins

add script to update/maintain channel lists

Script downloads channels lists, sorts, and separates into NDS and
EPICS lists based on sample rate.
parent 4e6f9596
Pipeline #46410 passed with stage
in 11 minutes and 45 seconds
#!/usr/bin/env python3
import os
import sys
import nds2
HOSTPORT = os.getenv('NDSSERVER', 'nds.ligo.caltech.edu:31200').split(',')[0].split(':')
HOST = HOSTPORT[0]
if len(HOSTPORT) == 1:
PORT = 31200
else:
PORT = int(HOSTPORT[1])
CACHE_DIR = os.path.expanduser('~/.cache/ligo-channel-list')
NDS_CHAN_LIST = os.getenv('NDS_CHAN_LIST', os.path.join(CACHE_DIR, 'nds-chan-list.txt'))
EPICS_CHAN_LIST = os.getenv('EPICS_CHAN_LIST', os.path.join(CACHE_DIR, 'epics-chan-list.txt'))
def main():
if len(sys.argv) > 1 and sys.argv[1] in ['-h', '--help']:
print("""Update channel file lists for use with ligo_channel_completion.
Downloads the channel list from NDS and updates the NDS and EPICS
channel list files. Uses the server specified in the NDSSERVER
environment variable, or 'nds.ligo.caltech.edu:31200' if not
specified. If the NDS_CHAN_LIST and EPICS_CHAN_LIST variables exist
they are assumed to be the paths to files to be updated. Otherwise
the files are updated in the default cache locations:
NDS_CHAN_LIST={}
EPICS_CHAN_LIST={}
Export these variables to your environment for bash channel
completion.""".format(NDS_CHAN_LIST, EPICS_CHAN_LIST))
sys.exit()
params = nds2.parameters(HOST, PORT)
chans = nds2.find_channels(
channel_type_mask=nds2.channel.CHANNEL_TYPE_RAW,
params=params,
)
os.makedirs(os.path.dirname(NDS_CHAN_LIST), exist_ok=True)
os.makedirs(os.path.dirname(EPICS_CHAN_LIST), exist_ok=True)
f_nds = open(NDS_CHAN_LIST+'.tmp', 'w')
f_epics = open(EPICS_CHAN_LIST+'.tmp', 'w')
for chan in sorted(chans, key=lambda c: c.name):
f_nds.write(chan.name+'\n')
if chan.sample_rate == 16:
f_epics.write(chan.name+'\n')
os.rename(NDS_CHAN_LIST+'.tmp', NDS_CHAN_LIST)
os.rename(EPICS_CHAN_LIST+'.tmp', EPICS_CHAN_LIST)
if __name__ == '__main__':
main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment