Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
7 changes: 5 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
napoleon_custom_sections = [
("Managed Parameters", "Attributes"),
("Usable Metadata", "Attributes"),
("General Metadata", "Attributes"),
("General Metadata", "params_style"),
("Metadata", "Attributes"),
("Properties", "Attributes"),
("Operator Attributes", "Attributes"),
Expand Down Expand Up @@ -334,4 +334,7 @@


# Example configuration for intersphinx: refer to the Python standard library.
# intersphinx_mapping = {'http://docs.python.org/': None}
intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
"numpy": ("https://numpy.org/doc/stable/", None),
}
23 changes: 23 additions & 0 deletions news/documentation-metadata.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* No News Added: rebuild the documentation with proper metadata handling

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
23 changes: 23 additions & 0 deletions news/fix-qmax-update.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* Fixed load new parsed data with updated `Qmax` attribute

**Security:**

* <news item>
23 changes: 23 additions & 0 deletions news/fix-test-package.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* Added `diffpy.structure` back to the requirements and run the test

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
23 changes: 23 additions & 0 deletions news/iteratepars-behavior.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* Changed `iterPars` method to match all equal-type atoms to have same ADPs

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
1 change: 1 addition & 0 deletions requirements/conda.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ numpy
scipy
bg-mpl-stylesheets
diffpy.utils
diffpy.structure
1 change: 1 addition & 0 deletions requirements/pip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ numpy
scipy
bg-mpl-stylesheets
diffpy.utils
diffpy.structure
3 changes: 3 additions & 0 deletions src/diffpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@
# See LICENSE.rst for license information.
#
##############################################################################
from pkgutil import extend_path

__path__ = extend_path(__path__, __name__)
35 changes: 19 additions & 16 deletions src/diffpy/srfit/fitbase/fitrecipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,16 +489,17 @@ def residual(self, p=[]):
----------
p : list or numpy.ndarray
The list of current variable values, provided in the same order
as the '_parameters' list. If p is an empty iterable (default),
then it is assumed that the parameters have already been
updated in some other way, and the explicit update within this
function is skipped.
as the ``_parameters`` list. If ``p`` is an empty iterable
(default), then it is assumed that the parameters have already
been updated in some other way, and the explicit update within
this function is skipped.

Return
------
chiv : numpy.ndarray
The array of residuals to be optimized. The array is such that
dot(chiv, chiv) = chi^2 + restraints.
Notes
-----
The residual is by default the weighted concatenation of each
:class:`FitContribution` residual, plus the value of each restraint.
The returned array ``chiv`` satisfies
``dot(chiv, chiv) = chi^2 + restraints``.
"""

# Prepare, if necessary
Expand Down Expand Up @@ -541,15 +542,17 @@ def scalar_residual(self, p=[]):
----------
p : list or numpy.ndarray
The list of current variable values, provided in the same order
as the '_parameters' list. If p is an empty iterable (default),
then it is assumed that the parameters have already been
updated in some other way, and the explicit update within this
function is skipped.
as the ``_parameters`` list. If ``p`` is an empty iterable
(default), then it is assumed that the parameters have already
been updated in some other way, and the explicit update within
this function is skipped.

Notes
-----
The residual is by default the weighted concatenation of each
FitContribution's residual, plus the value of each restraint. The array
returned, denoted chiv, is such that
dot(chiv, chiv) = chi^2 + restraints.
:class:`FitContribution` residual, plus the value of each restraint.
The returned array, denoted ``chiv``, is such that
``dot(chiv, chiv) = chi^2 + restraints``.
"""
chiv = self.residual(p)
return dot(chiv, chiv)
Expand Down
17 changes: 11 additions & 6 deletions src/diffpy/srfit/fitbase/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,16 @@ def set_observed_profile(self, xobs, yobs, dyobs=None):
Numpy array of the observed signal.
dyobs
Numpy array of the uncertainty in the observed signal. If
dyobs is None (default), it will be set to 1 at each
observed xobs.
`dyobs` is None (default), it will be set to 1 at each
observed `xobs`.

Raises ValueError if len(yobs) != len(xobs)
Raises ValueError if dyobs != None and len(dyobs) != len(xobs)

Raises
-----------
ValueError
if len(yobs) != len(xobs)
ValueError
if dyobs != None and len(dyobs) != len(xobs)
"""
if len(yobs) != len(xobs):
raise ValueError("xobs and yobs are different lengths")
Expand Down Expand Up @@ -247,8 +252,8 @@ def set_calculation_range(self, xmin=None, xmax=None, dx=None):
The sample spacing in the independent variable. When different
from the data, resample the ``x`` as anchored at ``xmin``.

Note that xmin is always inclusive (unless clipped). xmax is inclusive
if it is within the bounds of the observed data.
Note that ``xmin`` is always inclusive (unless clipped).
``xmax`` is inclusive if it is within the bounds of the observed data.

Raises
------
Expand Down
15 changes: 9 additions & 6 deletions src/diffpy/srfit/fitbase/profilegenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,18 @@ def set_profile(self, profile):
will store the calculated signal.
"""
if self.profile is not None:
self.profile.removeObserver(self._flush)
self.profile.removeObserver(self._on_profile_update)

self.profile = profile
self.profile.addObserver(self._flush)
self._flush(other=(self,))
self.profile.addObserver(self._on_profile_update)
self._on_profile_update(other=(self,))
return

# Merge the profiles metadata with our own
self.meta.update(self.profile.meta)
self._process_metadata()
def _on_profile_update(self, other=()):
if self.profile is not None:
self.meta.update(self.profile.meta)
self.processMetaData()
self._flush(other=other)
return

def _process_metadata(self):
Expand Down
19 changes: 15 additions & 4 deletions src/diffpy/srfit/fitbase/profileparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ def parseString(self, patstring):
patstring
A string containing the pattern

Raises ParseError if the string cannot be parsed
Raises
----------
ParseError if the string cannot be parsed
"""
raise NotImplementedError()

Expand All @@ -170,8 +172,12 @@ def parseFile(self, filename):
filename
The name of the file to parse

Raises IOError if the file cannot be read
Raises ParseError if the file cannot be parsed
Raises
----------
IOError
if the file cannot be read
ParseError
if the file cannot be parsed
"""
infile = open(filename, "r")
self._banks = []
Expand Down Expand Up @@ -339,7 +345,10 @@ def select_bank(self, index):
index
index of bank (integer, starting at 0).

Raises IndexError if requesting a bank that does not exist
Raises
----------
IndexError
if requesting a bank that does not exist
"""
if index is None:
index = self._meta.get("bank", 0)
Expand Down Expand Up @@ -384,6 +393,8 @@ def get_data(self, index=None):
index of bank (integer, starting at 0, default None). If
index is None then the currently selected bank is used.

Returns
----------
This returns (x, y, dx, dy) tuple for the bank. dx is 0 if it cannot
be determined from the data format.
"""
Expand Down
80 changes: 51 additions & 29 deletions src/diffpy/srfit/fitbase/recipeorganizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,48 +240,70 @@ def _iter_managed(self):
"""Get iterator over managed objects."""
return chain(*(d.values() for d in self.__managed))

def iterate_over_parameters(self, pattern="", recurse=True):
def iterPars(self, pattern="", recurse=True, fullnames=False):
"""Iterate over the Parameters contained in this object.

Parameters
----------
pattern : str, optional
The regular expression pattern to match parameter
names against. Only parameters with names matching
this pattern will be returned. Default is an empty
string, which matches all parameter names.
recurse : bool, optional
The flag indicating whether to recurse into managed
objects when iterating over parameters. If True
(default), the method will also iterate over
parameters in managed sub-objects. If False, only
top-level parameters will be iterated over.

Example
-------

..
for param in recipe.iterate_over_parameters(pattern="scale_"):
# print the name and value of parameters containing "scale_"
print(f"{param.name}={param.value}")
pattern : str
Iterate over parameters with names matching this regular expression
(all parameters by default).

When `fullnames` is True, the regular expression is matched against
dotted parameter names relative to this object, e.g. ``Ni0.Biso``.
recurse : bool
Recurse into managed objects when True (default).
fullnames : bool
Match against hierarchical dotted names relative to this object
when True. Match only leaf parameter names when False (default).
"""
regexp = re.compile(pattern)
for parameter in list(self._parameters.values()):
if regexp.search(parameter.name):
yield parameter
if not fullnames:
for par in list(self._parameters.values()):
if regexp.search(par.name):
yield par
if not recurse:
return
managed = self.__managed[:]
managed.remove(self._parameters)
for m in managed:
for obj in m.values():
if hasattr(obj, "iterPars"):
for par in obj.iterPars(pattern=pattern, recurse=True):
yield par
return
for par in self._iterpars_fullnames(
regexp, recurse=recurse, prefix=""
):
yield par

def _iterpars_fullnames(self, regexp, recurse=True, prefix=""):
"""Internal helper for iterPars(fullnames=True)."""
for par in list(self._parameters.values()):
name = f"{prefix}{par.name}"
if regexp.search(name):
yield par

if not recurse:
return
# Iterate over objects within the managed dictionaries.

managed = self.__managed[:]
managed.remove(self._parameters)
for m in managed:
for obj in m.values():
if hasattr(obj, "iterate_over_parameters"):
for parameter in obj.iterate_over_parameters(
pattern=pattern
if hasattr(obj, "_iterpars_fullnames"):
childprefix = f"{prefix}{obj.name}."
for par in obj._iterpars_fullnames(
regexp,
recurse=True,
prefix=childprefix,
):
yield parameter
return
yield par
elif hasattr(obj, "iterPars"):
for par in obj.iterPars(
pattern=regexp.pattern, recurse=True
):
yield par

@deprecated(iterPars_deprecation_msg)
def iterPars(self, pattern="", recurse=True):
Expand Down
Loading
Loading