Beispiel #1
0
def test_ne():
    ''' change timeseries '''
    ts1 = Timeseries(filename=wind_file)
    ts = ts1.get_timeseries()
    ts[0]['value'] += (1, 1)
    ts2 = Timeseries(timeseries=ts)
    assert ts1 != ts2
Beispiel #2
0
def test_ne():
    """ change timeseries """
    ts1 = Timeseries(filename=wind_file)
    ts = ts1.get_timeseries()
    ts[0]["value"] += (1, 1)
    ts2 = Timeseries(timeseries=ts)
    assert ts1 != ts2
Beispiel #3
0
def test_ne():
    ''' change timeseries '''
    ts1 = Timeseries(filename=wind_file)
    ts = ts1.get_timeseries()
    ts[0]['value'] += (1, 1)
    ts2 = Timeseries(timeseries=ts)
    assert ts1 != ts2
Beispiel #4
0
def test_init(wind_timeseries):
    ""
    rq = wind_timeseries["rq"]
    uv = wind_timeseries["uv"]
    ts = Timeseries(rq, format="r-theta")
    assert np.all(ts.get_timeseries()["time"] == rq["time"])
    assert np.allclose(ts.get_timeseries(format="r-theta")["value"], rq["value"], atol=1e-10)
    assert np.allclose(ts.get_timeseries()["value"], uv["value"], atol=1e-10)
Beispiel #5
0
def test__check_timeseries_scalar():
    ts = Timeseries()  # need one to get check methods..

    result = ts._check_timeseries((datetime.now(), (1.0, 2.0)))
    assert result

    with raises(TimeseriesError):
        result = ts._check_timeseries(('2007-03-01T13:00:00', (1.0, 2.0)))
        assert result
Beispiel #6
0
def test__check_timeseries_scalar():
    ts = Timeseries()  # need one to get check methods..

    result = ts._check_timeseries((datetime.now(), (1.0, 2.0)))
    assert result

    with raises(TimeseriesError):
        result = ts._check_timeseries(('2007-03-01T13:00:00', (1.0, 2.0)))
        assert result
Beispiel #7
0
def test_init(wind_timeseries):
    ''
    rq = wind_timeseries['rq']
    uv = wind_timeseries['uv']
    ts = Timeseries(rq, format='r-theta')
    assert np.all(ts.get_timeseries()['time'] == rq['time'])
    assert np.allclose(ts.get_timeseries(format='r-theta')['value'],
                       rq['value'],
                       atol=1e-10)
    assert np.allclose(ts.get_timeseries()['value'], uv['value'], atol=1e-10)
Beispiel #8
0
def test__check_timeseries_wrong_tuple():
    ts = Timeseries()  # need one to get check methods..

    with raises(TimeseriesError):
        result = ts._check_timeseries(((datetime.now(), (1.0, 2.0, 3.0)),))
        assert result

    with raises(TimeseriesError):
        result = ts._check_timeseries(((datetime.now(), ()),))
        assert result
Beispiel #9
0
def test_get_timeseries(wind_timeseries):
    uv = wind_timeseries['uv']
    ts = Timeseries(uv, format='uv')
    result = ts.get_timeseries()

    assert len(result) == 6

    for dt, value in result:
        assert type(dt) is np.datetime64
        assert len(value) == 2
Beispiel #10
0
def test__check_timeseries_wrong_tuple():
    ts = Timeseries()  # need one to get check methods..

    with raises(TimeseriesError):
        result = ts._check_timeseries(((datetime.now(), (1.0, 2.0, 3.0)), ))
        assert result

    with raises(TimeseriesError):
        result = ts._check_timeseries(((datetime.now(), ()), ))
        assert result
Beispiel #11
0
def test__check_timeseries_single_value():
    ts = Timeseries()  # need one to get check methods..

    result = ts._check_timeseries(((datetime.now(), (1.0, 2.0)), ))
    assert result

    with raises(TimeseriesError):
        print(('2007-03-01T13:00:00', (1.0, 2.0)), )
        result = ts._check_timeseries((('2007-03-01T13:00:00', (1.0, 2.0)), ))
        assert result
Beispiel #12
0
def test_get_timeseries(wind_timeseries):
    uv = wind_timeseries['uv']
    ts = Timeseries(uv, format='uv')
    result = ts.get_timeseries()

    assert len(result) == 6

    for dt, value in result:
        assert type(dt) is np.datetime64
        assert len(value) == 2
Beispiel #13
0
def test__check_timeseries_single_value():
    ts = Timeseries()  # need one to get check methods..

    result = ts._check_timeseries(((datetime.now(), (1.0, 2.0)),))
    assert result

    with raises(TimeseriesError):
        print (('2007-03-01T13:00:00', (1.0, 2.0)),)
        result = ts._check_timeseries((('2007-03-01T13:00:00', (1.0, 2.0)),))
        assert result
Beispiel #14
0
def test_empty():
    """
    can you create one with no data

    FixMe: why would you want to do this??
    """
    ts = Timeseries()
    arr = ts.get_timeseries()
    assert len(arr) == 1
    assert arr[0][1][0] == 0.0
    assert arr[0][1][1] == 0.0
Beispiel #15
0
def test_empty():
    """
    can you create one with no data

    FixMe: why would you want to do this??
    """
    ts = Timeseries()
    arr = ts.get_timeseries()
    assert len(arr) == 1
    assert arr[0][1][0] == 0.0
    assert arr[0][1][1] == 0.0
Beispiel #16
0
def test_get_timeseries_multiple(wind_timeseries):
    uv = wind_timeseries['uv']
    ts = Timeseries(uv, format='uv')

    dts = [datetime(2012, 11, 6, 20, 12), datetime(2012, 11, 6, 20, 14)]
    result = ts.get_timeseries(dts)

    assert len(result) == 2
    assert result[0][1][0] == -1.0
    assert result[0][1][1] == 0.0
    assert result[1][1][0] == 0.0
    assert result[1][1][1] == 1.0
Beispiel #17
0
def test_init(wind_timeseries):
    ''
    rq = wind_timeseries['rq']
    uv = wind_timeseries['uv']
    ts = Timeseries(rq, format='r-theta')
    assert np.all(ts.get_timeseries()['time'] == rq['time'])
    assert np.allclose(ts.get_timeseries(format='r-theta')['value'],
                       rq['value'],
                       atol=1e-10)
    assert np.allclose(ts.get_timeseries()['value'],
                       uv['value'],
                       atol=1e-10)
Beispiel #18
0
def test_set_timeseries_prop():
    '''
    following operation requires a numpy array
    '''
    ts = Timeseries(filename=wind_file)

    # Following is a 0-D array, make sure it gets
    # converted to a 1-D array correctly
    x = (datetime.now().replace(microsecond=0, second=0), (4, 5))
    ts.set_timeseries(x)
    assert ts.get_timeseries()['time'] == x[0]
    assert np.allclose(ts.get_timeseries()['value'], x[1], atol=1e-6)
Beispiel #19
0
def test_get_timeseries_multiple(wind_timeseries):
    uv = wind_timeseries['uv']
    ts = Timeseries(uv, format='uv')

    dts = [datetime(2012, 11, 6, 20, 12),
           datetime(2012, 11, 6, 20, 14)]
    result = ts.get_timeseries(dts)

    assert len(result) == 2
    assert result[0][1][0] == -1.0
    assert result[0][1][1] == 0.0
    assert result[1][1][0] == 0.0
    assert result[1][1][1] == 1.0
Beispiel #20
0
    def __eq__(self, other):
        '''
        invoke super to check equality for all 'save' parameters. Also invoke
        __eq__ for Timeseries object to check equality of timeseries. Super
        is not used in any of the __eq__ methods
        '''
        if not super(Wind, self).__eq__(other):
            return False

        if not Timeseries.__eq__(self, other):
            return False

        return True
Beispiel #21
0
    def __eq__(self, other):
        '''
        invoke super to check equality for all 'save' parameters. Also invoke
        __eq__ for Timeseries object to check equality of timeseries. Super
        is not used in any of the __eq__ methods
        '''
        if not super(Wind, self).__eq__(other):
            return False

        if not Timeseries.__eq__(self, other):
            return False

        return True
Beispiel #22
0
def test_set_timeseries_prop():
    '''
    following operation requires a numpy array
    '''
    ts = Timeseries(filename=wind_file)

    # Following is a 0-D array, make sure it gets
    # converted to a 1-D array correctly
    x = (datetime.now().replace(microsecond=0, second=0), (4, 5))
    ts.set_timeseries(x)
    assert ts.get_timeseries()['time'] == x[0]
    assert np.allclose(ts.get_timeseries()['value'], x[1], atol=1e-6)
        20,
        10 + i,
        30,
    ) for i in range(4)]
    dtv.value = (1, 0)

    # Following also raises ValueError. This gives invalid (r,theta) inputs
    # which are rejected by the transforms.r_theta_to_uv_wind method.
    # It tests the inner exception is correct

    with raises(TimeseriesError):
        invalid_dtv_rq = np.zeros((len(invalid_rq['rq']), ),
                                  dtype=datetime_value_2d)
        invalid_dtv_rq['value'] = invalid_rq['rq']

        Timeseries(timeseries=invalid_dtv_rq, coord_sys='r-theta')

    # exception raised if datetime values are not in ascending order
    # or not unique

    with raises(TimeseriesError):
        # not unique datetime values
        dtv_rq = np.zeros((2, ),
                          dtype=datetime_value_2d).view(dtype=np.recarray)
        (dtv_rq.value[0])[:] = (1, 0)
        (dtv_rq.value[1])[:] = (1, 10)

        Timeseries(timeseries=dtv_rq)

    with raises(TimeseriesError):
        # not in ascending order
Beispiel #24
0
def test__eq():
    ''' only checks timeseries values match '''
    ts1 = Timeseries(filename=wind_file)
    ts2 = Timeseries(timeseries=ts1.get_timeseries())
    assert ts1 == ts2
Beispiel #25
0
def test_filename():
    """ should really check for a real filename """
    ts = Timeseries()
    fn = ts.filename
    assert fn is None
Beispiel #26
0
        06,
        20,
        10 + i,
        30,
    ) for i in range(4)]
    dtv.value = (1, 0)

    # Following also raises ValueError. This gives invalid (r,theta) inputs
    # which are rejected by the transforms.r_theta_to_uv_wind method.
    # It tests the inner exception is correct

    with raises(TimeseriesError):
        invalid_dtv_rq = np.zeros((len(invalid_rq['rq']), ),
                                  dtype=datetime_value_2d)
        invalid_dtv_rq['value'] = invalid_rq['rq']
        Timeseries(timeseries=invalid_dtv_rq, format='r-theta')

    # exception raised if datetime values are not in ascending order
    # or not unique

    with raises(TimeseriesError):
        # not unique datetime values
        dtv_rq = np.zeros((2, ),
                          dtype=datetime_value_2d).view(dtype=np.recarray)
        (dtv_rq.value[0])[:] = (1, 0)
        (dtv_rq.value[1])[:] = (1, 10)
        Timeseries(timeseries=dtv_rq)

    with raises(TimeseriesError):
        # not in ascending order
        dtv_rq = np.zeros((4, ),
Beispiel #27
0
def test_str():
    ts = Timeseries()
    s = str(ts)
    # not much of a check, not much of a str.
    assert 'Timeseries' in s
Beispiel #28
0
def test__eq():
    ''' only checks timeseries values match '''
    ts1 = Timeseries(filename=wind_file)
    ts2 = Timeseries(timeseries=ts1.get_timeseries())
    assert ts1 == ts2