def confluencer(inlist):
    """
    Given a list of filenames, parse each one and print the relevant
    observing leg details (as well as takeoff and landing details).

    The formatting is specific to Confluence; to insert the results:
        - In the editor toolbar, click on the + icon
          ("Insert More Content") and choose "{ } Markup"

          - FOR HAWC+ Confluence (5.9.8 or higher)
             - Choose "Confluence Wiki" as the type, and paste the output
               into the lefthand window; it should then preview nicely on right

          - FOR NASA Confluence (5.4.ish)
             - Just paste the output into the box and insert it; it'll preview
               in the main editor window and should be fine
    """

    for i, each in enumerate(inlist):
        # Where the magic happens
        flight = fpmis.parseMIS(each)

        print "*FLIGHT %02d*" % (i + 1)
        print "*Notes:*\n"
        print "Flight Plan Filename: %s, Vintage: %s" %\
            (flight.filename, flight.saved)

        summy = flight.summarize()
        # Break at the line breaks so we can indent it
        #   (ended up taking out the tabs, but keeping this in case we want it)
        summarylines = summy.split("\n")
        for line in summarylines:
            print "%s" % (line)
        print ""

        for j, oach in enumerate(flight.legs):
            if oach.legtype != "Observing":
                oach.ra = None
                oach.dec = None
                oach.range_rof = [None, None]
                oach.range_elev = [None, None]

            # print the header before the first leg
            if j == 0:
                print "||*Leg Number*",
                print "||*Time Since Takeoff at Leg Start (hrs)*",
                print "||*Leg Type*||*Target*||*RA (2000)*||*Dec (2000)*",
                print "||*Obs Duration*||*Elevation Range*||*ROF Range*||"

            # Should be self explanatory here
            if oach.legtype == "Takeoff" or oach.legtype == "Landing" or\
               oach.legtype == "Observing":
                print "|%02d|%02.1f|%s|%s|%s|%s|%s|%s, %s|%s, %s|" %\
                      (oach.legno, oach.relative_time[0]/60./60.,
                       oach.legtype, oach.target, oach.ra, oach.dec,
                       oach.obsdur, oach.range_elev[0], oach.range_elev[1],
                       oach.range_rof[0], oach.range_rof[1])
        print "----"

    return 0
def reSTer(title, inlist, makeCommentTemplates=False, clobber=False):
    """
    Given a list of filenames, parse each one and print the relevant
    observing leg details (as well as takeoff and landing details).

    The formatting is specific to some of the specific (table)
    extensions of reST/Markdown.
    """

    print title
    print underliner(title, char="#")
    print ""
    print ".. contents:: Table of Contents"
    print "    :depth: 1"
    print "    :backlinks: top"
    print ""

    for i, each in enumerate(inlist):
        # Where the magic happens
        flight = fpmis.parseMIS(each)

        h1 = "FLIGHT %02d" % (i + 1)
        print underliner(h1)
        print h1
        print underliner(h1)
        print ""
        #
        #        h2 = "Flight Path"
        #        print h2
        #        print underliner(h2)
        #        print ""
        fpimg = each[:-4] + ".png"
        print ".. image:: %s" % (fpimg)
        print ""

        h2 = "Flight Information and Summary"
        print h2
        print underliner(h2)
        print "* Plan Filename: %s, Vintage: %s" %\
            (flight.filename, flight.saved)
        summy = flight.summarize()
        # Break at the line breaks so we can indent it
        #   (ended up taking out the tabs, but keeping this in case we want it)
        summarylines = summy.split("\n")
        for line in summarylines:
            print "* %s" % (line)
        print ""

        # Note that this will grab the table of JUST the
        #   takeoff, observing, and landing leg details
        obstab = []
        obstabhed = []
        for j, oach in enumerate(flight.legs):
            if oach.legtype != "Observing":
                oach.ra = None
                oach.dec = None
                oach.range_rof = [None, None]
                oach.range_elev = [None, None]

            # print the header before the first leg
            if j == 0:
                obstabhed = [
                    "Leg Number", "Time Since Takeoff at Leg Start (hrs)",
                    "Leg Type", "ObsBlk", "Target", "RA (2000)", "Dec (2000)",
                    "Obs Duration", "Elevation Range", "ROF Range"
                ]

            # Should be self explanatory here
            if oach.legtype == "Takeoff" or oach.legtype == "Landing" or\
               oach.legtype == "Observing":
                tabdat = [
                    oach.legno,
                    np.round(oach.relative_time[0] / 60. / 60., 1),
                    oach.legtype, oach.obsblk, oach.target, oach.ra, oach.dec,
                    str(oach.obsdur),
                    str(oach.range_elev),
                    str(oach.range_rof)
                ]

                obstab.append(tabdat)
        tabbie = aptable.Table(rows=obstab, names=obstabhed)
        tabbie.write(sys.stdout, format='ascii.rst')
        print ""

        h3 = "Comments"
        print h3
        print underliner(h3)
        print ""
        flightnotes = []

        if makeCommentTemplates is True:
            flightComFile = each[:-3] + 'rst'
            if os.path.exists(flightComFile) is True and clobber is False:
                print "FATAL ERROR: Output %s exists!" % (flightComFile)
                return -1
            else:
                cf = open(flightComFile, 'w')
                cf.write(".. note::\n")
                cf.write("    * General statements\n")
                cf.write("\n")
                cf.write(".. warning::\n")
                cf.write("    * Risky observations or caveats\n")
                cf.write("\n")
                cf.write(".. error::\n")
                cf.write("    * Broken observations/must be changed\n")
                cf.write("\n")
                cf.close()
        else:
            try:
                f = open(each[:-4] + '.rst')
                flightnotes = f.readlines()
                f.close()
            except IOError:
                pass
            if flightnotes == []:
                print "No supplemental notes"
            else:
                for com in flightnotes:
                    print com.rstrip()
        print ""

    return 0
def reSTer(infile, title, role='Team', outfile=None):
    """
    Given a MIS file, parse it and print out a summary as well as any
    additional specified AOR details for each leg.

    The formatting is specific to some of the specific (table)
    extensions of reST/Markdown.
    """
    if outfile is None:
        print "FATAL ERROR: No output file specified!"
        sys.exit(-1)
    else:
        f = open(outfile, 'w')

    # Where the magic happens
    flight = fpmis.parseMIS(infile)

    h1 = "%s" % (title)
    f.write(underliner(h1) + '\n')
    f.write(h1 + '\n')
    f.write(underliner(h1) + '\n')
    f.write('\n')
    r1 = "Cheat Sheet generated on %s" % (datetime.datetime.now())
    r1 += " by %s in %s mode \n" % (getpass.getuser(), role)
    f.write(r1)
    f.write('\n')

    if role == 'Team':
        h2 = "Flight Path"
        f.write(h2 + '\n')
        f.write(underliner(h2) + '\n')
        f.write('\n')
        fpimg = infile[:-4] + ".png"
        f.write(".. image:: %s\n" % (fpimg))
        f.write('\n')

    h2 = "Flight Metadata"
    f.write(h2 + '\n')
    f.write(underliner(h2) + '\n')
    f.write("* Plan Filename: %s, Vintage: %s\n" %
                 (flight.filename, flight.saved))
    summy = flight.summarize()
    # Break at the line breaks so we can indent it
    #   (ended up taking out the tabs, but keeping this in case we want it)
    summarylines = summy.split("\n")
    for line in summarylines:
        f.write("* %s\n" % (line))
    f.write('\n')

    # Note that this will grab the table of JUST the
    #   takeoff, observing, and landing leg details
    obstab = []
    obstabhed = []
    for j, oach in enumerate(flight.legs):
        if oach.legtype != "Observing":
            oach.ra = None
            oach.dec = None
            oach.range_rof = [None, None]
            oach.range_elev = [None, None]
            oach.range_rofrt = [None, None]
            oach.range_thdgrt = [None, None]

        # print the header before the first leg
        if j == 0:
            obstabhed = ["Leg Number",
                         "Time Since Takeoff at Leg Start (hrs)",
                         "Leg Type", "ObsBlk", "Target",
                         "RA (2000)", "Dec (2000)",
                         "Obs Duration",
                         "Elevation Range",
                         "ROF Range",
                         "ROF Rate", "THdg Rate"]

        # Should be self explanatory here
        if oach.legtype == "Takeoff" or oach.legtype == "Landing" or\
           oach.legtype == "Observing":
            tabdat = [oach.legno,
                      np.round(oach.relative_time[0]/60./60., 1),
                      oach.legtype, oach.obsblk,
                      oach.target, oach.ra, oach.dec,
                      str(oach.obsdur),
                      str(oach.range_elev)[1:-1],
                      str(oach.range_rof)[1:-1],
                      str(oach.range_rofrt)[1:-1],
                      str(oach.range_thdgrt)[1:-1]]

            obstab.append(tabdat)

    if role == 'Team':
        tabbie = aptable.Table(rows=obstab, names=obstabhed)
        tabbie.write(f, format='ascii.rst')
    elif role == 'TO':
        tabbie = aptable.Table(rows=obstab, names=obstabhed)
        tabbie.write(f, format='ascii.csv')

    if role == 'Team':
        output = 'rst'
    elif role == 'TO':
        output = 'tab'

    # Now go leg-by-leg and print out the gory details.
    if role == 'Team':
        f.write('\n')
        h2 = "Leg Specific Details"
        f.write(h2 + '\n')
        f.write(underliner(h2) + '\n')
        try:
            legconfig = conf.SafeConfigParser()
            legconfig.readfp(open(infile[:-4] + '.conf'))
        except IOError:
            pass
        for j, cleg in enumerate(flight.legs):
            sectitle = "Leg %d" % (cleg.legno)

            data = legconfig.has_section(sectitle)
            if data is True:
                f.write('\n')
                f.write(sectitle + '\n')
                f.write(underliner(sectitle, char="-") + '\n')

                items = legconfig.items(sectitle)
                if legconfig.has_option(sectitle, 'aorfile'):
                    aorfilename = legconfig.get(sectitle, 'aorfile')
                    legconfig.remove_option(sectitle, 'aorfile')
                else:
                    aorfilename = []

                if legconfig.has_option(sectitle, 'aors'):
                    aors = legconfig.get(sectitle, 'aors')
                    aors = aors.split(',')
                    aors = [each.strip() for each in aors]
                    legconfig.remove_option(sectitle, 'aors')
                else:
                    aors = []

                items = legconfig.items(sectitle)
                for each in items:
                    f.write("%s \n  %s\n" % (each[0].capitalize(), each[1]))
                f.write('\n')
                if aorfilename != []:
                    # HAWC+ specific parsing
                    paors, pgroups = aorparse.HAWCAORSorter(aorfilename,
                                                            aorids=aors,
                                                            output=output,
                                                            silent=True)
                    asummary = paors.summarize()
                    f.writelines(asummary)
                    f.write('\n')

                    # HAWC+ Specific gropus
                    if pgroups['POLARIZATION'] != []:
                        f.write('\n')
                        f.write("**POLARIZATION NMC**\n")
                        f.write('\n')
                        # PRINT TABLE
                        aorparse.hawcAORreSTer(pgroups['POLARIZATION'],
                                               'POLARIZATION',
                                               outie=f)

                    if pgroups['TOTAL_INTENSITY'] != []:
                        gshort = pgroups['TOTAL_INTENSITY']['OTFMAP']
                        if gshort['Box'] != []:
                            f.write('\n')
                            f.write("**TOTAL_INTENSITY OTFMAP RASTER**\n")
                            f.write('\n')
                            # PRINT TABLE
                            aorparse.hawcAORreSTer(gshort['Box'],
                                                   'OTFMAP',
                                                   'Box',
                                                   outie=f)
                        if gshort['Lissajous'] != []:
                            f.write('\n')
                            f.write("**TOTAL_INTENSITY OTFMAP LISSAJOUS**\n")
                            f.write('\n')
                            # PRINT TABLE
                            aorparse.hawcAORreSTer(gshort['Lissajous'],
                                                   'OTFMAP',
                                                   'Lissajous',
                                                   outie=f)
    f.close()
示例#4
0
def reSTer(inlist):
    """
    Given a list of filenames, parse each one and print the relevant
    observing leg details (as well as takeoff and landing details).

    The formatting is specific to some of the specific (table)
    extensions of reST/Markdown.
    """
    for i, each in enumerate(inlist):
        # Where the magic happens
        flight = fpmis.parseMIS(each)

        h1 = "FLIGHT %02d" % (i+1)
        print underliner(h1)
        print h1
        print underliner(h1)
        print ""

        h2 = "Flight Path"
        print h2
        print underliner(h2)
        print ""
        fpimg = each[:-4] + ".png"
        print ".. image:: %s" % (fpimg)
        print ""

        print "Top Level Notes"
        print underliner("Top Level Notes")
        print ""
        flightnotes = []
        try:
            f = open(each[:-4] + '.rst')
            flightnotes = f.readlines()
            f.close()
        except IOError:
            pass
        if flightnotes == []:
            print "No supplemental notes"
        else:
            for com in flightnotes:
                print com
        print ""

        h2 = "Flight Metadata"
        print h2
        print underliner(h2)
        print "* Plan Filename: %s, Vintage: %s" %\
            (flight.filename, flight.saved)
        summy = flight.summarize()
        # Break at the line breaks so we can indent it
        #   (ended up taking out the tabs, but keeping this in case we want it)
        summarylines = summy.split("\n")
        for line in summarylines:
            print "* %s" % (line)
        print ""

        # Note that this will grab the table of JUST the
        #   takeoff, observing, and landing leg details
        obstab = []
        obstabhed = []
        for j, oach in enumerate(flight.legs):
            if oach.legtype != "Observing":
                oach.ra = None
                oach.dec = None
                oach.range_rof = [None, None]
                oach.range_elev = [None, None]

            # print the header before the first leg
            if j == 0:
                obstabhed = ["Leg Number",
                             "Time Since Takeoff at Leg Start (hrs)",
                             "Leg Type", "ObsBlk", "Target",
                             "RA (2000)", "Dec (2000)",
                             "Obs Duration",
                             "Elevation Range",
                             "ROF Range"]

            # Should be self explanatory here
            if oach.legtype == "Takeoff" or oach.legtype == "Landing" or\
               oach.legtype == "Observing":
                tabdat = [oach.legno,
                          np.round(oach.relative_time[0]/60./60., 1),
                          oach.legtype, oach.obsblk,
                          oach.target, oach.ra, oach.dec,
                          str(oach.obsdur),
                          str(oach.range_elev),
                          str(oach.range_rof)]

                obstab.append(tabdat)
        tabbie = aptable.Table(rows=obstab, names=obstabhed)
        tabbie.write(sys.stdout, format='ascii.rst')
        print ""
def reSTer(infile, title, role='Team'):
    """
    Given a MIS file, parse it and print out a summary as well as any
    additional specified AOR details for each leg.

    The formatting is specific to some of the specific (table)
    extensions of reST/Markdown.
    """
    # Where the magic happens
    flight = fpmis.parseMIS(infile)

    h1 = "%s" % (title)
    print underliner(h1)
    print h1
    print underliner(h1)
    print ""
    print "Cheat Sheet generated on %s" % (datetime.datetime.now()),
    print "by %s in %s mode" % (getpass.getuser(), role)
    print ""

    if role == 'Team':
        h2 = "Flight Path"
        print h2
        print underliner(h2)
        print ""
        fpimg = infile[:-4] + ".png"
        print ".. image:: %s" % (fpimg)
        print ""

#    flightnotes = []
#    try:
#        f = open(infile[:-4] + '.rst')
#        flightnotes = f.readlines()
#        f.close()
#    except IOError:
#        pass
#    if flightnotes == []:
#        print "No supplemental notes"
#    else:
#        for com in flightnotes:
#            print com
#    print ""

    h2 = "Flight Metadata"
    print h2
    print underliner(h2)
    print "* Plan Filename: %s, Vintage: %s" %\
        (flight.filename, flight.saved)
    summy = flight.summarize()
    # Break at the line breaks so we can indent it
    #   (ended up taking out the tabs, but keeping this in case we want it)
    summarylines = summy.split("\n")
    for line in summarylines:
        print "* %s" % (line)
    print ""

    # Note that this will grab the table of JUST the
    #   takeoff, observing, and landing leg details
    obstab = []
    obstabhed = []
    for j, oach in enumerate(flight.legs):
        if oach.legtype != "Observing":
            oach.ra = None
            oach.dec = None
            oach.range_rof = [None, None]
            oach.range_elev = [None, None]
            oach.range_rofrt = [None, None]
            oach.range_thdgrt = [None, None]

        # print the header before the first leg
        if j == 0:
            obstabhed = ["Leg Number",
                         "Time Since Takeoff at Leg Start (hrs)",
                         "Leg Type", "ObsBlk", "Target",
                         "RA (2000)", "Dec (2000)",
                         "Obs Duration",
                         "Elevation Range",
                         "ROF Range",
                         "ROF Rate", "THdg Rate"]

        # Should be self explanatory here
        if oach.legtype == "Takeoff" or oach.legtype == "Landing" or\
           oach.legtype == "Observing":
            tabdat = [oach.legno,
                      np.round(oach.relative_time[0]/60./60., 1),
                      oach.legtype, oach.obsblk,
                      oach.target, oach.ra, oach.dec,
                      str(oach.obsdur),
                      str(oach.range_elev),
                      str(oach.range_rof),
                      str(oach.range_rofrt),
                      str(oach.range_thdgrt)]

            obstab.append(tabdat)
    if role == 'Team':
        tabbie = aptable.Table(rows=obstab, names=obstabhed)
        tabbie.write(sys.stdout, format='ascii.rst')
    elif role == 'TO':
        tabbie = aptable.Table(rows=obstab, names=obstabhed)
        tabbie.write(sys.stdout, format='ascii.csv')
    print ""

    print "Flight AOR Catalog"
    print underliner("Flight AOR Catalog")
    print ""

#    OMC AORs
#    aorids = [['88_0005_43', '88_0005_42', '88_0005_41', '88_0005_40',
#           '88_0005_65', '88_0005_64', '88_0005_67', '88_0005_66',
#           '88_0005_61', '88_0005_60', '88_0005_63', '88_0005_62',
#           '88_0005_68', '88_0005_9', '88_0005_55', '88_0005_56',
#           '88_0005_57', '88_0005_38', '88_0005_39', '88_0005_73',
#           '88_0005_32', '88_0005_33', '88_0005_30', '88_0005_31',
#           '88_0005_36', '88_0005_37', '88_0005_34', '88_0005_35',
#           '88_0005_82', '88_0005_81', '88_0005_80', '88_0005_79',
#           '88_0005_69', '88_0005_51', '88_0005_52', '88_0005_53',
#           '88_0005_54', '88_0005_72', '88_0005_70', '88_0005_71']

    aorfiles = ['/Users/rhamilton/Desktop/AORs/88_0006.aor',
                '/Users/rhamilton/Desktop/AORs/90_0083.aor',
                '/Users/rhamilton/Desktop/AORs/04_0011.aor',
                '/Users/rhamilton/Desktop/AORs/88_0006.aor',
                '/Users/rhamilton/Desktop/AORs/88_0005.aor',
                '/Users/rhamilton/Desktop/AORs/04_0138_v4.aor']

    aorids = [
              ['88_0006_23', '88_0006_34', '88_0006_40'],
              ['90_0083_4', '90_0083_14', '90_0083_15'],
              ['04_0011_9', '04_0011_10'],
              ['88_0006_25', '88_0006_48', '88_0006_49',
               '88_0006_35', '88_0006_36'],
              ['88_0005_20', '88_0005_21', '88_0005_58', '88_0005_78',
               '88_0005_75'],
              ['04_0138_2', '04_0138_1', '04_0138_11', '04_0138_12']
              ]

    if role == 'Team':
        output = 'rst'
    elif role == 'TO':
        output = 'tab'

    for i, each in enumerate(aorfiles):
        aorparse.HAWCAORSorter(each, aorids=aorids[i], output=output)

    # Now go leg-by-leg and print out the gory details.
    if role == 'Team':
        print "Leg Details"
        print underliner("Leg Details")
        print ""
        legnotes = []
        try:
            f = open(infile[:-4] + '.conf')
            flightnotes = f.readlines()
            f.close()
        except IOError:
            pass
        for j, cleg in enumerate(flight.legs):
            pass

    print ""