Beispiel #1
0
    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)
Beispiel #2
0
    def do_bfs_OW(self, freqbndobj, duration, pointing, bfdsesdumpdir,
                  starttime):
        """Record BeamFormed Streams (BFS) with particular beamlet allocation.
        """

        band = freqbndobj.rcubands[0]
        ###
        bits = 8  # 8
        attenuation = None
        # Subbands allocation
        if band == '10_90' or band == '30_90':
            # LBA
            lanes = (0, 1)  # (0,1)
            beamlets = '0:243'  # '0:243'
            subbands = '164:407'  # '164:407'
        elif band == '110_190':
            # HBAlo
            lanes = (0, 1, 2, 3)  # Normally (0,1,2,3) for all 4 lanes.
            beamlets = '0:487'
            subbands = '12:499'
        elif band == '210_250':
            # HBAhi
            lanes = (0, 1)
            beamlets = '0:243'
            subbands = '12:255'
        else:
            raise ValueError(
                "Wrong band: "
                "should be 10_90 (LBA), 110_190 (HBAlo) or 210_250 (HBAhi).")

        # Wait until it is time to start
        starttime_req = starttime
        warmuptime = 14
        pause = 0  # Sufficient?
        beaminittime = 13
        #self.stationdriver._waittoboot(rectime, pause)
        margin = datetime.timedelta(seconds=(warmuptime + pause +
                                             beaminittime))
        starttime = waituntil(starttime_req, margin)
        rectime = starttime

        # Necessary since fork creates multiple instances of myobs and each one
        # will call it's __del__ on completion and __del__ shutdown...
        shutdown = self.stationdriver.halt_observingstate_when_finished
        self.stationdriver.halt_observingstate_when_finished = False
        self.stationdriver.exit_check = False

        dir_bmctl = ilisa.monitorcontrol.directions.normalizebeamctldir(
            pointing)

        # BEGIN Dummy or hot beam start: (takes about 14sec)
        print("Running warmup beam... @ {}".format(datetime.datetime.utcnow()))
        # Setting bits is necessary:
        self.stationdriver._rcusetup(bits, attenuation)
        self.stationdriver._run_beamctl(beamlets, subbands, band, dir_bmctl)
        self.stationdriver.stop_beam()
        # END Dummy or hot start

        print("Pause {}s after boot.".format(pause))
        time.sleep(pause)

        # Real beam start:
        print("Beam started @ UT {}".format(datetime.datetime.utcnow()))
        rcu_setup_cmds = self.stationdriver._rcusetup(bits, attenuation)
        beamctl_cmds = self.stationdriver._run_beamctl(beamlets, subbands,
                                                       band, dir_bmctl)
        rspctl_cmds = []
        beamstart = datetime.datetime.utcnow()
        timeleft = rectime - beamstart
        if timeleft.total_seconds() < 0.:
            rectime = beamstart
        print("(Beam started) Time left before recording: {}".format(
            timeleft.total_seconds()))
        bfsnametime = starttime.strftime("%Y%m%d_%H%M%S")
        obsinfo = dataIO.LDatInfo('bfs', self.stationdriver.get_stnid(),
                                  rcu_setup_cmds, beamctl_cmds, rspctl_cmds)
        obsinfo.filenametime = bfsnametime

        REC = True
        if REC == True:
            port0 = self.stationdriver.bf_port0
            stnid = self.stationdriver.get_stnid()
            compress = True
            datafiles, _logfiles = bfbackend.rec_bf_streams(
                rectime, duration, lanes, band, bfdsesdumpdir, port0, stnid,
                compress)
            bfsdatapaths = []
            for lane in lanes:
                datafileguess = datafiles.pop()
                if not datafileguess:
                    _outdumpdir, _outarg, datafileguess, _dumplogname = \
                        bfbackend.bfsfilepaths(lane, rectime,
                                               modeparms.band2rcumode(band),
                                               bfdsesdumpdir, port0, stnid)
                bfsdatapaths.append(datafileguess)
        else:
            print("Not recording")
            time.sleep(duration)
        sys.stdout.flush()
        self.stationdriver.stop_beam()
        self.stationdriver.halt_observingstate_when_finished = shutdown
        return [obsinfo]