def write_footer(rootname, calcfile=sys.stdout): """ Write last 2 lines of the calc file. """ print "Write last 2 lines of the calc file" print_parameter("DELAY FILENAME", rootname + '.delay', calcfile) print_parameter("UVW FILENAME", rootname + '.uvw', calcfile)
def write_scan(vex_path, calcfile, offset=None, tail=None, inc=None, obscode=None): print 'Writing scan table of calc table' if offset == None: offset = observation.offset if tail == None: tail = observation.tail if inc == None: inc = observation.increment if obscode == None: obscode = '' #get info from vex file source_dict = VexSource(vex_path) sched = VexSched(vex_path) #initialise variables n_scan = -1 laststart = 0 lastpoints = 0 thisstart = 0 thispoints = 0 thisend = 0 nextstart = 0 nextpoints = 0 nextsource = '' nextra = 0 nextdec = 0 nextcalcode = ' ' print_parameter('NUM SCANS', len(sched.keys()), calcfile) for scan in sched.keys(): # This loop goes over every scan, and for each # Writing out the *previous* scan: # i.e. # everything read in current loop is called next* # on the next loop this is copied to this* # on the next loop this is copied to last* laststart = thisstart lastend = thisend thisstart = nextstart thissource = nextsource thisra = nextra thisdec = nextdec thiscalcode = nextcalcode #get new info time = sched[scan]['start'][0] day = int(datetime2mjd(time)) nextstart = (day * 86400 + (time.hour * 3600.0) + (time.minute * 60) + time.second) / inc nextsource = sched[scan]['source'][0] try: nextra = source_dict[nextsource]['ra'][0] nextdec = source_dict[nextsource]['dec'][0] except: raise RuntimeError, "unknown source " + nextsource # check all the stations have the same duration # if not warn and take the longest duration = sched[scan]['station'][0][2] for i in range(1, len(sched[scan]['station'])): if not duration == sched[scan]['station'][i][2]: 'Warning Strange durations in scan ' + scan if duration < sched[scan]['station'][i][2]: duration = sched[scan]['station'][i][2] if n_scan == -1: first = nextstart nextstart -= first # nextstart is the start of the current pointing # nextstart + nextpoints is the end of the current pointing # lastpoint is the start of the last pointing # lastpoint + lastpoints is the end of the last pointing # we are actually writing lastpoint if n_scan >= 0: #run on everyloop except the first npoints = nextstart - thisstart thisstarthms = df2hms((first + thisstart - offset) * inc / 86400.) thisendhms = df2hms( (first + thisstart - offset + npoints) * inc / 86400.) printscan(n_scan, thisstart - offset, npoints, thissource, thisra, thisdec, thiscalcode, obscode, calcfile) n_scan += 1 #print out last scan once we've fallen off the end of the loop npoints = duration + tail nextstarthms = df2hms((first + nextstart - offset) * inc / 86400.) nextendhms = df2hms((first + nextstart - offset + npoints) * inc / 86400.) printscan(n_scan, nextstart - offset, npoints, nextsource, nextra, nextdec, nextcalcode, obscode, calcfile)
def printscan(n_scan, start, npoints, source, ra, dec, calcode, obscode, calcfile): scan = "SCAN %d " % (n_scan) print_parameter(scan + 'POINTS', str(int(npoints)), calcfile) print_parameter(scan + 'START PT', str(int(start)), calcfile) print_parameter(scan + 'SRC NAME', obscode + '_default', calcfile) print_parameter(scan + 'REAL NAME', source, calcfile) print_parameter(scan + 'SRC RA', '%.15f' % ra, calcfile) print_parameter(scan + 'SRC DEC', '%.15f' % dec, calcfile) print_parameter(scan + 'CALCODE', calcode, calcfile) print_parameter(scan + 'QUAL', 0, calcfile)
def create_eop_table(mjd, eop_file, iat_file, calcfile, extra=2, ndays=0): """ call create_eop_list and print a calc table to calcfile """ print 'Writing EOP table of calc file' eop_array = create_eop_list(mjd, eop_file, iat_file, extra, ndays) num = len(eop_array[0]) print_parameter("NUM EOP", str(num), calcfile, 22) for i in range(num): print_parameter('EOP ' + str(i) + ' TIME (mjd)', '%.6f' % eop_array[0][i], calcfile, 22) print_parameter('EOP ' + str(i) + ' TAI_UTC (sec)', '%.0f' % eop_array[1][i], calcfile, 22) print_parameter('EOP ' + str(i) + ' UT1_UTC (sec)', '%.6f' % eop_array[2][i], calcfile, 22) print_parameter('EOP ' + str(i) + ' XPOLE (arcsec)', '%.6f' % eop_array[3][i], calcfile, 22) print_parameter('EOP ' + str(i) + ' YPOLE (arcsec)', '%.6f' % eop_array[4][i], calcfile, 22)
root = args[0] inputfilepath = root + '.input' # set defaults obscode = root job_id = None increment = None spectral_average = None taper_function = None calcfile = None for o, a in opts: if o == "--obscode": obscode = a if o == "--jobid": jobid = a if o in ("-i", "--increment"): increment = int(a) if o == "--spectralaverage": spectral_average = a if o == "--taperfunction": taper_function = a for i in calc_gen(inputfilepath, obscode, job_id, increment, spectral_average, taper_function): print_parameter(i[0], i[1]) if __name__ == "__main__": main()
def write_header(vex_path, calcfile, obscode="", job_id=None, increment=None, spectral_average=None, taper_function=None): print "Writing header of .calc file" try: difx_version = os.environ['DIFX_VERSION'] except: print "Warning, DIFX_VERSION not set. Setting to ''" difx_version = '' sched = VexSched(vex_path) #cross match telescope names against input file in final version? i = 0 if job_id == None: job_id = observation.job_id if increment == None: increment = observation.increment if spectral_average == None: spectral_average = observation.spectral_average if taper_function == None: taper_function = observation.taper_function start_datetime = sched[sched.keys()[0]]['start'][0] start_time = str(datetime2mjd(start_datetime)) last_scan = datetime2mjd(sched[sched.keys()[-1]]['start'][0]) end_time = last_scan + float( sched[sched.keys()[-1]]['station'][0][2]) / 86400. print_parameter("JOB ID", job_id, calcfile) print_parameter("JOB START TIME", start_time, calcfile) print_parameter("JOB END TIME", +end_time, calcfile) print_parameter("DUTY CYCLE", 1.0, calcfile) print_parameter("OBSCODE", obscode.upper(), calcfile) print_parameter("DIFX VERSION", difx_version, calcfile) print_parameter("SUBJOB ID", '0', calcfile) print_parameter("START MJD", start_time, calcfile) print_parameter("START YEAR", start_datetime.year, calcfile) print_parameter("START MONTH", start_datetime.month, calcfile) print_parameter("START DAY", start_datetime.day, calcfile) print_parameter("START HOUR", start_datetime.hour, calcfile) print_parameter("START MINUTE", start_datetime.minute, calcfile) print_parameter("START SECOND", start_datetime.second, calcfile) print_parameter("INCREMENT (SECS)", increment, calcfile) print_parameter("SPECTRAL AVG", spectral_average, calcfile) print_parameter("TAPER FUNCTION", taper_function, calcfile)
def write_antenna(vex_path, calcfile, antennas=None): site = VexSite(vex_path) antenna = VexAntenna(vex_path) # cross match telescope names against input file in final version? i = 0 if not antennas: try: antennas = observation.antennas except AttributeError: antennas = site.id_dict().keys() antennas.sort() print "Writing antenna table of calc file" print_parameter("NUM TELESCOPES", len(antennas), calcfile) for telescope in antennas: name = telescope.upper() fullname = site.id_dict()[telescope] print_parameter("TELESCOPE %d NAME" % i, name, calcfile) # TODO look up different types of mount and how they are notated in vex file and # for calc file if True: #if antenna[site[telescope]['site_name']]['axis_type'] == ['az', 'el']: print_parameter("TELESCOPE %d MOUNT" % i, 'azel', calcfile) else: print antenna[site[fullname]['site_name']]['axis_type'][0] raise RuntimeError, 'unknown axis type' print_parameter("TELESCOPE %d OFFSET (m)" % i, '%.6f' % (antenna[fullname]['axis_offset'][-1]), calcfile) print_parameter("TELESCOPE %d X (m)" % i, '%.6f' % site[fullname]['site_position'][0], calcfile) print_parameter("TELESCOPE %d Y (m)" % i, '%.6f' % site[fullname]['site_position'][1], calcfile) print_parameter("TELESCOPE %d Z (m)" % i, '%.6f' % site[fullname]['site_position'][2], calcfile) #print_parameter("TELESCOPE %d SHELF" % i, "NONE", calcfile) i += 1
sys.exit(2) if not len(args) == 1: print 'Error Wrong number of arguments' print main.__doc__ sys.exit(2) # read arguments logfilename = args[0] # set defaults inputtime = None telescope_index = 0 for o, a in opts: if o in ("-t", "--time"): inputtime = datetime(*strptime(a, "%Y%m%dT%H%M%S")[0:6]) log.debug('start time: ' + inputtime.isoformat()) elif o in ("-i", "--index"): telescope_index = int(a) log.debug('telescope_index: ' + a) intercept, rate = log2delay(logfilename, inputtime) l = clock_parameters(intercept, rate, telescope_index) for line in l: print_parameter(line[0], line[1]) if __name__ == "__main__": main()