def addVEX(self, vexfilename): """Add all frequency setups (whether actually used or not!) from a VEX file""" f = open(vexfilename, 'r') v = vex.parse(f.read()) f.close() # todo: build list of freq names by going through v['SCHED'] scan modes per antenna, # adding freqs from those modes to the list, then use list instead of all v['FREQ'].keys() for fqname in v['FREQ']: bandlist = [[], []] for chinfo in v['FREQ'][fqname].getall('chan_def'): f, sb, bw = [s.upper() for s in chinfo[1:4]] f_Hz = float(f.split()[0]) bw_Hz = float(bw.split()[0]) if 'MHZ' in f: f_Hz *= 1e6 elif 'GHZ' in f: f_Hz *= 1e9 if 'MHZ' in bw: bw_Hz *= 1e6 elif 'GHZ' in bw: bw_Hz *= 1e9 if 'L' in sb: f0, f1 = f_Hz-bw_Hz, f_Hz else: f0, f1 = f_Hz, f_Hz+bw_Hz if f0 not in bandlist[0]: bandlist[0].append(f0) bandlist[1].append(f1) if bandlist[0]: self.add(bandlist) if self.verbosity > 0: print ('Autobands::addVEX() found %d recorded bands in VEX Freq definition %s' % (len(bandlist[0]), fqname))
def POST(self): if not web.ctx['ip'] in access_list: return error_response("Access denied") try: vex = vex.parse(web.data) except: return error_response("Can't parse VEX") start = get_start(vex) stop = get_stop(vex) start = vex2time(start) stop = vex2time(stop) if stop < time.time(): return error_response("Experiment is in the past") # Schedule the correlation job for this experiment. If the # experiment already started, the job will be started # immediately. interval = max(0, start - pre_start - time.time()) t = threading.Timer(interval, start_job, args=[fp, vex]) t.start() web.header('Content-Type', 'application/json') response = {} response['status'] = "scheduled" return json.dumps(response) + "\n"
def POST(self): web.header('Content-Type', 'application/json') input = json.loads(web.data()) try: self.vex = vex.parse(input['vex']) except: result = {} result['error'] = "couldn't parse VEX" return json.dumps(result) mtu = 1500 if 'mtu' in input: try: mtu = int(input['mtu']) except: result = {} result['error'] = "malformed mtu: %s" % input['mtu'] return json.dumps(result) pass try: self.init(mtu) except: result = {} result['error'] = "couldn't determine data format" return json.dumps(result) if config.sfxc: return self.sink(input, self.vex, mtu) else: return self.source(input, self.vex, mtu)
def POST(self): print web.data() web.header('Access-Control-Allow-Origin', '*') web.header('Content-Type', 'application/json') input = json.loads(web.data()) if 'method' in input: response = dispatcher._marshaled_dispatch(web.data()) print response return response try: v = vex.parse(input['vex']) except: result = {} result['error'] = "couldn't parse VEX" return json.dumps(result) result = do_vex2ccf(v) return json.dumps(result)
def Autozoom(vexfile, scan, v2dfile, opts, zoombw): zoomfreqs = {} fp = open(vexfile, 'r') v = vex.parse(fp.read()) fp.close() # calculate zoom frequencies for each station within each mode md = v['SCHED'][scan]['mode'] zoomfreqs[md] = {} zoom = cal_zoomfreqs(v, md, opts, zoombw) for freq in v['MODE'][md].getall('FREQ'): for st in v['STATION']: if st in freq: zoomfreqs[md][st] = zoom[freq[0]] # read .v2d file v2d = open(v2dfile, 'r') # construct name for the new v2d file (with scan number in it) name = v2dfile.split('.')[:-1] name.extend([scan, 'v2d']) name = '.'.join(name) scanv2d = open(name, 'wb') token = False for line in v2d: if line.strip()[:7] == 'ANTENNA': token = True st = line.strip()[-2:] if line.strip() == '}' and token == True: token = False for zf in zoomfreqs[md][st]: scanv2d.write('\t%s\n' % zf) scanv2d.write(line) # write station zoomfreqs into a new .v2d file (with scan number in the filename) v2d.close() scanv2d.close() return
def update(src, dest): v = vex.parse(src.read()) exper = v['GLOBAL']['EXPER'] start = get_start(v) start = vex2time(start) tm = time.gmtime(start - 86400) ref_exper = re.compile(r'\s*ref \$EXPER') ref_eop = re.compile(r'\s*ref \$EOP') ref_das = re.compile(r'\s*ref \$DAS') ref_clock = re.compile(r'\s*ref \$CLOCK') ref_tapelog_obs = re.compile(r'\s*ref \$TAPELOG_OBS') def_station = re.compile(r'\s*def ([a-zA-Z]+);') enddef = re.compile(r'\s*enddef;') block = re.compile(r'\$[A-Z_]+;') block_mode = re.compile(r'\$MODE;') block_eop = re.compile(r'\$EOP;') block_clock = re.compile(r'\$CLOCK;') block_station = re.compile(r'\$STATION;') block_site = re.compile(r'\$SITE;') site_position_epoch = re.compile(r'\s*site_position_epoch\s*=\s*(\d+);') has_eop = False has_clock = False has_tapelog_obs = False has_bitstreams = False for line in src: if ref_eop.match(line): has_eop = True pass if ref_clock.match(line): has_clock = True pass if ref_tapelog_obs.match(line): has_tapelog_obs = True pass continue src.seek(0) suppress_block = False mode_block = False station_block = False site_block = False comment_line = False station = None for line in src: if not has_eop and ref_exper.match(line): dest.write(line) dest.write(" ref $EOP = EOP%d;\n" % tm.tm_yday) continue if ref_eop.match(line): dest.write(" ref $EOP = EOP%d;\n" % tm.tm_yday) continue if ref_clock.match(line): dest.write(" ref $CLOCK = %s;\n" % station.upper()) continue if ref_das.match(line): if not has_clock: dest.write(" ref $CLOCK = %s;\n" % station.upper()) pass if not has_tapelog_obs and ref_das.match(line): dest.write(" ref $TAPELOG_OBS = %s;\n" % station.upper()) pass dest.write(line) continue if block.match(line): suppress_block = False mode_block = False station_block = False site_block = False pass if block_mode.match(line): mode_block = True pass if mode_block and enddef.match(line): if not has_bitstreams: for station in v['STATION']: if station in bitstreams: dest.write(" ref $BITSTREAMS = %s:%s;\n" % (station.upper(), station)) pass continue pass mode_block = False pass if block_station.match(line): station_block = True pass if station_block and def_station.match(line): station = def_station.match(line).group(1) pass if station_block and enddef.match(line): station = None pass if block_site.match(line): site_block = True pass if site_block and site_position_epoch.match(line): epoch = int(site_position_epoch.match(line).group(1)) secs = (epoch - 40587) * 86400 tupletime = time.gmtime(secs) epoch = time.strftime("%Yy%jd", tupletime) dest.write(" site_position_epoch = %s;\n" % epoch) continue if block_eop.match(line) or block_clock.match(line): suppress_block = True pass if not suppress_block: dest.write(line) comment_line = line.startswith("*-") continue continue if not has_bitstreams: dest.write("*" + 77 * "-" + "\n") dest.write("$BITSTREAMS;\n") for station in bitstreams: dest.write("*\n") dest.write("def %s;\n" % station.upper()) mapping = bitstreams[station] for stream in mapping: dest.write(" stream_def = &CH%02d : sign : %2d : %2d;\n" % (stream[0], stream[1], stream[1])) dest.write(" stream_def = &CH%02d : mag : %2d : %2d;\n" % (stream[0], stream[1] + 1, stream[1] + 1)) continue dest.write("enddef;\n") continue pass if not has_tapelog_obs: dest.write("*" + 77 * "-" + "\n") dest.write("$TAPELOG_OBS;\n") for station in v['STATION']: dest.write("*\n") dest.write("def %s;\n" % station.upper()) dest.write(" VSN = 1 : %s-eVLBI : %s : %s;\n" \ % (station, get_start(v), get_stop(v))) dest.write("enddef;\n") continue pass if not comment_line: dest.write("*" + 77 * "-" + "\n") pass gps.create_clock_block(v, dest) dest.write("*" + 77 * "-" + "\n") eop.create_eop_block(v, dest) return
def vex2ccf(s): v = vex.parse(s) json_output = do_vex2ccf(v) return json_output