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
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/release_checklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Please let the maintainer know that all checks are done and the package is ready
<!-- After the maintainer releases the PyPI package, please check the following when creating a PR for conda-forge release.-->

- [ ] Ensure that the full release has appeared on PyPI successfully.
- [ ] New package dependencies listed in `conda.txt` and `test.txt` are added to `meta.yaml` in the feedstock.
- [ ] New package dependencies listed in `conda.txt` and `tests.txt` are added to `meta.yaml` in the feedstock.
- [ ] Close any open issues on the feedstock. Reach out to the maintainer if you have questions.
- [ ] Tag the maintainer for conda-forge release.

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-wheel-release-upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- "*" # Trigger on all tags initially, but tag and release privilege are verified in _build-wheel-release-upload.yml

jobs:
release:
build-release:
uses: scikit-package/release-scripts/.github/workflows/_build-wheel-release-upload.yml@v0
with:
project: diffpy.utils
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
:target: https://anaconda.org/conda-forge/diffpy.utils

.. |PR| image:: https://img.shields.io/badge/PR-Welcome-29ab47ff
:target: https://github.com/diffpy/diffpy.utils/pulls

.. |PyPI| image:: https://img.shields.io/pypi/v/diffpy.utils
:target: https://pypi.org/project/diffpy.utils/
Expand All @@ -35,8 +36,7 @@
.. |Tracking| image:: https://img.shields.io/badge/issue_tracking-github-blue
:target: https://github.com/diffpy/diffpy.utils/issues

diffpy.utils Package
========================================================================
Shared utilities for diffpy packages.

General utilities for analyzing diffraction data

Expand Down
18 changes: 18 additions & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"maintainer_name": "Simon Billinge",
"maintainer_email": "sb2896@columbia.edu",
"maintainer_github_username": "sbillinge",
"contributors": "Timur Davis, Chris Farrow, Pavol Juhas",
"license_holders": "The Trustees of Columbia University in the City of New York",
"project_name": "diffpy.utils",
"github_username_or_orgname": "diffpy",
"github_repo_name": "diffpy.utils",
"conda_pypi_package_dist_name": "diffpy.utils",
"package_dir_name": "diffpy.utils",
"project_short_description": "Shared utilities for diffpy packages.",
"project_keywords": "text data parsers, wx grid, diffraction objects",
"minimum_supported_python_version": "3.11",
"maximum_supported_python_version": "3.13",
"project_needs_c_code_compiled": "No",
"project_has_gui_tests": "No"
}
4 changes: 2 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

diffpy.utils - General utilities for analyzing diffraction data

| Software version |release|.
| Software version |release|
| Last updated |today|.
The diffpy.utils package provides a number of functions and classes designed to help
Expand All @@ -33,7 +33,7 @@ Illustrations of when and how one would use various diffpy.utils functions.
Authors
=======

diffpy.utils is developed by members of the Billinge Group at
``diffpy.utils`` is developed by members of the Billinge Group at
Columbia University and at Brookhaven National Laboratory including
Pavol Juhás, Christopher L. Farrow, Simon J. L. Billinge, Andrew Yang,
with contributions from many Billinge Group members and
Expand Down
23 changes: 23 additions & 0 deletions news/scikit-package.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* No News Added: recut diffpy.utils using latest scikit-package

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ include = ["*"] # package names should match these glob patterns (["*"] by defa
exclude = [] # exclude packages matching these glob patterns (empty by default)
namespaces = false # to disable scanning PEP 420 namespaces (true by default)

[project.scripts]
diffpy-utils = "diffpy.utils_app:main"

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

Expand All @@ -56,6 +59,11 @@ exclude-file = ".codespell/ignore_lines.txt"
ignore-words = ".codespell/ignore_words.txt"
skip = "*.cif,*.dat"

[tool.docformatter]
recursive = true
wrap-summaries = 72
wrap-descriptions = 72

[tool.black]
line-length = 79
include = '\.pyi?$'
Expand Down
4 changes: 2 additions & 2 deletions src/diffpy/utils/_deprecator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@


def deprecated(message, *, category=DeprecationWarning, stacklevel=1):
"""Deprecation decorator for functions and classes that is compatible with
Python versions prior to 3.13.
"""Deprecation decorator for functions and classes that is
compatible with Python versions prior to 3.13.

Examples
--------
Expand Down
37 changes: 21 additions & 16 deletions src/diffpy/utils/diffraction_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ def __eq__(self, other):
return True

def __add__(self, other):
"""Add a scalar value or another DiffractionObject to the yarray of the
DiffractionObject.
"""Add a scalar value or another DiffractionObject to the yarray
of the DiffractionObject.

Parameters
----------
Expand Down Expand Up @@ -262,8 +262,8 @@ def __add__(self, other):
__radd__ = __add__

def __sub__(self, other):
"""Subtract scalar value or another DiffractionObject to the yarray of
the DiffractionObject.
"""Subtract scalar value or another DiffractionObject to the
yarray of the DiffractionObject.

This method behaves similarly to the `__add__` method, but performs
subtraction instead of addition. For details on parameters, returns
Expand All @@ -290,8 +290,8 @@ def __sub__(self, other):
__rsub__ = __sub__

def __mul__(self, other):
"""Multiply a scalar value or another DiffractionObject with the yarray
of this DiffractionObject.
"""Multiply a scalar value or another DiffractionObject with the
yarray of this DiffractionObject.

This method behaves similarly to the `__add__` method, but performs
multiplication instead of addition. For details on parameters,
Expand All @@ -318,8 +318,8 @@ def __mul__(self, other):
__rmul__ = __mul__

def __truediv__(self, other):
"""Divide the yarray of this DiffractionObject by a scalar value or
another DiffractionObject.
"""Divide the yarray of this DiffractionObject by a scalar value
or another DiffractionObject.

This method behaves similarly to the `__add__` method, but performs
division instead of addition. For details on parameters, returns,
Expand Down Expand Up @@ -474,7 +474,8 @@ def _get_original_array(self):
return self.on_d(), "d"

def on_q(self):
"""Return the tuple of two 1D numpy arrays containing q and y data.
"""Return the tuple of two 1D numpy arrays containing q and y
data.

Returns
-------
Expand All @@ -484,7 +485,8 @@ def on_q(self):
return [self.all_arrays[:, 1], self.all_arrays[:, 0]]

def on_tth(self):
"""Return the tuple of two 1D numpy arrays containing tth and y data.
"""Return the tuple of two 1D numpy arrays containing tth and y
data.

Returns
-------
Expand All @@ -494,7 +496,8 @@ def on_tth(self):
return [self.all_arrays[:, 2], self.all_arrays[:, 0]]

def on_d(self):
"""Return the tuple of two 1D numpy arrays containing d and y data.
"""Return the tuple of two 1D numpy arrays containing d and y
data.

Returns
-------
Expand All @@ -506,8 +509,8 @@ def on_d(self):
def scale_to(
self, target_diff_object, q=None, tth=None, d=None, offset=None
):
"""Return a new diffraction object which is the current object but
rescaled in y to the target.
"""Return a new diffraction object which is the current object
but rescaled in y to the target.

By default, if `q`, `tth`, or `d` are not provided, scaling is
based on the max intensity from each object. Otherwise, y-value in
Expand Down Expand Up @@ -568,7 +571,8 @@ def scale_to(
return scaled_do

def on_xtype(self, xtype):
"""Return a tuple of two 1D numpy arrays containing x and y data.
"""Return a tuple of two 1D numpy arrays containing x and y
data.

Parameters
----------
Expand Down Expand Up @@ -597,8 +601,9 @@ def on_xtype(self, xtype):
raise ValueError(_xtype_wmsg(xtype))

def dump(self, filepath, xtype=None):
"""Dump the xarray and yarray of the diffraction object to a two-column
file, with the associated information included in the header.
"""Dump the xarray and yarray of the diffraction object to a
two-column file, with the associated information included in the
header.

Parameters
----------
Expand Down
5 changes: 3 additions & 2 deletions src/diffpy/utils/parsers/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ def serialize_data(
show_path=True,
serial_file=None,
):
"""Serialize file data into a dictionary. Can also save dictionary into a
serial language file. Dictionary is formatted as {filename: data}.
"""Serialize file data into a dictionary. Can also save dictionary
into a serial language file. Dictionary is formatted as {filename:
data}.

Requires hdata and data_table (can be generated by loadData).

Expand Down
4 changes: 2 additions & 2 deletions src/diffpy/utils/resampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def wsinterp(x, xp, fp, left=None, right=None):


def nsinterp(xp, fp, qmin=0, qmax=25, left=None, right=None):
"""One-dimensional Whittaker-Shannon interpolation onto the Nyquist-Shannon
grid.
"""One-dimensional Whittaker-Shannon interpolation onto the Nyquist-
Shannon grid.
Takes a band-limited function fp and original grid xp and resamples fp on
the NS grid. Uses the minimum number of points N required by the Nyquist
Expand Down
33 changes: 18 additions & 15 deletions src/diffpy/utils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def _load_config(file_path):


def get_user_info(owner_name=None, owner_email=None, owner_orcid=None):
"""Get name, email, and ORCID of the owner/user from various sources and
return it as a metadata dictionary.
"""Get name, email, and ORCID of the owner/user from various sources
and return it as a metadata dictionary.

The function looks for information in JSON configuration files named
``diffpyconfig.json``. These can be in the user's home directory and in
Expand Down Expand Up @@ -109,8 +109,8 @@ def get_user_info(owner_name=None, owner_email=None, owner_orcid=None):


def check_and_build_global_config(skip_config_creation=False):
"""Check for a global diffpu config file in user's home directory and
creates one if it is missing.
"""Check for a global diffpu config file in user's home directory
and creates one if it is missing.

The file it looks for is called diffpyconfig.json. This can contain
anything in json format, but minimally contains information about the
Expand Down Expand Up @@ -234,7 +234,8 @@ def get_density_from_cloud(sample_composition, mp_token=""):
def compute_mu_using_xraydb(
sample_composition, energy, sample_mass_density=None, packing_fraction=None
):
"""Compute the attenuation coefficient (mu) using the XrayDB database.
"""Compute the attenuation coefficient (mu) using the XrayDB
database.

Computes mu based on the sample composition and energy.
User should provide a sample mass density or a packing fraction.
Expand Down Expand Up @@ -287,8 +288,8 @@ def compute_mu_using_xraydb(


def _top_hat(z, half_slit_width):
"""Create a top-hat function, return 1.0 for values within the specified
slit width and 0 otherwise."""
"""Create a top-hat function, return 1.0 for values within the
specified slit width and 0 otherwise."""
return np.where((z >= -half_slit_width) & (z <= half_slit_width), 1.0, 0.0)


Expand Down Expand Up @@ -319,9 +320,10 @@ def _model_function(z, diameter, z0, I0, mud, slope):


def _extend_z_and_convolve(z, diameter, half_slit_width, z0, I0, mud, slope):
"""Extend z values and I values for padding (so that we don't have tails in
convolution), then perform convolution (note that the convolved I values
are the same as modeled I values if slit width is close to 0)"""
"""Extend z values and I values for padding (so that we don't have
tails in convolution), then perform convolution (note that the
convolved I values are the same as modeled I values if slit width is
close to 0)"""
n_points = len(z)
z_left_pad = np.linspace(
z.min() - n_points * (z[1] - z[0]), z.min(), n_points
Expand All @@ -342,8 +344,8 @@ def _extend_z_and_convolve(z, diameter, half_slit_width, z0, I0, mud, slope):

def _objective_function(params, z, observed_data):
"""Compute the objective function for fitting a model to the
observed/experimental data by minimizing the sum of squared residuals
between the observed data and the convolved model data."""
observed/experimental data by minimizing the sum of squared
residuals between the observed data and the convolved model data."""
diameter, half_slit_width, z0, I0, mud, slope = params
convolved_model_data = _extend_z_and_convolve(
z, diameter, half_slit_width, z0, I0, mud, slope
Expand All @@ -353,7 +355,8 @@ def _objective_function(params, z, observed_data):


def _compute_single_mud(z_data, I_data):
"""Perform dual annealing optimization and extract the parameters."""
"""Perform dual annealing optimization and extract the
parameters."""
bounds = [
(
1e-5,
Expand Down Expand Up @@ -382,8 +385,8 @@ def _compute_single_mud(z_data, I_data):


def compute_mud(filepath):
"""Compute the best-fit mu*D value from a z-scan file, removing the sample
holder effect.
"""Compute the best-fit mu*D value from a z-scan file, removing the
sample holder effect.

This function loads z-scan data and fits it to a model
that convolves a top-hat function with I = I0 * e^{-mu * l}.
Expand Down
16 changes: 10 additions & 6 deletions src/diffpy/utils/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def q_to_tth(q, wavelength):


def tth_to_q(tth, wavelength):
r"""Helper function to convert two-theta to q on independent variable axis.
r"""Helper function to convert two-theta to q on independent variable
axis.

If wavelength is missing, returns independent variable axis as integer
indexes.
Expand Down Expand Up @@ -124,8 +125,8 @@ def tth_to_q(tth, wavelength):


def q_to_d(q):
r"""Helper function to convert q to d on independent variable axis, using
:math:`d = \frac{2 \pi}{q}`.
r"""Helper function to convert q to d on independent variable axis,
using :math:`d = \frac{2 \pi}{q}`.

Parameters
----------
Expand All @@ -144,7 +145,8 @@ def q_to_d(q):


def tth_to_d(tth, wavelength):
r"""Helper function to convert two-theta to d on independent variable axis.
r"""Helper function to convert two-theta to d on independent variable
axis.

The formula is ..
math:: d = \frac{\lambda}{2 \sin\left(\frac{2\theta}{2}\right)}.
Expand Down Expand Up @@ -178,7 +180,8 @@ def tth_to_d(tth, wavelength):


def d_to_q(d):
r"""Helper function to convert q to d using :math:`d = \frac{2 \pi}{q}`.
r"""Helper function to convert q to d using :math:`d = \frac{2
\pi}{q}`.

Parameters
----------
Expand All @@ -197,7 +200,8 @@ def d_to_q(d):


def d_to_tth(d, wavelength):
r"""Helper function to convert d to two-theta on independent variable axis.
r"""Helper function to convert d to two-theta on independent variable
axis.

The formula is ..
math:: 2\theta = 2 \arcsin\left(\frac{\lambda}{2d}\right).
Expand Down
Loading
Loading