Beispiel #1
0
def m5_to_vextime(m5time):
    """Convert from m5time (MJD = MJD/hh:mm:ss.ss) to vex time"""

    if m5time is None:
        return m5time
    m5time = m5time.split("=")[1]
    m5time = m5time.strip()
    # convert m5time to constitute parts, noting this match truncates the
    # seconds (which vextime requires anyway)
    day, hours, mins, secs = re.match(r"(\d+)/(\d+):(\d+):(\d+)",
                                      m5time).groups()
    day = int(day)
    hours = int(hours)
    mins = int(mins)
    secs = int(secs)

    # account for fact that sometimes day wraps in m5time aren't recognised so
    # get times like: 56990/24:00:01.00 instead of the expected
    # 56991/00:00:01.00
    while hours >= 24:
        hours -= 24
        day += 1

    fracday = hours / 24. + mins / (24. * 60.) + secs / (24. * 60. * 60.)
    vextime = espressolib.convertdate(day + fracday, outformat="vex")

    return vextime
Beispiel #2
0
def parse_clock(line, gps_style):
    """Find gps/fmout lines in the log, extract offset and time, convert to
    clock offset with common convention

    Returns time and offset, or None if line did not parse
    Example line:
2018.250.12:44:03.01/fmout-gps/+7.1182E-006
or
2019.192.18:42:11.36#maser#/maser2gps/+7.6755E-006
    """

    date_re = r"(\d{4})\.(\d{3})\.(\d{2}):(\d{2}):(\d{2})"
    clockline = None
    #clockline = re.match(date_re + ".*/(.*fmout.*)/(.*)$", line)
    clockline = re.match(date_re + r".*/(.*gps.*)/(\S*)", line)
    if not clockline:
        return None
    year, doy, hour, minute, sec, clocktype, offset = clockline.groups()
    offset = float(offset)
    if re.match(gps_style + r"[-2]gps", clocktype):
        offset *= -1e6
    elif re.match(r"gps[-2]" + gps_style, clocktype):
        offset *= 1e6
    else:
        return None
    #else:
    #    sys.stdout.write("Clock type not recognised: " + clocktype + "\n")
    #    return None

    vextime = year + "y" + doy + "d" + hour + "h" + minute + "m" + sec + "s"
    time = espressolib.convertdate(vextime)
    return time, offset
Beispiel #3
0
Multiple dates can be given (separated by spaces)
"""

parser = optparse.OptionParser(usage=usage, version="%prog " + "2.0")
parser.add_option(
    "--format",
    "-f",
    type="str",
    dest="outformat",
    default=None,
    help="Output format (vex, vlba, iso, mjd). "
    "Default is mjd unless first input format is mjd, then vex is default")
(options, args) = parser.parse_args()

if len(args) < 1:
    parser.print_help()
    parser.error("At least 1 date required")

# by default, convert to MJD except for MJD which converts to vex
outformat = options.outformat
if outformat is None:
    try:
        indate = float(args[0])
        outformat = "vex"
    except ValueError:
        outformat = "mjd"
outformat = outformat.lower()

for indate in args:
    print(espressolib.convertdate(indate, outformat))
Beispiel #4
0
(options, args) = parser.parse_args()

if len(args) < 1:
    parser.print_help()
    parser.error("Give date(s) in MJD, VEX, ISO8601 or VLBA format")

atca_url_template = (
        "http://www.atnf.csiro.au/cgi-bin/vlbi/atca_summary.pl?"
        "start={}&end={}&year={}&site=ATCA")
#print >>sys.stderr, "Fetching ATCA status from", atca_url_template

refant_pad = None
for targetdate in args:
    # convert targetdate to vex
    targetdate = espressolib.convertdate(targetdate, "vex")
    # convert from vex to atca_summary format
    startdate, enddate, year = vexdate2atca(targetdate)

    # fetch atca summary data
    url = atca_url_template.format(startdate, enddate, year)
    atca_summary = requests.get(url).content.split("\n")

    # parse the summary page
    refant_pad = None
    pads = []
    for iline, line in enumerate(atca_summary):
        if iline == 1:
            pads = line.split()
        if iline == 2:
            refant = re.sub(r"Refant:\s*CA0", "", line)
Beispiel #5
0
    parser.error("Give at least one .joblist file")

jobfilenames = args
line_format = "{:s}: {:s} \t {:0.3f} {:s} \t {:0.2f} {:s} \t {:d} {:s} {:s}"
summary_format = "{:s}: {:0.3f} {:s} \t {:0.2f} {:s} \t {:0.1f} {:s}"

for jobfilename in jobfilenames:
    jobfile = open(jobfilename).readlines()
    header = jobfile.pop(0)
    print(header)
    passlen = 0
    pass_size = 0
    pass_stations = 0
    for line in jobfile:
        jobinfo = line.split()
        jobstart = espressolib.convertdate(float(jobinfo[1]), outformat="vex")
        joblen = float(jobinfo[2]) - float(jobinfo[1])
        jobstations = int(jobinfo[3])
        jobsize = float(jobinfo[6])
        station_list = " ".join(jobinfo[8:])

        pass_stations = ((jobstations * joblen + pass_stations * passlen) /
                         (joblen + passlen))
        passlen += joblen
        pass_size += jobsize

        print(
            line_format.format(jobinfo[0], jobstart, joblen * 24., "hours",
                               jobsize, "TOps", jobstations, "stations",
                               station_list))
Beispiel #6
0
(options, args) = parser.parse_args()

if len(args) != 1:
    parser.print_help()
    parser.error("Give a date in MJD or VEX format")

if options.vex:
    comment = "*"
else:
    comment = "#"

mjd_jd = 2400000.5
# get target MJD
target_mjd = args[0]
# convert to MJD if necessary
target_mjd = espressolib.convertdate(target_mjd, "mjd")
target_jd = round(target_mjd) + mjd_jd

# dates before June 1979 not valid (earliest EOPs)
if (target_jd < 2444055.5):
    raise Exception("Date too early. No valid EOPs before July 1979")

# fetch EOP data
leapsec_page = None
if not options.local:
    #gsfc_url = "ftp://cddis.gsfc.nasa.gov/vlbi/gsfc/ancillary/solve_apriori/"
    #eop_url = gsfc_url + "usno_finals.erp"
    #leapsec_url = gsfc_url + "ut1ls.dat"
    gsfc_url = "gdc.cddis.eosdis.nasa.gov"
    eop_dir = "vlbi/gsfc/ancillary/solve_apriori/"
    eop_filename = "usno_finals.erp"
Beispiel #7
0
def check_file(infile, m5bopts):
    """ check each file, then return time range and format. Check for
    Corrupt/missing files. """

    corrupt = False
    starttime = None
    endtime = None
    m5time = espressolib.which("m5time")
    m5bsum = espressolib.which("m5bsum")
    vsum = espressolib.which("vsum")
    m5findformats = espressolib.which("m5findformats")

    if not os.path.exists(infile):
        sys.stderr.write(infile + " missing\n")
        corrupt = True

    elif os.path.getsize(infile) == 0:
        # 0 file size will cause difx to hang (at least for LBA format)
        sys.stderr.write(infile + " empty\n")
        corrupt = True

    elif re.search(r".lba$", infile):
        # LBA format
        header = vsib_header(infile)
        if not (header and re.match(r"^TIME\s\d{8}:\d{6}", header[0])):
            if (header):
                sys.stderr.write("header for " + infile + " is corrupt: " +
                                 header[0] + "\n\n")
            else:
                sys.stderr.write("header for " + infile +
                                 " is corrupt or missing\n\n")
            corrupt = True

        try:
            starttime, endtime = lbafile_timerange(infile, header)
        except:
            corrupt = True

    elif (m5bsum and m5time and vsum and m5findformats):
        # assume it is a mark5 or vdif file of some description. Details of
        # the format are not very important for extracting the start time
        # (YMMV). If we don't have m5bsum and m5time in our path we simply will
        # not do this.

        summary_program = " ".join([m5bsum, m5bopts])

        if '.vdif' in infile.lower():
            # assume we must have a VDIF file.

            summary_program = vsum

        try:
            # get the start/stop time with m5bsum/vsum
            command = " ".join([summary_program, "-s", infile])
            error = str()
            m5bsum_out, error = subprocess.Popen(
                command,
                shell=True,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE).communicate()
            starttime_m5, endtime_m5 = m5bsum_out.split()[1:3]
            starttime = espressolib.convertdate(float(starttime_m5), "vex")
            endtime = espressolib.convertdate(float(endtime_m5), "vex")
            #print starttime, endtime
        except:
            try:
                # must be a mark5a then.
                #sys.stderr.write(infile)
                command = " ".join([m5findformats, infile])
                stdout, error = subprocess.Popen(
                    command,
                    shell=True,
                    stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE).communicate()
                #sys.stderr.write(error)
                stdout = stdout.decode("utf-8")
                error = error.decode("utf-8")
                m5_output = stdout.split("\n")
                m5format = parse_m5findformats(m5_output)
                command = " ".join([m5time, infile, m5format])
                starttime_m5, error = subprocess.Popen(
                    command,
                    shell=True,
                    stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE).communicate()
                #sys.stderr.write(error)

                lastsample = 1000000
                filesize = os.path.getsize(infile)
                command = " ".join(
                    [m5time, infile, m5format,
                     str(filesize - lastsample)])
                endtime_m5, error = subprocess.Popen(
                    command,
                    shell=True,
                    stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE).communicate()
                #sys.stderr.write(error)

                starttime = m5_to_vextime(starttime_m5)
                endtime = m5_to_vextime(endtime_m5)

            except:
                # couldn't decode time.
                sys.stderr.write("cannot decode time for " + infile + "\n\n")
                sys.stderr.write(error)

                starttime = None
                endtime = None

        if not starttime:
            # we know nothing about this format, abandon this file
            corrupt = True

    return infile, starttime, endtime, corrupt
Beispiel #8
0
    will check the VLBI baseband files listed in <datafiles.dat> for validity
    and return the list with their stop/start times appended in format suitable
    for vex2difx. Works for LBA, Mark5A/B, VDIF formats.
    """
    parser = optparse.OptionParser(usage=usage, version="%prog " + "1.0")
    parser.add_option("-r",
                      "--refmjd",
                      type="str",
                      dest="refmjd",
                      default=None,
                      help="Reference date for resolving Mk5B date ambiguity.")
    (options, args) = parser.parse_args()

    m5bopts = ""
    if options.refmjd is not None:
        refmjd = espressolib.convertdate(options.refmjd, outformat="mjd")
        m5bopts = " ".join(["-r", str(refmjd)])
    else:
        refmjd = None

    # read the list of files
    filelist = []
    outfilelist = []
    for filelistname in args:
        filelist += open(filelistname).readlines()
        filelist = [line.rstrip() for line in filelist]

    # check each file, then print it with its time range.

    for infile in filelist:
        outfile = check_file(infile, m5bopts)
Beispiel #9
0
                  help="Subtract specified delay from all stations")

(options, args) = parser.parse_args()
if len(args) != 1:
    parser.print_help()
    parser.error("no v2d file given")

if options.rate_adjust and not options.frequency:
    raise Exception(
        "You must set the frequency (-f) if you are adjusting the rate!")

newclockepoch = options.newclockepoch

if newclockepoch:
    # convert to MJD
    newclockepoch = espressolib.convertdate(newclockepoch, "mjd")

station_list = []
offset_list = []
rate_list = []
if options.stations:
    station_list = re.sub(r"\s*", "", options.stations)
    station_list = station_list.split(",")
    station_list = [station.upper() for station in station_list]
if options.offset_adjust:
    offset_list = options.offset_adjust.split(",")
if options.rate_adjust:
    rate_list = options.rate_adjust.split(",")

if options.stations:
    if options.offset_adjust and len(offset_list) != len(station_list):
Beispiel #10
0
  clockEpoch = {epoch:0.3f}
}}
"""

vex_format = """
  def {station:s};
*                 Valid from          clock_early  clock_early_epoch    rate
    clock_early = {epoch_valid:s} : {offset:0.3f} usec : {epoch:s} : {rate:0.3E} ;
  enddef;
"""

epoch_valid = None
if options.vex:
    # clock in usec, rate in sec/sec, dates in vex format, reverse sign
    # convention
    epoch = espressolib.convertdate(times[0], outformat="vex")
    # make valid from 1 day before first gps measure
    epoch_valid = espressolib.convertdate((times[0] - 1.0), outformat="vex")
    offset = offset * -1.
    rate = rate / (-24. * 3600. * 1e6)
    output_format = vex_format
else:
    # clock in microsec, rate in microsec/sec, dates in MJD
    rate = rate / (24. * 3600.)
    epoch = times[0]
    output_format = v2d_format

print(
    output_format.format(station=station.upper(),
                         epoch_valid=epoch_valid,
                         epoch=epoch,