Esempio n. 1
0
    def test_at(self):

        dates2 = np.array([
            dt.datetime(2000, 1, 1, 0),
            dt.datetime(2000, 1, 1, 2),
            dt.datetime(2000, 1, 1, 4),
            dt.datetime(2000, 1, 1, 6),
            dt.datetime(2000, 1, 1, 8),
        ])
        u_data = np.array([2., 4., 6., 8., 10.])
        u = TimeSeriesProp(name='u', units='m/s', time=dates2, data=u_data)

        corners = np.array(((1, 1), (2, 2)))
        t1 = dt.datetime(1999, 12, 31, 23)
        t2 = dt.datetime(2000, 1, 1, 0)
        t3 = dt.datetime(2000, 1, 1, 1)
        t4 = dt.datetime(2000, 1, 1, 8)
        t5 = dt.datetime(2000, 1, 1, 9)

        # No extrapolation. out of bounds time should fail
        with pytest.raises(ValueError):
            u.at(corners, t1)
        assert (u.at(corners, t2) == np.array([2])).all()
        assert (u.at(corners, t3) == np.array([3])).all()
        assert (u.at(corners, t4) == np.array([10])).all()
        with pytest.raises(ValueError):
            u.at(corners, t5)

        # turn extrapolation on
        assert (u.at(corners, t1, extrapolate=True) == np.array([2])).all()
        assert (u.at(corners, t5, extrapolate=True) == np.array([10])).all()
Esempio n. 2
0
            return self.wind_var.at(points, time, units, extrapolate)


if __name__ == "__main__":
    import datetime as dt
    dates = np.array([
        dt.datetime(2000, 1, 1, 0),
        dt.datetime(2000, 1, 1, 2),
        dt.datetime(2000, 1, 1, 4)
    ])
    u_data = np.array([3, 4, 5])
    v_data = np.array([4, 3, 12])
    u = TimeSeriesProp('u', 'm/s', dates, u_data)
    v = TimeSeriesProp('v', 'm/s', dates, v_data)

    print u.at(np.array([(1, 1), (1, 2)]), dt.datetime(2000, 1, 1, 1))

    vprop = TSVectorProp('velocity', 'm/s', variables=[u, v])
    print vprop.at(np.array([(1, 1), (1, 2)]), dt.datetime(2000, 1, 1, 3))

    vel = VelocityTS('test_vel', variables=[u, v])
    print vel.at(np.array([(1, 1), (1, 2)]), dt.datetime(2000, 1, 1, 3))

    import pprint
    pp = pprint.PrettyPrinter(indent=4)
    pp.pprint(vel.serialize())
    pp.pprint(VelocityTS.deserialize(vel.serialize()))

    velfromweb = VelocityTS.new_from_dict(
        VelocityTS.deserialize(vel.serialize()))
    velfromweb.name = 'velfromweb'