Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make test assertions approximate #154

Merged
merged 5 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 16 additions & 56 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
# Custom config files
*.conf.custom

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Cython
*.c
*.cpp

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
Expand All @@ -26,11 +20,9 @@ lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
Expand All @@ -50,9 +42,8 @@ htmlcov/
.cache
nosetests.xml
coverage.xml
*.cover
*,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
Expand All @@ -61,63 +52,32 @@ coverage.xml
# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
# Flask instance folder
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
doc/build/
docs/_build/

# pydocmd
_build/
mkdocs.yml
# MkDocs documentation
/site/

# PyBuilder
target/

# Jupyter Notebook
# Pycharm and VSCode
.idea/
venv/
.vscode/

# IPython Notebook
.ipynb_checkpoints

# pyenv
.python-version

# vscode
.vscode

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

.idea/
# OS
.DS_Store

*.~lock.*
*.zip
# written by setuptools_scm
**/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,33 @@ def test_track_export(
sleep(8)
spline_validate = np.load(validate_tracks_dir / "test_track.npy")
spline_test = np.load(test_tracks_dir / "test_track.npy")
np.testing.assert_equal(spline_validate, spline_test)
np.testing.assert_allclose(spline_validate, spline_test)


def compare_dataframes(df1, df2, threshold=0.9):
"""
Function to check how many entries are the same,
not how similar they are.

Required due to slight differences between operating
systems & architectures
"""
if df1.shape != df2.shape:
raise ValueError("DataFrames are not the same shape.")

total_entries = df1.shape[0] * df1.shape[1]
matching_entries = (df1 == df2).sum().sum()
similarity = matching_entries / total_entries
return similarity >= threshold


def check_analysis(test_tracks_dir, validate_tracks_dir):
regions_validate = pd.read_csv(validate_tracks_dir / "test_track.csv")
regions_test = pd.read_csv(test_tracks_dir / "test_track.csv")
pd.testing.assert_frame_equal(regions_validate, regions_test)
# Threshold of 0.9 is not ideal but sight differences in the analysis
# can have big effects on the final result (e.g. assigning to
# neighbouring anatomical areas
assert compare_dataframes(regions_validate, regions_test)


def check_saving(test_tracks_dir, validate_tracks_dir, rtol):
Expand Down
Loading