Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/examples/coreshellnp.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def makeRecipe(stru1, stru2, datname):
# Load data and add it to the profile
parser = PDFParser()
parser.parseFile(datname)
profile.loadParsedData(parser)
profile.setCalculationRange(xmin=1.5, xmax=45, dx=0.1)
profile.load_parsed_data(parser)
profile.set_calculation_range(xmin=1.5, xmax=45, dx=0.1)

# The ProfileGenerator
# In order to fit the core and shell phases simultaneously, we must use two
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/crystalpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def makeRecipe(ciffile, datname):
# configuration steps.
parser = PDFParser()
parser.parseFile(datname)
profile.loadParsedData(parser)
profile.setCalculationRange(xmax=20)
profile.load_parsed_data(parser)
profile.set_calculation_range(xmax=20)

# The ProfileGenerator
# The PDFGenerator is for configuring and calculating a PDF profile. Here,
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/crystalpdfall.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def makeProfile(datafile):
profile = Profile()
parser = PDFParser()
parser.parseFile(datafile)
profile.loadParsedData(parser)
profile.setCalculationRange(xmax=20)
profile.load_parsed_data(parser)
profile.set_calculation_range(xmax=20)
return profile


Expand Down
4 changes: 2 additions & 2 deletions docs/examples/crystalpdfobjcryst.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def makeRecipe(ciffile, datname):
# structure being refined.
parser = PDFParser()
parser.parseFile(datname)
profile.loadParsedData(parser)
profile.setCalculationRange(xmax=20)
profile.load_parsed_data(parser)
profile.set_calculation_range(xmax=20)

# The ProfileGenerator
# This time we use the CreateCrystalFromCIF method of pyobjcryst.crystal to
Expand Down
8 changes: 4 additions & 4 deletions docs/examples/crystalpdftwodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ def makeRecipe(ciffile, xdatname, ndatname):
# Load data and add it to the proper Profile.
parser = PDFParser()
parser.parseFile(xdatname)
xprofile.loadParsedData(parser)
xprofile.setCalculationRange(xmax=20)
xprofile.load_parsed_data(parser)
xprofile.set_calculation_range(xmax=20)

parser = PDFParser()
parser.parseFile(ndatname)
nprofile.loadParsedData(parser)
nprofile.setCalculationRange(xmax=20)
nprofile.load_parsed_data(parser)
nprofile.set_calculation_range(xmax=20)

# The ProfileGenerators
# We need one of these for the x-ray data.
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/crystalpdftwophase.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def makeRecipe(niciffile, siciffile, datname):
# Load data and add it to the profile
parser = PDFParser()
parser.parseFile(datname)
profile.loadParsedData(parser)
profile.setCalculationRange(xmax=20)
profile.load_parsed_data(parser)
profile.set_calculation_range(xmax=20)

# The ProfileGenerator
# In order to fit two phases simultaneously, we must use two PDFGenerators.
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/debyemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def makeRecipe():
# data into the profile.
xydy = numpy.array(data.split(), dtype=float).reshape(-1, 3)
x, y, dy = xydy.T
profile.setObservedProfile(x, y, dy)
profile.set_observed_profile(x, y, dy)

# The FitContribution
# The FitContribution associates the profile with the Debye function.
Expand Down
8 changes: 4 additions & 4 deletions docs/examples/debyemodelII.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ def makeRecipeII():
# Change the fit ranges of the Profiles embedded within the
# FitContributions. We want to fit one of the contributions at low
# temperature, and one at high.
lowT.profile.setCalculationRange(0, 150)
highT.profile.setCalculationRange(400, 500)
lowT.profile.set_calculation_range(0, 150)
highT.profile.set_calculation_range(400, 500)

# Vary the offset from each FitContribution separately, while keeping the
# Debye temperatures the same. We give each offset variable a different
Expand All @@ -102,8 +102,8 @@ def plotResults(recipe):

# We want to extend the fitting range to its full extent so we can get a
# nice full plot.
recipe.lowT.profile.setCalculationRange(xmin="obs", xmax="obs")
recipe.highT.profile.setCalculationRange(xmin="obs", xmax="obs")
recipe.lowT.profile.set_calculation_range(xmin="obs", xmax="obs")
recipe.highT.profile.set_calculation_range(xmin="obs", xmax="obs")
T = recipe.lowT.profile.x
U = recipe.lowT.profile.y
# We can use a FitContribution's 'evaluateEquation' method to evaluate
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/ellipsoidsas.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def makeRecipe(datname):
# properly and pass the metadata along.
parser = SASParser()
parser.parseFile(datname)
profile.loadParsedData(parser)
profile.load_parsed_data(parser)

# The ProfileGenerator
# The SASGenerator is for configuring and calculating a SAS profile. We use
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/nppdfcrystal.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def makeRecipe(ciffile, grdata):

pdfparser = PDFParser()
pdfparser.parseFile(grdata)
pdfprofile.loadParsedData(pdfparser)
pdfprofile.setCalculationRange(xmin=0.1, xmax=20)
pdfprofile.load_parsed_data(pdfparser)
pdfprofile.set_calculation_range(xmin=0.1, xmax=20)

pdfcontribution = FitContribution("pdf")
pdfcontribution.set_profile(pdfprofile, xname="r")
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/nppdfobjcryst.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def makeRecipe(molecule, datname):

# Load data and add it to the profile
profile.loadtxt(datname)
profile.setCalculationRange(xmin=1.2, xmax=8)
profile.set_calculation_range(xmin=1.2, xmax=8)

# The ProfileGenerator
# Create a DebyePDFGenerator named "G".
Expand Down
6 changes: 3 additions & 3 deletions docs/examples/nppdfsas.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def makeRecipe(ciffile, grdata, iqdata):
pdfprofile = Profile()
pdfparser = PDFParser()
pdfparser.parseFile(grdata)
pdfprofile.loadParsedData(pdfparser)
pdfprofile.setCalculationRange(xmin=0.1, xmax=20)
pdfprofile.load_parsed_data(pdfparser)
pdfprofile.set_calculation_range(xmin=0.1, xmax=20)

pdfcontribution = FitContribution("pdf")
pdfcontribution.set_profile(pdfprofile, xname="r")
Expand All @@ -66,7 +66,7 @@ def makeRecipe(ciffile, grdata, iqdata):
sasprofile = Profile()
sasparser = SASParser()
sasparser.parseFile(iqdata)
sasprofile.loadParsedData(sasparser)
sasprofile.load_parsed_data(sasparser)
if all(sasprofile.dy == 0):
sasprofile.dy[:] = 1

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/simplepdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def makeRecipe(ciffile, datname):
# Work directly with a custom PDFContribution to load the data
contribution = PDFContribution("nickel")
contribution.loadData(datname)
contribution.setCalculationRange(xmin=1, xmax=20, dx=0.1)
contribution.set_calculation_range(xmin=1, xmax=20, dx=0.1)

# and the phase
stru = Structure()
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/simplepdftwophase.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def makeRecipe(niciffile, siciffile, datname):
# Load data and add it to the profile
contribution = PDFContribution("nisi")
contribution.loadData(datname)
contribution.setCalculationRange(xmax=20)
contribution.set_calculation_range(xmax=20)

stru = loadCrystal(niciffile)
contribution.addStructure("ni", stru)
Expand Down
2 changes: 1 addition & 1 deletion docs/source/extending.rst
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ customized Profile is the ``SASProfile`` class in the

The ``__init__`` method sets the ``xobs``, ``yobs`` and ``dyobs`` attributes of
the ``SASProfile`` to the associated arrays within the ``_datainfo`` attribute.
The ``setObservedProfile`` method is overloaded to modify the ``_datainfo``
The ``set_observed_profile`` method is overloaded to modify the ``_datainfo``
arrays when their corresponding attributes are modified. This keeps the arrays
in sync.

Expand Down
29 changes: 29 additions & 0 deletions news/profile-dep.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
**Added:**

* Added ``load_parsed_data`` in replace of ``loadParsedData`` in ``Profile`` and ``SimpleRecipe``.
* Added ``set_observed_profile`` in replace of ``setObservedProfile`` in ``Profile`` and ``SimpleRecipe``.
* Added ``set_calculation_range`` in replace of ``setCalculationRange`` in ``Profile`` and ``SimpleRecipe``.
* Added ``set_calculation_points`` in replace of ``setCalculationPoints`` in ``Profile`` and ``SimpleRecipe``.

**Changed:**

* <news item>

**Deprecated:**

* Deprecated ``loadParsedData`` in ``Profile`` and ``SimpleRecipe`` for removal in 4.0.0.
* Deprecated ``setObservedProfile`` in ``Profile`` and ``SimpleRecipe`` for removal in 4.0.0.
* Deprecated ``setCalculationRange`` in ``Profile`` and ``SimpleRecipe`` for removal in 4.0.0.
* Deprecated ``setCalculationPoints`` in ``Profile`` and ``SimpleRecipe`` for removal in 4.0.0.

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
108 changes: 95 additions & 13 deletions src/diffpy/srfit/fitbase/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,40 @@
from diffpy.srfit.fitbase.parameter import Parameter
from diffpy.srfit.fitbase.validatable import Validatable
from diffpy.srfit.util.observable import Observable
from diffpy.utils._deprecator import build_deprecation_message, deprecated

# This is the roundoff tolerance for selecting bounds on arrays.
epsilon = 1e-8
base = "diffpy.srfit.fitbase.profile.Profile"
removal_version = "4.0.0"

loadParsedData_dep_msg = build_deprecation_message(
base,
"loadParsedData",
"load_parsed_data",
removal_version,
)

setObservedProfile_dep_msg = build_deprecation_message(
base,
"setObservedProfile",
"set_observed_profile",
removal_version,
)

setCalculationRange_dep_msg = build_deprecation_message(
base,
"setCalculationRange",
"set_calculation_range",
removal_version,
)

setCalculationPoints_dep_msg = build_deprecation_message(
base,
"setCalculationPoints",
"set_calculation_points",
removal_version,
)


class Profile(Observable, Validatable):
Expand Down Expand Up @@ -125,17 +156,28 @@ def __init__(self):
yobs = property(lambda self: self._yobs)
dyobs = property(lambda self: self._dyobs)

def loadParsedData(self, parser):
def load_parsed_data(self, parser):
"""Load parsed data from a ProfileParser.

This sets the xobs, yobs, dyobs arrays as well as the metadata.
"""
x, y, junk, dy = parser.getData()
self.meta = dict(parser.getMetaData())
self.setObservedProfile(x, y, dy)
self.set_observed_profile(x, y, dy)
return

def setObservedProfile(self, xobs, yobs, dyobs=None):
@deprecated(loadParsedData_dep_msg)
def loadParsedData(self, parser):
"""This function has been deprecated and will be removed in version
4.0.0.

Please use diffpy.srfit.fitbase.profile.Profile.load_parsed_data
instead.
"""
self.load_parsed_data(parser)
return

def set_observed_profile(self, xobs, yobs, dyobs=None):
"""Set the observed profile.

Parameters
Expand Down Expand Up @@ -167,13 +209,25 @@ def setObservedProfile(self, xobs, yobs, dyobs=None):

# Set the default calculation points
if self.x is None:
self.setCalculationPoints(self._xobs)
self.set_calculation_points(self._xobs)
else:
self.setCalculationPoints(self.x)
self.set_calculation_points(self.x)

return

def setCalculationRange(self, xmin=None, xmax=None, dx=None):
@deprecated(setObservedProfile_dep_msg)
def setObservedProfile(self, xobs, yobs, dyobs=None):
"""This function has been deprecated and will be removed in version
4.0.0.

Please use
diffpy.srfit.fitbase.profile.Profile.set_observed_profile
instead.
"""
self.set_observed_profile(xobs, yobs, dyobs)
return

def set_calculation_range(self, xmin=None, xmax=None, dx=None):
"""Set epsilon-inclusive calculation range.

Adhere to the observed ``xobs`` points when ``dx`` is the same
Expand Down Expand Up @@ -274,10 +328,22 @@ def _isobs(a):
self.dy = self.dyobs[indices]
else:
x1 = numpy.arange(lo, hi + epshi, step)
self.setCalculationPoints(x1)
self.set_calculation_points(x1)
return

def setCalculationPoints(self, x):
@deprecated(setCalculationRange_dep_msg)
def setCalculationRange(self, xmin=None, xmax=None, dx=None):
"""This function has been deprecated and will be removed in version
4.0.0.

Please use
diffpy.srfit.fitbase.profile.Profile.set_calculation_range
instead.
"""
self.set_calculation_range(xmin, xmax, dx)
return

def set_calculation_points(self, x):
"""Set the calculation points.

Parameters
Expand All @@ -295,16 +361,32 @@ def setCalculationPoints(self, x):
x = x[x <= self.xobs[-1] + epsilon]
self.x = x
if self.yobs is not None:
self.y = rebinArray(self.yobs, self.xobs, self.x)
self.y = rebin_array(self.yobs, self.xobs, self.x)
if self.dyobs is not None:
# work around for interpolation issue making some of these non-1
if (self.dyobs == 1).all():
self.dy = numpy.ones_like(self.x)
else:
# FIXME - This does not follow error propagation rules and it
# introduces (more) correlation between the data points.
self.dy = rebinArray(self.dyobs, self.xobs, self.x)
self.dy = rebin_array(self.dyobs, self.xobs, self.x)

return

@deprecated(setCalculationPoints_dep_msg)
def setCalculationPoints(self, x):
"""Set the calculation points.

Parameters
----------
x
A non-empty numpy array containing the calculation points. If
xobs exists, the bounds of x will be limited to its bounds.

This will create y and dy on the specified grid if xobs, yobs and
dyobs exist.
"""
self.set_calculation_points(x)
return

def loadtxt(self, *args, **kw):
Expand All @@ -314,7 +396,7 @@ def loadtxt(self, *args, **kw):
enforced. The first two arrays returned by numpy.loadtxt are
assumed to be x and y. If there is a third array, it is assumed
to by dy. Any other arrays are ignored. These are passed to
setObservedProfile.
set_observed_profile.

Raises ValueError if the call to numpy.loadtxt returns fewer
than 2 arrays.
Expand Down Expand Up @@ -345,7 +427,7 @@ def loadtxt(self, *args, **kw):
if len(cols) > 2:
dy = cols[2]

self.setObservedProfile(x, y, dy)
self.set_observed_profile(x, y, dy)
return x, y, dy

def savetxt(self, fname, **kwargs):
Expand Down Expand Up @@ -418,7 +500,7 @@ def _validate(self):
# End class Profile


def rebinArray(A, xold, xnew):
def rebin_array(A, xold, xnew):
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this name. It is only used in the file and this doesn't seem like something people are accessing. Maybe this should be a private function? seems more like a helper to me

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I Agree

"""Rebin the an array by interpolating over the new x range.

Parameters
Expand Down
Loading
Loading