Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .github/workflows/matrix-and-codecov-on-merge-to-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ jobs:
project: diffpy.cmipdf
c_extension: false
headless: false
run: |
set -Eeuo pipefail
python -m pip install --no-deps diffpy.srfit==3.4.0rc0
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
3 changes: 3 additions & 0 deletions .github/workflows/tests-on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ jobs:
project: diffpy.cmipdf
c_extension: false
headless: false
run: |
set -Eeuo pipefail
python -m pip install --no-deps diffpy.srfit==3.4.0rc0
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
31 changes: 0 additions & 31 deletions docs/source/api/diffpy.cmipdf.example_package.rst

This file was deleted.

58 changes: 44 additions & 14 deletions docs/source/api/diffpy.cmipdf.rst
Original file line number Diff line number Diff line change
@@ -1,30 +1,60 @@
:tocdepth: -1

|title|
=======

.. |title| replace:: diffpy.cmipdf package
diffpy.cmipdf package
=====================

.. automodule:: diffpy.cmipdf
:members:
:undoc-members:
:show-inheritance:

Subpackages
-----------

.. toctree::
diffpy.cmipdf.example_package

Submodules
----------

|module|
--------
diffpy.cmipdf.pdfgenerator module
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. automodule:: diffpy.cmipdf.pdfgenerator
:members:
:undoc-members:
:show-inheritance:

diffpy.cmipdf.debyepdfgenerator module
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. automodule:: diffpy.cmipdf.debyepdfgenerator
:members:
:undoc-members:
:show-inheritance:

diffpy.cmipdf.basepdfgenerator module
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. automodule:: diffpy.cmipdf.basepdfgenerator
:members:
:undoc-members:
:show-inheritance:

diffpy.cmipdf.pdfcontribution module
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. automodule:: diffpy.cmipdf.pdfcontribution
:members:
:undoc-members:
:show-inheritance:

diffpy.cmipdf.pdfparser module
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. automodule:: diffpy.cmipdf.pdfparser
:members:
:undoc-members:
:show-inheritance:

.. |module| replace:: diffpy.cmipdf.example_submodule module
diffpy.cmipdf.characteristicfunctions module
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. automodule:: diffpy.cmipdf.example_submodule
.. automodule:: diffpy.cmipdf.characteristicfunctions
:members:
:undoc-members:
:show-inheritance:
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"sphinx.ext.intersphinx",
"sphinx_rtd_theme",
"sphinx_copybutton",
"m2r",
"m2r2",
]

# Add any paths that contain templates here, relative to this directory.
Expand Down
23 changes: 23 additions & 0 deletions news/sync-srfit-3.4.0.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* No news needed: syncing with srfit.

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

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

* No news added: Restyle tests to the group standards; no user-facing change.

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,17 @@ exclude = [] # exclude packages matching these glob patterns (empty by default)
namespaces = false # to disable scanning PEP 420 namespaces (true by default)

[project.scripts]
diffpy-cmipdf = "diffpy.cmipdf.app:main"
diffpy-cmipdf = "diffpy.cmipdf.cmipdf_app:main"

[tool.setuptools.dynamic]
dependencies = {file = ["requirements/pip.txt"]}

[tool.pytest.ini_options]
# Fail when cmipdf source calls one of its own deprecated names.
filterwarnings = [
"error:'diffpy\\.cmipdf\\.:DeprecationWarning:diffpy\\.cmipdf",
]

[tool.codespell]
exclude-file = ".codespell/ignore_lines.txt"
ignore-words = ".codespell/ignore_words.txt"
Expand Down
2 changes: 1 addition & 1 deletion requirements/docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ sphinx
sphinx_rtd_theme
sphinx-copybutton
doctr
m2r
m2r2
4 changes: 4 additions & 0 deletions src/diffpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@
# See LICENSE.rst for license information.
#
##############################################################################

from pkgutil import extend_path

__path__ = extend_path(__path__, __name__)
4 changes: 2 additions & 2 deletions src/diffpy/cmipdf/basepdfgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def _set_calculator(self, calc):
"""
self._calc = calc
for pname in self.__class__._parnames:
self.addParameter(ParameterAdapter(pname, self._calc, attr=pname))
self.add_parameter(ParameterAdapter(pname, self._calc, attr=pname))
self._process_metadata()
return

Expand Down Expand Up @@ -195,7 +195,7 @@ def set_scattering_type(self, stype="X"):
ValueError
If the scattering type is unknown.
"""
self._calc.setScatteringFactorTableByType(stype)
self._calc.scatteringfactortable = stype
# update the meta dictionary only if there was no exception
self.meta["stype"] = self.get_scattering_type()
return
Expand Down
20 changes: 11 additions & 9 deletions src/diffpy/cmipdf/characteristicfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,20 @@ def lognormal_spherical_distribution(radial_dist, p_diameter, p_sigma):
(not of the particle size), and s is the width of the distribution.
This is
the characteristic function for the lognormal distribution of particle
diameter:
diameter::

F(r, mu, s) = 0.5*Erfc((-mu-3*s^2+Log(r))/(sqrt(2)*s))
+ 0.25*r^3*Erfc((-mu+Log(r))/(sqrt(2)*s))*exp(-3*mu-4.5*s^2)
- 0.75*r*Erfc((-mu-2*s^2+Log(r))/(sqrt(2)*s))*exp(-mu-2.5*s^2)
F(r, mu, s) = (
0.5*Erfc((-mu-3*s^2+Log(r))/(sqrt(2)*s))
+ 0.25*r^3*Erfc((-mu+Log(r))/(sqrt(2)*s))*exp(-3*mu-4.5*s^2)
- 0.75*r*Erfc((-mu-2*s^2+Log(r))/(sqrt(2)*s))*exp(-mu-2.5*s^2)
)

The expectation value of the distribution gives the average particle
diameter, p_diameter. The variance of the distribution gives p_sigma^2.
mu and s can be expressed in terms of these as:
mu and s can be expressed in terms of these as::

s^2 = log((p_sigma/p_diameter)^2 + 1)
mu = log(p_diameter) - s^2/2
s^2 = log((p_sigma/p_diameter)^2 + 1)
mu = log(p_diameter) - s^2/2

Source unknown
"""
Expand Down Expand Up @@ -402,14 +404,14 @@ def __init__(self, name, model):
# Wrap normal parameters
for parname in model.params:
par = SASParameter(parname, model)
self.addParameter(par)
self.add_parameter(par)

# Wrap dispersion parameters
for parname in model.dispersion:
name = parname + "_width"
parname += ".width"
par = SASParameter(name, model, parname)
self.addParameter(par)
self.add_parameter(par)

return

Expand Down
6 changes: 3 additions & 3 deletions src/diffpy/cmipdf/pdfcontribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ def __init__(self, name):

# Need a parameter for the overall scale, in the case that this is a
# multi-phase fit.
self.newParameter("scale", 1.0)
self.new_parameter("scale", 1.0)
# Profile-related parameters that will be shared between the generators
self.newParameter("qdamp", 0)
self.newParameter("qbroad", 0)
self.new_parameter("qdamp", 0)
self.new_parameter("qbroad", 0)
return

# Data methods
Expand Down
1 change: 1 addition & 0 deletions src/diffpy/cmipdf/pdfparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class PDFParser(ProfileParser):
_banks
The data from each bank. Each bank contains a
(x, y, dx, dy) tuple:

x
A numpy array containing the independent
variable read from the file.
Expand Down
55 changes: 12 additions & 43 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import importlib.resources
import json
import logging
from functools import lru_cache
from pathlib import Path

import pytest

logger = logging.getLogger(__name__)
from diffpy.structure import PDFFitStructure


@pytest.fixture
Expand All @@ -23,46 +21,6 @@ def user_filesystem(tmp_path):
yield tmp_path


# diffpy.structure
@lru_cache()
def has_diffpy_structure():
try:
import diffpy.structure as m

del m
return True
except ImportError:
logger.warning(
"Cannot import diffpy.structure, Structure tests skipped."
)
return False


# diffpy.srreal


@lru_cache()
def has_diffpy_srreal():
try:
import diffpy.srreal.pdfcalculator as m

del m
return True
except ImportError:
logger.warning("Cannot import diffpy.srreal, PDF tests skipped.")
return False


@pytest.fixture(scope="session")
def diffpy_structure_available():
return has_diffpy_structure()


@pytest.fixture(scope="session")
def diffpy_srreal_available():
return has_diffpy_srreal()


@pytest.fixture(scope="session")
def datafile():
"""Fixture to load a test data file from the testdata package
Expand All @@ -81,3 +39,14 @@ def _as_list(values):
return None if values is None else values.tolist()

return _as_list


@pytest.fixture
def ni_pdffit_structure(datafile):
"""Fixture for the Ni structure from ni.cif with Biso = 1 on every
atom."""
structure = PDFFitStructure()
structure.read(str(datafile("ni.cif")))
for atom in structure:
atom.Bisoequiv = 1
return structure
Loading
Loading