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
23 changes: 23 additions & 0 deletions news/cf-names-match-srfit.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* No news added: The unreleased fix-cfs news item already covers the characteristic function changes and lists the srfit 3.4.0 names.

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
2 changes: 1 addition & 1 deletion news/fix-cfs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

**Changed:**

* Rename the parameters of the characteristic functions ``spherical_particle``, ``spheroidal_particle``, ``lognormal_spherical_distribution``, ``sheet_particle``, and ``spherical_shell`` to match ``diffpy.srfit.pdf.characteristicfunctions``.
* Rename the parameters of the characteristic functions ``spherical_particle``, ``spheroidal_particle``, ``lognormal_spherical_particle``, ``sheet_particle``, and ``shell_particle`` to match ``diffpy.srfit.pdf.characteristicfunctions``.
* Issue a ``RuntimeWarning`` once per process when a characteristic function is given non-physical input and returns zero.

**Deprecated:**
Expand Down
18 changes: 9 additions & 9 deletions src/diffpy/cmipdf/characteristicfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
__all__ = [
"spherical_particle",
"spheroidal_particle",
"lognormal_spherical_distribution",
"lognormal_spherical_particle",
"sheet_particle",
"spherical_shell",
"shell_particle",
]

import warnings
Expand Down Expand Up @@ -245,7 +245,7 @@ def spheroidal_particle(r, equatorial_radius, polar_radius):
return f


def lognormal_spherical_distribution(
def lognormal_spherical_particle(
r, particle_diameter, particle_diameter_sigma
):
"""Compute the spherical nanoparticle characteristic function with
Expand Down Expand Up @@ -298,13 +298,13 @@ def lognormal_spherical_distribution(
"""
if particle_diameter <= 0:
_warn_non_physical(
"lognormal_spherical_distribution",
"lognormal_spherical_particle",
"'particle_diameter' must be positive",
)
return numpy.zeros(numpy.shape(r), dtype=float)
if particle_diameter_sigma < 0:
_warn_non_physical(
"lognormal_spherical_distribution",
"lognormal_spherical_particle",
"'particle_diameter_sigma' must not be negative",
)
return numpy.zeros(numpy.shape(r), dtype=float)
Expand All @@ -323,7 +323,7 @@ def lognormal_spherical_distribution(
mu = log(particle_diameter) - s * s / 2
if mu < 0:
_warn_non_physical(
"lognormal_spherical_distribution",
"lognormal_spherical_particle",
"'particle_diameter' is too small for 'particle_diameter_sigma'",
)
return numpy.zeros(numpy.shape(r), dtype=float)
Expand Down Expand Up @@ -394,7 +394,7 @@ def sheet_particle(r, sheet_thickness):
return characteristic_function


def spherical_shell(r, radius, thickness):
def shell_particle(r, radius, thickness):
"""Compute the spherical shell characteristic function.

The outer radius equals ``radius + thickness``. From Lei et al.,
Expand Down Expand Up @@ -423,10 +423,10 @@ def spherical_shell(r, radius, thickness):
rather than an error and does not warn.
"""
if thickness <= 0:
_warn_non_physical("spherical_shell", "'thickness' must be positive")
_warn_non_physical("shell_particle", "'thickness' must be positive")
return numpy.zeros(numpy.shape(r), dtype=float)
if radius < 0:
_warn_non_physical("spherical_shell", "'radius' must not be negative")
_warn_non_physical("shell_particle", "'radius' must not be negative")
return numpy.zeros(numpy.shape(r), dtype=float)

d = 1.0 * thickness
Expand Down
24 changes: 12 additions & 12 deletions tests/test_characteristicfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ def test_spheroidal_particle(
),
],
)
def test_lognormal_spherical_distribution(
def test_lognormal_spherical_particle(
input_r,
input_particle_diameter,
input_particle_diameter_sigma,
expected_characteristic_function,
):
actual_characteristic_function = cf.lognormal_spherical_distribution(
actual_characteristic_function = cf.lognormal_spherical_particle(
input_r, input_particle_diameter, input_particle_diameter_sigma
)
npt.assert_allclose(
Expand Down Expand Up @@ -196,10 +196,10 @@ def test_sheet_particle(
),
],
)
def test_spherical_shell(
def test_shell_particle(
input_r, input_radius, input_thickness, expected_characteristic_function
):
actual_characteristic_function = cf.spherical_shell(
actual_characteristic_function = cf.shell_particle(
input_r, input_radius, input_thickness
)
npt.assert_allclose(
Expand Down Expand Up @@ -264,7 +264,7 @@ def test_spherical_shell(
# Expected: zero everywhere, warning that the diameter must be
# positive.
(
"lognormal_spherical_distribution",
"lognormal_spherical_particle",
(numpy.array([1.0, 2.0]), 0.0, 1.0),
"'particle_diameter' must be positive",
),
Expand All @@ -274,7 +274,7 @@ def test_spherical_shell(
# Expected: zero everywhere, warning that the width must not be
# negative.
(
"lognormal_spherical_distribution",
"lognormal_spherical_particle",
(numpy.array([1.0, 5.0, 10.0]), 10.0, -2.0),
"'particle_diameter_sigma' must not be negative",
),
Expand All @@ -284,7 +284,7 @@ def test_spherical_shell(
# Expected: zero everywhere, warning that the diameter is too small
# for the width.
(
"lognormal_spherical_distribution",
"lognormal_spherical_particle",
(numpy.array([1.0, 5.0]), 2.0, 4.0),
"'particle_diameter' is too small for 'particle_diameter_sigma'",
),
Expand All @@ -310,7 +310,7 @@ def test_spherical_shell(
# Expected: zero everywhere, warning that the thickness must be
# positive.
(
"spherical_shell",
"shell_particle",
(numpy.array([1.0, 5.0, 10.0]), 10.0, 0.0),
"'thickness' must be positive",
),
Expand All @@ -320,15 +320,15 @@ def test_spherical_shell(
# Expected: zero everywhere, warning that the thickness must be
# positive.
(
"spherical_shell",
"shell_particle",
(numpy.array([1.0, 5.0, 10.0]), 10.0, -5.0),
"'thickness' must be positive",
),
# C12: the shell inner radius is negative.
# Expected: zero everywhere, warning that the radius must not be
# negative.
(
"spherical_shell",
"shell_particle",
(numpy.array([1.0, 5.0, 10.0]), -20.0, 5.0),
"'radius' must not be negative",
),
Expand Down Expand Up @@ -366,7 +366,7 @@ def test_non_physical_input_returns_zero_and_warns(
# Expected: matches spherical_particle for the same diameter, with no
# warning.
(
"lognormal_spherical_distribution",
"lognormal_spherical_particle",
(numpy.array([1.0, 5.0, 10.0]), 10.0, 0.0),
cf.spherical_particle(numpy.array([1.0, 5.0, 10.0]), 10.0),
),
Expand All @@ -375,7 +375,7 @@ def test_non_physical_input_returns_zero_and_warns(
# Expected: matches spherical_particle for twice the thickness, with
# no warning.
(
"spherical_shell",
"shell_particle",
(numpy.array([1.0, 5.0, 10.0]), 0.0, 5.0),
cf.spherical_particle(numpy.array([1.0, 5.0, 10.0]), 10.0),
),
Expand Down
Loading