Ejemplo n.º 1
0
def make_spline(collection, start_date):
    collection = sorted(collection, key=lambda x: x.time)
    collection = average_over(collection, 7)
    dates = []
    phi = []
    lam = []
    h = []
    for elem in collection:
        if (get_date(elem)-start_date).days >= 0:
            dates.append((get_date(elem)-start_date).days)
            phi.append(elem.pos[0])
            lam.append(elem.pos[1])
            h.append(elem.pos[2])

    return (CubicSpline(dates, phi),CubicSpline(dates, lam), CubicSpline(dates, h), dates)
Ejemplo n.º 2
0
def make_spline(collection, start_date):
    collection = sorted(collection, key=lambda x: x.time)
    collection = average_over(collection, 7)
    dates = [-1]
    phi = [collection[0].pos[0]]
    lam = [collection[0].pos[1]]
    h = [collection[0].pos[2]]
    for elem in collection:
        if (get_date(elem) - start_date).days >= 0:
            dates.append((get_date(elem) - start_date).days)
            phi.append(elem.pos[0])
            lam.append(elem.pos[1])
            h.append(elem.pos[2])
    return (scipy.interpolate.interp1d(dates, phi),
            scipy.interpolate.interp1d(dates, lam),
            scipy.interpolate.interp1d(dates, h), dates)
Ejemplo n.º 3
0
def graph_series(series):
    series = sorted(series, key=lambda x: x.time)
    series = average_over(series, 7)
    p0 = np.array(series[0].pos)
    phi, lam, h = p0
    mat = np.array(
        [[-1 * sin(lam), cos(lam), 0.],
         [-1 * cos(lam) * sin(phi), -1 * sin(lam) * sin(phi),
          cos(phi)], [cos(lam) * cos(phi),
                      sin(lam) * cos(phi),
                      sin(phi)]]).T

    positions = []
    errors = []
    times = []
    i = 0
    for elem in series:
        year = elem.time // 1000
        days = elem.time - year * 1000
        date = datetime.date.fromordinal(
            datetime.date(year, 1, 1).toordinal() + days - 1)
        if not (datetime.date(1999, 1, 1) <= date < datetime.date(2012, 1, 1)):
            continue
        times.append(date)
        tmp = elem.pos - p0
        positions.append(np.matmul(mat, tmp))
        print(np.matmul(mat, tmp))
        pos = np.zeros([3])
        errors.append(elem.err)

    plotpos = np.array(positions)
    ploterr = np.array(errors)
    errors = np.array(errors)
    print(plotpos[:, 2])
    times2 = []
    mindate = times[0]
    for elem in times:
        times2.append((elem - mindate).days)

    north = linregress(times2, plotpos[:, 0])
    east = linregress(times2, plotpos[:, 1])
    up, away = curve_fit(to_fit, times2, plotpos[:, 2])
    print("{} mm/y".format(north[0] * 365 * 1000))
    print("{} mm/y".format(east[0] * 365 * 1000))
    print("{} mm/y".format(up[1] * 365 * 1000))
    print(north)
    print(east)
Ejemplo n.º 4
0
def make_spline(collection, start_date):
    collection = sorted(collection, key=lambda x: x.time)
    collection = average_over(collection, 7)
    dates = [0]
    phi = [collection[0].pos[0]]
    lam = [collection[0].pos[1]]
    h = [collection[0].pos[2]]
    for elem in collection:
        if (get_date(elem)-start_date).days >= 0:
            dates.append((get_date(elem)-start_date).days)
            phi.append(elem.pos[0])
            lam.append(elem.pos[1])
            h.append(elem.pos[2])
    s = 0
    smooth = 1000
    dev = 0.1
    cleanphi = outlierdet(np.array([dates,phi]).T,smooth,dev)
    cleanlam = outlierdet(np.array([dates,lam]).T,smooth,dev)
    n = 8
    return (scipy.interpolate.UnivariateSpline(cleanphi[:,0][::n], cleanphi[:,1][::n], k=2, s=s),scipy.interpolate.UnivariateSpline(cleanlam[:,0][::n], cleanlam[:,1][::n], k=2, s=s), scipy.interpolate.UnivariateSpline(dates, h, s=s), dates)
Ejemplo n.º 5
0
def graph_series(series):
    series = sorted(series, key=lambda x: x.time)
    series = average_over(series, 7)
    p0 = np.array(series[0].pos)
    phi, lam, h = p0
    mat = np.array(
        [[-1 * sin(lam), cos(lam), 0.],
         [-1 * cos(lam) * sin(phi), -1 * sin(lam) * sin(phi),
          cos(phi)], [cos(lam) * cos(phi),
                      sin(lam) * cos(phi),
                      sin(phi)]]).T

    positions = []
    errors = []
    times = []
    i = 0
    for elem in series:
        year = elem.time // 1000
        days = elem.time - year * 1000
        date = datetime.date.fromordinal(
            datetime.date(year, 1, 1).toordinal() + days - 1)
        if not (datetime.date(1999, 1, 1) <= date < datetime.date(2012, 1, 1)):
            continue
        times.append(date)
        tmp = p0 - elem.pos
        positions.append(np.matmul(mat, tmp))
        print(np.matmul(mat, tmp))
        pos = np.zeros([3])
        errors.append(elem.err)

    plotpos = np.array(positions)
    ploterr = np.array(errors)
    errors = np.array(errors)

    times2 = []
    mindate = times[0]
    for elem in times:
        times2.append((elem - mindate).days)

    north = linregress(times2, plotpos[:, 0])
    east = linregress(times2, plotpos[:, 1])
    up, away = curve_fit(to_fit, times2, plotpos[:, 2])
    print("{} mm/y".format(north[0] * 365 * 1000))
    print("{} mm/y".format(east[0] * 365 * 1000))
    print("{} mm/y".format(up[1] * 365 * 1000))
    print(north)

    f, axarr = plt.subplots(3, sharex=True)
    #f.suptitle(sys.argv[1].split("\\")[1][:4])
    # for i in range(0,3):
    #     axarr[i].axhline(y=0, color='k')
    #     axarr[i].set_xlim([times[0], times[-1]])
    #     axarr[i].errorbar(times, plotpos[:, i], yerr=errors[:,i], linewidth=0.5, fmt='x', markersize=0.81)

    for i in range(0, 3):
        axarr[i].axhline(y=0, color='k')
        axarr[i].set_xlim([times[0], times[-1]])
        data = np.zeros([len(times), 2])
        t = [t.toordinal() for t in times]
        data[:, 0] = t
        data[:, 1] = plotpos[:, 1]
        #data = outlierdet(data, 3000, 1)
        axarr[i].scatter(
            data[:, 0], data[:, i], s=0.1
        )  #, yerr=errors[:,i], linewidth=0.5, fmt='x', markersize=0.81)

    axarr[0].plot([mindate, times[-1]],
                  [north[1], north[1] + north[0] * times2[-1]])
    axarr[1].plot([mindate, times[-1]],
                  [east[1], east[1] + east[0] * times2[-1]])
    axarr[2].plot(
        times,
        list(map(lambda x: to_fit(x, up[0], up[1], up[2], up[3]), times2)))

    plt.show()