Skip to content

Commit

Permalink
ref: cleanup model functions
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Nov 20, 2020
1 parent 5ee8c4f commit 63d29c4
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 194 deletions.
49 changes: 0 additions & 49 deletions nanite/model/model_hertz_paraboloidal.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import lmfit
import numpy as np

from . import weight


def get_parameter_defaults():
"""Return the default model parameters"""
Expand Down Expand Up @@ -88,53 +86,6 @@ def hertz_paraboloidal(delta, E, R, nu, contact_point=0, baseline=0):
return aa*bb + baseline


def model(params, x):
if x[0] < x[-1]:
revert = True
else:
revert = False
if revert:
x = x[::-1]
mf = hertz_paraboloidal(E=params["E"].value,
delta=x,
R=params["R"].value,
nu=params["nu"].value,
contact_point=params["contact_point"].value,
baseline=params["baseline"].value)
if revert:
return mf[::-1]
return mf


def residual(params, delta, force, weight_cp=5e-7):
"""Compute residuals for fitting
Parameters
----------
params: lmfit.Parameters
The fitting parameters for `model`
delta: 1D ndarray of lenght M
The indentation distances
force: 1D ndarray of length M
The corresponding force data
weight_cp: positive float or zero/False
The distance from the contact point until which
linear weights will be applied. Set to zero to
disable weighting.
"""
md = model(params, delta)
resid = force-md

if weight_cp:
# weight the curve so that the data around the contact_point do
# not affect the fit so much.
weights = weight.weight_cp(cp=params["contact_point"].value,
delta=delta,
weight_dist=weight_cp)
resid *= weights
return resid


model_doc = hertz_paraboloidal.__doc__
model_func = hertz_paraboloidal
model_key = "hertz_para"
Expand Down
49 changes: 0 additions & 49 deletions nanite/model/model_hertz_three_sided_pyramid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import numpy as np
from numpy import pi

from . import weight


def get_parameter_defaults():
"""Return the default model parameters"""
Expand Down Expand Up @@ -72,53 +70,6 @@ def hertz_three_sided_pyramid(delta, E, alpha, nu, contact_point=0,
return aa*bb + baseline


def model(params, x):
if x[0] < x[-1]:
revert = True
else:
revert = False
if revert:
x = x[::-1]
mf = hertz_three_sided_pyramid(E=params["E"].value,
delta=x,
alpha=params["alpha"].value,
nu=params["nu"].value,
contact_point=params["contact_point"].value,
baseline=params["baseline"].value)
if revert:
return mf[::-1]
return mf


def residual(params, delta, force, weight_cp=5e-7):
"""Compute residuals for fitting
Parameters
----------
params: lmfit.Parameters
The fitting parameters for `model`
delta: 1D ndarray of lenght M
The indentation distances
force: 1D ndarray of length M
The corresponding force data
weight_cp: positive float or zero/False
The distance from the contact point until which
linear weights will be applied. Set to zero to
disable weighting.
"""
md = model(params, delta)
resid = force-md

if weight_cp:
# weight the curve so that the data around the contact_point do
# not affect the fit so much.
weights = weight.weight_cp(cp=params["contact_point"].value,
delta=delta,
weight_dist=weight_cp)
resid *= weights
return resid


model_doc = hertz_three_sided_pyramid.__doc__
model_func = hertz_three_sided_pyramid
model_key = "hertz_pyr3s"
Expand Down
47 changes: 0 additions & 47 deletions nanite/model/model_sneddon_spherical.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# cython: binding=True
import lmfit
import numpy as np
from . import weight
cimport numpy as np


Expand Down Expand Up @@ -123,52 +122,6 @@ def delta_of_a(a, R):
return _delta_of_a(a, R)


def model(params, x):
if x[0]<x[-1]:
revert = True
else:
revert = False
if revert:
x = x[::-1]
mf = hertz_spherical(E=params["E"].value,
delta=x,
R=params["R"].value,
nu=params["nu"].value,
contact_point=params["contact_point"].value,
baseline=params["baseline"].value)
if revert:
return mf[::-1]
return mf


def residual(params, delta, force, weight_cp=5e-7):
"""Compute residuals for fitting
Parameters
----------
params: lmfit.Parameters
The fitting parameters for `model`
delta: 1D ndarray of lenght M
The indentation distances
force: 1D ndarray of length M
The corresponding force data
weight_cp: positive float or zero/False
The distance from the contact point until which
linear weights will be applied. Set to zero to
disable weighting.
"""
md = model(params, delta)
resid = force-md

if weight_cp:
# weight the curve so that the data around the contact_point do
# not affect the fit so much.
weights = weight.weight_cp(cp=params["contact_point"].value,
delta=delta,
weight_dist=weight_cp)
resid *= weights
return resid

model_doc = hertz_spherical.__doc__
model_func = hertz_spherical
model_key = "sneddon_spher"
Expand Down
49 changes: 0 additions & 49 deletions nanite/model/model_sneddon_spherical_approximation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import lmfit
import numpy as np
from . import weight


def get_parameter_defaults():
Expand Down Expand Up @@ -82,54 +81,6 @@ def hertz_sneddon_spherical_approx(delta, E, R, nu, contact_point=0,
return aa*bb + baseline


def model(params, x):
if x[0] < x[-1]:
revert = True
else:
revert = False
if revert:
x = x[::-1]
mf = hertz_sneddon_spherical_approx(
E=params["E"].value,
delta=x,
R=params["R"].value,
nu=params["nu"].value,
contact_point=params["contact_point"].value,
baseline=params["baseline"].value)
if revert:
return mf[::-1]
return mf


def residual(params, delta, force, weight_cp=5e-7):
""" Compute residuals for fitting
Parameters
----------
params: lmfit.Parameters
The fitting parameters for `model`
delta: 1D ndarray of lenght M
The indentation distances
force: 1D ndarray of length M
The corresponding force data
weight_cp: positive float or zero/False
The distance from the contact point until which
linear weights will be applied. Set to zero to
disable weighting.
"""
md = model(params, delta)
resid = force-md

if weight_cp:
# weight the curve so that the data around the contact_point do
# not affect the fit so much.
weights = weight.weight_cp(cp=params["contact_point"].value,
delta=delta,
weight_dist=weight_cp)
resid *= weights
return resid


model_doc = hertz_sneddon_spherical_approx.__doc__
model_func = hertz_sneddon_spherical_approx
model_key = "sneddon_spher_approx"
Expand Down

0 comments on commit 63d29c4

Please sign in to comment.