-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
19 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,30 @@ | ||
import io | ||
|
||
import numpy as np | ||
import pandas as pd | ||
|
||
from mantis.cli.estimate_stabilization import estimate_position_focus, get_mean_z_positions | ||
|
||
|
||
def test_estimate_position_focus(): | ||
# Create input data | ||
z_positions = [1, 2, 3, 4, 5] | ||
focus_scores = [0.1, 0.2, 0.3, 0.4, 0.5] | ||
|
||
# Call the function | ||
result = estimate_position_focus(z_positions, focus_scores) | ||
|
||
# Check the result | ||
assert isinstance(result, tuple) | ||
assert len(result) == 2 | ||
assert isinstance(result[0], float) | ||
assert isinstance(result[1], float) | ||
from mantis.cli.estimate_stabilization import get_mean_z_positions | ||
|
||
|
||
def test_mean_z_positions(): | ||
# Create input data | ||
df = pd.DataFrame( | ||
{ | ||
"channel": ["GFP"], | ||
"channel_idx": [0, 0, 0, 0, 0, 0, 0, 0], | ||
"time_min": [1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0], | ||
"focal_idx": [20, 25, 19, 16, 24, 29, 21, 18], | ||
"position_idx": [1, 2, 3, 4, 1, 2, 3, 4], | ||
"position": ['0/2/000000'] * 4 + ['0/2/001002'] * 4, | ||
"time_idx": [0, 1, 2, 3] * 2, | ||
"channel": ["GFP"] * 8, | ||
"focus_idx": [20, 25, np.nan, 16, 24, 29, 21, 18], | ||
} | ||
) | ||
|
||
# Create a pretend file | ||
s_buf = io.StringIO() | ||
df.to_csv(s_buf) | ||
s_buf.seek(0) | ||
|
||
# Call the function | ||
result = get_mean_z_positions(df, 0) | ||
pos_1 = np.array([20, 25, 19, 16]).mean() | ||
pos_2 = np.array([24, 29, 21, 18]).mean() | ||
result = get_mean_z_positions(s_buf, verbose=False) | ||
correct_result = np.array([22, 27, 25, 17]) | ||
|
||
# Check the result | ||
assert result == [pos_1, pos_2] | ||
assert all(result == correct_result) |