def record_obsprog(stationdriver, scan): """At starttime execute the observation program specified by the obsfun method pointer and run with arguments specified by obsargs dict. """ scan_flat = dict(scan) del scan_flat['beam'] for k in scan['beam'].keys(): scan_flat[k] = scan['beam'][k] freqbndobj = modeparms.FreqSetup(scan['beam']['freqspec']) scan_flat['freqbndobj'] = freqbndobj prg = ObsPrograms(stationdriver) obsfun, obsargs_sig = prg.getprogram(scan['obsprog']) scan_flat['bfdsesdumpdir'] = stationdriver.bf_data_dir # Map only args required by obsargs = {k: scan_flat[k] for k in obsargs_sig} # Setup Calibration tables on LCU: CALTABLESRC = 'default' # FIXME put this in args ## (Only BST uses calibration tables) # Choose between 'default' or 'local' stationdriver.set_caltable(CALTABLESRC) # Prepare for obs program. try: stationdriver.goto_observingstate() except RuntimeError as e: raise RuntimeError(e) # Run the observation program: obsinfolist = obsfun(**obsargs) # Stop program beam stationdriver.stop_beam() scan_id = None scanpath_scdat = None scanresult = {} if obsinfolist is not None: datatype = 'sop:' + scan['obsprog'] scanrec = dataIO.ScanRecInfo() scanrec.set_stnid(stationdriver.get_stnid()) scanrec.set_scanrecparms(datatype, freqbndobj.arg, scan['duration_tot'], scan['beam']['pointing']) beamstarted = datetime.datetime.strptime(obsinfolist[0].filenametime, "%Y%m%d_%H%M%S") scan_id = stationdriver.get_scanid(beamstarted) scanpath_scdat = os.path.join(stationdriver.scanpath, scan_id) # Add caltables used caltabinfos = stationdriver.get_caltableinfos(freqbndobj.rcumodes) # Add obsinfos to scanrecs for obsinfo in obsinfolist: obsinfo.caltabinfos = caltabinfos scanrec.add_obs(obsinfo) # Move data to archive stationdriver.movefromlcu(stationdriver.get_lcuDumpDir() + "/*.dat", scanpath_scdat) scanrec.path = scanpath_scdat scanresult[datatype] = scanrec scanresult['scan_id'] = scan_id scanresult['scanpath_scdat'] = scanpath_scdat return scanresult
def do_tbb(self, duration_scan, band, start_after=0, observer="", project=""): """Record duration_scan seconds of TBB data from rcumode. """ observationID = "Null" # Prepare for obs program. try: self.goto_observingstate() except RuntimeError as e: raise RuntimeError(e) # Start a beam pointing = directions.std_pointings('Z') freqband = modeparms.FreqSetup(band) # FreqSetup obtained from band spec sets 8 bit mode, # so create a new FreqSetup object with only center frequency freqlo, freqhi = freqband.edgefreqs() freq0 = (freqlo+freqhi)/2.0 actualfb = modeparms.FreqSetup(freq0) antset = actualfb.antsets[0] self.streambeams(actualfb, pointing) print("Setting up TBBs") self._setupTBBs() print("Will start TBB recording in {}s".format(start_after)) time.sleep(start_after) print("Will freeze TBB recording in {}s".format(duration_scan)) time.sleep(duration_scan) # Arbitrary time to trigger print("Sending trigger to TBBs") self._freezeTBBdata() # Start data capture process locally dalcap = \ multiprocessing.Process(target=capture_data_DAL1, args=(self.tbbraw2h5cmd, self.tbbh5dumpdir, observer, antset, project, observationID, False)) dalcap.start() print("Streaming {}s of TBB data out of LCU".format(duration_scan)) self._startTBBdataStream(float(duration_scan)) dalcap.join()
def goto_observingstate(self, warmup=False): """Put station into the main observing state. Parameters ---------- warmup: bool, optional Do a beam warmup after reaching swlevel 3. """ if not self.checkobservingallowed(): raise RuntimeError('Observations not allowed') self._lcu_interface.cleanup() # Could be leftovers from previous runs swlevel_changed = self._lcu_interface.set_swlevel(3) if swlevel_changed and warmup: # Dummy or hot beam start: (takes about 10sec) # This seems necessary: first beamctl after going to swlevel 3 # seems to crash. print("Running warmup beam... @ {}".format( datetime.datetime.utcnow())) self.streambeams(modeparms.FreqSetup('10_90'), '0.,1.5707963,AZELGEO') self._lcu_interface.stop_beam() print("Finished warmup beam... @ {}".format( datetime.datetime.utcnow()))
def main(): """ Record LOFAR station data via CLI Entry_point for ilisa_rec. """ parser = argparse.ArgumentParser() parser.add_argument('-m', '--mockrun', help="Run mock rec", action='store_true') parser.add_argument('-s', '--starttime', help="Start Time (format: YYYY-mm-ddTHH:MM:SS)", type=str, default='NOW') parser.add_argument('-i', '--integration', help="Integration time [s]", type=float, default=modeparms.MIN_STATS_INTG) parser.add_argument('-a', '--acc', help="Enable ACC", action='store_true') parser.add_argument('-b', '--bfs', help="Record also BST", action='store_true') parser.add_argument('ldat_type', help="""\ lofar data type to record. Choose from 'bst', 'sst', 'tbb', 'xst', 'dmp' or 'None'.""") parser.add_argument('freqspec', help='Frequency spec in Hz.') parser.add_argument('duration_tot', help='Duration in seconds. ' '(Can be an arithmetic expression)', type=str) parser.add_argument('pointing', nargs='?', default=None, help='Direction in az,el,ref (radians) or source name.') args = parser.parse_args() accessconf = ilisa.monitorcontrol.default_access_lclstn_conf() stndrv = StationDriver(accessconf['LCU'], accessconf['DRU'], mockrun=args.mockrun) sesspath = accessconf['DRU']['LOFARdataArchive'] rec_type = args.ldat_type if rec_type == 'None': rec_type = None if args.acc: sesspath = os.path.join(sesspath, 'acc') else: sesspath = os.path.join(sesspath, args.ldat_type) bfdsesdumpdir = accessconf['DRU']['BeamFormDataDir'] freqsetup = modeparms.FreqSetup(args.freqspec) # Start criteria: Time args.starttime = modeparms.timestr2datetime(args.starttime) starttime = waituntil(args.starttime, datetime.timedelta(seconds=2)) duration_tot, ldatinfos, ldatinfo_bfs, bfsdatapaths, bfslogpaths =\ rec_scan_start(stndrv, rec_type, freqsetup, args.duration_tot, args.pointing, args.integration, starttime, args.acc, args.bfs, destpath=sesspath) # (Note: ACC has no time keeping) if not args.bfs and not _xtract_bsx(rec_type): print('Recording for {}s'.format(duration_tot + 10)) time.sleep(duration_tot + 10) # Finished Recording. Now stop things that are running rec_scan_stop(stndrv, rec_type, freqsetup, args.pointing, starttime, args.acc, args.bfs, duration_tot, ldatinfos, ldatinfo_bfs, bfsdatapaths, bfslogpaths) for res in stndrv.scanresult['rec']: print("Saved {} scanrec here: {}".format( res, stndrv.scanresult[res].get_scanrecpath())) stndrv.scanresult[res].write() if not stndrv.scanresult['rec']: print("No data recorded ('None' selected)")
def run_scansess(self, sesscans_in, session_id=None): """Run a local session given a stn_ses_schedule dict. That is, dispatch to the stationdrivers to setup corresponding monitorcontrol.""" sesscans = self.process_scansess(sesscans_in, session_id) self.projectmeta, _ = projid2meta(sesscans['projectid']) self.set_stn_session_id(sesscans['session_id']) # Set where ldata should be put after recording on LCU sesspath = self.get_sesspath() bfdsesdumpdir = self.get_bfdsesdumpdir() self.stndrv.scanpath = sesspath self.stndrv.bf_data_dir = bfdsesdumpdir # Boot Time handling nw = datetime.datetime.utcnow() startscantime = sesscans['scans'][0]['starttime'] if startscantime == 'NOW': startscantime = nw beaminittime = 13 bootupstart = startscantime - datetime.timedelta(seconds=beaminittime) # Wait until it is time to bootup print("In scansess: Will start scansession @ {}".format(bootupstart)) waituntil(bootupstart) self.stndrv.goto_observingstate() scans_done = [] for scan in sesscans['scans']: freqbndobj = modeparms.FreqSetup(scan['beam']['freqspec']) if scan['obsprog'] is not None: _mockrun = False if not _mockrun: scanresult = programs.record_obsprog(self.stndrv, scan) else: scanresult = {} else: duration_tot = scan['duration_tot'] pointing = scan['beam']['pointing'] starttime = scan['starttime'] rec = scan['rec'] integration = scan['integration'] acc = False if 'acc' in rec: acc = True rec.remove('acc') bfs = False if 'bfs' in rec: bfs = True rec.remove('bfs') rec_type = None if len(rec) > 0: rec_type = rec.pop() # Should only be bsx left freqspec = scan['beam']['freqspec'] freqsetup = modeparms.FreqSetup(freqspec) starttime = waituntil(starttime, datetime.timedelta(seconds=2)) duration_tot, ldatinfos, ldatinfo_bfs, bfsdatapaths,\ bfslogpaths =\ rec_scan_start(self.stndrv, rec_type, freqsetup, duration_tot, pointing, integration, starttime, acc=acc, bfs=bfs, destpath=sesspath) if not bfs and not _xtract_bsx(rec_type): print('Recording for {}s'.format(duration_tot + 10)) time.sleep(duration_tot + 10) rec_scan_stop(self.stndrv, rec_type, freqsetup, pointing, starttime, acc, bfs, duration_tot, ldatinfos, ldatinfo_bfs, bfsdatapaths, bfslogpaths) scanresult = self.stndrv.scanresult scan['id'] = scanresult.pop('scan_id', None) scanpath_scdat = scanresult.pop('scanpath_scdat', None) self._writescanrecs(scanresult) print("Saved scan here: {}".format(scanpath_scdat)) print("Finished scan @ {}".format(datetime.datetime.utcnow())) scans_done.append(scan) sesscans['scans'] = scans_done self.save_scansess(sesscans)