def test_two_days_two_files(tmpdir): t0 = utcdate(year=2018, month=1, day=31, hour=23) t1 = utcdate(year=2018, month=2, day=1, hour=3, minute=1) rng = pd.date_range(t0, t1, freq='30T', name="time") data = np.array(range(9), dtype=np.int64) ts = pd.Series(data, name="value", index=rng) generate_output(tmpdir, ts, t0, t1) assert_files_list(tmpdir, t0, 2) assert_correctly_loaded(ts, tmpdir, t0, t1)
def test_one_day_one_file(tmpdir): t0 = utcdate(year=2018, month=1, day=1, hour=10) t1 = utcdate(year=2018, month=1, day=1, hour=13) rng = pd.date_range(t0, t1, freq='H', name="time", closed='left') data = np.random.randn(len(rng)) ts = pd.Series(data, name="value", index=rng) bazeout = Bazeoutput(str(tmpdir)) bazeout(ts, "test", t0, t1) assert_files_list(tmpdir, t0, 1) assert_correctly_loaded(ts, tmpdir, t0, t1)
def test_Zephyre_source(): start_date = utcdate(year=2030, month=1, day=1) end_date = utcdate(year=2030, month=1, day=2) z = Zephyre() with patch( 'camille.source.zephyre.Zephyre._get_token', return_value='token' ), patch( 'camille.source.zephyre.requests.get', side_effect=requests_get_mock, ): result = z('Sin-T60s-SR01hz', start_date, end_date) reference = bz('Sin-T60s-SR01hz', start_date, end_date) pd.testing.assert_series_equal(result, reference)
def test_multiple_writes_to_same_file_with_full_overlap_overwrite(tmpdir): t0 = utcdate(year=2018, month=1, day=1, hour=5) t1 = utcdate(year=2018, month=1, day=1, hour=15) rng = pd.date_range(t0, t1, freq='H', name="time", closed='left') data = np.random.randn(len(rng)) ts = pd.Series(data, name="value", index=rng) data2 = data + 1 ts2 = pd.Series(data2, name="value", index=rng) bazeout = Bazeoutput(str(tmpdir)) bazeout(ts, "test", t0, t1) bazeout(ts2, "test", t0, t1, overwrite=True) assert_files_list(tmpdir, t0, 1) assert_correctly_loaded(ts2, tmpdir, t0, t1) assert_correct_raw_values(ts2, tmpdir, t0)
def test_valid_date(): reference = [ ('2030-02-02', utcdate(year=2030, month=2, day=2)), ('2030-02-02T01:00:00', utcdate(year=2030, month=2, day=2, hour=1)), ('2030-02-02T01:00:00.123456', utcdate(year=2030, month=2, day=2, hour=1, minute=0, second=0, microsecond=123456)), ] for arg, expected in reference: args = cli.parser.parse_args(['zephyre', 'tag', arg, arg]) assert args.start_time == expected assert args.end_time == expected
def test_multiple_writes_to_same_file_with_left_overlap_overwrite(tmpdir): t0 = utcdate(year=2018, month=1, day=1, hour=5) t1 = utcdate(year=2018, month=1, day=1, hour=8) t2 = utcdate(year=2018, month=1, day=1, hour=10) t3 = utcdate(year=2018, month=1, day=1, hour=15) rng = pd.date_range(t0, t3, freq='H', name="time", closed='left') data = np.random.randn(len(rng)) ts = pd.Series(data, name="value", index=rng) data2 = data + 1 ts2 = pd.Series(data2, name="value", index=rng) bazeout = Bazeoutput(str(tmpdir)) bazeout(ts, "test", t1, t3) bazeout(ts2, "test", t0, t2, overwrite=True) expected = pd.concat([ts2[:(t2 - eps)], ts[t2:]], sort=True) assert_files_list(tmpdir, t0, 1) assert_correctly_loaded(expected, tmpdir, t0, t3) assert_correct_raw_values(expected, tmpdir, t0)
def test_multiple_writes_to_same_file_with_overlap_no_overwrite(tmpdir): t0 = utcdate(year=2018, month=1, day=1, hour=5) t1 = utcdate(year=2018, month=1, day=1, hour=8) t2 = utcdate(year=2018, month=1, day=1, hour=10) t3 = utcdate(year=2018, month=1, day=1, hour=15) rng = pd.date_range(t0, t3, freq='H', name="time", closed='left') data = np.random.randn(len(rng)) ts = pd.Series(data, name="value", index=rng) bazeout = Bazeoutput(str(tmpdir)) bazeout(ts, "test", t1, t2) with pytest.raises(ValueError): bazeout(ts, "test", t0, (t2 - eps)) with pytest.raises(ValueError): bazeout(ts, "test", (t1 + eps), t3) with pytest.raises(ValueError): bazeout(ts, "test", (t1 + eps), (t2 - eps)) with pytest.raises(ValueError): bazeout(ts, "test", t0, t3) assert_files_list(tmpdir, t0, 1) assert_correctly_loaded(ts[t1:(t2 - eps)], tmpdir, t1, t2)
def generate_input(windfield, lidar, distance, n=4, start_date=utcdate(year=2030, month=1, day=1, hour=12)): df = pd.DataFrame(columns=[ 'los_id', 'radial_windspeed', 'status', 'surge', 'heave', 'pitch', 'roll', 'surge_velocity', 'sway_velocity', 'heave_velocity', 'pitch_velocity', 'roll_velocity', 'yaw_velocity' ]) time = (start_date + timedelta(seconds=1) * i for i in range(n)) beam = (i % 4 for i in count()) for t, b in zip(time, beam): timestamp, *xs = lidar(windfield, t, distance, b) df.loc[timestamp] = xs return distance, windfield, lidar, df
def parse_date(str): return utcdate(datetime.datetime.strptime(str, date_fmt))
def test_utcdate_new_date(): date = utcdate(year=2030, month=1, day=1) assert date.tzinfo == pytz.utc assert date.isoformat() == '2030-01-01T00:00:00+00:00'
def test_utcdate_other_timezone(): oslo = pytz.timezone('Europe/Oslo').localize(datetime(2030, 1, 1, 10, 0, 0)) as_utc = utcdate(oslo) assert as_utc.tzinfo == pytz.utc assert as_utc.isoformat() == '2030-01-01T09:00:00+00:00'
def test_utcdate_local_date(): date = datetime(2030, 1, 1) as_utc = utcdate(date) assert as_utc.tzinfo == pytz.utc assert as_utc.isoformat() == '2030-01-01T00:00:00+00:00'
def parse_date(str): return utcdate(datetime.datetime.strptime(str, date_fmt)) def format_date(date): return datetime.datetime.strftime(date, date_fmt[:-1])