def main(argv):
    inputfilepath = argv[0]
    days_per_object = argv[1]
    rows_per_day = int(argv[2])
    coeff = int(argv[3])
    range = np.float(argv[4])

    short = False
    print 'working on file ', inputfilepath
    print 'timespan in days ', days_per_object
    print 'rows per day ', rows_per_day
    print 'number of coefficients ', coeff

    # SETTINGS #
    daystart = int(range*rows_per_day)
    skip = 1

    ###################################
    # open output files
    inputfilename = inputfilepath.split("/")
    CoeffFile = open(inputfilename[-1] + '.coef_vartime_' + str(coeff) + '.dat', 'w')
    ResidualSumfile = open(inputfilename[-1] + '.resid_sum_vartime_' + str(coeff) + '.dat', 'w')

    # utc2tai = 32./86400.
    vUtc2Tai = np.vectorize(utc2tai)
    # get input
    ephem = np.loadtxt(inputfilepath, comments='#', usecols=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 14, 15),
                       delimiter=None, dtype=np.float64, unpack=True)
    if short:
        ssmid = ephem[0]
        t = vUtc2Tai(ephem[1])
        ra = ephem[3]
        dec = ephem[4]
        draskydt = ephem[6]
        ddecdt = ephem[7]
        dist = ephem[2]
        distdt = ephem[5]
        vmag = ephem[8]
        se = ephem[10]
    else:
        ssmid = ephem[0]
        t = vUtc2Tai(ephem[2])
        ra = ephem[4]
        dec = ephem[5]
        draskydt = ephem[7]
        ddecdt = ephem[8]
        dist = ephem[3]
        distdt = ephem[6]
        vmag = ephem[9]
        se = ephem[11]

    advance_next_day = int(rows_per_day)*int(days_per_object) + 1
    objectcount = 1
    outerday0 = 0
    rowarray = np.array([])
    residarray = np.array([])
    deltaresidarray = np.array([])
    vmagresidarray = np.array([])
    v_360_to_neg = np.vectorize(three_sixy_to_neg)

    # Make Multiplier Dict:
    VMAG_COEFF = 9
    DIST_COEFF = 5
    SE_COEFF = 6
    npoints = int(rows_per_day)*int(range)
    # Precompute multiplier because
    # we don't want to invert a matrix for every segment
    multiplier = {}
    multiplier['POSITION'] = cg.makeChebMatrix(npoints + 1, coeff, weight=0.16)
    multiplier['VMAG_X'] = cg.makeChebMatrixOnlyX(npoints + 1, VMAG_COEFF)
    multiplier['DIST'] = cg.makeChebMatrix(npoints + 1, DIST_COEFF, weight=0.16)
    multiplier['DIST_X'] = cg.makeChebMatrixOnlyX(npoints + 1, DIST_COEFF)
    multiplier['SE_X'] = cg.makeChebMatrixOnlyX(npoints + 1, SE_COEFF)

    while outerday0 < len(ephem[0]):
        day0 = outerday0
        day1 = outerday0 + daystart
        rows = 1
        # NEW OBJECT
        # For one object over the course of 1 month or 43200 minutes
        while day0 < advance_next_day*objectcount - 1:
            ngran = day1 - day0
            npoint = day1 - day0
            pdec, pra, p_resid = get_coeffs_position(t[day0:day1 + 1:skip],
                                                     v_360_to_neg(ra[day0:day1 + 1:skip],
                                                                  np.min(ra[day0:day1 + 1:skip]),
                                                                  np.max(ra[day0:day1 + 1:skip])),
                                                     dec[day0:day1 + 1:skip], draskydt[day0:day1 + 1:skip],
                                                     ddecdt[day0:day1 + 1:skip], ngran, npoint, coeff,
                                                     multiplier['POSITION'])
            d, d_resid = get_coeffs_dist(t[day0:day1 + 1:skip], dist[day0:day1 + 1:skip],
                                         distdt[day0:day1 + 1:skip], ngran, npoint, 5,
                                         multiplier['DIST'])
            v, v_resid = get_coeffs_vmag(t[day0:day1 + 1:skip], vmag[day0:day1 + 1:skip], ngran, npoint, 9,
                                         multiplier['VMAG_X'])
            s, s_resid = get_coeffs_se(t[day0:day1 + 1:skip], se[day0:day1 + 1:skip], ngran, npoint, 6,
                                       multiplier['SE_X'])
            vmagresidarray = np.append(vmagresidarray,  v_resid)
            deltaresidarray = np.append(deltaresidarray,  d_resid)
            residarray = np.append(residarray, p_resid)

            print >>ResidualSumfile, "%i %i %.14f %.14f %.14f %.14e %.14e %.14e %.14e %s"%(ssmid[day0], rows, t[day0], t[day1], t[day1] - t[day0], p_resid, d_resid, v_resid, s_resid, inputfilename[-1])
            print >>CoeffFile, "%i %s %.6f %.6f %s %s %s %s %s"%(0,
                                ssmid[day0], t[day0], t[day1],  " ".join('%.14e'%j for j in pra), " ".join('%.14e'%j for j in pdec),
                                " ".join('%.7e'%j for j in d), " ".join('%.7e'%j for j in v),   " ".join('%.7e'%j for j in s))

            # advance to the next day if less than 6 points left in month
            day0 = day1
            day1 = day0 + daystart
            rows = rows + 1
        rowarray = np.append(rowarray, rows)
        objectcount = objectcount + 1
        outerday0 = outerday0 + advance_next_day

    print np.min(rowarray), np.max(rowarray), np.mean(rowarray)
    print np.min(residarray), np.max(residarray), np.mean(residarray)
    print np.min(deltaresidarray), np.max(deltaresidarray), np.mean(deltaresidarray)
    print np.min(vmagresidarray), np.max(vmagresidarray), np.mean(vmagresidarray)
    CompletedNotice = open(inputfilename[-1] + '.done.txt', 'w')
    print >>CompletedNotice, "Success"
def main(argv):
    inputfilepath = argv[0]
    start_time = float(argv[1])
    days = int(argv[2])
    coeff = int(argv[3])
    totaldays = int(argv[4])

    print 'Generating and Fitting Ephems starting:', start_time
    print 'working on file ', inputfilepath
    print 'timespan in days ', days
    print 'number of coefficients ', coeff

    # open output files
    inputfilename = inputfilepath.split("/")
    CoeffFile = open(
        inputfilename[-1] + '.coef_vartime_' + str(coeff) + '.dat', 'w')
    ResidualSumfile = open(
        inputfilename[-1] + '.resid_sum_vartime_' + str(coeff) + '.dat', 'w')
    Failedfile = open(inputfilename[-1] + '.failed_' + str(coeff) + '.dat',
                      'w')

    # get input
    orbit = np.loadtxt(inputfilepath,
                       comments='!!',
                       usecols=(2, 3, 4, 5, 6, 7, 8, 9),
                       delimiter=None,
                       dtype=np.float64,
                       unpack=True)
    ssmid = np.loadtxt(inputfilepath,
                       comments='!!',
                       usecols=(0, ),
                       delimiter=None,
                       dtype=np.str,
                       unpack=True)
    q = orbit[0]
    e = orbit[1]
    inc = orbit[2]
    omega = orbit[3]
    argperi = orbit[4]
    t_p = orbit[5]
    H = orbit[6]
    t_0 = orbit[7]

    oo.pyoorb.oorb_init(ephemeris_fname="")
    print 'total days ', totaldays

    # Make Multiplier Dict:
    VMAG_COEFF = 9
    DIST_COEFF = 5
    SE_COEFF = 6

    # Precompute multiplier because
    # we don't want to invert a matrix for every segment
    nPoints = 64
    multipliers = {}
    multipliers['POSITION'] = cg.makeChebMatrix(nPoints + 1,
                                                coeff,
                                                weight=0.16)
    multipliers['VMAG_X'] = cg.makeChebMatrixOnlyX(nPoints + 1, VMAG_COEFF)
    multipliers['DIST'] = cg.makeChebMatrix(nPoints + 1,
                                            DIST_COEFF,
                                            weight=0.16)
    multipliers['DIST_X'] = cg.makeChebMatrixOnlyX(nPoints + 1, DIST_COEFF)
    multipliers['SE_X'] = cg.makeChebMatrixOnlyX(nPoints + 1, SE_COEFF)

    # check if only 1 row
    theShape = orbit.shape
    if len(theShape) == 2:
        datalen = theShape[1]
    else:
        datalen = 1
    if DEBUG:
        print 'datalen', datalen
    for i in range(datalen):
        if datalen == 1:
            id = ssmid
            mymo = mo.MovingObject(q,
                                   e,
                                   inc,
                                   omega,
                                   argperi,
                                   t_p,
                                   t_0,
                                   objid=ssmid,
                                   magHv=H)
        else:
            id = ssmid[i]
            mymo = mo.MovingObject(q[i],
                                   e[i],
                                   inc[i],
                                   omega[i],
                                   argperi[i],
                                   t_p[i],
                                   t_0[i],
                                   objid=ssmid[i],
                                   magHv=H[i])

        tmpStartTime = start_time
        while tmpStartTime < start_time + totaldays:
            doOneMonth(id, mymo, tmpStartTime, days, coeff, multipliers,
                       CoeffFile, ResidualSumfile, Failedfile,
                       inputfilename[-1])
            tmpStartTime += days

    CompletedNotice = open(inputfilename[-1] + '.done.txt', 'w')
    print >> CompletedNotice, "Success"
Example #3
0
def main(argv):
    inputfilepath = argv[0]
    days_per_object = argv[1]
    rows_per_day = int(argv[2])
    coeff = int(argv[3])
    range = np.float(argv[4])

    short = False
    print 'working on file ', inputfilepath
    print 'timespan in days ', days_per_object
    print 'rows per day ', rows_per_day
    print 'number of coefficients ', coeff

    # SETTINGS #
    daystart = int(range * rows_per_day)
    skip = 1

    ###################################
    # open output files
    inputfilename = inputfilepath.split("/")
    CoeffFile = open(
        inputfilename[-1] + '.coef_vartime_' + str(coeff) + '.dat', 'w')
    ResidualSumfile = open(
        inputfilename[-1] + '.resid_sum_vartime_' + str(coeff) + '.dat', 'w')

    # utc2tai = 32./86400.
    vUtc2Tai = np.vectorize(utc2tai)
    # get input
    ephem = np.loadtxt(inputfilepath,
                       comments='#',
                       usecols=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 14, 15),
                       delimiter=None,
                       dtype=np.float64,
                       unpack=True)
    if short:
        ssmid = ephem[0]
        t = vUtc2Tai(ephem[1])
        ra = ephem[3]
        dec = ephem[4]
        draskydt = ephem[6]
        ddecdt = ephem[7]
        dist = ephem[2]
        distdt = ephem[5]
        vmag = ephem[8]
        se = ephem[10]
    else:
        ssmid = ephem[0]
        t = vUtc2Tai(ephem[2])
        ra = ephem[4]
        dec = ephem[5]
        draskydt = ephem[7]
        ddecdt = ephem[8]
        dist = ephem[3]
        distdt = ephem[6]
        vmag = ephem[9]
        se = ephem[11]

    advance_next_day = int(rows_per_day) * int(days_per_object) + 1
    objectcount = 1
    outerday0 = 0
    rowarray = np.array([])
    residarray = np.array([])
    deltaresidarray = np.array([])
    vmagresidarray = np.array([])
    v_360_to_neg = np.vectorize(three_sixy_to_neg)

    # Make Multiplier Dict:
    VMAG_COEFF = 9
    DIST_COEFF = 5
    SE_COEFF = 6
    npoints = int(rows_per_day) * int(range)
    # Precompute multiplier because
    # we don't want to invert a matrix for every segment
    multiplier = {}
    multiplier['POSITION'] = cg.makeChebMatrix(npoints + 1, coeff, weight=0.16)
    multiplier['VMAG_X'] = cg.makeChebMatrixOnlyX(npoints + 1, VMAG_COEFF)
    multiplier['DIST'] = cg.makeChebMatrix(npoints + 1,
                                           DIST_COEFF,
                                           weight=0.16)
    multiplier['DIST_X'] = cg.makeChebMatrixOnlyX(npoints + 1, DIST_COEFF)
    multiplier['SE_X'] = cg.makeChebMatrixOnlyX(npoints + 1, SE_COEFF)

    while outerday0 < len(ephem[0]):
        day0 = outerday0
        day1 = outerday0 + daystart
        rows = 1
        # NEW OBJECT
        # For one object over the course of 1 month or 43200 minutes
        while day0 < advance_next_day * objectcount - 1:
            ngran = day1 - day0
            npoint = day1 - day0
            pdec, pra, p_resid = get_coeffs_position(
                t[day0:day1 + 1:skip],
                v_360_to_neg(ra[day0:day1 + 1:skip],
                             np.min(ra[day0:day1 + 1:skip]),
                             np.max(ra[day0:day1 + 1:skip])),
                dec[day0:day1 + 1:skip], draskydt[day0:day1 + 1:skip],
                ddecdt[day0:day1 + 1:skip], ngran, npoint, coeff,
                multiplier['POSITION'])
            d, d_resid = get_coeffs_dist(t[day0:day1 + 1:skip],
                                         dist[day0:day1 + 1:skip],
                                         distdt[day0:day1 + 1:skip], ngran,
                                         npoint, 5, multiplier['DIST'])
            v, v_resid = get_coeffs_vmag(t[day0:day1 + 1:skip],
                                         vmag[day0:day1 + 1:skip], ngran,
                                         npoint, 9, multiplier['VMAG_X'])
            s, s_resid = get_coeffs_se(t[day0:day1 + 1:skip],
                                       se[day0:day1 + 1:skip], ngran, npoint,
                                       6, multiplier['SE_X'])
            vmagresidarray = np.append(vmagresidarray, v_resid)
            deltaresidarray = np.append(deltaresidarray, d_resid)
            residarray = np.append(residarray, p_resid)

            print >> ResidualSumfile, "%i %i %.14f %.14f %.14f %.14e %.14e %.14e %.14e %s" % (
                ssmid[day0], rows, t[day0], t[day1], t[day1] - t[day0],
                p_resid, d_resid, v_resid, s_resid, inputfilename[-1])
            print >> CoeffFile, "%i %s %.6f %.6f %s %s %s %s %s" % (
                0, ssmid[day0], t[day0], t[day1], " ".join('%.14e' % j
                                                           for j in pra),
                " ".join('%.14e' % j for j in pdec), " ".join(
                    '%.7e' % j
                    for j in d), " ".join('%.7e' % j
                                          for j in v), " ".join('%.7e' % j
                                                                for j in s))

            # advance to the next day if less than 6 points left in month
            day0 = day1
            day1 = day0 + daystart
            rows = rows + 1
        rowarray = np.append(rowarray, rows)
        objectcount = objectcount + 1
        outerday0 = outerday0 + advance_next_day

    print np.min(rowarray), np.max(rowarray), np.mean(rowarray)
    print np.min(residarray), np.max(residarray), np.mean(residarray)
    print np.min(deltaresidarray), np.max(deltaresidarray), np.mean(
        deltaresidarray)
    print np.min(vmagresidarray), np.max(vmagresidarray), np.mean(
        vmagresidarray)
    CompletedNotice = open(inputfilename[-1] + '.done.txt', 'w')
    print >> CompletedNotice, "Success"
def main(argv):
    inputfilepath = argv[0]
    start_time = float(argv[1])
    days = int(argv[2])
    coeff = int(argv[3])
    totaldays = int(argv[4])

    print 'Generating and Fitting Ephems starting:', start_time
    print 'working on file ', inputfilepath
    print 'timespan in days ', days
    print 'number of coefficients ', coeff

    # open output files
    inputfilename = inputfilepath.split("/")
    CoeffFile = open(inputfilename[-1] + '.coef_vartime_' + str(coeff) + '.dat', 'w')
    ResidualSumfile = open(inputfilename[-1] + '.resid_sum_vartime_' + str(coeff) + '.dat', 'w')
    Failedfile = open(inputfilename[-1] + '.failed_' + str(coeff) + '.dat', 'w')

    # get input
    orbit = np.loadtxt(inputfilepath, comments='!!', usecols=(2, 3, 4, 5, 6, 7, 8, 9),
                       delimiter=None, dtype=np.float64, unpack=True)
    ssmid = np.loadtxt(inputfilepath, comments='!!', usecols=(0,), delimiter=None, dtype=np.str, unpack=True)
    q = orbit[0]
    e = orbit[1]
    inc = orbit[2]
    omega = orbit[3]
    argperi = orbit[4]
    t_p = orbit[5]
    H = orbit[6]
    t_0 = orbit[7]

    oo.pyoorb.oorb_init(ephemeris_fname="")
    print 'total days ', totaldays

    # Make Multiplier Dict:
    VMAG_COEFF = 9
    DIST_COEFF = 5
    SE_COEFF = 6

    # Precompute multiplier because
    # we don't want to invert a matrix for every segment
    nPoints = 64
    multipliers = {}
    multipliers['POSITION'] = cg.makeChebMatrix(nPoints + 1, coeff, weight=0.16)
    multipliers['VMAG_X'] = cg.makeChebMatrixOnlyX(nPoints + 1, VMAG_COEFF)
    multipliers['DIST'] = cg.makeChebMatrix(nPoints + 1, DIST_COEFF, weight=0.16)
    multipliers['DIST_X'] = cg.makeChebMatrixOnlyX(nPoints + 1, DIST_COEFF)
    multipliers['SE_X'] = cg.makeChebMatrixOnlyX(nPoints + 1, SE_COEFF)

    # check if only 1 row
    theShape = orbit.shape
    if len(theShape) == 2:
        datalen = theShape[1]
    else:
        datalen = 1
    if DEBUG:
        print 'datalen', datalen
    for i in range(datalen):
        if datalen == 1:
            id = ssmid
            mymo = mo.MovingObject(q, e, inc, omega, argperi, t_p, t_0, objid=ssmid, magHv=H)
        else:
            id = ssmid[i]
            mymo = mo.MovingObject(q[i], e[i], inc[i], omega[i], argperi[i],
                                   t_p[i], t_0[i], objid=ssmid[i], magHv=H[i])

        tmpStartTime = start_time
        while tmpStartTime < start_time + totaldays:
            doOneMonth(id, mymo, tmpStartTime, days, coeff, multipliers, CoeffFile,
                       ResidualSumfile, Failedfile, inputfilename[-1])
            tmpStartTime += days

    CompletedNotice = open(inputfilename[-1] + '.done.txt', 'w')
    print >>CompletedNotice, "Success"