Skip to content

Commit

Permalink
Merge branch 'Cookie' of github.com:diffpy/diffpy.srmise into Cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
sbillinge committed Jul 30, 2024
2 parents 5249bf2 + 978dca1 commit b44c264
Show file tree
Hide file tree
Showing 22 changed files with 101 additions and 120 deletions.
34 changes: 13 additions & 21 deletions diffpy/srmise/applications/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,25 +419,19 @@ def main():
from diffpy.srmise.pdfpeakextraction import PDFPeakExtraction
from diffpy.srmise.srmiseerrors import SrMiseDataFormatError, SrMiseFileError

if options.peakfunction is not None:
from diffpy.srmise import peaks

try:
options.peakfunction = eval("peaks." + options.peakfunction)
except Exception as err:
print(err)
print("Could not create peak function '%s'. Exiting." % options.peakfunction)
return

if options.modelevaluator is not None:
from diffpy.srmise import modelevaluators

try:
options.modelevaluator = eval("modelevaluators." + options.modelevaluator)
except Exception as err:
print(err)
print("Could not find ModelEvaluator '%s'. Exiting." % options.modelevaluator)
return
try:
options.peakfunction = eval("peaks." + options.peakfunction)
except Exception as err:
print(err)
print("Could not create peak function '%s'. Exiting." % options.peakfunction)
return

try:
options.modelevaluator = eval("modelevaluators." + options.modelevaluator)
except Exception as err:
print(err)
print("Could not find ModelEvaluator '%s'. Exiting." % options.modelevaluator)
return

if options.bcrystal is not None:
from diffpy.srmise.baselines import Polynomial
Expand Down Expand Up @@ -475,8 +469,6 @@ def main():

bl = NanoSpherical()
options.baseline = parsepars(bl, options.bspherical)
elif options.baseline is not None:
from diffpy.srmise import baselines

try:
options.baseline = eval("baselines." + options.baseline)
Expand Down
3 changes: 1 addition & 2 deletions diffpy/srmise/basefunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#
# SrMise by Luke Granlund
# (c) 2014 trustees of the Michigan State University
# (c) 2024 trustees of Columia University in the City of New York
# (c) 2024 trustees of Columia University in the City of New York
# (c) 2024 trustees of Columbia University in the City of New York
# All rights reserved.
#
# File coded by: Luke Granlund
Expand Down
14 changes: 7 additions & 7 deletions diffpy/srmise/baselines/arbitrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# SrMise by Luke Granlund
# (c) 2014 trustees of the Michigan State University
# (c) 2024 trustees of Columia University in the City of New York
# (c) 2024 trustees of Columbia University in the City of New York
# All rights reserved.
#
# File coded by: Luke Granlund
Expand Down Expand Up @@ -89,11 +89,12 @@ def __init__(self, npars, valuef, jacobianf=None, estimatef=None, Cache=None):

# TODO: figure out how the metadict can be used to save the functions
# and use them again when a file is loaded...
metadict = {}
metadict["npars"] = (npars, repr)
metadict["valuef"] = (valuef, repr)
metadict["jacobianf"] = (jacobianf, repr)
metadict["estimatef"] = (estimatef, repr)
metadict = {
"npars": (npars, repr),
"valuef": (valuef, repr),
"jacobianf": (jacobianf, repr),
"estimatef": (estimatef, repr),
}
BaselineFunction.__init__(self, parameterdict, formats, default_formats, metadict, None, Cache)

# Methods required by BaselineFunction ####
Expand Down Expand Up @@ -182,7 +183,6 @@ def _transform_parametersraw(self, pars, in_format, out_format):
def _valueraw(self, pars, r):
"""Return value of polynomial for the given parameters and r values.
Parameters
Parameters
pars: Sequence of parameters
pars[0] = a_0
Expand Down
2 changes: 1 addition & 1 deletion diffpy/srmise/baselines/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# SrMise by Luke Granlund
# (c) 2014 trustees of the Michigan State University
# (c) 2024 trustees of Columia University in the City of New York
# (c) 2024 trustees of Columbia University in the City of New York
# All rights reserved.
#
# File coded by: Luke Granlund
Expand Down
2 changes: 1 addition & 1 deletion diffpy/srmise/baselines/fromsequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# SrMise by Luke Granlund
# (c) 2014 trustees of the Michigan State University
# (c) 2024 trustees of Columia University in the City of New York
# (c) 2024 trustees of Columbia University in the City of New York
# All rights reserved.
#
# File coded by: Luke Granlund
Expand Down
4 changes: 2 additions & 2 deletions diffpy/srmise/baselines/nanospherical.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# SrMise by Luke Granlund
# (c) 2014 trustees of the Michigan State University
# (c) 2024 trustees of Columia University in the City of New York
# (c) 2024 trustees of Columbia University in the City of New York
# All rights reserved.
#
# File coded by: Luke Granlund
Expand Down Expand Up @@ -35,7 +35,7 @@ class NanoSpherical(BaselineFunction):
scale factor is 4*pi*rho_0, where rho_r is the nanoparticle density.
gamma_0(r) Reference:
Guinier et. al. (1955). Small-angle Scattering from X-rays. New York: John Wiley & Sons, Inc.
Guinier et al. (1955). Small-angle Scattering from X-rays. New York: John Wiley & Sons, Inc.
"""

def __init__(self, Cache=None):
Expand Down
10 changes: 4 additions & 6 deletions diffpy/srmise/baselines/polynomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# SrMise by Luke Granlund
# (c) 2014 trustees of the Michigan State University
# (c) 2024 trustees of Columia University in the City of New York
# (c) 2024 trustees of Columbia University in the City of New York
# All rights reserved.
#
# File coded by: Luke Granlund
Expand Down Expand Up @@ -49,8 +49,7 @@ def __init__(self, degree, Cache=None):
parameterdict["a_" + str(d)] = self.degree - d
formats = ["internal"]
default_formats = {"default_input": "internal", "default_output": "internal"}
metadict = {}
metadict["degree"] = (degree, repr)
metadict = {"degree": (degree, repr)}
BaselineFunction.__init__(self, parameterdict, formats, default_formats, metadict, None, Cache)

# Methods required by BaselineFunction ####
Expand Down Expand Up @@ -95,12 +94,11 @@ def estimate_parameters(self, r, y):

import numpy.linalg as la

A = np.array([r[cut_idx]]).T
slope = la.lstsq(A, y[cut_idx])[0][0]
a = np.array([r[cut_idx]]).T
slope = la.lstsq(a, y[cut_idx])[0][0]
return np.array([slope, 0.0])
except Exception as e:
emsg = "Error during estimation -- " + str(e)
raise
raise SrMiseEstimationError(emsg)

def _jacobianraw(self, pars, r, free):
Expand Down
2 changes: 1 addition & 1 deletion diffpy/srmise/dataclusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# SrMise by Luke Granlund
# (c) 2014 trustees of the Michigan State University
# (c) 2024 trustees of Columia University in the City of New York
# (c) 2024 trustees of Columbia University in the City of New York
# All rights reserved.
#
# File coded by: Luke Granlund
Expand Down
2 changes: 1 addition & 1 deletion diffpy/srmise/modelcluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# SrMise by Luke Granlund
# (c) 2014 trustees of the Michigan State University
# (c) 2024 trustees of Columia University in the City of New York
# (c) 2024 trustees of Columbia University in the City of New York
# All rights reserved.
#
# File coded by: Luke Granlund
Expand Down
15 changes: 8 additions & 7 deletions diffpy/srmise/modelevaluators/aic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# SrMise by Luke Granlund
# (c) 2014 trustees of the Michigan State University
# (c) 2024 trustees of Columia University in the City of New York
# (c) 2024 trustees of Columbia University in the City of New York
# All rights reserved.
#
# File coded by: Luke Granlund
Expand All @@ -16,7 +16,6 @@

import numpy as np

import diffpy.srmise.srmiselog
from diffpy.srmise.modelevaluators.base import ModelEvaluator
from diffpy.srmise.srmiseerrors import SrMiseModelEvaluatorError

Expand Down Expand Up @@ -72,7 +71,7 @@ def evaluate(self, fit, count_fixed=False, kshift=0):
logger.warn("AIC.evaluate(): too few data to evaluate quality reliably.")
n = self.minpoints(k)

if self.chisq == None:
if self.chisq is None:
self.chisq = self.chi_squared(fit.value(), fit.y_cluster, fit.error_cluster)

self.stat = self.chisq + self.parpenalty(k, n)
Expand All @@ -94,10 +93,12 @@ def parpenalty(self, k, n):
return (2 * k) * fudgefactor

def growth_justified(self, fit, k_prime):
"""Returns whether adding k_prime parameters to the given model (ModelCluster) is justified given the current quality of the fit.
The assumption is that adding k_prime parameters will result in "effectively 0" chiSquared cost, and so adding it is justified
if the cost of adding these parameters is less than the current chiSquared cost. The validity of this assumption (which
depends on an unknown chiSquared value) and the impact of the errors used should be examined more thoroughly in the future.
"""Returns whether adding k_prime parameters to the given model (ModelCluster) is justified
given the current quality of the fit. The assumption is that adding k_prime parameters will
result in "effectively 0" chiSquared cost, and so adding it is justified if the cost of adding
these parameters is less than the current chiSquared cost.
The validity of this assumption (which depends on an unknown chiSquared value)
and the impact of the errors used should be examined more thoroughly in the future.
"""

if self.chisq is None:
Expand Down
2 changes: 1 addition & 1 deletion diffpy/srmise/modelevaluators/aicc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# SrMise by Luke Granlund
# (c) 2014 trustees of the Michigan State University
# (c) 2024 trustees of Columia University in the City of New York
# (c) 2024 trustees of Columbia University in the City of New York
# All rights reserved.
#
# File coded by: Luke Granlund
Expand Down
2 changes: 1 addition & 1 deletion diffpy/srmise/modelevaluators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# SrMise by Luke Granlund
# (c) 2014 trustees of the Michigan State University
# (c) 2024 trustees of Columia University in the City of New York
# (c) 2024 trustees of Columbia University in the City of New York
# All rights reserved.
#
# File coded by: Luke Granlund
Expand Down
Loading

0 comments on commit b44c264

Please sign in to comment.