Skip to content

Commit

Permalink
tests: reduced warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Nov 5, 2018
1 parent b7bfac2 commit a863fff
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
6 changes: 5 additions & 1 deletion nanite/preproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
from .smooth import smooth_axis_monotone


class CannotSplitWarning(UserWarning):
pass


class IndentationPreprocessor(object):
@staticmethod
def apply(apret, preproc_names):
Expand Down Expand Up @@ -119,7 +123,7 @@ def correct_split_approach_retract(apret):
else:
msg = "Cannot correct splitting of approach and retract curve " +\
"because the contact point position could not be estimated."
warnings.warn(msg)
warnings.warn(msg, CannotSplitWarning)

@staticmethod
def smooth_height(apret):
Expand Down
12 changes: 9 additions & 3 deletions nanite/smooth.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
""" smooth data
"""
"""smooth data"""
import warnings

import numpy as np
import scipy.ndimage as im


class DoubledSmoothingWindowWarning(UserWarning):
pass


def smooth_axis(data, window=15):
"""
Smooth a 1D data array with a median filter of `width`.
Expand Down Expand Up @@ -39,7 +42,10 @@ def smooth_axis_monotone(data, window=15):
window = window * 2 + 1
smooth = smooth_axis(data, window=window)
gradient = np.gradient(smooth)
warnings.warn("Doubled smoothing window size to {}".format(window))
warnings.warn("Automatically doubled smoothing `window` size to "
+ "{}. You might consider using a ".format(window)
+ "larger value by default.",
DoubledSmoothingWindowWarning)

while (np.unique(smooth).shape != smooth.shape):
# keep axis unique
Expand Down
3 changes: 3 additions & 0 deletions tests/test_indent_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pathlib

import numpy as np
import pytest

from nanite import IndentationDataSet

Expand All @@ -10,6 +11,8 @@
jpkfile = datapath / "spot3-0192.jpk-force"


@pytest.mark.filterwarnings('ignore::nanite.smooth.'
+ 'DoubledSmoothingWindowWarning')
def test_app_ret():
ds = IndentationDataSet(jpkfile)
ar = ds[0]
Expand Down
3 changes: 3 additions & 0 deletions tests/test_process_bad_files.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
"""Test of basic opening functionalities"""
import pathlib

import pytest

from nanite import IndentationDataSet


datadir = pathlib.Path(__file__).resolve().parent / "data"
bad_files = list(datadir.glob("bad*"))


@pytest.mark.filterwarnings('ignore::nanite.preproc.CannotSplitWarning')
def test_process_bad():
for bf in bad_files:
ds = IndentationDataSet(bf)
Expand Down

0 comments on commit a863fff

Please sign in to comment.