diffpy.utils 3.6.0rc4__tar.gz → 3.6.1rc1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/PKG-INFO +24 -16
  2. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/README.rst +18 -11
  3. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/pyproject.toml +6 -6
  4. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/requirements/docs.txt +1 -0
  5. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/src/diffpy/utils/__init__.py +4 -2
  6. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/src/diffpy/utils/diffraction_objects.py +143 -65
  7. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/src/diffpy/utils/parsers/custom_exceptions.py +3 -1
  8. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/src/diffpy/utils/parsers/loaddata.py +61 -32
  9. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/src/diffpy/utils/parsers/serialization.py +29 -14
  10. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/src/diffpy/utils/resampler.py +28 -21
  11. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/src/diffpy/utils/tools.py +131 -70
  12. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/src/diffpy/utils/transforms.py +21 -12
  13. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/src/diffpy/utils/validators.py +3 -2
  14. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/src/diffpy/utils/version.py +4 -2
  15. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/src/diffpy/utils/wx/gridutils.py +9 -3
  16. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/src/diffpy.utils.egg-info/PKG-INFO +24 -16
  17. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/src/diffpy.utils.egg-info/SOURCES.txt +1 -1
  18. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/tests/conftest.py +39 -16
  19. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/tests/test_diffraction_objects.py +261 -71
  20. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/tests/test_loaddata.py +6 -4
  21. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/tests/test_resample.py +2 -1
  22. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/tests/test_serialization.py +48 -13
  23. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/tests/test_tools.py +152 -45
  24. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/tests/test_transforms.py +134 -43
  25. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/AUTHORS.rst +0 -0
  26. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/LICENSE.rst +0 -0
  27. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/LICENSE_DANSE.txt +0 -0
  28. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/MANIFEST.in +0 -0
  29. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/requirements/build.txt +0 -0
  30. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/requirements/conda.txt +0 -0
  31. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/requirements/pip.txt +0 -0
  32. /diffpy_utils-3.6.0rc4/requirements/test.txt → /diffpy_utils-3.6.1rc1/requirements/tests.txt +0 -0
  33. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/setup.cfg +0 -0
  34. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/src/diffpy/__init__.py +0 -0
  35. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/src/diffpy/utils/parsers/__init__.py +0 -0
  36. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/src/diffpy/utils/wx/__init__.py +0 -0
  37. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/src/diffpy.utils.egg-info/dependency_links.txt +0 -0
  38. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/src/diffpy.utils.egg-info/requires.txt +0 -0
  39. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/src/diffpy.utils.egg-info/top_level.txt +0 -0
  40. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/tests/test_validators.py +0 -0
  41. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/tests/test_version.py +0 -0
  42. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/tests/testdata/dbload/e1.gr +0 -0
  43. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/tests/testdata/dbload/e2.gr +0 -0
  44. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/tests/testdata/dbload/e3.gr +0 -0
  45. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/tests/testdata/generated_db.json +0 -0
  46. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/tests/testdata/generatewarnings.txt +0 -0
  47. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/tests/testdata/loaddata01.txt +0 -0
  48. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/tests/testdata/loaddatawithheaders.txt +0 -0
  49. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/tests/testdata/loadfile.txt +0 -0
  50. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/tests/testdata/strumining.json +0 -0
  51. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/tests/testdata/targetjson.json +0 -0
  52. {diffpy_utils-3.6.0rc4 → diffpy_utils-3.6.1rc1}/tests/testdata/wrong.type +0 -0
@@ -1,9 +1,9 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: diffpy.utils
3
- Version: 3.6.0rc4
4
- Summary: Shared utilities for diffpy packages
5
- Author-email: "Simon J.L. Billinge group" <simon.billinge@gmail.com>
6
- Maintainer-email: "Simon J.L. Billinge group" <simon.billinge@gmail.com>
3
+ Version: 3.6.1rc1
4
+ Summary: General utilities for analyzing diffraction data
5
+ Author-email: Simon Billinge <sb2896@columbia.edu>
6
+ Maintainer-email: Simon Billinge <sb2896@columbia.edu>
7
7
  Project-URL: Homepage, https://github.com/diffpy/diffpy.utils/
8
8
  Project-URL: Issues, https://github.com/diffpy/diffpy.utils/issues/
9
9
  Keywords: text data parsers,wx grid,diffraction objects
@@ -29,6 +29,7 @@ License-File: AUTHORS.rst
29
29
  Requires-Dist: numpy
30
30
  Requires-Dist: xraydb
31
31
  Requires-Dist: scipy
32
+ Dynamic: license-file
32
33
 
33
34
  |Icon| |title|_
34
35
  ===============
@@ -40,7 +41,7 @@ Requires-Dist: scipy
40
41
  :target: https://diffpy.github.io/diffpy.utils
41
42
  :height: 100px
42
43
 
43
- |PyPi| |Forge| |PythonVersion| |PR|
44
+ |PyPI| |Forge| |PythonVersion| |PR|
44
45
 
45
46
  |CI| |Codecov| |Black| |Tracking|
46
47
 
@@ -58,7 +59,7 @@ Requires-Dist: scipy
58
59
 
59
60
  .. |PR| image:: https://img.shields.io/badge/PR-Welcome-29ab47ff
60
61
 
61
- .. |PyPi| image:: https://img.shields.io/pypi/v/diffpy.utils
62
+ .. |PyPI| image:: https://img.shields.io/pypi/v/diffpy.utils
62
63
  :target: https://pypi.org/project/diffpy.utils/
63
64
 
64
65
  .. |PythonVersion| image:: https://img.shields.io/pypi/pyversions/diffpy.utils
@@ -70,14 +71,16 @@ Requires-Dist: scipy
70
71
  diffpy.utils Package
71
72
  ========================================================================
72
73
 
73
- General purpose shared utilities for the diffpy libraries.
74
+ General utilities for analyzing diffraction data
75
+
76
+ The diffpy.utils package provides a number of functions and classes designed to help
77
+ researchers analyze their diffraction data. It also includes some functionality for
78
+ carrying out PDF analysis. Examples are parsers for reading common format diffraction
79
+ data files, ``DiffractionObjects`` that allow you to do algebra on diffraction patterns,
80
+ tools for better capture and propagation of metadata,
81
+ diffraction-friendly interpolation routines, as well as some other tools used across
82
+ diffpy libraries.
74
83
 
75
- The diffpy.utils package provides functions for extracting array data from
76
- variously formatted text files, an interpolation function based on the
77
- Whittaker-Shannon formula that can be used to resample a PDF or other profile
78
- function over a new grid, `DiffractionObject` for conveniently manipulating
79
- diffraction data, and some wx GUI utilities used by the PDFgui
80
- program.
81
84
 
82
85
  Citation
83
86
  --------
@@ -166,9 +169,14 @@ trying to commit again.
166
169
 
167
170
  Improvements and fixes are always appreciated.
168
171
 
169
- Before contributing, please read our `Code of Conduct <https://github.com/diffpy/diffpy.utils/blob/main/CODE_OF_CONDUCT.rst>`_.
172
+ Before contributing, please read our `Code of Conduct <https://github.com/diffpy/diffpy.utils/blob/main/CODE-OF-CONDUCT.rst>`_.
170
173
 
171
174
  Contact
172
175
  -------
173
176
 
174
- For more information on diffpy.utils please visit the project `web-page <https://diffpy.github.io/>`_ or email Prof. Simon Billinge at sb2896@columbia.edu.
177
+ For more information on diffpy.utils please visit the project `web-page <https://diffpy.github.io/>`_ or email Simon Billinge at sb2896@columbia.edu.
178
+
179
+ Acknowledgements
180
+ ----------------
181
+
182
+ ``diffpy.utils`` is built and maintained with `scikit-package <https://scikit-package.github.io/scikit-package/>`_.
@@ -8,7 +8,7 @@
8
8
  :target: https://diffpy.github.io/diffpy.utils
9
9
  :height: 100px
10
10
 
11
- |PyPi| |Forge| |PythonVersion| |PR|
11
+ |PyPI| |Forge| |PythonVersion| |PR|
12
12
 
13
13
  |CI| |Codecov| |Black| |Tracking|
14
14
 
@@ -26,7 +26,7 @@
26
26
 
27
27
  .. |PR| image:: https://img.shields.io/badge/PR-Welcome-29ab47ff
28
28
 
29
- .. |PyPi| image:: https://img.shields.io/pypi/v/diffpy.utils
29
+ .. |PyPI| image:: https://img.shields.io/pypi/v/diffpy.utils
30
30
  :target: https://pypi.org/project/diffpy.utils/
31
31
 
32
32
  .. |PythonVersion| image:: https://img.shields.io/pypi/pyversions/diffpy.utils
@@ -38,14 +38,16 @@
38
38
  diffpy.utils Package
39
39
  ========================================================================
40
40
 
41
- General purpose shared utilities for the diffpy libraries.
41
+ General utilities for analyzing diffraction data
42
+
43
+ The diffpy.utils package provides a number of functions and classes designed to help
44
+ researchers analyze their diffraction data. It also includes some functionality for
45
+ carrying out PDF analysis. Examples are parsers for reading common format diffraction
46
+ data files, ``DiffractionObjects`` that allow you to do algebra on diffraction patterns,
47
+ tools for better capture and propagation of metadata,
48
+ diffraction-friendly interpolation routines, as well as some other tools used across
49
+ diffpy libraries.
42
50
 
43
- The diffpy.utils package provides functions for extracting array data from
44
- variously formatted text files, an interpolation function based on the
45
- Whittaker-Shannon formula that can be used to resample a PDF or other profile
46
- function over a new grid, `DiffractionObject` for conveniently manipulating
47
- diffraction data, and some wx GUI utilities used by the PDFgui
48
- program.
49
51
 
50
52
  Citation
51
53
  --------
@@ -134,9 +136,14 @@ trying to commit again.
134
136
 
135
137
  Improvements and fixes are always appreciated.
136
138
 
137
- Before contributing, please read our `Code of Conduct <https://github.com/diffpy/diffpy.utils/blob/main/CODE_OF_CONDUCT.rst>`_.
139
+ Before contributing, please read our `Code of Conduct <https://github.com/diffpy/diffpy.utils/blob/main/CODE-OF-CONDUCT.rst>`_.
138
140
 
139
141
  Contact
140
142
  -------
141
143
 
142
- For more information on diffpy.utils please visit the project `web-page <https://diffpy.github.io/>`_ or email Prof. Simon Billinge at sb2896@columbia.edu.
144
+ For more information on diffpy.utils please visit the project `web-page <https://diffpy.github.io/>`_ or email Simon Billinge at sb2896@columbia.edu.
145
+
146
+ Acknowledgements
147
+ ----------------
148
+
149
+ ``diffpy.utils`` is built and maintained with `scikit-package <https://scikit-package.github.io/scikit-package/>`_.
@@ -6,13 +6,13 @@ build-backend = "setuptools.build_meta"
6
6
  name = "diffpy.utils"
7
7
  dynamic=['version', 'dependencies']
8
8
  authors = [
9
- { name="Simon J.L. Billinge group", email="simon.billinge@gmail.com" },
9
+ { name="Simon Billinge", email="sb2896@columbia.edu" },
10
10
  ]
11
11
  maintainers = [
12
- { name="Simon J.L. Billinge group", email="simon.billinge@gmail.com" },
12
+ { name="Simon Billinge", email="sb2896@columbia.edu" },
13
13
  ]
14
- description = "Shared utilities for diffpy packages"
15
- keywords = ["text data parsers", "wx grid", "diffraction objects"]
14
+ description = "General utilities for analyzing diffraction data"
15
+ keywords = ['text data parsers', 'wx grid', 'diffraction objects']
16
16
  readme = "README.rst"
17
17
  requires-python = ">=3.11, <3.14"
18
18
  classifiers = [
@@ -27,7 +27,7 @@ classifiers = [
27
27
  'Operating System :: Unix',
28
28
  'Programming Language :: Python :: 3.11',
29
29
  'Programming Language :: Python :: 3.12',
30
- 'Programming Language :: Python :: 3.13',
30
+ 'Programming Language :: Python :: 3.13',
31
31
  'Topic :: Scientific/Engineering :: Physics',
32
32
  'Topic :: Scientific/Engineering :: Chemistry',
33
33
  ]
@@ -57,7 +57,7 @@ ignore-words = ".codespell/ignore_words.txt"
57
57
  skip = "*.cif,*.dat"
58
58
 
59
59
  [tool.black]
60
- line-length = 115
60
+ line-length = 79
61
61
  include = '\.pyi?$'
62
62
  exclude = '''
63
63
  /(
@@ -2,3 +2,4 @@ sphinx
2
2
  sphinx_rtd_theme
3
3
  doctr
4
4
  m2r
5
+ sphinx-copybutton
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env python
2
2
  ##############################################################################
3
3
  #
4
- # (c) 2024 The Trustees of Columbia University in the City of New York.
4
+ # (c) 2025 The Trustees of Columbia University in the City of New York.
5
5
  # All rights reserved.
6
6
  #
7
- # File coded by: Billinge Group members and community contributors.
7
+ # File coded by: Simon Billinge, Billinge Group members.
8
8
  #
9
9
  # See GitHub contributions for a more detailed list of contributors.
10
10
  # https://github.com/diffpy/diffpy.utils/graphs/contributors
@@ -19,3 +19,5 @@ from diffpy.utils.version import __version__
19
19
 
20
20
  # silence the pyflakes syntax checker
21
21
  assert __version__ or True
22
+
23
+ # End of file
@@ -6,24 +6,42 @@ from copy import deepcopy
6
6
  import numpy as np
7
7
 
8
8
  from diffpy.utils.tools import get_package_info
9
- from diffpy.utils.transforms import d_to_q, d_to_tth, q_to_d, q_to_tth, tth_to_d, tth_to_q
9
+ from diffpy.utils.transforms import (
10
+ d_to_q,
11
+ d_to_tth,
12
+ q_to_d,
13
+ q_to_tth,
14
+ tth_to_d,
15
+ tth_to_q,
16
+ )
10
17
 
11
18
  QQUANTITIES = ["q"]
12
19
  ANGLEQUANTITIES = ["angle", "tth", "twotheta", "2theta"]
13
20
  DQUANTITIES = ["d", "dspace"]
14
21
  XQUANTITIES = ANGLEQUANTITIES + DQUANTITIES + QQUANTITIES
15
- XUNITS = ["degrees", "radians", "rad", "deg", "inv_angs", "inv_nm", "nm-1", "A-1"]
22
+ XUNITS = [
23
+ "degrees",
24
+ "radians",
25
+ "rad",
26
+ "deg",
27
+ "inv_angs",
28
+ "inv_nm",
29
+ "nm-1",
30
+ "A-1",
31
+ ]
16
32
 
17
33
  x_values_not_equal_emsg = (
18
- "The two objects have different values in x arrays (my_do.all_arrays[:, [1, 2, 3]]). "
19
- "Please ensure the x values of the two objects are identical by re-instantiating "
20
- "the DiffractionObject with the correct x value inputs."
34
+ "The two objects have different values in x arrays "
35
+ "(my_do.all_arrays[:, [1, 2, 3]]). "
36
+ "Please ensure the x values of the two objects are identical by "
37
+ "re-instantiating the DiffractionObject with the correct x value inputs."
21
38
  )
22
39
 
23
40
  invalid_add_type_emsg = (
24
- "You may only add a DiffractionObject with another DiffractionObject or a scalar value. "
25
- "Please rerun by adding another DiffractionObject instance or a scalar value. "
26
- "e.g., my_do_1 + my_do_2 or my_do + 10 or 10 + my_do"
41
+ "You may only add a DiffractionObject with another DiffractionObject or "
42
+ "a scalar value. "
43
+ "Please rerun by adding another DiffractionObject instance or a "
44
+ "scalar value. e.g., my_do_1 + my_do_2 or my_do + 10 or 10 + my_do"
27
45
  )
28
46
 
29
47
 
@@ -54,11 +72,14 @@ class DiffractionObject:
54
72
  Attributes
55
73
  ----------
56
74
  scat_quantity : str
57
- The type of scattering experiment (e.g., "x-ray", "neutron"). Default is an empty string "".
75
+ The type of scattering experiment (e.g., "x-ray", "neutron"). Default
76
+ is an empty string "".
58
77
  wavelength : float
59
- The wavelength of the incoming beam, specified in angstroms (Å). Default is none.
78
+ The wavelength of the incoming beam, specified in angstroms (Å).
79
+ Default is none.
60
80
  name: str
61
- The name or label for the scattering data. Default is an empty string "".
81
+ The name or label for the scattering data. Default is an empty string
82
+ "".
62
83
  qmin : float
63
84
  The minimum q value.
64
85
  qmax : float
@@ -92,7 +113,8 @@ class DiffractionObject:
92
113
  yarray : ndarray
93
114
  The dependent variable array corresponding to intensity values.
94
115
  xtype : str
95
- The type of the independent variable in `xarray`. Must be one of {*XQUANTITIES}.
116
+ The type of the independent variable in `xarray`. Must be one of
117
+ {*XQUANTITIES}.
96
118
  wavelength : float, optional, default is None.
97
119
  The wavelength of the incoming beam, specified in angstroms (Å)
98
120
  scat_quantity : str, optional, default is an empty string "".
@@ -108,7 +130,7 @@ class DiffractionObject:
108
130
  >>> import numpy as np
109
131
  >>> from diffpy.utils.diffraction_objects import DiffractionObject
110
132
  ...
111
- >>> x = np.array([0.12, 0.24, 0.31, 0.4]) # independent variable (e.g., q)
133
+ >>> x = np.array([0.12, 0.24, 0.31, 0.4]) # independent variable (e.g., q) # noqa: E501
112
134
  >>> y = np.array([10, 20, 40, 60]) # intensity values
113
135
  >>> metadata = {
114
136
  ... "sample": "rock salt from the beach",
@@ -129,9 +151,13 @@ class DiffractionObject:
129
151
  """
130
152
 
131
153
  self._uuid = uuid.uuid4()
132
- self._input_data(xarray, yarray, xtype, wavelength, scat_quantity, name, metadata)
154
+ self._input_data(
155
+ xarray, yarray, xtype, wavelength, scat_quantity, name, metadata
156
+ )
133
157
 
134
- def _input_data(self, xarray, yarray, xtype, wavelength, scat_quantity, name, metadata):
158
+ def _input_data(
159
+ self, xarray, yarray, xtype, wavelength, scat_quantity, name, metadata
160
+ ):
135
161
  if xtype not in XQUANTITIES:
136
162
  raise ValueError(_xtype_wmsg(xtype))
137
163
  if len(xarray) != len(yarray):
@@ -152,8 +178,12 @@ class DiffractionObject:
152
178
  def __eq__(self, other):
153
179
  if not isinstance(other, DiffractionObject):
154
180
  return NotImplemented
155
- self_attributes = [key for key in self.__dict__ if not key.startswith("_")]
156
- other_attributes = [key for key in other.__dict__ if not key.startswith("_")]
181
+ self_attributes = [
182
+ key for key in self.__dict__ if not key.startswith("_")
183
+ ]
184
+ other_attributes = [
185
+ key for key in other.__dict__ if not key.startswith("_")
186
+ ]
157
187
  if not sorted(self_attributes) == sorted(other_attributes):
158
188
  return False
159
189
  for key in self_attributes:
@@ -167,8 +197,13 @@ class DiffractionObject:
167
197
  or not np.isclose(value, other_value, rtol=1e-5)
168
198
  ):
169
199
  return False
170
- elif isinstance(value, list) and all(isinstance(i, np.ndarray) for i in value):
171
- if not all(np.allclose(i, j, rtol=1e-5) for i, j in zip(value, other_value)):
200
+ elif isinstance(value, list) and all(
201
+ isinstance(i, np.ndarray) for i in value
202
+ ):
203
+ if not all(
204
+ np.allclose(i, j, rtol=1e-5)
205
+ for i, j in zip(value, other_value)
206
+ ):
172
207
  return False
173
208
  else:
174
209
  if value != other_value:
@@ -182,23 +217,29 @@ class DiffractionObject:
182
217
  Parameters
183
218
  ----------
184
219
  other : DiffractionObject, int, or float
185
- The item to be added. If `other` is a scalar value, this value will be added to each element of the
186
- yarray of this DiffractionObject instance. If `other` is another DiffractionObject, the yarrays of the
187
- two DiffractionObjects will be combined element-wise. The result is a new DiffractionObject instance,
188
- representing the addition and using the xarray from the left-hand side DiffractionObject.
220
+ The item to be added. If `other` is a scalar value, this value
221
+ will be added to each element of the yarray of this
222
+ DiffractionObject instance. If `other` is another DiffractionObject
223
+ , the yarrays of the two DiffractionObjects will be combined
224
+ element -wise. The result is a new DiffractionObject instance,
225
+ representing the addition and using the xarray from the left-hand
226
+ side DiffractionObject.
189
227
 
190
228
  Returns
191
229
  -------
192
230
  DiffractionObject
193
- The new DiffractionObject instance with modified yarray values. This instance is a deep copy of the
194
- original with the additions applied.
231
+ The new DiffractionObject instance with modified yarray values.
232
+ This instance is a deep copy of the original with the additions
233
+ applied.
195
234
 
196
235
  Raises
197
236
  ------
198
237
  ValueError
199
- Raised when the xarrays of two DiffractionObject instances are not equal.
238
+ Raised when the xarrays of two DiffractionObject instances are
239
+ not equal.
200
240
  TypeError
201
- Raised when `other` is not an instance of DiffractionObject, int, or float.
241
+ Raised when `other` is not an instance of DiffractionObject, int,
242
+ or float.
202
243
 
203
244
  Examples
204
245
  --------
@@ -224,12 +265,14 @@ class DiffractionObject:
224
265
  """Subtract scalar value or another DiffractionObject to the yarray of
225
266
  the DiffractionObject.
226
267
 
227
- This method behaves similarly to the `__add__` method, but performs subtraction instead of addition.
228
- For details on parameters, returns, and exceptions, refer to the documentation for `__add__`.
268
+ This method behaves similarly to the `__add__` method, but performs
269
+ subtraction instead of addition. For details on parameters, returns
270
+ , and exceptions, refer to the documentation for `__add__`.
229
271
 
230
272
  Examples
231
273
  --------
232
- Subtract a scalar value from the yarray of a DiffractionObject instance:
274
+ Subtract a scalar value from the yarray of a DiffractionObject
275
+ instance:
233
276
  >>> new_do = my_do - 10.1
234
277
 
235
278
  Subtract the yarrays of two DiffractionObject instances:
@@ -250,12 +293,14 @@ class DiffractionObject:
250
293
  """Multiply a scalar value or another DiffractionObject with the yarray
251
294
  of this DiffractionObject.
252
295
 
253
- This method behaves similarly to the `__add__` method, but performs multiplication instead of addition.
254
- For details on parameters, returns, and exceptions, refer to the documentation for `__add__`.
296
+ This method behaves similarly to the `__add__` method, but performs
297
+ multiplication instead of addition. For details on parameters,
298
+ returns, and exceptions, refer to the documentation for `__add__`.
255
299
 
256
300
  Examples
257
301
  --------
258
- Multiply a scalar value with the yarray of a DiffractionObject instance:
302
+ Multiply a scalar value with the yarray of a DiffractionObject
303
+ instance:
259
304
  >>> new_do = my_do * 3.5
260
305
 
261
306
  Multiply the yarrays of two DiffractionObject instances:
@@ -276,8 +321,9 @@ class DiffractionObject:
276
321
  """Divide the yarray of this DiffractionObject by a scalar value or
277
322
  another DiffractionObject.
278
323
 
279
- This method behaves similarly to the `__add__` method, but performs division instead of addition.
280
- For details on parameters, returns, and exceptions, refer to the documentation for `__add__`.
324
+ This method behaves similarly to the `__add__` method, but performs
325
+ division instead of addition. For details on parameters, returns,
326
+ and exceptions, refer to the documentation for `__add__`.
281
327
 
282
328
  Examples
283
329
  --------
@@ -303,7 +349,9 @@ class DiffractionObject:
303
349
  if isinstance(other, DiffractionObject):
304
350
  if self.all_arrays.shape != other.all_arrays.shape:
305
351
  raise ValueError(x_values_not_equal_emsg)
306
- if not np.allclose(self.all_arrays[:, [1, 2, 3]], other.all_arrays[:, [1, 2, 3]]):
352
+ if not np.allclose(
353
+ self.all_arrays[:, [1, 2, 3]], other.all_arrays[:, [1, 2, 3]]
354
+ ):
307
355
  raise ValueError(x_values_not_equal_emsg)
308
356
 
309
357
  @property
@@ -313,8 +361,8 @@ class DiffractionObject:
313
361
  Returns
314
362
  -------
315
363
  ndarray
316
- The shape (len(data), 4) 2D array with columns containing the `yarray` (intensity)
317
- and the `xarray` values in q, tth, and d.
364
+ The shape (len(data), 4) 2D array with columns containing the `
365
+ yarray` (intensity) and the `xarray` values in q, tth, and d.
318
366
 
319
367
  Examples
320
368
  --------
@@ -361,27 +409,35 @@ class DiffractionObject:
361
409
  def uuid(self, _):
362
410
  raise AttributeError(_setter_wmsg("uuid"))
363
411
 
364
- def get_array_index(self, xtype, xvalue):
365
- """Return the index of the closest value in the array associated with
412
+ def get_array_index(self, xvalue, xtype=None):
413
+ f"""Return the index of the closest value in the array associated with
366
414
  the specified xtype and the value provided.
367
415
 
368
416
  Parameters
369
417
  ----------
370
- xtype : str
371
- The type of the independent variable in `xarray`. Must be one of {*XQUANTITIES}.
372
418
  xvalue : float
373
419
  The value of the xtype to find the closest index for.
420
+ xtype : str, optional
421
+ The type of the independent variable in `xarray`. Must be one
422
+ of {*XQUANTITIES, }. Default is {self._input_xtype}
374
423
 
375
424
  Returns
376
425
  -------
377
426
  index : int
378
- The index of the closest value in the array associated with the specified xtype and the value provided.
427
+ The index of the closest value in the array associated with the
428
+ specified xtype and the value provided.
379
429
  """
380
-
381
- xtype = self._input_xtype
430
+ if xtype is None:
431
+ xtype = self._input_xtype
432
+ else:
433
+ if xtype not in XQUANTITIES:
434
+ raise ValueError(_xtype_wmsg(xtype))
382
435
  xarray = self.on_xtype(xtype)[0]
383
436
  if len(xarray) == 0:
384
- raise ValueError(f"The '{xtype}' array is empty. Please ensure it is initialized.")
437
+ raise ValueError(
438
+ f"The '{xtype}' array is empty. "
439
+ "Please ensure it is initialized."
440
+ )
385
441
  index = (np.abs(xarray - xvalue)).argmin()
386
442
  return index
387
443
 
@@ -447,14 +503,19 @@ class DiffractionObject:
447
503
  """
448
504
  return [self.all_arrays[:, 3], self.all_arrays[:, 0]]
449
505
 
450
- def scale_to(self, target_diff_object, q=None, tth=None, d=None, offset=None):
506
+ def scale_to(
507
+ self, target_diff_object, q=None, tth=None, d=None, offset=None
508
+ ):
451
509
  """Return a new diffraction object which is the current object but
452
510
  rescaled in y to the target.
453
511
 
454
- By default, if `q`, `tth`, or `d` are not provided, scaling is based on the max intensity from each object.
455
- Otherwise, y-value in the target at the closest specified x-value will be used as the factor to scale to.
456
- The entire array is scaled by this factor so that one object places on top of the other at that point.
457
- If multiple values of `q`, `tth`, or `d` are provided, an error will be raised.
512
+ By default, if `q`, `tth`, or `d` are not provided, scaling is
513
+ based on the max intensity from each object. Otherwise, y-value in
514
+ the target at the closest specified x-value will be used as the
515
+ factor to scale to. The entire array is scaled by this factor so
516
+ that one object places on top of the other at that point. If
517
+ multiple values of `q`, `tth`, or `d` are provided, an error will
518
+ be raised.
458
519
 
459
520
  Parameters
460
521
  ----------
@@ -462,8 +523,9 @@ class DiffractionObject:
462
523
  The diffraction object you want to scale the current one onto.
463
524
 
464
525
  q, tth, d : float, optional, default is None
465
- The value of the x-array where you want the curves to line up vertically.
466
- Specify a value on one of the allowed grids, q, tth, or d), e.g., q=10.
526
+ The value of the x-array where you want the curves to line up
527
+ vertically. Specify a value on one of the allowed grids, q, tth,
528
+ or d), e.g., q=10.
467
529
 
468
530
  offset : float, optional, default is None
469
531
  The offset to add to the scaled y-values.
@@ -486,7 +548,10 @@ class DiffractionObject:
486
548
  if count == 0:
487
549
  q_target_max = max(target_diff_object.on_q()[1])
488
550
  q_self_max = max(self.on_q()[1])
489
- scaled_do._all_arrays[:, 0] = scaled_do._all_arrays[:, 0] * q_target_max / q_self_max + offset
551
+ scaled_do._all_arrays[:, 0] = (
552
+ scaled_do._all_arrays[:, 0] * q_target_max / q_self_max
553
+ + offset
554
+ )
490
555
  return scaled_do
491
556
 
492
557
  xtype = "q" if q is not None else "tth" if tth is not None else "d"
@@ -497,7 +562,9 @@ class DiffractionObject:
497
562
 
498
563
  xindex_data = (np.abs(data[0] - xvalue)).argmin()
499
564
  xindex_target = (np.abs(target[0] - xvalue)).argmin()
500
- scaled_do._all_arrays[:, 0] = data[1] * target[1][xindex_target] / data[1][xindex_data] + offset
565
+ scaled_do._all_arrays[:, 0] = (
566
+ data[1] * target[1][xindex_target] / data[1][xindex_data] + offset
567
+ )
501
568
  return scaled_do
502
569
 
503
570
  def on_xtype(self, xtype):
@@ -506,7 +573,8 @@ class DiffractionObject:
506
573
  Parameters
507
574
  ----------
508
575
  xtype : str
509
- The type of quantity for the independent variable chosen from {*XQUANTITIES, }
576
+ The type of quantity for the independent variable chosen from
577
+ {*XQUANTITIES, }
510
578
 
511
579
  Raises
512
580
  ------
@@ -516,7 +584,8 @@ class DiffractionObject:
516
584
  Returns
517
585
  -------
518
586
  (xarray, yarray) : tuple of ndarray
519
- The tuple containing two 1D numpy arrays with x and y data for the specified xtype.
587
+ The tuple containing two 1D numpy arrays with x and y data for
588
+ the specified xtype.
520
589
  """
521
590
  if xtype.lower() in ANGLEQUANTITIES:
522
591
  return self.on_tth()
@@ -536,12 +605,13 @@ class DiffractionObject:
536
605
  filepath : str
537
606
  The filepath where the diffraction object will be dumped
538
607
  xtype : str, optional, default is q
539
- The type of quantity for the independent variable chosen from {*XQUANTITIES, }
608
+ The type of quantity for the independent variable chosen from
609
+ {*XQUANTITIES, }
540
610
 
541
611
  Examples
542
612
  --------
543
- To save a diffraction object to a file named "diffraction_data.chi" in the current directory
544
- with the independent variable 'q':
613
+ To save a diffraction object to a file named "diffraction_data.chi"
614
+ in the current directory with the independent variable 'q':
545
615
 
546
616
  >>> file = "diffraction_data.chi"
547
617
  >>> do.dump(file, xtype="q")
@@ -551,7 +621,8 @@ class DiffractionObject:
551
621
  >>> file = "./output/diffraction_data.chi"
552
622
  >>> do.dump(file, xtype="q")
553
623
 
554
- To save the diffraction data with a different independent variable, such as 'tth':
624
+ To save the diffraction data with a different independent variable,
625
+ such as 'tth':
555
626
 
556
627
  >>> file = "diffraction_data_tth.chi"
557
628
  >>> do.dump(file, xtype="tth")
@@ -561,17 +632,23 @@ class DiffractionObject:
561
632
  if xtype in QQUANTITIES:
562
633
  data_to_save = np.column_stack((self.on_q()[0], self.on_q()[1]))
563
634
  elif xtype in ANGLEQUANTITIES:
564
- data_to_save = np.column_stack((self.on_tth()[0], self.on_tth()[1]))
635
+ data_to_save = np.column_stack(
636
+ (self.on_tth()[0], self.on_tth()[1])
637
+ )
565
638
  elif xtype in DQUANTITIES:
566
639
  data_to_save = np.column_stack((self.on_d()[0], self.on_d()[1]))
567
640
  else:
568
641
  warnings.warn(_xtype_wmsg(xtype))
569
- self.metadata.update(get_package_info("diffpy.utils", metadata=self.metadata))
642
+ self.metadata.update(
643
+ get_package_info("diffpy.utils", metadata=self.metadata)
644
+ )
570
645
  self.metadata["creation_time"] = datetime.datetime.now()
571
646
 
572
647
  with open(filepath, "w") as f:
573
648
  f.write(
574
- f"[DiffractionObject]\nname = {self.name}\nwavelength = {self.wavelength}\n"
649
+ f"[DiffractionObject]\n"
650
+ f"name = {self.name}\n"
651
+ f"wavelength = {self.wavelength}\n"
575
652
  f"scat_quantity = {self.scat_quantity}\n"
576
653
  )
577
654
  for key, value in self.metadata.items():
@@ -585,6 +662,7 @@ class DiffractionObject:
585
662
  Returns
586
663
  -------
587
664
  DiffractionObject
588
- The new instance of DiffractionObject, which is a deep copy of the current instance.
665
+ The new instance of DiffractionObject, which is a deep copy of
666
+ the current instance.
589
667
  """
590
668
  return deepcopy(self)
@@ -51,5 +51,7 @@ class ImproperSizeError(Exception):
51
51
 
52
52
  def __init__(self, bad_object, message=None):
53
53
  if message is None:
54
- self.message = f"The size of {bad_object} is different than expected."
54
+ self.message = (
55
+ f"The size of {bad_object} is different than expected."
56
+ )
55
57
  super().__init__(self.message)