def test_split_series_using_lytaf(): """ test the downloading of the LYTAF file and subsequent queries. """ # test split_series_using_lytaf # construct a dummy signal for testing purposes basetime = parse_time('2010-06-13 02:00') seconds = 3600 dummy_time = [basetime + TimeDelta(s * u.second) for s in range(seconds)] dummy_data = np.random.random(seconds) lytaf_tmp = lyra.get_lytaf_events('2010-06-13 02:00', '2010-06-13 06:00', combine_files=["ppt"]) split = lyra.split_series_using_lytaf(dummy_time, dummy_data, lytaf_tmp) assert type(split) == list assert len(split) == 4 assert is_time_equal(split[0]['subtimes'][0], parse_time((2010, 6, 13, 2, 0))) assert is_time_equal(split[0]['subtimes'][-1], parse_time((2010, 6, 13, 2, 7, 2))) assert is_time_equal(split[3]['subtimes'][0], parse_time((2010, 6, 13, 2, 59, 42))) assert is_time_equal(split[3]['subtimes'][-1], parse_time((2010, 6, 13, 2, 59, 58))) # Test case when no LYTAF events found in time series. split_no_lytaf = lyra.split_series_using_lytaf(dummy_time, dummy_data, LYTAF_TEST) assert type(split_no_lytaf) == list assert type(split_no_lytaf[0]) == dict assert not set(split_no_lytaf[0].keys()).symmetric_difference( {'subtimes', 'subdata'}) assert split_no_lytaf[0]["subtimes"] == dummy_time assert split_no_lytaf[0]["subdata"].all() == dummy_data.all()
def test_split_series_using_lytaf(): '''test the downloading of the LYTAF file and subsequent queries''' tmp_dir = tempfile.mkdtemp() lyra.download_lytaf_database(lytaf_dir=tmp_dir) assert os.path.exists(os.path.join(tmp_dir, 'annotation_ppt.db')) # test split_series_using_lytaf # construct a dummy signal for testing purposes basetime = parse_time('2010-06-13 02:00') seconds = 3600 dummy_time = [basetime + datetime.timedelta(0, s) for s in range(seconds)] dummy_data = np.random.random(seconds) lytaf_tmp = lyra.get_lytaf_events('2010-06-13 02:00', '2010-06-13 06:00', lytaf_path=tmp_dir, combine_files=["ppt"]) split = lyra.split_series_using_lytaf(dummy_time, dummy_data, lytaf_tmp) assert type(split) == list assert len(split) == 4 assert split[0]['subtimes'][0] == datetime.datetime(2010, 6, 13, 2, 0) assert split[0]['subtimes'][-1] == datetime.datetime(2010, 6, 13, 2, 7, 2) assert split[3]['subtimes'][0] == datetime.datetime(2010, 6, 13, 2, 59, 41) assert split[3]['subtimes'][-1] == datetime.datetime( 2010, 6, 13, 2, 59, 58) # Test case when no LYTAF events found in time series. split_no_lytaf = lyra.split_series_using_lytaf(dummy_time, dummy_data, LYTAF_TEST) assert type(split_no_lytaf) == list assert type(split_no_lytaf[0]) == dict assert not set(split_no_lytaf[0].keys()).symmetric_difference( {'subtimes', 'subdata'}) assert split_no_lytaf[0]["subtimes"] == dummy_time assert split_no_lytaf[0]["subdata"].all() == dummy_data.all()
def test_lytaf_utils(): '''test the downloading of the LYTAF file and subsequent queries''' tmp_dir = tempfile.mkdtemp() lyra.download_lytaf_database(lytaf_dir=tmp_dir) assert os.path.exists(os.path.join(tmp_dir, 'annotation_ppt.db')) #try doing a query on the temporary database lar = lyra.get_lytaf_events(TimeRange('2010-06-13 02:00', '2010-06-13 06:00'), lytaf_dir=tmp_dir) assert type(lar) == list assert type(lar[0]) == dict assert type(lar[0]['start_time']) == datetime.datetime assert type(lar[0]['end_time']) == datetime.datetime assert type(lar[0]['roi_description']) == str assert type(lar[0]['event_type_description']) == str assert lar[0]['start_time'] == parse_time('2010-06-13 02:07:04') assert lar[0]['end_time'] == parse_time('2010-06-13 02:10:04') assert lar[0]['event_type_description'] == 'LAR' #test split_series_using_lytaf #construct a dummy signal for testing purposes basetime = parse_time('2010-06-13 02:00') seconds = 3600 dummy_time = [basetime + datetime.timedelta(0, s) for s in range(seconds)] dummy_data = np.random.random(seconds) split = lyra.split_series_using_lytaf(dummy_time, dummy_data, lar) assert type(split) == list assert len(split) == 4 assert split[0]['subtimes'][0] == datetime.datetime(2010, 6, 13, 2, 0) assert split[0]['subtimes'][-1] == datetime.datetime(2010, 6, 13, 2, 7, 2) assert split[3]['subtimes'][0] == datetime.datetime(2010, 6, 13, 2, 59, 41) assert split[3]['subtimes'][-1] == datetime.datetime( 2010, 6, 13, 2, 59, 58)
def test_split_series_using_lytaf(): '''test the downloading of the LYTAF file and subsequent queries''' tmp_dir = tempfile.mkdtemp() lyra.download_lytaf_database(lytaf_dir=tmp_dir) assert os.path.exists(os.path.join(tmp_dir, 'annotation_ppt.db')) #test split_series_using_lytaf #construct a dummy signal for testing purposes basetime = parse_time('2010-06-13 02:00') seconds = 3600 dummy_time = [basetime + datetime.timedelta(0, s) for s in range(seconds)] dummy_data = np.random.random(seconds) lytaf_tmp = lyra.get_lytaf_events('2010-06-13 02:00', '2010-06-13 06:00', lytaf_path=tmp_dir, combine_files=["ppt"]) split = lyra.split_series_using_lytaf(dummy_time, dummy_data, lytaf_tmp) assert type(split) == list assert len(split) == 4 assert split[0]['subtimes'][0] == datetime.datetime(2010, 6, 13, 2, 0) assert split[0]['subtimes'][-1] == datetime.datetime(2010, 6, 13, 2, 7, 2) assert split[3]['subtimes'][0] == datetime.datetime(2010, 6, 13, 2, 59, 41) assert split[3]['subtimes'][-1] == datetime.datetime(2010, 6, 13, 2, 59, 58) # Test case when no LYTAF events found in time series. split_no_lytaf = lyra.split_series_using_lytaf(dummy_time, dummy_data, LYTAF_TEST) assert type(split_no_lytaf) == list assert type(split_no_lytaf[0]) == dict assert split_no_lytaf[0].keys() == ['subtimes', 'subdata'] assert split_no_lytaf[0]["subtimes"] == dummy_time assert split_no_lytaf[0]["subdata"].all() == dummy_data.all()
def test_lytaf_utils(): '''test the downloading of the LYTAF file and subsequent queries''' tmp_dir=tempfile.mkdtemp() lyra.download_lytaf_database(lytaf_dir=tmp_dir) assert os.path.exists(os.path.join(tmp_dir,'annotation_ppt.db')) #try doing a query on the temporary database lar=lyra.get_lytaf_events(TimeRange('2010-06-13 02:00','2010-06-13 06:00'),lytaf_dir=tmp_dir) assert type(lar) == list assert type(lar[0]) == dict assert type(lar[0]['start_time']) == datetime.datetime assert type(lar[0]['end_time']) == datetime.datetime assert type(lar[0]['roi_description']) == str assert type(lar[0]['event_type_description']) == str assert lar[0]['start_time'] == parse_time('2010-06-13 02:07:04') assert lar[0]['end_time'] == parse_time('2010-06-13 02:10:04') assert lar[0]['event_type_description'] == 'LAR' #test split_series_using_lytaf #construct a dummy signal for testing purposes basetime=parse_time('2010-06-13 02:00') seconds=3600 dummy_time = [basetime + datetime.timedelta(0, s) for s in range(seconds)] dummy_data=np.random.random(seconds) split=lyra.split_series_using_lytaf(dummy_time, dummy_data, lar) assert type(split) == list assert len(split) == 4 assert split[0]['subtimes'][0] == datetime.datetime(2010, 6, 13, 2, 0) assert split[0]['subtimes'][-1] == datetime.datetime(2010, 6, 13, 2, 7, 2) assert split[3]['subtimes'][0] == datetime.datetime(2010, 6, 13, 2, 59, 41) assert split[3]['subtimes'][-1] == datetime.datetime(2010, 6, 13, 2, 59, 58)
def test_lytaf_utils(): '''test the downloading of the LYTAF file and subsequent queries''' tmp_dir=tempfile.mkdtemp() lyra.download_lytaf_database(lytaf_dir=tmp_dir) assert os.path.exists(os.path.join(tmp_dir,'annotation_ppt.db')) #try doing a query on the temporary database lar=lyra.get_lytaf_events(TimeRange('2010-06-13 02:00','2010-06-13 06:00'),lytaf_dir=tmp_dir) assert type(lar) == list assert type(lar[0]) == dict assert type(lar[0]['start_time']) == datetime.datetime assert type(lar[0]['end_time']) == datetime.datetime assert type(lar[0]['roi_description']) == str assert type(lar[0]['event_type_description']) == str assert lar[0]['start_time'] == parse_time('2010-06-13 02:07:04') assert lar[0]['end_time'] == parse_time('2010-06-13 02:10:04') assert lar[0]['event_type_description'] == 'LAR'
def test_get_lytaf_events(local_cache): """ Test if LYTAF events are correctly downloaded and read in. """ # Run get_lytaf_events lytaf_test = lyra.get_lytaf_events("2008-01-01", "2014-01-01", force_use_local_lytaf=True) # Form expected result of extract_combined_lytaf insertion_time = [ datetime.datetime.utcfromtimestamp(1371459961), datetime.datetime.utcfromtimestamp(1371460063), datetime.datetime.utcfromtimestamp(1371460411), datetime.datetime.utcfromtimestamp(1371460493), datetime.datetime.utcfromtimestamp(1371460403), datetime.datetime.utcfromtimestamp(1371470988), datetime.datetime.utcfromtimestamp(1371211791), datetime.datetime.utcfromtimestamp(1371212303) ] begin_time = [ datetime.datetime.utcfromtimestamp(1359677220), datetime.datetime.utcfromtimestamp(1359681764), datetime.datetime.utcfromtimestamp(1360748513), datetime.datetime.utcfromtimestamp(1361115900), datetime.datetime.utcfromtimestamp(1361980964), datetime.datetime.utcfromtimestamp(1368581100), datetime.datetime.utcfromtimestamp(1371032084), datetime.datetime.utcfromtimestamp(1371158167) ] reference_time = [ datetime.datetime.utcfromtimestamp(1359677250), datetime.datetime.utcfromtimestamp(1359682450), datetime.datetime.utcfromtimestamp(1360751528), datetime.datetime.utcfromtimestamp(1361116200), datetime.datetime.utcfromtimestamp(1361983979), datetime.datetime.utcfromtimestamp(1368582480), datetime.datetime.utcfromtimestamp(1371045475), datetime.datetime.utcfromtimestamp(1371162600) ] end_time = [ datetime.datetime.utcfromtimestamp(1359677400), datetime.datetime.utcfromtimestamp(1359683136), datetime.datetime.utcfromtimestamp(1360754543), datetime.datetime.utcfromtimestamp(1361116320), datetime.datetime.utcfromtimestamp(1361986994), datetime.datetime.utcfromtimestamp(1368583080), datetime.datetime.utcfromtimestamp(1371050025), datetime.datetime.utcfromtimestamp(1371167100) ] event_type = [ "LAR", "UV occ.", "Vis LED on", "M Flare", "UV LED on", "X Flare", "Off-limb event", "Unexplained feature" ] event_description = [ "Large Angle Rotation.", "Occultation in the UV spectrum.", "Visual LED is turned on.", "M class solar flare.", "UV LED is turned on.", "X class solar flare.", "Off-limb event in SWAP.", "Unexplained feature." ] lytaf_expected = np.empty((8, ), dtype=[("insertion_time", object), ("begin_time", object), ("reference_time", object), ("end_time", object), ("event_type", object), ("event_definition", object)]) lytaf_expected["insertion_time"] = insertion_time lytaf_expected["begin_time"] = begin_time lytaf_expected["reference_time"] = reference_time lytaf_expected["end_time"] = end_time lytaf_expected["event_type"] = event_type lytaf_expected["event_definition"] = event_description # Assert that extract_combined_lytaf gives the right result np.testing.assert_array_equal(lytaf_test, lytaf_expected) # Check correct error is raised if names of different lytaf files # are incorrectly input. with pytest.raises(ValueError): lytaf_test = lyra.get_lytaf_events("2008-01-01", "2014-01-01", combine_files=["gigo"], force_use_local_lytaf=True)
def test_get_lytaf_events(): """Test if LYTAF events are correctly downloaded and read in.""" # Run get_lytaf_events lytaf_test = lyra.get_lytaf_events("2008-01-01", "2014-01-01", lytaf_path=TEST_DATA_PATH, force_use_local_lytaf=True) # Form expected result of extract_combined_lytaf insertion_time = [datetime.datetime.utcfromtimestamp(1371459961), datetime.datetime.utcfromtimestamp(1371460063), datetime.datetime.utcfromtimestamp(1371460411), datetime.datetime.utcfromtimestamp(1371460493), datetime.datetime.utcfromtimestamp(1371460403), datetime.datetime.utcfromtimestamp(1371470988), datetime.datetime.utcfromtimestamp(1371211791), datetime.datetime.utcfromtimestamp(1371212303)] begin_time = [datetime.datetime.utcfromtimestamp(1359677220), datetime.datetime.utcfromtimestamp(1359681764), datetime.datetime.utcfromtimestamp(1360748513), datetime.datetime.utcfromtimestamp(1361115900), datetime.datetime.utcfromtimestamp(1361980964), datetime.datetime.utcfromtimestamp(1368581100), datetime.datetime.utcfromtimestamp(1371032084), datetime.datetime.utcfromtimestamp(1371158167)] reference_time = [datetime.datetime.utcfromtimestamp(1359677250), datetime.datetime.utcfromtimestamp(1359682450), datetime.datetime.utcfromtimestamp(1360751528), datetime.datetime.utcfromtimestamp(1361116200), datetime.datetime.utcfromtimestamp(1361983979), datetime.datetime.utcfromtimestamp(1368582480), datetime.datetime.utcfromtimestamp(1371045475), datetime.datetime.utcfromtimestamp(1371162600)] end_time = [datetime.datetime.utcfromtimestamp(1359677400), datetime.datetime.utcfromtimestamp(1359683136), datetime.datetime.utcfromtimestamp(1360754543), datetime.datetime.utcfromtimestamp(1361116320), datetime.datetime.utcfromtimestamp(1361986994), datetime.datetime.utcfromtimestamp(1368583080), datetime.datetime.utcfromtimestamp(1371050025), datetime.datetime.utcfromtimestamp(1371167100)] event_type = [u"LAR", u"UV occ.", u"Vis LED on", u"M Flare", u"UV LED on", u"X Flare", u"Off-limb event", u"Unexplained feature"] event_description = [u"Large Angle Rotation.", u"Occultation in the UV spectrum.", u"Visual LED is turned on.", u"M class solar flare.", u"UV LED is turned on.", u"X class solar flare.", u"Off-limb event in SWAP.", u"Unexplained feature."] lytaf_expected = np.empty((8,), dtype=[("insertion_time", object), ("begin_time", object), ("reference_time", object), ("end_time", object), ("event_type", object), ("event_definition", object)]) lytaf_expected["insertion_time"] = insertion_time lytaf_expected["begin_time"] = begin_time lytaf_expected["reference_time"] = reference_time lytaf_expected["end_time"] = end_time lytaf_expected["event_type"] = event_type lytaf_expected["event_definition"] = event_description # Assert that extract_combined_lytaf gives the right result np.testing.assert_array_equal(lytaf_test, lytaf_expected) # Check correct error is raised if names of different lytaf files # are incorrectly input. with pytest.raises(ValueError): lytaf_test = lyra.get_lytaf_events("2008-01-01", "2014-01-01", lytaf_path="test_data", combine_files=["gigo"], force_use_local_lytaf=True)