def main(): alist = ['1a', '1c', '2h'] #define antennas list (alist) src = 'moon' #define target source #az_off = 5 #define azimuth offset for on-off scan #el_off = 5 #define elevation offset for on-off scan freq = 1400 #set center frequency in MHz duration = 30 #duration of tracking #lock out the antennas you will be using ac.reserve_antennas(alist) #turn on the LNAs if they're not already on ac.try_on_lnas(alist) #set up with Autotune ac.autotune(alist) #display starting coordinates so #you can verify antennas have moved start_radec = ac.getRaDec(alist) print("The current coordinates are: ", start_radec) #create ephemeris file that tells the antenna #where it should be pointing at each timestamp ac.make_and_track_ephems(src, alist) #set the center frequency ac.set_freq(freq, alist) #print the coordinates after the antennas have #been given the point and track command to ensure #that they moved. src_radec = ac.getRaDec(alist) print("The source coordinates are: ", src_radec) #stay on source for the given duration time.sleep(duration) #unlock the antennas once you're done ac.release_antennas(alist, True)
def main(): logger = logger_defaults.getProgramLogger("observe", loglevel=logging.INFO) #parser = argparse.ArgumentParser(description="Observing script") #parser.add_argument("ants", nargs="+", help="ant names") #args = parser.parse_args() #ants = args.ants nbatches = 15 ant_list = ["1a","1c","1f","2a","2b","2h","4g","5c"] az_offset = 0 el_offset = 10 obs_time = 30 source = "casa" #source = "moon" ata_control.try_on_lnas(ant_list) #ata_control.make_and_track_ephems(source, ant_list) ata_control.create_ephems2(source, az_offset, el_offset) #freqs = np.arange(1200, 8000, 400) freqs = np.arange(1000, 11000, 500) for freq in freqs: print (freq) ata_control.set_freq(freq, ant_list) # record on ata_control.point_ants2(source, "on", ant_list) ant_list.append('rfi') utc = snap_dada.start_recording(ant_list, obs_time) ant_list.remove('rfi') # record off ata_control.point_ants2(source, "off", ant_list) ant_list.append('rfi') utc = snap_dada.start_recording(ant_list, obs_time) ant_list.remove('rfi') ata_control.release_antennas(ant_list, True)
def handle_msg(self, msg): ''' message handler function''' self.obs_info = pmt.to_python(msg) cfreq = self.obs_info['freq'] ant_list = [ a.strip() for a in self.obs_info['antennas_list'].split(',') ] self.my_ants = ant_list ## Set the center frequency (if you have permission), and/or ## ## set the feed focus frequency, and turn on the LNAs ## if not self.is_configured: if cfreq and self.my_ants: if self.is_user: ac.try_on_lnas(self.my_ants) ac.set_freq(cfreq - FREQ_OFF, self.my_ants, lo=USRP_LO) else: ac.try_on_lnas(self.my_ants) ac.set_freq_focus(cfreq - FREQ_OFF, self.my_ants, lo=USRP_LO) elif cfreq and not self.my_ants: print("No antenna list specified. You must specify \n" "one or more antennas in order to observe.") elif self.my_ants and not cfreq: print("No center frequency specified. You must specify \n" "a center frequency in order to observe.") else: print("You have not specified an antennas list or \n" "a frequency setting. Please specify an antennas \n" "list and the center frequency, then try again.") ## Run observation ## if 'source_id' in self.obs_info: #First, check if this is an off-source scan if ('az_off' and 'el_off') in self.obs_info: self.point_src_id(self.obs_info['source_id'], self.my_ants, True, self.obs_info['az_off'], self.obs_info['el_off']) #if not, observe on-source else: self.point_src_id(self.obs_info['source_id'], self.my_ants) elif ('ra' and 'dec') in self.obs_info: #run ra / dec observation #First, check if this is an off-source scan if ('az_off' and 'el_off') in self.obs_info: self.point_src_radec(self.obs_info['ra'], self.obs_info['dec'], \ self.my_ants, True, self.obs_info['az_off'], \ self.obs_info['el_off']) #if not, observe on-source else: self.point_src_radec(self.obs_info['ra'], self.obs_info['dec'], \ self.my_ants) elif ('az' and 'el') in self.obs_info: #run az / el observation #First, check if this is an off-source scan if ('az_off' and 'el_off') in self.obs_info: self.point_src_azel(self.obs_info['az'], self.obs_info['el'], \ self.my_ants, self.obs_info['az_off'], \ self.obs_info['el_off']) #if not, observe on-source else: self.point_src_azel(self.obs_info['az'], self.obs_info['el'], self.my_ants) else: print("You have not specified a source location. \n" "Please specify a target source and try again.") self.is_configured = True
def theMainFunction(various_options): #ant_list = ['1a','2b'] logger = logger_defaults.getModuleLogger(__name__) try: ata_control.reserve_antennas(ant_list) except: logger.exception("can't reserve antennas") raise try: #there is no guarantee that the antenna LNA's are on. Check it and if needed turn them on ata_control.try_on_lnas(ant_list) #point the antenna to the source after generation the ephemeris. This function may be #insufficient for some non-standard targets. notify me (J.S. Kulpa) if it needs expanding ata_control.make_and_track_ephems(source, ant_list ); #autotune the pam values ata_control.autotune(ant_list) #set LO A and feed focus ata_control.set_freq(freq, full_ant_str) #snap0-2 only: #if using RFSwitch, switch to those antennas. In general, using RFswitch means that you should use also #ant_groups = ata_control.get_snap_dictionary(ant_list) #so you know which antennas are hooked up where andin general use only one ant from each group at a time #and build cirrent_ant_list based on ant_groups #ata_control.rf_switch_thread(current_ant_list) #also if using snaps, you should probably call #attendict = snap_observations.setRMS(ant_dict,fpga_file,default_rms) #cobsid = snap_observations.record_same(...) #obs_db.updateAttenVals(cobsid,attendict) #obs_db.markRecordingsOK([cobsid]) #and that's it #but let's get away from snap0-2 from now on, so you are free to ignore it completely #grouping recordings into observation set #if you want to create new observation set, call: #obs_set_id = obs_db.getNewObsSetID("THIS IS MY OBS SET DESCRIPTION!") #if you already have an exiting observation set, make sure it does exist: #obs_db.getSetData(obs_set_id) #if it is a single-shot, leave it as none #obs_set_id=None #initializing the new recording for backend and type see: #ATAobs.obs_common.getRecType and ATAobs.obs_common.getRecBackend recid = obs_db.initRecording(freq,obstype,backend,desc,obsuser,obs_set_id) #now, we populate the second table with each antenna pointing #most likely az_ and el_offset should be set to 0 #the last one is set to True to fetch pam settings to the db obs_db.initAntennasTable(recid,ant_list,source,az_offset,el_offset,True) #we are about to start the recordings, let's note what the starting time is obs_db.startRecording(recid) #here you should put your function call to do the recording and wait for it to be complete #if you are calculating the signal power, in the meantime of afterwards tou can you can call: obs_db.updateRMSVals(recid,rmsDict) #where rmsdict looks like that: #rmsDict={'1a':{'rmsx': 15.2,'rmsy':16.231}} #or #rmsDict={'1a':{'rmsx': 15.2,'rmsy':16.231},'2b':{'rmsx': 15.2,'rmsy':16.231}} #ok, measurements are done, so: obs_db.stopRecording(recid) #now, if it was a single shot or measurements in the set are independent from each other, call obs_db.markRecordingsOK([recid]) #but if this is a set of recordings (e.g. On-Off where a you need several recordings close in time #to finish successfully, you should wait and populate a list of recordings, then call #obs_db.markRecordingsOK(all_that_recids) except: #do whatever you want if something crashed, Yes, some functions can raise the exception finally: #does not matter if that succeeded or not, you should always release the antennas # the do_park bool determines if the antennas should go back do default position # for the debugging process, it's better to let them be, because you won't waste time # to re-acquire the source, but in normal operation you should by default part the antennas ata_control.release_antennas(ant_list, do_park)
def doOnOffObservations(ant_str,freq_str, pointings_str,az_offset,el_offset,repetitions,ncaptures,obs_set_id,fpga_file): logger = logger_defaults.getModuleLogger(__name__) ant_list = snap_array_helpers.string_to_array(ant_str); pointings = snap_array_helpers.string_to_array(pointings_str); freq_list = snap_array_helpers.string_to_numeric_array(freq_str); ant_list = remove_dups(ant_list) full_ant_str = snap_array_helpers.array_to_string(ant_list) info_string = ("OnOff Started\nDataset ID {7}\n\nAnts: {0!s}\nFreq: {1!s}\n" "Pointings: {2!s}\nOff positions: Az={3:3.2f} El={4:3.2f}\n" "Repetitions {5:d}\nCaptures {6:d}").format(full_ant_str, freq_str, pointings_str,az_offset,el_offset,repetitions,ncaptures,obs_set_id) logger.info(info_string) logger.warning("Communication disabled, edit code") ATAComm.sendMail("SNAP Obs started",info_string) ATAComm.postSlackMsg(info_string) try: ant_groups = ata_control.get_snap_dictionary(ant_list) except: logstr = "unable to match antennas with snaps" logger.exception(logstr) ATAComm.sendMail("SNAP Obs exception",logstr) raise #getting the antennas. From now on we can modify any antenna parameters # Reserve the antennas logger.info("Reserving antennas %s in bfa antgroup" % full_ant_str) try: ata_control.reserve_antennas(ant_list) except: logstr = "unable to reserve the antennas" logger.exception(logstr) ATAComm.sendMail("SNAP Obs exception",logstr) raise # For each SNAP. set the minicircuits attenuators to 12.0 # To do this, get a list of the first antenna in each snap group try: default_atten_db = 12 # Suggested by jack antpols_list_list = [] atten_list_list = [] for a in ant_groups.keys(): antpols_list_list.append(["%sx"%ant_groups[a][0],"%sy"%ant_groups[a][0]]) atten_list_list.append([default_atten_db, default_atten_db]) ata_control.set_atten_thread(antpols_list_list,atten_list_list) except: logstr = "unable to set attenuators" logger.exception(logstr) ATAComm.sendMail("SNAP Obs exception",logstr) ata_control.release_antennas(ant_list, True) raise current_source = None new_antennas = True logger.info("starting observations") try: ata_control.try_on_lnas(ant_list) while(1): new_antennas = True #gets a antenna dictionary and curr_ant_dict,curr_freq_list = onoff_db.get_obs_params(obs_set_id,pointings,ant_groups,freq_list) #if None, it meast that all was measured if not curr_ant_dict: logger.info("all seems to be measured") break for curr_freq in curr_freq_list: current_source,was_changed = ata_positions.ATAPositions.getPreferedSourceUp(current_source,pointings) if not current_source: errormsg = 'no source is up ({}). terminating observation set {}'.format(','.join(pointings),obs_set_id) logger.error(errormsg) raise RuntimeError(errormsg) #we either changed antennas or changed source. #need to generate the ephemeris and autotune PAMs if was_changed: #if we only switched the antennas, we don't need to regenerate # the ephemeris logger.info("source changed to {}".format(current_source)) ata_control.create_ephems(current_source, az_offset, el_offset); if( was_changed or new_antennas): logger.info("need to (re)run autotune") curr_ant_list = snap_array_helpers.dict_to_list(curr_ant_dict) curr_ant_string = snap_array_helpers.array_to_string(curr_ant_list) logger.info("pointing the antennas") ata_control.point_ants("on", curr_ant_string ); logger.info("autotuning") ata_control.autotune(curr_ant_string) ata_control.rf_switch_thread(curr_ant_list) new_antennas = False logger.info("changing to frequency {}".format(curr_freq)) ata_control.set_freq(curr_freq, curr_ant_string) onoff_observations(curr_ant_dict,obs_set_id,curr_freq,fpga_file,current_source,repetitions,ncaptures,az_offset,el_offset) #snap_control.do_onoff_obs(args.hosts, \ # "/home/sonata/dev/ata_snap/snap_adc5g_spec/outputs/snap_adc5g_spec_2018-06-23_1048.fpg", \ # source, args.ncaptures, args.repetitions, ants_to_observe, freq, obsid, 0.0, 10.0) #now, we believe we have measured all frequencies for curr_ant_dict, so we may #remove the content of it from our original ant_groups. Note that this function #alters the ant_groups! onoff_db.remove_antennas_from_dict(ant_groups,curr_ant_dict); ATAComm.sendMail("SNAP Obs End","Finishing measurements - success") ATAComm.postSlackMsg("Finishing measurements - success") except KeyboardInterrupt: logger.info("Keyboard interuption") ATAComm.sendMail("SNAP Obs End","Finishing measurements - keyboard interrupt, obsid {}".format(obs_set_id)) ATAComm.postSlackMsg("Finishing measurements - keyboard interrupt") except Exception as e: logger.exception("something went wrong") errmsg = "Finishing measurements - failed, obsid {}: {}".format(obs_set_id,e) ATAComm.sendMail("SNAP Obs End",errmsg) ATAComm.postSlackMsg(errmsg) raise finally: logger.info("shutting down") ata_control.release_antennas(ant_list, True)
def main(): logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO) options = pol.argument_parser().parse_args() if gr.enable_realtime_scheduling() != gr.RT_OK: logging.warning("Error: failed to enable real-time scheduling.") tb = pol.flowgraph(directory=options.directory, gaindB=options.gaindB, samp_rate=options.samp_rate, src_name=obs_source, lo_freq = obs_freqs[0]) def sig_handler(sig=None, frame=None): tb.stop() tb.wait() park_antennas() logging.shutdown() sys.exit(0) signal.signal(signal.SIGINT, sig_handler) signal.signal(signal.SIGTERM, sig_handler) logging.info('Setting up feeds and IF switch') if do_observation: ac.try_on_lnas(antennas) ac.set_freq(obs_freqs[0], antennas, lo) ac.rf_switch_thread(antennas) ac.set_atten_thread([[f'{ant}x',f'{ant}y'] for ant in antennas], [[if_switch_att,if_switch_att] for _ in antennas]) else: time.sleep(1) logging.info('Feeds and IF set') logging.info(f'Slewing to source {obs_source}') if do_observation: ac.make_and_track_source(obs_source, antennas) else: time.sleep(1) logging.info(f'On source {obs_source}') logging.info('Running autotune') if do_observation: ac.autotune(antennas) logging.info(f'Detectors: {ac.get_dets(antennas)}') logging.info(f'PAMs: {ac.get_pams(antennas)}') else: time.sleep(1) logging.info('Autotune done') first_period = True while True: for freq in obs_freqs: if not first_period: logging.info(f'Setting LO {lo} to {freq} MHz') if do_observation: ac.set_freq(freq, antennas, lo) else: time.sleep(1) logging.info('LO set') else: logging.info(f'Starting first observation at {freq} MHz') logging.info('Starting recording') if first_period: first_period = False tb.make_sinks(freq) tb.start() else: tb.reload_sinks(freq) tb.unlock() time.sleep(obs_period) tb.lock() logging.info('Stopping recording')
def do_snap_rec(ant_str, freq, source, ncaptures, obs_set_id, fpga_file, obsuser, obstype, obsdesc, do_park=False): logger = logger_defaults.getModuleLogger(__name__) ant_list = snap_array_helpers.string_to_array(ant_str) full_ant_str = snap_array_helpers.array_to_string(ant_list) try: ant_groups = ata_control.get_snap_dictionary(ant_list) except: logstr = "unable to match antennas with snaps" logger.exception(logstr) raise ant_dict = {} for csnap in ant_groups: if len(ant_groups[csnap]) != 1: logger.error( 'only one antenna per snap allowed, got {}: {}'.format( csnap, ",".join(ant_groups[csnap]))) raise RuntimeError("only 1 antenna per snap allowed") ant_dict[csnap] = ant_groups[csnap][0] if obs_set_id: info_string = ( "Starting observation:\nDataset ID {4:d}\n\nAnts: {0!s}\nFreq: {1:0.2f}\n" "Source: {2:s}\nCaptures {3:d}\n" "Type: {5:s} by {6:s} [{7:s}]").format(full_ant_str, freq, source, ncaptures, obs_set_id, obstype, obsuser, obsdesc) else: info_string = ( "Starting observation:\nNO Dataset ID!\n\nAnts: {0!s}\nFreq: {1:0.2f}\n" "Source: {2:s}\nCaptures {3:d}\n" "Type: {5:s} by {6:s} [{7:s}]").format(full_ant_str, freq, source, ncaptures, obs_set_id, obstype, obsuser, obsdesc) logger.info(info_string) ATAComm.sendMail("SNAP Obs started", info_string) ATAComm.postSlackMsg(info_string) logger.info("Reserving antennas %s in bfa antgroup" % full_ant_str) try: ata_control.reserve_antennas(ant_list) except: logstr = "unable to reserve the antennas" logger.exception(logstr) ATAComm.sendMail("SNAP Obs exception", logstr) raise logger.info("starting observations") try: ata_control.try_on_lnas(ant_list) source_status = ata_positions.ATAPositions.getFirstInListThatIsUp( [source]) if not source_status: errormsg = 'source {} is not up (or too close to sun/moon)... terminating observation set {}'.format( source, obs_set_id) logger.error(errormsg) raise RuntimeError(errormsg) if source_status['status'] != 'up': if source_status['status'] == 'next_up': errormsg = 'source {} is not up (or too close to sun/moon). Will be up in {} minutes. Terminating observation set {}'.format( source, source_status['minutes'], obs_set_id) else: errormsg = 'source {} is not up (or too close to sun/moon)... terminating observation set {}'.format( source, obs_set_id) logger.error(errormsg) raise RuntimeError(errormsg) logger.info("pointing the antennas") ata_control.make_and_track_ephems(source, full_ant_str) logger.info("autotuning") ata_control.autotune(full_ant_str) ata_control.rf_switch_thread(ant_list) logger.info("changing to frequency {}".format(freq)) ata_control.set_freq(freq, full_ant_str) single_snap_recording(ant_dict, obs_set_id, obstype, obsuser, obsdesc, freq, fpga_file, source, ncaptures) ATAComm.sendMail("SNAP recording ended", "Finishing measurements - success") ATAComm.postSlackMsg("Finishing recording - success") except KeyboardInterrupt: logger.info("Keyboard interuption") ATAComm.sendMail( "SNAP recording ended", "Finishing measurements - keyboard interrupt, obsid {}".format( obs_set_id)) ATAComm.postSlackMsg("Finishing recording - keyboard interrupt") except Exception as e: logger.exception("something went wrong") errmsg = "Finishing recording - failed, obsid {}: {}".format( obs_set_id, e) ATAComm.sendMail("SNAP recording ended", errmsg) ATAComm.postSlackMsg(errmsg) raise finally: logger.info("shutting down") ata_control.release_antennas(ant_list, do_park)