Exemplo n.º 1
0
def test_retrieve():
    sheet = Sheet("3", *three_faces_sheet())
    history = History(sheet, {"face": ["area"]})
    sheet_ = history.retrieve(0)
    for elem, dset in sheet_.datasets.items():
        assert dset.shape[0] == sheet.datasets[elem].shape[0]
    assert "area" in sheet_.datasets["face"].columns
    sheet_ = history.retrieve(1)
    for elem, dset in sheet_.datasets.items():
        assert dset.shape[0] == sheet.datasets[elem].shape[0]

    sheet.vert_df.loc[0, "x"] = 100
    sheet.face_df["area"] = 100
    history.record()
    sheet_ = history.retrieve(1)
    for elem, dset in sheet_.datasets.items():
        assert dset.shape[0] == sheet.datasets[elem].shape[0]
        print(dset)
    assert sheet_.datasets["vert"].loc[0, "x"] == 100
    assert sheet_.datasets["face"].loc[0, "area"] != 100
    history.record(["vert", "face"])
    sheet_ = history.retrieve(2)
    assert sheet_.datasets["face"].loc[0, "area"] == 100
    sheet_ = history.retrieve(1)
    assert sheet_.datasets["face"].loc[0, "area"] != 100
Exemplo n.º 2
0
def test_overwrite_time():
    sheet = Sheet("3", *three_faces_sheet())
    history = History(sheet)
    history.record(time_stamp=1)
    history.record(time_stamp=1)
    sheet_ = history.retrieve(1)
    assert sheet_.Nv == sheet.Nv
Exemplo n.º 3
0
def test_retrieve():
    sheet = Sheet("3", *three_faces_sheet())
    history = History(sheet)
    sheet_ = history.retrieve(0)
    for elem, dset in sheet_.datasets.items():
        assert dset.shape[0] == sheet.datasets[elem].shape[0]
    assert "area" in sheet_.datasets["face"].columns
    with pytest.warns(UserWarning):
        sheet_ = history.retrieve(1)
    for elem, dset in sheet_.datasets.items():
        assert dset.shape[0] == sheet.datasets[elem].shape[0]

    sheet.vert_df.loc[0, "x"] = 100.0
    sheet.face_df["area"] = 100.0
    history.record()
    sheet_ = history.retrieve(1)
    for elem, dset in sheet_.datasets.items():
        assert dset.shape[0] == sheet.datasets[elem].shape[0]
        print(dset)
    assert sheet_.datasets["vert"].loc[0, "x"] == 100.0
    assert sheet_.datasets["face"].loc[0, "area"] == 100.0
    history.record()
    sheet_ = history.retrieve(2)
    assert sheet_.datasets["face"].loc[0, "area"] == 100.0
    sheet_ = history.retrieve(1)
    assert sheet_.datasets["face"].loc[0, "area"] == 100.0
Exemplo n.º 4
0
def test_to_and_from_archive():

    sheet = Sheet("3", *three_faces_sheet())
    history = History(sheet)
    history.record()
    history.record()
    history.record()
    history.to_archive("test.hf5")
    history_h = HistoryHdf5.from_archive("test.hf5")
    sheet_ = history_h.retrieve(2)
    try:
        assert sheet_.Nv == sheet.Nv
    finally:
        os.remove("test.hf5")
Exemplo n.º 5
0
def test_browse():
    sheet = Sheet("3", *three_faces_sheet())
    history = History(sheet)
    for i in range(30):
        history.record(i / 10)

    times = [t for t, _ in history.browse()]
    np.testing.assert_allclose(times, history.time_stamps)

    times_areas = np.array([[t, s.face_df.loc[0, "area"]]
                            for t, s in history.browse(2, 8, endpoint=True)])
    assert times_areas.shape == (7, 2)
    assert times_areas[0, 0] == history.time_stamps[2]
    assert times_areas[-1, 0] == history.time_stamps[8]
    assert set(times_areas[:, 0]).issubset(history.time_stamps)

    times_areas = np.array([[t, s.face_df.loc[0, "area"]]
                            for t, s in history.browse(2, 8, 4, endpoint=False)
                            ])
    assert times_areas.shape == (4, 2)
    assert times_areas[0, 0] == history.time_stamps[2]
    assert times_areas[-1, 0] == history.time_stamps[7]
    assert set(times_areas[:, 0]).issubset(history.time_stamps)

    times_areas = np.array([[t, s.face_df.loc[0, "area"]]
                            for t, s in history.browse(2, 8, 4, endpoint=True)
                            ])
    assert times_areas.shape == (4, 2)
    assert times_areas[0, 0] == history.time_stamps[2]
    assert times_areas[-1, 0] == history.time_stamps[8]
    assert set(times_areas[:, 0]).issubset(history.time_stamps)

    times_areas = np.array([[t, s.face_df.loc[0, "area"]]
                            for t, s in history.browse(2, 8, 10)])
    assert times_areas.shape == (10, 2)
    assert times_areas[0, 0] == history.time_stamps[2]
    assert times_areas[-1, 0] == history.time_stamps[8]
    assert set(times_areas[:, 0]).issubset(history.time_stamps)

    times_areas = np.array([[t, s.edge_df.loc[0, "length"]]
                            for t, s in history.browse(size=40)])
    assert times_areas.shape == (40, 2)
    assert set(times_areas[:, 0]) == set(history.time_stamps)
Exemplo n.º 6
0
def test_simple_history():
    sheet = Sheet("3", *three_faces_sheet())
    history = History(sheet)
    assert "dx" in history.datasets["edge"].columns

    for element in sheet.datasets:
        assert sheet.datasets[element].shape[0] == history.datasets[
            element].shape[0]
    history.record()
    assert sheet.datasets["vert"].shape[0] * 2 == history.datasets[
        "vert"].shape[0]
    history.record()
    assert sheet.datasets["vert"].shape[0] * 3 == history.datasets[
        "vert"].shape[0]
    assert sheet.datasets["face"].shape[0] * 3 == history.datasets[
        "face"].shape[0]
    mono = Epithelium("eptm", extrude(sheet.datasets))
    histo2 = History(mono)
    for element in mono.datasets:
        assert mono.datasets[element].shape[0] == histo2.datasets[
            element].shape[0]
Exemplo n.º 7
0
def test_retrieve_coords():
    sheet = Sheet("3", *three_faces_sheet())
    history = History(sheet)
    history.record()
    assert history.retrieve(0).coords == sheet.coords