Skip to content

Commit

Permalink
tests: increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Nov 5, 2018
1 parent 3ac1eb9 commit 22415fa
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 5 deletions.
8 changes: 4 additions & 4 deletions nanite/rate/rater.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,14 @@ def rate(self, samples=None, datasets=None):
fsamples = []
bsamples = []
# float features
for dataset in datasets:
for idnt in datasets:
samp = self.compute_features(
dataset=dataset,
idnt=idnt,
names=self.names,
which_type=["continuous", "discrete"])
fsamples.append(samp)
for dataset in datasets:
bsamp = self.compute_features(dataset=dataset,
for idnt in datasets:
bsamp = self.compute_features(idnt=idnt,
names=self.names,
which_type="binary")
bsamples.append(bsamp)
Expand Down
Binary file not shown.
65 changes: 64 additions & 1 deletion tests/test_qmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

import numpy as np

from nanite import qmap
from nanite import model, qmap


datadir = pathlib.Path(__file__).resolve().parent / "data"
jpkfile = datadir / "map2x2_extracted.jpk-force-map"
jpkfile2 = datadir / "map-data-reference-points.jpk-force-map"


def test_metadata():
Expand Down Expand Up @@ -48,6 +49,68 @@ def test_feat_emod_nofit():
assert np.alltrue(np.isnan(qd))


def test_feat_emod_withfit():
qm = qmap.QMap(jpkfile2)
# fit data
for idnt in qm.ds:
idnt.apply_preprocessing(["compute_tip_position",
"correct_force_offset",
"correct_tip_offset",
])
inparams = model.model_sneddon_spherical_approximation \
.get_parameter_defaults()
inparams["E"].value = 50
inparams["R"].value = 37.28e-6 / 2

# Fit with absolute full range
idnt.fit_model(model_key="sneddon_spher_approx",
params_initial=inparams,
range_x=(0, 0),
range_type="absolute",
x_axis="tip position",
y_axis="force",
segment="approach",
weight_cp=2e-6)

qd = qm.get_qmap("fit young's modulus", qmap_only=True)
vals = qd.flat[~np.isnan(qd.flat)]
assert np.allclose(vals[0], 57.629464729399096), "gray matter"
assert np.allclose(vals[2], 46.614068655067435), "white matter"
assert np.allclose(vals[1], 17605.034108797558), "background"


def test_feat_rating():
"""Reproduces rating in figures 5K-M"""
qm = qmap.QMap(jpkfile2)
# fit data
for idnt in qm.ds:
idnt.apply_preprocessing(["compute_tip_position",
"correct_force_offset",
"correct_tip_offset"])
inparams = model.model_sneddon_spherical_approximation \
.get_parameter_defaults()
inparams["E"].value = 50
inparams["R"].value = 37.28e-6 / 2

# Fit with absolute full range
idnt.fit_model(model_key="sneddon_spher_approx",
params_initial=inparams,
range_x=(0, 0),
range_type="absolute",
x_axis="tip position",
y_axis="force",
segment="approach",
weight_cp=2e-6)
idnt.rate_quality(method="MERGE", ts_label="zef18")

qd = qm.get_qmap("meta rating", qmap_only=True)
vals = qd.flat[~np.isnan(qd.flat)]

assert np.allclose(vals[0], 9.765420865311263), "gray matter"
assert np.allclose(vals[2], 4.981720718347044), "white matter"
assert np.allclose(vals[1], 1.7713407492968665), "background"


if __name__ == "__main__":
# Run all tests
loc = locals()
Expand Down

0 comments on commit 22415fa

Please sign in to comment.