Example #1
0
def test_remove_lytaf_events_from_timeseries(lyra_ts):
    """
    Test if artifact are correctly removed from a TimeSeries.
    """
    # Check correct errors are raised due to bad input
    with pytest.raises(AttributeError):
        ts_test = lyra.remove_lytaf_events_from_timeseries(
            [], force_use_local_lytaf=True)

    # Run remove_artifacts_from_timeseries, returning artifact
    # status
    ts_test, artifact_status_test = \
        lyra.remove_lytaf_events_from_timeseries(
            lyra_ts, artifacts=["LAR", "Offpoint"], return_artifacts=True,
            force_use_local_lytaf=True)
    # Generate expected data by calling _remove_lytaf_events and
    # constructing expected dataframe manually.
    time, channels, artifact_status_expected = lyra._remove_lytaf_events(
        lyra_ts.to_dataframe().index,
        channels=[
            np.asanyarray(lyra_ts.to_dataframe()["CHANNEL1"]),
            np.asanyarray(lyra_ts.to_dataframe()["CHANNEL2"]),
            np.asanyarray(lyra_ts.to_dataframe()["CHANNEL3"]),
            np.asanyarray(lyra_ts.to_dataframe()["CHANNEL4"])
        ],
        artifacts=["LAR", "Offpoint"],
        return_artifacts=True,
        force_use_local_lytaf=True)
    dataframe_expected = pandas.DataFrame(index=time,
                                          data={
                                              "CHANNEL1": channels[0],
                                              "CHANNEL2": channels[1],
                                              "CHANNEL3": channels[2],
                                              "CHANNEL4": channels[3]
                                          })
    # Assert expected result is returned
    pandas.testing.assert_frame_equal(ts_test.to_dataframe(),
                                      dataframe_expected)
    assert artifact_status_test.keys() == artifact_status_expected.keys()
    np.testing.assert_array_equal(artifact_status_test["lytaf"],
                                  artifact_status_expected["lytaf"])
    np.testing.assert_array_equal(artifact_status_test["removed"],
                                  artifact_status_expected["removed"])
    np.testing.assert_array_equal(artifact_status_test["not_removed"],
                                  artifact_status_expected["not_removed"])
    assert artifact_status_test["not_found"] == \
        artifact_status_expected["not_found"]

    # Run remove_artifacts_from_timeseries, without returning
    # artifact status
    ts_test = \
        lyra.remove_lytaf_events_from_timeseries(
            lyra_ts, artifacts=["LAR", "Offpoint"],
            force_use_local_lytaf=True)
    # Assert expected result is returned
    pandas.testing.assert_frame_equal(ts_test.to_dataframe(),
                                      dataframe_expected)
Example #2
0
def test_remove_lytaf_events_from_timeseries(dtype):
    """Test if artefacts are correctly removed from a TimeSeries.
    Also test LYRALightCurve for backwards compatibility."""
    # Check correct errors are raised due to bad input
    with pytest.raises(AttributeError):
        ts_test = lyra.remove_lytaf_events_from_timeseries(
            [], lytaf_path=TEST_DATA_PATH, force_use_local_lytaf=True)

    # Run remove_artifacts_from_timeseries, returning artifact
    # status
    ts = get_lyradata(dtype)
    ts_test, artifact_status_test = \
        lyra.remove_lytaf_events_from_timeseries(
            ts, artifacts=["LAR", "Offpoint"], return_artifacts=True,
            lytaf_path=TEST_DATA_PATH, force_use_local_lytaf=True)
    # Generate expected data by calling _remove_lytaf_events and
    # constructing expected dataframe manually.
    time, channels, artifact_status_expected = lyra._remove_lytaf_events(
        ts.data.index,
        channels=[
            np.asanyarray(ts.data["CHANNEL1"]),
            np.asanyarray(ts.data["CHANNEL2"]),
            np.asanyarray(ts.data["CHANNEL3"]),
            np.asanyarray(ts.data["CHANNEL4"])
        ],
        artifacts=["LAR", "Offpoint"],
        return_artifacts=True,
        lytaf_path=TEST_DATA_PATH,
        force_use_local_lytaf=True)
    dataframe_expected = pandas.DataFrame(index=time,
                                          data={
                                              "CHANNEL1": channels[0],
                                              "CHANNEL2": channels[1],
                                              "CHANNEL3": channels[2],
                                              "CHANNEL4": channels[3]
                                          })
    # Assert expected result is returned
    pandas.util.testing.assert_frame_equal(ts_test.data, dataframe_expected)
    assert artifact_status_test.keys() == artifact_status_expected.keys()
    np.testing.assert_array_equal(artifact_status_test["lytaf"],
                                  artifact_status_expected["lytaf"])
    np.testing.assert_array_equal(artifact_status_test["removed"],
                                  artifact_status_expected["removed"])
    np.testing.assert_array_equal(artifact_status_test["not_removed"],
                                  artifact_status_expected["not_removed"])
    assert artifact_status_test["not_found"] == \
        artifact_status_expected["not_found"]

    # Run remove_artifacts_from_timeseries, without returning
    # artifact status
    ts_test = \
        lyra.remove_lytaf_events_from_timeseries(
            ts, artifacts=["LAR", "Offpoint"],
            lytaf_path=TEST_DATA_PATH, force_use_local_lytaf=True)
    # Assert expected result is returned
    pandas.util.testing.assert_frame_equal(ts_test.data, dataframe_expected)
Example #3
0
def test_remove_lytaf_events_from_timeseries(dtype):
    """Test if artefacts are correctly removed from a TimeSeries.
    Also test LYRALightCurve for backwards compatibility."""
    # Check correct errors are raised due to bad input
    with pytest.raises(AttributeError):
        ts_test = lyra.remove_lytaf_events_from_timeseries(
            [], lytaf_path=TEST_DATA_PATH, force_use_local_lytaf=True)

    # Run remove_artifacts_from_timeseries, returning artifact
    # status
    ts = get_lyradata(dtype)
    ts_test, artifact_status_test = \
        lyra.remove_lytaf_events_from_timeseries(
            ts, artifacts=["LAR", "Offpoint"], return_artifacts=True,
            lytaf_path=TEST_DATA_PATH, force_use_local_lytaf=True)
    # Generate expected data by calling _remove_lytaf_events and
    # constructing expected dataframe manually.
    time, channels, artifact_status_expected = lyra._remove_lytaf_events(
        ts.data.index, channels=[np.asanyarray(ts.data["CHANNEL1"]),
                                 np.asanyarray(ts.data["CHANNEL2"]),
                                 np.asanyarray(ts.data["CHANNEL3"]),
                                 np.asanyarray(ts.data["CHANNEL4"])],
        artifacts=["LAR", "Offpoint"], return_artifacts=True,
        lytaf_path=TEST_DATA_PATH, force_use_local_lytaf=True)
    dataframe_expected = pandas.DataFrame(index=time,
                                          data={"CHANNEL1": channels[0],
                                                "CHANNEL2": channels[1],
                                                "CHANNEL3": channels[2],
                                                "CHANNEL4": channels[3]})
    # Assert expected result is returned
    pandas.util.testing.assert_frame_equal(ts_test.data, dataframe_expected)
    assert artifact_status_test.keys() == artifact_status_expected.keys()
    np.testing.assert_array_equal(artifact_status_test["lytaf"],
                                  artifact_status_expected["lytaf"])
    np.testing.assert_array_equal(artifact_status_test["removed"],
                                  artifact_status_expected["removed"])
    np.testing.assert_array_equal(artifact_status_test["not_removed"],
                                  artifact_status_expected["not_removed"])
    assert artifact_status_test["not_found"] == \
        artifact_status_expected["not_found"]

    # Run remove_artifacts_from_timeseries, without returning
    # artifact status
    ts_test = \
        lyra.remove_lytaf_events_from_timeseries(
            ts, artifacts=["LAR", "Offpoint"],
            lytaf_path=TEST_DATA_PATH, force_use_local_lytaf=True)
    # Assert expected result is returned
    pandas.util.testing.assert_frame_equal(ts_test.data, dataframe_expected)