diffpy.utils 3.6.0rc3__tar.gz → 3.6.1rc0__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.0rc3 → diffpy_utils-3.6.1rc0}/PKG-INFO +23 -15
  2. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/README.rst +17 -10
  3. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/pyproject.toml +6 -6
  4. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/requirements/docs.txt +1 -0
  5. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/src/diffpy/utils/__init__.py +4 -2
  6. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/src/diffpy/utils/diffraction_objects.py +135 -60
  7. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/src/diffpy/utils/parsers/custom_exceptions.py +3 -1
  8. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/src/diffpy/utils/parsers/loaddata.py +61 -32
  9. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/src/diffpy/utils/parsers/serialization.py +29 -14
  10. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/src/diffpy/utils/resampler.py +28 -21
  11. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/src/diffpy/utils/tools.py +131 -70
  12. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/src/diffpy/utils/transforms.py +21 -12
  13. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/src/diffpy/utils/validators.py +3 -2
  14. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/src/diffpy/utils/version.py +4 -2
  15. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/src/diffpy/utils/wx/gridutils.py +9 -3
  16. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/src/diffpy.utils.egg-info/PKG-INFO +23 -15
  17. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/tests/conftest.py +39 -16
  18. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/tests/test_diffraction_objects.py +228 -68
  19. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/tests/test_loaddata.py +6 -4
  20. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/tests/test_resample.py +2 -1
  21. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/tests/test_serialization.py +48 -13
  22. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/tests/test_tools.py +152 -45
  23. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/tests/test_transforms.py +134 -43
  24. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/AUTHORS.rst +0 -0
  25. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/LICENSE.rst +0 -0
  26. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/LICENSE_DANSE.txt +0 -0
  27. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/MANIFEST.in +0 -0
  28. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/requirements/build.txt +0 -0
  29. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/requirements/conda.txt +0 -0
  30. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/requirements/pip.txt +0 -0
  31. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/requirements/test.txt +0 -0
  32. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/setup.cfg +0 -0
  33. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/src/diffpy/__init__.py +0 -0
  34. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/src/diffpy/utils/parsers/__init__.py +0 -0
  35. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/src/diffpy/utils/wx/__init__.py +0 -0
  36. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/src/diffpy.utils.egg-info/SOURCES.txt +0 -0
  37. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/src/diffpy.utils.egg-info/dependency_links.txt +0 -0
  38. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/src/diffpy.utils.egg-info/requires.txt +0 -0
  39. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/src/diffpy.utils.egg-info/top_level.txt +0 -0
  40. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/tests/test_validators.py +0 -0
  41. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/tests/test_version.py +0 -0
  42. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/tests/testdata/dbload/e1.gr +0 -0
  43. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/tests/testdata/dbload/e2.gr +0 -0
  44. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/tests/testdata/dbload/e3.gr +0 -0
  45. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/tests/testdata/generated_db.json +0 -0
  46. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/tests/testdata/generatewarnings.txt +0 -0
  47. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/tests/testdata/loaddata01.txt +0 -0
  48. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/tests/testdata/loaddatawithheaders.txt +0 -0
  49. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/tests/testdata/loadfile.txt +0 -0
  50. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/tests/testdata/strumining.json +0 -0
  51. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/tests/testdata/targetjson.json +0 -0
  52. {diffpy_utils-3.6.0rc3 → diffpy_utils-3.6.1rc0}/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.0rc3
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.1rc0
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
  --------
@@ -171,4 +174,9 @@ Before contributing, please read our `Code of Conduct <https://github.com/diffpy
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
  --------
@@ -139,4 +141,9 @@ Before contributing, please read our `Code of Conduct <https://github.com/diffpy
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
  --------
@@ -368,20 +416,25 @@ class DiffractionObject:
368
416
  Parameters
369
417
  ----------
370
418
  xtype : str
371
- The type of the independent variable in `xarray`. Must be one of {*XQUANTITIES}.
419
+ The type of the independent variable in `xarray`. Must be one
420
+ of {*XQUANTITIES}.
372
421
  xvalue : float
373
422
  The value of the xtype to find the closest index for.
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
430
 
381
431
  xtype = self._input_xtype
382
432
  xarray = self.on_xtype(xtype)[0]
383
433
  if len(xarray) == 0:
384
- raise ValueError(f"The '{xtype}' array is empty. Please ensure it is initialized.")
434
+ raise ValueError(
435
+ f"The '{xtype}' array is empty. "
436
+ "Please ensure it is initialized."
437
+ )
385
438
  index = (np.abs(xarray - xvalue)).argmin()
386
439
  return index
387
440
 
@@ -447,14 +500,19 @@ class DiffractionObject:
447
500
  """
448
501
  return [self.all_arrays[:, 3], self.all_arrays[:, 0]]
449
502
 
450
- def scale_to(self, target_diff_object, q=None, tth=None, d=None, offset=None):
503
+ def scale_to(
504
+ self, target_diff_object, q=None, tth=None, d=None, offset=None
505
+ ):
451
506
  """Return a new diffraction object which is the current object but
452
507
  rescaled in y to the target.
453
508
 
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.
509
+ By default, if `q`, `tth`, or `d` are not provided, scaling is
510
+ based on the max intensity from each object. Otherwise, y-value in
511
+ the target at the closest specified x-value will be used as the
512
+ factor to scale to. The entire array is scaled by this factor so
513
+ that one object places on top of the other at that point. If
514
+ multiple values of `q`, `tth`, or `d` are provided, an error will
515
+ be raised.
458
516
 
459
517
  Parameters
460
518
  ----------
@@ -462,8 +520,9 @@ class DiffractionObject:
462
520
  The diffraction object you want to scale the current one onto.
463
521
 
464
522
  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.
523
+ The value of the x-array where you want the curves to line up
524
+ vertically. Specify a value on one of the allowed grids, q, tth,
525
+ or d), e.g., q=10.
467
526
 
468
527
  offset : float, optional, default is None
469
528
  The offset to add to the scaled y-values.
@@ -486,7 +545,10 @@ class DiffractionObject:
486
545
  if count == 0:
487
546
  q_target_max = max(target_diff_object.on_q()[1])
488
547
  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
548
+ scaled_do._all_arrays[:, 0] = (
549
+ scaled_do._all_arrays[:, 0] * q_target_max / q_self_max
550
+ + offset
551
+ )
490
552
  return scaled_do
491
553
 
492
554
  xtype = "q" if q is not None else "tth" if tth is not None else "d"
@@ -497,7 +559,9 @@ class DiffractionObject:
497
559
 
498
560
  xindex_data = (np.abs(data[0] - xvalue)).argmin()
499
561
  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
562
+ scaled_do._all_arrays[:, 0] = (
563
+ data[1] * target[1][xindex_target] / data[1][xindex_data] + offset
564
+ )
501
565
  return scaled_do
502
566
 
503
567
  def on_xtype(self, xtype):
@@ -506,7 +570,8 @@ class DiffractionObject:
506
570
  Parameters
507
571
  ----------
508
572
  xtype : str
509
- The type of quantity for the independent variable chosen from {*XQUANTITIES, }
573
+ The type of quantity for the independent variable chosen from
574
+ {*XQUANTITIES, }
510
575
 
511
576
  Raises
512
577
  ------
@@ -516,7 +581,8 @@ class DiffractionObject:
516
581
  Returns
517
582
  -------
518
583
  (xarray, yarray) : tuple of ndarray
519
- The tuple containing two 1D numpy arrays with x and y data for the specified xtype.
584
+ The tuple containing two 1D numpy arrays with x and y data for
585
+ the specified xtype.
520
586
  """
521
587
  if xtype.lower() in ANGLEQUANTITIES:
522
588
  return self.on_tth()
@@ -536,12 +602,13 @@ class DiffractionObject:
536
602
  filepath : str
537
603
  The filepath where the diffraction object will be dumped
538
604
  xtype : str, optional, default is q
539
- The type of quantity for the independent variable chosen from {*XQUANTITIES, }
605
+ The type of quantity for the independent variable chosen from
606
+ {*XQUANTITIES, }
540
607
 
541
608
  Examples
542
609
  --------
543
- To save a diffraction object to a file named "diffraction_data.chi" in the current directory
544
- with the independent variable 'q':
610
+ To save a diffraction object to a file named "diffraction_data.chi"
611
+ in the current directory with the independent variable 'q':
545
612
 
546
613
  >>> file = "diffraction_data.chi"
547
614
  >>> do.dump(file, xtype="q")
@@ -551,7 +618,8 @@ class DiffractionObject:
551
618
  >>> file = "./output/diffraction_data.chi"
552
619
  >>> do.dump(file, xtype="q")
553
620
 
554
- To save the diffraction data with a different independent variable, such as 'tth':
621
+ To save the diffraction data with a different independent variable,
622
+ such as 'tth':
555
623
 
556
624
  >>> file = "diffraction_data_tth.chi"
557
625
  >>> do.dump(file, xtype="tth")
@@ -561,17 +629,23 @@ class DiffractionObject:
561
629
  if xtype in QQUANTITIES:
562
630
  data_to_save = np.column_stack((self.on_q()[0], self.on_q()[1]))
563
631
  elif xtype in ANGLEQUANTITIES:
564
- data_to_save = np.column_stack((self.on_tth()[0], self.on_tth()[1]))
632
+ data_to_save = np.column_stack(
633
+ (self.on_tth()[0], self.on_tth()[1])
634
+ )
565
635
  elif xtype in DQUANTITIES:
566
636
  data_to_save = np.column_stack((self.on_d()[0], self.on_d()[1]))
567
637
  else:
568
638
  warnings.warn(_xtype_wmsg(xtype))
569
- self.metadata.update(get_package_info("diffpy.utils", metadata=self.metadata))
639
+ self.metadata.update(
640
+ get_package_info("diffpy.utils", metadata=self.metadata)
641
+ )
570
642
  self.metadata["creation_time"] = datetime.datetime.now()
571
643
 
572
644
  with open(filepath, "w") as f:
573
645
  f.write(
574
- f"[DiffractionObject]\nname = {self.name}\nwavelength = {self.wavelength}\n"
646
+ f"[DiffractionObject]\n"
647
+ f"name = {self.name}\n"
648
+ f"wavelength = {self.wavelength}\n"
575
649
  f"scat_quantity = {self.scat_quantity}\n"
576
650
  )
577
651
  for key, value in self.metadata.items():
@@ -585,6 +659,7 @@ class DiffractionObject:
585
659
  Returns
586
660
  -------
587
661
  DiffractionObject
588
- The new instance of DiffractionObject, which is a deep copy of the current instance.
662
+ The new instance of DiffractionObject, which is a deep copy of
663
+ the current instance.
589
664
  """
590
665
  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)