From 615427f1e7d221b84958f5287cc33463a1c4dc26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20M=C3=BCller?= Date: Mon, 15 Jan 2024 23:22:32 +0100 Subject: [PATCH] ref: make nanite pure Python --- .github/workflows/check.yml | 2 +- .readthedocs.yml | 2 +- CHANGELOG | 4 + nanite/model/model_sneddon_spherical.pyx | 134 ------------------ pyproject.toml | 13 +- setup.py | 13 -- {nanite => src/nanite}/__init__.py | 0 {nanite => src/nanite}/cli/__init__.py | 0 {nanite => src/nanite}/cli/plotting.py | 0 {nanite => src/nanite}/cli/profile.py | 0 {nanite => src/nanite}/cli/rating.py | 0 {nanite => src/nanite}/fit.py | 0 {nanite => src/nanite}/group.py | 0 {nanite => src/nanite}/indent.py | 0 {nanite => src/nanite}/model/__init__.py | 9 +- {nanite => src/nanite}/model/core.py | 0 {nanite => src/nanite}/model/logic.py | 0 .../nanite}/model/model_conical_indenter.py | 0 .../nanite}/model/model_hertz_paraboloidal.py | 0 .../model/model_hertz_three_sided_pyramid.py | 0 .../model_sneddon_spherical_approximation.py | 0 {nanite => src/nanite}/model/residuals.py | 0 {nanite => src/nanite}/model/weight.py | 0 {nanite => src/nanite}/poc.py | 0 {nanite => src/nanite}/preproc.py | 0 {nanite => src/nanite}/qmap.py | 0 {nanite => src/nanite}/rate/__init__.py | 0 {nanite => src/nanite}/rate/features.py | 0 {nanite => src/nanite}/rate/io.py | 0 {nanite => src/nanite}/rate/rater.py | 0 {nanite => src/nanite}/rate/regressors.py | 0 .../train_feat_bin_apr_spikes_count.txt | 0 .../ts_zef18/train_feat_bin_cp_position.txt | 0 .../rate/ts_zef18/train_feat_bin_size.txt | 0 .../ts_zef18/train_feat_con_apr_flatness.txt | 0 .../rate/ts_zef18/train_feat_con_apr_size.txt | 0 .../rate/ts_zef18/train_feat_con_apr_sum.txt | 0 .../ts_zef18/train_feat_con_bln_slope.txt | 0 .../ts_zef18/train_feat_con_bln_variation.txt | 0 .../ts_zef18/train_feat_con_cp_curvature.txt | 0 .../ts_zef18/train_feat_con_cp_magnitude.txt | 0 .../train_feat_con_idt_maxima_75perc.txt | 0 .../ts_zef18/train_feat_con_idt_monotony.txt | 0 .../train_feat_con_idt_spike_area.txt | 0 .../rate/ts_zef18/train_feat_con_idt_sum.txt | 0 .../train_feat_con_idt_sum_75perc.txt | 0 .../nanite}/rate/ts_zef18/train_response.txt | 0 {nanite => src/nanite}/read.py | 0 {nanite => src/nanite}/smooth.py | 0 49 files changed, 17 insertions(+), 160 deletions(-) delete mode 100644 nanite/model/model_sneddon_spherical.pyx delete mode 100644 setup.py rename {nanite => src/nanite}/__init__.py (100%) rename {nanite => src/nanite}/cli/__init__.py (100%) rename {nanite => src/nanite}/cli/plotting.py (100%) rename {nanite => src/nanite}/cli/profile.py (100%) rename {nanite => src/nanite}/cli/rating.py (100%) rename {nanite => src/nanite}/fit.py (100%) rename {nanite => src/nanite}/group.py (100%) rename {nanite => src/nanite}/indent.py (100%) rename {nanite => src/nanite}/model/__init__.py (93%) rename {nanite => src/nanite}/model/core.py (100%) rename {nanite => src/nanite}/model/logic.py (100%) rename {nanite => src/nanite}/model/model_conical_indenter.py (100%) rename {nanite => src/nanite}/model/model_hertz_paraboloidal.py (100%) rename {nanite => src/nanite}/model/model_hertz_three_sided_pyramid.py (100%) rename {nanite => src/nanite}/model/model_sneddon_spherical_approximation.py (100%) rename {nanite => src/nanite}/model/residuals.py (100%) rename {nanite => src/nanite}/model/weight.py (100%) rename {nanite => src/nanite}/poc.py (100%) rename {nanite => src/nanite}/preproc.py (100%) rename {nanite => src/nanite}/qmap.py (100%) rename {nanite => src/nanite}/rate/__init__.py (100%) rename {nanite => src/nanite}/rate/features.py (100%) rename {nanite => src/nanite}/rate/io.py (100%) rename {nanite => src/nanite}/rate/rater.py (100%) rename {nanite => src/nanite}/rate/regressors.py (100%) rename {nanite => src/nanite}/rate/ts_zef18/train_feat_bin_apr_spikes_count.txt (100%) rename {nanite => src/nanite}/rate/ts_zef18/train_feat_bin_cp_position.txt (100%) rename {nanite => src/nanite}/rate/ts_zef18/train_feat_bin_size.txt (100%) rename {nanite => src/nanite}/rate/ts_zef18/train_feat_con_apr_flatness.txt (100%) rename {nanite => src/nanite}/rate/ts_zef18/train_feat_con_apr_size.txt (100%) rename {nanite => src/nanite}/rate/ts_zef18/train_feat_con_apr_sum.txt (100%) rename {nanite => src/nanite}/rate/ts_zef18/train_feat_con_bln_slope.txt (100%) rename {nanite => src/nanite}/rate/ts_zef18/train_feat_con_bln_variation.txt (100%) rename {nanite => src/nanite}/rate/ts_zef18/train_feat_con_cp_curvature.txt (100%) rename {nanite => src/nanite}/rate/ts_zef18/train_feat_con_cp_magnitude.txt (100%) rename {nanite => src/nanite}/rate/ts_zef18/train_feat_con_idt_maxima_75perc.txt (100%) rename {nanite => src/nanite}/rate/ts_zef18/train_feat_con_idt_monotony.txt (100%) rename {nanite => src/nanite}/rate/ts_zef18/train_feat_con_idt_spike_area.txt (100%) rename {nanite => src/nanite}/rate/ts_zef18/train_feat_con_idt_sum.txt (100%) rename {nanite => src/nanite}/rate/ts_zef18/train_feat_con_idt_sum_75perc.txt (100%) rename {nanite => src/nanite}/rate/ts_zef18/train_response.txt (100%) rename {nanite => src/nanite}/read.py (100%) rename {nanite => src/nanite}/smooth.py (100%) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index e7dd950..e7e84f6 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -25,7 +25,7 @@ jobs: python -m pip install --upgrade pip wheel python -m pip install coverage flake8 pytest # install dependencies - pip install -e .[CLI] + pip install -e .[ALL] # show installed packages pip freeze - name: Test with pytest diff --git a/.readthedocs.yml b/.readthedocs.yml index 1862a4b..e4fa3a3 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -9,5 +9,5 @@ python: - method: pip path: . extra_requirements: - - CLI + - ALL diff --git a/CHANGELOG b/CHANGELOG index eadc30f..98772eb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +4.1.0 + - ref: move to "src"-rooted source tree + - ref: move iterative `sneddon_spher` model to separate package which + makes nanite a pure Python package 4.0.0 - BREAKING CHANGE: Due to the new imputation of nan-valued features, rating inference might change slightly. For the "zef18" dataset, diff --git a/nanite/model/model_sneddon_spherical.pyx b/nanite/model/model_sneddon_spherical.pyx deleted file mode 100644 index 6a8a4ec..0000000 --- a/nanite/model/model_sneddon_spherical.pyx +++ /dev/null @@ -1,134 +0,0 @@ -# cython: language_level=3 -# cython: binding=True -import lmfit -import numpy as np -cimport numpy as np - - -def get_parameter_defaults(): - """Return the default model parameters""" - # The order of the parameters must match the order - # of ´parameter_names´ and ´parameter_keys´. - params = lmfit.Parameters() - params.add("E", value=3e3, min=0) - params.add("R", value=10e-6, min=0, vary=False) - params.add("nu", value=.5, min=0, max=0.5, vary=False) - params.add("contact_point", value=0) - params.add("baseline", value=0) - return params - - -def hertz_spherical(delta, double E, double R, double nu, - double contact_point=0, double baseline=0): - r"""Hertz model for Spherical indenter - modified by Sneddon - - - .. math:: - - F &= \frac{E}{1-\nu^2} \left( \frac{R^2+a^2}{2} \ln \! \left( - \frac{R+a}{R-a}\right) -aR \right)\\ - \delta &= \frac{a}{2} \ln - \! \left(\frac{R+a}{R-a}\right) - - (:math:`a` is the radius of the circular contact area between bead - and sample.) - - Parameters - ---------- - delta: 1d ndarray - Indentation [m] - E: float - Young's modulus [N/m²] - R: float - Tip radius [m] - nu: float - Poisson's ratio - contact_point: float - Indentation offset [m] - baseline: float - Force offset [N] - - Returns - ------- - F: float - Force [N] - - Notes - ----- - These approximations are made by the Hertz model: - - - The sample is isotropic. - - The sample is a linear elastic solid. - - The sample is extended infinitely in one half space. - - The indenter is not deformable. - - There are no additional interactions between sample and indenter. - - Additional assumptions: - - - no surface forces - - References - ---------- - Sneddon (1965) :cite:`Sneddon1965` (equations 6.13 and 6.15) - """ - cdef double a - cdef int ii - FF = np.zeros_like(delta) - root = delta-contact_point - root[root >0]=0 - root=-1*root - for ii in range(root.shape[0]): - if root[ii]==0: - FF[ii]=0 - else: - a=_get_a(R, root[ii]) - FF[ii]=E/(1-nu**2)*((R**2+a**2)/2*np.log((R+a)/(R-a))-a*R) - return FF + baseline - - -cdef double _get_a(double R, double delta, double accuracy=1e-12): - cdef double a_left, a_center, a_right, d_delta, delta_predict - a_left=0 - a_center=0.5*R - a_right=R - d_delta=1e200 #np.inf - while d_delta>accuracy: - delta_predict=_delta_of_a(a_center, R) - if delta_predict>delta: - a_left,a_right=a_left,a_center - a_center=a_left+(a_right-a_left)/2 - elif delta_predict=45", "setuptools_scm[toml]>=6.2" ] @@ -46,6 +42,8 @@ CLI = ["appdirs", "matplotlib>=2.2.2", "tifffile>=0.15.0", ] +ACA = ["nanite_model_sneddon_spher"] +ALL = ["nanite[CLI,ACA]"] [project.scripts] nanite-setup-profile = "nanite.cli:setup_profile [CLI]" @@ -59,12 +57,7 @@ tracker = "https://github.com/AFM-Analysis/nanite/issues" documentation = "https://nanite.readthedocs.io/en/stable/" changelog = "https://nanite.readthedocs.io/en/stable/sec_changelog.html" -# We need the following, because automatic package discovery does not work -# when running cibuildwheel on GitHub Actions (there will be a "wheelhouse" -# directory). -[tool.setuptools] -packages = ["nanite"] [tool.setuptools_scm] -write_to = "nanite/_version.py" +write_to = "src/nanite/_version.py" version_scheme = "post-release" diff --git a/setup.py b/setup.py deleted file mode 100644 index 790a3d6..0000000 --- a/setup.py +++ /dev/null @@ -1,13 +0,0 @@ -from setuptools import Extension, setup - -import numpy as np - - -setup( - ext_modules=[ - Extension("nanite.model.model_sneddon_spherical", - sources=["nanite/model/model_sneddon_spherical.pyx"], - include_dirs=[np.get_include()], - ) - ] -) diff --git a/nanite/__init__.py b/src/nanite/__init__.py similarity index 100% rename from nanite/__init__.py rename to src/nanite/__init__.py diff --git a/nanite/cli/__init__.py b/src/nanite/cli/__init__.py similarity index 100% rename from nanite/cli/__init__.py rename to src/nanite/cli/__init__.py diff --git a/nanite/cli/plotting.py b/src/nanite/cli/plotting.py similarity index 100% rename from nanite/cli/plotting.py rename to src/nanite/cli/plotting.py diff --git a/nanite/cli/profile.py b/src/nanite/cli/profile.py similarity index 100% rename from nanite/cli/profile.py rename to src/nanite/cli/profile.py diff --git a/nanite/cli/rating.py b/src/nanite/cli/rating.py similarity index 100% rename from nanite/cli/rating.py rename to src/nanite/cli/rating.py diff --git a/nanite/fit.py b/src/nanite/fit.py similarity index 100% rename from nanite/fit.py rename to src/nanite/fit.py diff --git a/nanite/group.py b/src/nanite/group.py similarity index 100% rename from nanite/group.py rename to src/nanite/group.py diff --git a/nanite/indent.py b/src/nanite/indent.py similarity index 100% rename from nanite/indent.py rename to src/nanite/indent.py diff --git a/nanite/model/__init__.py b/src/nanite/model/__init__.py similarity index 93% rename from nanite/model/__init__.py rename to src/nanite/model/__init__.py index fe52dac..971419c 100644 --- a/nanite/model/__init__.py +++ b/src/nanite/model/__init__.py @@ -3,7 +3,6 @@ from . import model_conical_indenter # noqa: F401 from . import model_hertz_paraboloidal # noqa: F401 from . import model_hertz_three_sided_pyramid # noqa: F401 -from . import model_sneddon_spherical # noqa: F401 from . import model_sneddon_spherical_approximation # noqa: F401 from .core import NaniteFitModel # noqa: F401 @@ -11,6 +10,14 @@ from .logic import models_available, register_model from .logic import deregister_model, load_model_from_file # noqa: F401 +try: + # Since version 4.1.0, the iterative sneddon_spher model is not + # part of nanite anymore. + from nanite_model_sneddon_spher import \ + model_sneddon_spherical # noqa: F401 +except (ImportError, MemoryError): + pass + def compute_anc_parms(idnt, model_key): """Compute ancillary parameters for a force-distance dataset diff --git a/nanite/model/core.py b/src/nanite/model/core.py similarity index 100% rename from nanite/model/core.py rename to src/nanite/model/core.py diff --git a/nanite/model/logic.py b/src/nanite/model/logic.py similarity index 100% rename from nanite/model/logic.py rename to src/nanite/model/logic.py diff --git a/nanite/model/model_conical_indenter.py b/src/nanite/model/model_conical_indenter.py similarity index 100% rename from nanite/model/model_conical_indenter.py rename to src/nanite/model/model_conical_indenter.py diff --git a/nanite/model/model_hertz_paraboloidal.py b/src/nanite/model/model_hertz_paraboloidal.py similarity index 100% rename from nanite/model/model_hertz_paraboloidal.py rename to src/nanite/model/model_hertz_paraboloidal.py diff --git a/nanite/model/model_hertz_three_sided_pyramid.py b/src/nanite/model/model_hertz_three_sided_pyramid.py similarity index 100% rename from nanite/model/model_hertz_three_sided_pyramid.py rename to src/nanite/model/model_hertz_three_sided_pyramid.py diff --git a/nanite/model/model_sneddon_spherical_approximation.py b/src/nanite/model/model_sneddon_spherical_approximation.py similarity index 100% rename from nanite/model/model_sneddon_spherical_approximation.py rename to src/nanite/model/model_sneddon_spherical_approximation.py diff --git a/nanite/model/residuals.py b/src/nanite/model/residuals.py similarity index 100% rename from nanite/model/residuals.py rename to src/nanite/model/residuals.py diff --git a/nanite/model/weight.py b/src/nanite/model/weight.py similarity index 100% rename from nanite/model/weight.py rename to src/nanite/model/weight.py diff --git a/nanite/poc.py b/src/nanite/poc.py similarity index 100% rename from nanite/poc.py rename to src/nanite/poc.py diff --git a/nanite/preproc.py b/src/nanite/preproc.py similarity index 100% rename from nanite/preproc.py rename to src/nanite/preproc.py diff --git a/nanite/qmap.py b/src/nanite/qmap.py similarity index 100% rename from nanite/qmap.py rename to src/nanite/qmap.py diff --git a/nanite/rate/__init__.py b/src/nanite/rate/__init__.py similarity index 100% rename from nanite/rate/__init__.py rename to src/nanite/rate/__init__.py diff --git a/nanite/rate/features.py b/src/nanite/rate/features.py similarity index 100% rename from nanite/rate/features.py rename to src/nanite/rate/features.py diff --git a/nanite/rate/io.py b/src/nanite/rate/io.py similarity index 100% rename from nanite/rate/io.py rename to src/nanite/rate/io.py diff --git a/nanite/rate/rater.py b/src/nanite/rate/rater.py similarity index 100% rename from nanite/rate/rater.py rename to src/nanite/rate/rater.py diff --git a/nanite/rate/regressors.py b/src/nanite/rate/regressors.py similarity index 100% rename from nanite/rate/regressors.py rename to src/nanite/rate/regressors.py diff --git a/nanite/rate/ts_zef18/train_feat_bin_apr_spikes_count.txt b/src/nanite/rate/ts_zef18/train_feat_bin_apr_spikes_count.txt similarity index 100% rename from nanite/rate/ts_zef18/train_feat_bin_apr_spikes_count.txt rename to src/nanite/rate/ts_zef18/train_feat_bin_apr_spikes_count.txt diff --git a/nanite/rate/ts_zef18/train_feat_bin_cp_position.txt b/src/nanite/rate/ts_zef18/train_feat_bin_cp_position.txt similarity index 100% rename from nanite/rate/ts_zef18/train_feat_bin_cp_position.txt rename to src/nanite/rate/ts_zef18/train_feat_bin_cp_position.txt diff --git a/nanite/rate/ts_zef18/train_feat_bin_size.txt b/src/nanite/rate/ts_zef18/train_feat_bin_size.txt similarity index 100% rename from nanite/rate/ts_zef18/train_feat_bin_size.txt rename to src/nanite/rate/ts_zef18/train_feat_bin_size.txt diff --git a/nanite/rate/ts_zef18/train_feat_con_apr_flatness.txt b/src/nanite/rate/ts_zef18/train_feat_con_apr_flatness.txt similarity index 100% rename from nanite/rate/ts_zef18/train_feat_con_apr_flatness.txt rename to src/nanite/rate/ts_zef18/train_feat_con_apr_flatness.txt diff --git a/nanite/rate/ts_zef18/train_feat_con_apr_size.txt b/src/nanite/rate/ts_zef18/train_feat_con_apr_size.txt similarity index 100% rename from nanite/rate/ts_zef18/train_feat_con_apr_size.txt rename to src/nanite/rate/ts_zef18/train_feat_con_apr_size.txt diff --git a/nanite/rate/ts_zef18/train_feat_con_apr_sum.txt b/src/nanite/rate/ts_zef18/train_feat_con_apr_sum.txt similarity index 100% rename from nanite/rate/ts_zef18/train_feat_con_apr_sum.txt rename to src/nanite/rate/ts_zef18/train_feat_con_apr_sum.txt diff --git a/nanite/rate/ts_zef18/train_feat_con_bln_slope.txt b/src/nanite/rate/ts_zef18/train_feat_con_bln_slope.txt similarity index 100% rename from nanite/rate/ts_zef18/train_feat_con_bln_slope.txt rename to src/nanite/rate/ts_zef18/train_feat_con_bln_slope.txt diff --git a/nanite/rate/ts_zef18/train_feat_con_bln_variation.txt b/src/nanite/rate/ts_zef18/train_feat_con_bln_variation.txt similarity index 100% rename from nanite/rate/ts_zef18/train_feat_con_bln_variation.txt rename to src/nanite/rate/ts_zef18/train_feat_con_bln_variation.txt diff --git a/nanite/rate/ts_zef18/train_feat_con_cp_curvature.txt b/src/nanite/rate/ts_zef18/train_feat_con_cp_curvature.txt similarity index 100% rename from nanite/rate/ts_zef18/train_feat_con_cp_curvature.txt rename to src/nanite/rate/ts_zef18/train_feat_con_cp_curvature.txt diff --git a/nanite/rate/ts_zef18/train_feat_con_cp_magnitude.txt b/src/nanite/rate/ts_zef18/train_feat_con_cp_magnitude.txt similarity index 100% rename from nanite/rate/ts_zef18/train_feat_con_cp_magnitude.txt rename to src/nanite/rate/ts_zef18/train_feat_con_cp_magnitude.txt diff --git a/nanite/rate/ts_zef18/train_feat_con_idt_maxima_75perc.txt b/src/nanite/rate/ts_zef18/train_feat_con_idt_maxima_75perc.txt similarity index 100% rename from nanite/rate/ts_zef18/train_feat_con_idt_maxima_75perc.txt rename to src/nanite/rate/ts_zef18/train_feat_con_idt_maxima_75perc.txt diff --git a/nanite/rate/ts_zef18/train_feat_con_idt_monotony.txt b/src/nanite/rate/ts_zef18/train_feat_con_idt_monotony.txt similarity index 100% rename from nanite/rate/ts_zef18/train_feat_con_idt_monotony.txt rename to src/nanite/rate/ts_zef18/train_feat_con_idt_monotony.txt diff --git a/nanite/rate/ts_zef18/train_feat_con_idt_spike_area.txt b/src/nanite/rate/ts_zef18/train_feat_con_idt_spike_area.txt similarity index 100% rename from nanite/rate/ts_zef18/train_feat_con_idt_spike_area.txt rename to src/nanite/rate/ts_zef18/train_feat_con_idt_spike_area.txt diff --git a/nanite/rate/ts_zef18/train_feat_con_idt_sum.txt b/src/nanite/rate/ts_zef18/train_feat_con_idt_sum.txt similarity index 100% rename from nanite/rate/ts_zef18/train_feat_con_idt_sum.txt rename to src/nanite/rate/ts_zef18/train_feat_con_idt_sum.txt diff --git a/nanite/rate/ts_zef18/train_feat_con_idt_sum_75perc.txt b/src/nanite/rate/ts_zef18/train_feat_con_idt_sum_75perc.txt similarity index 100% rename from nanite/rate/ts_zef18/train_feat_con_idt_sum_75perc.txt rename to src/nanite/rate/ts_zef18/train_feat_con_idt_sum_75perc.txt diff --git a/nanite/rate/ts_zef18/train_response.txt b/src/nanite/rate/ts_zef18/train_response.txt similarity index 100% rename from nanite/rate/ts_zef18/train_response.txt rename to src/nanite/rate/ts_zef18/train_response.txt diff --git a/nanite/read.py b/src/nanite/read.py similarity index 100% rename from nanite/read.py rename to src/nanite/read.py diff --git a/nanite/smooth.py b/src/nanite/smooth.py similarity index 100% rename from nanite/smooth.py rename to src/nanite/smooth.py