Skip to content

Commit

Permalink
merge from main and add tests for unknown materials
Browse files Browse the repository at this point in the history
  • Loading branch information
yucongalicechen committed Dec 27, 2024
2 parents 1879f44 + b0b6676 commit a108205
Show file tree
Hide file tree
Showing 20 changed files with 357 additions and 212 deletions.
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,10 @@ repos:
- id: prettier
additional_dependencies:
- "prettier@^3.2.4"
# docformatter - formats docstrings using PEP 257
- repo: https://github.com/s-weigand/docformatter
rev: 5757c5190d95e5449f102ace83df92e7d3b06c6c
hooks:
- id: docformatter
additional_dependencies: [tomli]
args: [--in-place, --config, ./pyproject.toml]
4 changes: 4 additions & 0 deletions doc/source/examples/tools_example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ After receiving the inputs, the function will write the information to
the `diffpyconfig.json` file in your home directory.


``check_and_build_global_config()`` returns ``True`` if the config file exists (whether it created it or not)
and ``False`` if the config file does not exist in the user's home allowing you to develop your own
workflow for handling missing config files after running it with ``skip_config_creation=True``.

I entered the wrong information in my config file so it always loads incorrect information, how do I fix that?
--------------------------------------------------------------------------------------------------------------

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

* no news added: covered in the news from the get_user_info work

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

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

* docforamtter in pre-commit for automatic formatting of docstrings to PEP 257

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

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

* <news item>

**Changed:**

* DiffractionObject's "id" property renamed to "uuid"

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
1 change: 0 additions & 1 deletion src/diffpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# See LICENSE.rst for license information.
#
##############################################################################

"""diffpy - tools for structure analysis by diffraction.
Blank namespace package.
Expand Down
3 changes: 1 addition & 2 deletions src/diffpy/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
# See LICENSE.rst for license information.
#
##############################################################################

"""Shared utilities for diffpy packages"""
"""Shared utilities for diffpy packages."""

# package version
from diffpy.utils.version import __version__
Expand Down
52 changes: 39 additions & 13 deletions src/diffpy/utils/diffraction_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ class DiffractionObject:
Attributes
----------
all_arrays : ndarray
The array containing the quantity of q, tth, d values.
input_xtype : str
The type of the independent variable in `xarray`. Must be one of {*XQUANTITIES}
id : uuid
The unique identifier for the diffraction object.
scat_quantity : str
The type of scattering experiment (e.g., "x-ray", "neutron"). Default is an empty string "".
wavelength : float
Expand Down Expand Up @@ -127,7 +121,7 @@ def __init__(
>>> print(do.metadata)
"""

self._id = uuid.uuid4()
self._uuid = uuid.uuid4()
self._input_data(xarray, yarray, xtype, wavelength, scat_quantity, name, metadata)

def _input_data(self, xarray, yarray, xtype, wavelength, scat_quantity, name, metadata):
Expand Down Expand Up @@ -284,6 +278,23 @@ def __rtruediv__(self, other):

@property
def all_arrays(self):
"""The 2D array containing `xarray` and `yarray` values.
Returns
-------
ndarray
The shape (len(data), 4) 2D array with columns containing the `yarray` (intensity)
and the `xarray` values in q, tth, and d.
Examples
--------
To access specific arrays individually, use these slices:
>>> my_do.all_arrays[:, 0] # yarray
>>> my_do.all_arrays[:, 1] # xarray in q
>>> my_do.all_arrays[:, 2] # xarray in tth
>>> my_do.all_arrays[:, 3] # xarray in d
"""
return self._all_arrays

@all_arrays.setter
Expand All @@ -292,19 +303,33 @@ def all_arrays(self, _):

@property
def input_xtype(self):
"""The type of the independent variable in `xarray`.
Returns
-------
str
The type of `xarray`, which must be one of {*XQUANTITIES}.
"""
return self._input_xtype

@input_xtype.setter
def input_xtype(self, _):
raise AttributeError(_setter_wmsg("input_xtype"))

@property
def id(self):
return self._id
def uuid(self):
"""The unique identifier for the DiffractionObject instance.
Returns
-------
uuid
The unique identifier of the DiffractionObject instance.
"""
return self._uuid

@id.setter
def id(self, _):
raise AttributeError(_setter_wmsg("id"))
@uuid.setter
def uuid(self, _):
raise AttributeError(_setter_wmsg("uuid"))

def get_array_index(self, value, xtype=None):
"""Return the index of the closest value in the array associated with
Expand All @@ -319,7 +344,8 @@ def get_array_index(self, value, xtype=None):
Returns
-------
the index of the value in the array
list
The list containing the index of the closest value in the array.
"""

xtype = self._input_xtype
Expand Down
4 changes: 1 addition & 3 deletions src/diffpy/utils/parsers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@
# See LICENSE_DANSE.txt for license information.
#
##############################################################################

"""Various utilities related to data parsing and manipulation.
"""
"""Various utilities related to data parsing and manipulation."""
4 changes: 2 additions & 2 deletions src/diffpy/utils/parsers/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ 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 @@ -12,7 +12,6 @@
# See LICENSE_DANSE.txt for license information.
#
##############################################################################

"""Various utilities related to data parsing and manipulation."""

import warnings
Expand Down Expand Up @@ -80,7 +79,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 sampling theorem.
Expand Down
Loading

0 comments on commit a108205

Please sign in to comment.