Skip to content

Commit

Permalink
ref: rename IndentationDataSet to IndentationGroup to avoid ambiguities
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Nov 6, 2018
1 parent 5c053da commit 3c88897
Show file tree
Hide file tree
Showing 24 changed files with 159 additions and 90 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,4 @@ venv.bak/

*.c
_version_save.py
*.bib.bak
12 changes: 6 additions & 6 deletions docs/sec_code_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ at the module level.

alias of :class:`nanite.indent.Indentation`

.. class:: nanite.IndentationDataSet
.. class:: nanite.IndentationGroup

alias of :class:`nanite.dataset.IndentationDataSet`
alias of :class:`nanite.group.IndentationGroup`

.. class:: nanite.IndentationRater

Expand All @@ -41,12 +41,12 @@ Force-indentation data
:undoc-members:


.. _sec_ref_dataset:
.. _sec_ref_group:

Datasets
========
Groups
======

.. automodule:: nanite.dataset
.. automodule:: nanite.group
:members:
:undoc-members:

Expand Down
2 changes: 1 addition & 1 deletion nanite/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .dataset import IndentationDataSet # noqa: F401
from .group import IndentationGroup # noqa: F401
from . import fit # noqa: F401
from .indent import Indentation, type_indentation # noqa: F401
from . import model # noqa: F401
Expand Down
8 changes: 4 additions & 4 deletions nanite/cli/rating.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import tifffile

from ..indent import Indentation
from ..dataset import IndentationDataSet
from ..group import IndentationGroup
from ..read import get_data_paths, get_data_paths_enum
from ..rate import io as rio

Expand Down Expand Up @@ -186,8 +186,8 @@ def fit():
ptsv.open(mode="a") as ts:
for pp in datapaths:
print("Processing: {}".format(pp))
ds = IndentationDataSet(pp)
for idnt in ds:
grp = IndentationGroup(pp)
for idnt in grp:
fit_data(idnt)
# save statistics
stats = [str(dd[1](idnt)) for dd in dlist]
Expand All @@ -211,7 +211,7 @@ def fit_data(path, enum=0, profile_path=PROFILE_PATH):
if isinstance(path, Indentation):
idnt = path
else:
idnt = IndentationDataSet(path)[enum]
idnt = IndentationGroup(path)[enum]

pf = Profile(path=profile_path, create=False)

Expand Down
18 changes: 9 additions & 9 deletions nanite/dataset.py → nanite/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from .indent import Indentation, type_indentation


class IndentationDataSet(object):
class IndentationGroup(object):
def __init__(self, path=None, callback=None):
"""Collection of Indentation
"""Group of Indentation
Parameters
----------
Expand Down Expand Up @@ -34,7 +34,7 @@ def __init__(self, path=None, callback=None):
))

def __add__(self, ds):
out = IndentationDataSet()
out = IndentationGroup()
out._mmlist = self._mmlist + ds._mmlist
return out

Expand All @@ -52,18 +52,18 @@ def __len__(self):
return len(self._mmlist)

def __repr__(self):
return "IndentationDataSet: {} ".format(self._mmlist.__repr__())
return "IndentationGroup: {} ".format(self._mmlist.__repr__())

def append(self, item):
self._mmlist.append(item)

def index(self, item):
return self._mmlist.index(item)

def subset_with_path(self, path):
"""Return a subset with measurements matching `path`"""
subset = IndentationDataSet()
def subgroup_with_path(self, path):
"""Return a subgroup with measurements matching `path`"""
subgroup = IndentationGroup()
for idnt in self:
if pathlib.Path(idnt.path) == pathlib.Path(path):
subset.append(idnt)
return subset
subgroup.append(idnt)
return subgroup
22 changes: 11 additions & 11 deletions nanite/qmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import numpy as np

from .dataset import IndentationDataSet
from .group import IndentationGroup


class DataMissingWarning(UserWarning):
Expand All @@ -16,20 +16,20 @@ def __init__(self, path_or_dataset, callback=None):
Parameters
----------
path_or_dataset: str or nanite.IndentationDataSet
path_or_dataset: str or nanite.IndentationGroup
The path to the data file. The data format is determined
using the extension of the file and the data is loaded
with the correct method.
callback: callable or None
A method that accepts a float between 0 and 1
to externally track the process of loading the data.
"""
if isinstance(path_or_dataset, IndentationDataSet):
ds = path_or_dataset
if isinstance(path_or_dataset, IndentationGroup):
group = path_or_dataset
else:
ds = IndentationDataSet(path=path_or_dataset, callback=callback)
#: Experimental dataset
self.ds = ds
group = IndentationGroup(path=path_or_dataset, callback=callback)
#: Indentation data (instance of :class:`nanite.IndentationGroup`)
self.group = group

# Feature functions
self._feature_funcs = {
Expand Down Expand Up @@ -98,7 +98,7 @@ def _map_grid(self, coords, map_data):
@functools.lru_cache(maxsize=32)
def extent(self):
"""extent (x1, x2, y1, y2) [µm]"""
idnt0 = self.ds[0]
idnt0 = self.group[0]
# get extent of the map
sx = idnt0.metadata["grid size x [µm]"]
sy = idnt0.metadata["grid size y [µm]"]
Expand All @@ -113,7 +113,7 @@ def extent(self):
@functools.lru_cache(maxsize=32)
def shape(self):
"""shape of the map [px]"""
idnt0 = self.ds[0]
idnt0 = self.group[0]
# get shape of the map
shape = (idnt0.metadata["grid size x [px]"],
idnt0.metadata["grid size y [px]"]
Expand Down Expand Up @@ -170,7 +170,7 @@ def get_coords(self, which="px"):
kx = "position x [µm]"
ky = "position y [µm]"
coords = []
for idnt in self.ds:
for idnt in self.group:
# We assume that kx and ky are given. This has to be
# ensured by the file format reader for qmaps.
cc = [idnt.metadata[kx], idnt.metadata[ky]]
Expand Down Expand Up @@ -200,7 +200,7 @@ def get_qmap(self, feature, qmap_only=False):

map_data = []
ffunc = self._feature_funcs[feature]
for idnt in self.ds:
for idnt in self.group:
val = ffunc(idnt)
map_data.append(val)

Expand Down
4 changes: 2 additions & 2 deletions nanite/rate/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import numpy as np
from sklearn import model_selection

from ..dataset import IndentationDataSet
from ..group import IndentationGroup
from . import rater


Expand Down Expand Up @@ -248,7 +248,7 @@ def load_hdf5(path, meta_only=False):
name = dkey + "_" + pathlib.Path(dset.attrs["path"]).name
dpath = pathlib.Path(tdir) / name
dbin.tofile(str(dpath))
dataset_dict[dkey] = IndentationDataSet(dpath)
dataset_dict[dkey] = IndentationGroup(dpath)
# load individual curves
for akey in h5["analysis"]:
h5gr = h5["analysis"][akey]
Expand Down
6 changes: 3 additions & 3 deletions tests/test_dataset.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"""Test of data set functionalities"""
import pathlib

from nanite import Indentation, IndentationDataSet
from nanite import Indentation, IndentationGroup


datadir = pathlib.Path(__file__).resolve().parent / "data"
jpkfile = datadir / "spot3-0192.jpk-force"


def test_afm_data_set():
ds1 = IndentationDataSet(jpkfile)
ds2 = IndentationDataSet(jpkfile)
ds1 = IndentationGroup(jpkfile)
ds2 = IndentationGroup(jpkfile)

ds3 = ds1 + ds2
assert len(ds3) == 2
Expand Down
8 changes: 4 additions & 4 deletions tests/test_fit_emodulus_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import numpy as np

from nanite import IndentationDataSet
from nanite import IndentationGroup
from nanite.fit import FitDataError


Expand All @@ -14,7 +14,7 @@


def test_emodulus_search():
ds = IndentationDataSet(jpkfile)
ds = IndentationGroup(jpkfile)
ar = ds[0]
ar.apply_preprocessing(["compute_tip_position",
"correct_force_offset",
Expand Down Expand Up @@ -65,7 +65,7 @@ def test_cache_emodulus():
# Check that the fitting procedure does not perform unneccessary
# double fits and uses the cached variables for emoduli and
# minimal indentations.
ds = IndentationDataSet(jpkfile)
ds = IndentationGroup(jpkfile)
ar = ds[0]
ar.apply_preprocessing(["compute_tip_position",
"correct_force_offset",
Expand Down Expand Up @@ -99,7 +99,7 @@ def test_cache_emodulus():
def test_fit_data_error():
# a FitDataError is raised when it is not possible to compute an
# E(delta) curve:
ds = IndentationDataSet(badjpk)
ds = IndentationGroup(badjpk)
ar = ds[0]
ar.apply_preprocessing(["compute_tip_position",
"correct_force_offset",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_fit_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import time

import nanite
from nanite import IndentationDataSet
from nanite import IndentationGroup


datapath = pathlib.Path(__file__).parent / "data"
jpkfile = datapath / "spot3-0192.jpk-force"


def test_hash_time():
ds1 = IndentationDataSet(jpkfile)
ds1 = IndentationGroup(jpkfile)
apret = ds1[0]
apret.apply_preprocessing(["compute_tip_position"])

Expand Down
8 changes: 4 additions & 4 deletions tests/test_fit_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pathlib

from nanite.fit import FitProperties, FP_DEFAULT, FitKeyError
from nanite import IndentationDataSet
from nanite import IndentationGroup
from nanite import model


Expand Down Expand Up @@ -34,7 +34,7 @@ def test_fp_reset():


def test_with_dataset():
ar = IndentationDataSet(jpkfile)[0]
ar = IndentationGroup(jpkfile)[0]
# Initially, fit properties are not set
assert not ar.fit_properties
assert isinstance(ar.fit_properties, dict)
Expand Down Expand Up @@ -64,7 +64,7 @@ def test_with_dataset():


def test_change_model_key():
ar = IndentationDataSet(jpkfile)[0]
ar = IndentationGroup(jpkfile)[0]
# Prepprocessing
ar.apply_preprocessing(["compute_tip_position",
"correct_tip_offset",
Expand All @@ -91,7 +91,7 @@ def test_wrong_key():


def test_wrong_params_initial():
ar = IndentationDataSet(jpkfile)[0]
ar = IndentationGroup(jpkfile)[0]
# Prepprocessing
ar.apply_preprocessing(["compute_tip_position",
"correct_tip_offset",
Expand Down
18 changes: 9 additions & 9 deletions tests/test_indent.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


def test_apply_preprocessing():
ds1 = nanite.IndentationDataSet(jpkfile)
ds1 = nanite.IndentationGroup(jpkfile)
idnt = ds1[0]
# apply preprocessing by manually setting the list
idnt.preprocessing = ["compute_tip_position"]
Expand All @@ -26,7 +26,7 @@ def test_apply_preprocessing_remember_fit_properties():
if the preprocessing changes. For user convenience,
nanite remembers it. This is the test
"""
ds1 = nanite.IndentationDataSet(jpkfile)
ds1 = nanite.IndentationGroup(jpkfile)
idnt = ds1[0]
idnt.apply_preprocessing(["compute_tip_position"])

Expand Down Expand Up @@ -55,7 +55,7 @@ def test_apply_preprocessing_remember_fit_properties():


def test_basic():
ds1 = nanite.IndentationDataSet(jpkfile)
ds1 = nanite.IndentationGroup(jpkfile)
idnt = ds1[0]
# tip-sample separation
idnt.apply_preprocessing(["compute_tip_position"])
Expand All @@ -69,7 +69,7 @@ def test_basic():


def test_export():
ds1 = nanite.IndentationDataSet(jpkfile)
ds1 = nanite.IndentationGroup(jpkfile)
idnt = ds1[0]
# tip-sample separation
idnt.apply_preprocessing(["compute_tip_position"])
Expand All @@ -93,7 +93,7 @@ def test_export():


def test_fitting():
ds1 = nanite.IndentationDataSet(jpkfile)
ds1 = nanite.IndentationGroup(jpkfile)
idnt = ds1[0]
idnt.apply_preprocessing(["compute_tip_position"])

Expand Down Expand Up @@ -146,7 +146,7 @@ def test_fitting():
@pytest.mark.filterwarnings('ignore::nanite.fit.FitWarning')
def test_get_initial_fit_parameters():
"""This is a convenience function"""
ds1 = nanite.IndentationDataSet(jpkfile)
ds1 = nanite.IndentationGroup(jpkfile)
idnt = ds1[0]
# A: sanity check
try:
Expand Down Expand Up @@ -179,7 +179,7 @@ def test_get_model():


def test_rate_quality_cache():
ds1 = nanite.IndentationDataSet(jpkfile)
ds1 = nanite.IndentationGroup(jpkfile)
idnt = ds1[0]
idnt.apply_preprocessing(["compute_tip_position"])

Expand All @@ -205,7 +205,7 @@ def test_rate_quality_cache():


def test_rate_quality_disabled():
ds1 = nanite.IndentationDataSet(jpkfile)
ds1 = nanite.IndentationGroup(jpkfile)
idnt = ds1[0]
idnt.apply_preprocessing(["compute_tip_position"])

Expand All @@ -229,7 +229,7 @@ def test_rate_quality_disabled():


def test_rate_quality_nofit():
ds1 = nanite.IndentationDataSet(jpkfile)
ds1 = nanite.IndentationGroup(jpkfile)
idnt = ds1[0]
r1 = idnt.rate_quality()
assert r1 == -1
Expand Down

0 comments on commit 3c88897

Please sign in to comment.