diffpy.utils 3.2.7__tar.gz → 3.3.1__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 (46) hide show
  1. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/PKG-INFO +14 -11
  2. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/README.rst +6 -3
  3. diffpy.utils-3.3.1/pyproject.toml +50 -0
  4. diffpy.utils-3.3.1/src/diffpy/utils/scattering_objects/__init__.py +19 -0
  5. diffpy.utils-3.3.1/src/diffpy/utils/scattering_objects/diffraction_objects.py +428 -0
  6. diffpy.utils-3.3.1/src/diffpy/utils/tests/test_diffraction_objects.py +25 -0
  7. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy/utils/version.py +1 -1
  8. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy.utils.egg-info/PKG-INFO +14 -11
  9. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy.utils.egg-info/SOURCES.txt +4 -2
  10. diffpy.utils-3.2.7/setup.py +0 -127
  11. diffpy.utils-3.2.7/src/diffpy.utils.egg-info/not-zip-safe +0 -1
  12. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/AUTHORS.txt +0 -0
  13. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/LICENSE.txt +0 -0
  14. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/LICENSE_DANSE.txt +0 -0
  15. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/MANIFEST.in +0 -0
  16. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/setup.cfg +0 -0
  17. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy/__init__.py +0 -0
  18. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy/utils/__init__.py +0 -0
  19. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy/utils/parsers/__init__.py +0 -0
  20. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy/utils/parsers/custom_exceptions.py +0 -0
  21. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy/utils/parsers/loaddata.py +0 -0
  22. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy/utils/parsers/resample.py +0 -0
  23. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy/utils/parsers/serialization.py +0 -0
  24. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy/utils/tests/__init__.py +0 -0
  25. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy/utils/tests/debug.py +0 -0
  26. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy/utils/tests/run.py +0 -0
  27. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy/utils/tests/test_loaddata.py +0 -0
  28. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy/utils/tests/test_resample.py +0 -0
  29. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy/utils/tests/test_serialization.py +0 -0
  30. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy/utils/tests/testdata/dbload/e1.gr +0 -0
  31. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy/utils/tests/testdata/dbload/e2.gr +0 -0
  32. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy/utils/tests/testdata/dbload/e3.gr +0 -0
  33. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy/utils/tests/testdata/generated_db.json +0 -0
  34. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy/utils/tests/testdata/generatewarnings.txt +0 -0
  35. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy/utils/tests/testdata/loaddata01.txt +0 -0
  36. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy/utils/tests/testdata/loaddatawithheaders.txt +0 -0
  37. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy/utils/tests/testdata/loadfile.txt +0 -0
  38. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy/utils/tests/testdata/strumining.json +0 -0
  39. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy/utils/tests/testdata/targetjson.json +0 -0
  40. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy/utils/tests/testdata/wrong.type +0 -0
  41. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy/utils/tests/testhelpers.py +0 -0
  42. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy/utils/version.cfg +0 -0
  43. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy/utils/wx/__init__.py +0 -0
  44. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy/utils/wx/gridutils.py +0 -0
  45. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy.utils.egg-info/dependency_links.txt +0 -0
  46. {diffpy.utils-3.2.7 → diffpy.utils-3.3.1}/src/diffpy.utils.egg-info/top_level.txt +0 -0
@@ -1,14 +1,12 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: diffpy.utils
3
- Version: 3.2.7
3
+ Version: 3.3.1
4
4
  Summary: Shared utilities for diffpy packages.
5
- Home-page: https://github.com/diffpy/diffpy.utils/
6
- Author: Simon J.L. Billinge group
7
- Author-email: sb2896@columbia.edu
8
- Maintainer: Simon J.L. Billinge group
9
- Maintainer-email: sb2896@columbia.edu
10
- License: BSD-style license
11
- Keywords: text data parsers wx grid
5
+ Author-email: "Simon J.L. Billinge group" <simon.billinge@gmail.com>
6
+ Maintainer-email: "Simon J.L. Billinge group" <simon.billinge@gmail.com>
7
+ Project-URL: Homepage, https://github.com/diffpy/diffpy.utils/
8
+ Project-URL: Issues, https://github.com/diffpy/diffpy.utils/issues
9
+ Keywords: text data parsers,wx grid,diffraction objects
12
10
  Classifier: Development Status :: 5 - Production/Stable
13
11
  Classifier: Environment :: Console
14
12
  Classifier: Intended Audience :: Developers
@@ -19,10 +17,12 @@ Classifier: Operating System :: Microsoft :: Windows
19
17
  Classifier: Operating System :: POSIX
20
18
  Classifier: Operating System :: Unix
21
19
  Classifier: Programming Language :: Python :: 2.7
20
+ Classifier: Programming Language :: Python :: 3.9
22
21
  Classifier: Programming Language :: Python :: 3.10
23
22
  Classifier: Programming Language :: Python :: 3.11
24
23
  Classifier: Programming Language :: Python :: 3.12
25
24
  Classifier: Topic :: Scientific/Engineering :: Physics
25
+ Requires-Python: >=3.9
26
26
  Description-Content-Type: text/x-rst
27
27
  License-File: LICENSE.txt
28
28
  License-File: LICENSE_DANSE.txt
@@ -87,7 +87,7 @@ If you prefer to install from sources, after installing the dependencies, obtain
87
87
  `GitHub <https://github.com/diffpy/diffpy.utils/>`_. Once installed, ``cd`` into your ``diffpy.utils`` directory
88
88
  and run the following ::
89
89
 
90
- pip install -e .
90
+ pip install .
91
91
 
92
92
  To check the installation integrity, if the following passes all checks, you are good! ::
93
93
 
@@ -105,9 +105,12 @@ https://github.com/diffpy/diffpy.utils.
105
105
 
106
106
  Feel free to fork the project and contribute. To install diffpy.utils
107
107
  in a development mode, with its sources being directly used by Python
108
- rather than copied to a package directory, use ::
108
+ rather than copied to a package directory, use the following in the root
109
+ directory ::
110
+
111
+ pip install -e .
109
112
 
110
- python setup.py develop --user
113
+ Note that this is only supported for `setuptools` version 62.0 and above.
111
114
 
112
115
 
113
116
  CONTACTS
@@ -57,7 +57,7 @@ If you prefer to install from sources, after installing the dependencies, obtain
57
57
  `GitHub <https://github.com/diffpy/diffpy.utils/>`_. Once installed, ``cd`` into your ``diffpy.utils`` directory
58
58
  and run the following ::
59
59
 
60
- pip install -e .
60
+ pip install .
61
61
 
62
62
  To check the installation integrity, if the following passes all checks, you are good! ::
63
63
 
@@ -75,9 +75,12 @@ https://github.com/diffpy/diffpy.utils.
75
75
 
76
76
  Feel free to fork the project and contribute. To install diffpy.utils
77
77
  in a development mode, with its sources being directly used by Python
78
- rather than copied to a package directory, use ::
78
+ rather than copied to a package directory, use the following in the root
79
+ directory ::
80
+
81
+ pip install -e .
79
82
 
80
- python setup.py develop --user
83
+ Note that this is only supported for `setuptools` version 62.0 and above.
81
84
 
82
85
 
83
86
  CONTACTS
@@ -0,0 +1,50 @@
1
+ [build-system]
2
+ requires = ["setuptools>=62.0", "setuptools-git-versioning<2"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "diffpy.utils"
7
+ dynamic=['version']
8
+ authors = [
9
+ { name="Simon J.L. Billinge group", email="simon.billinge@gmail.com" },
10
+ ]
11
+ maintainers = [
12
+ { name="Simon J.L. Billinge group", email="simon.billinge@gmail.com" },
13
+ ]
14
+ description = "Shared utilities for diffpy packages."
15
+ keywords = ["text data parsers", "wx grid", "diffraction objects"]
16
+ readme = "README.rst"
17
+ requires-python = ">=3.9"
18
+ classifiers = [
19
+ 'Development Status :: 5 - Production/Stable',
20
+ 'Environment :: Console',
21
+ 'Intended Audience :: Developers',
22
+ 'Intended Audience :: Science/Research',
23
+ 'License :: OSI Approved :: BSD License',
24
+ 'Operating System :: MacOS :: MacOS X',
25
+ 'Operating System :: Microsoft :: Windows',
26
+ 'Operating System :: POSIX',
27
+ 'Operating System :: Unix',
28
+ 'Programming Language :: Python :: 2.7',
29
+ 'Programming Language :: Python :: 3.9',
30
+ 'Programming Language :: Python :: 3.10',
31
+ 'Programming Language :: Python :: 3.11',
32
+ 'Programming Language :: Python :: 3.12',
33
+ 'Topic :: Scientific/Engineering :: Physics',
34
+ ]
35
+
36
+ [project.urls]
37
+ Homepage = "https://github.com/diffpy/diffpy.utils/"
38
+ Issues = "https://github.com/diffpy/diffpy.utils/issues"
39
+
40
+ [tool.setuptools-git-versioning]
41
+ enabled = true
42
+ template = "{tag}"
43
+ dev_template = "{tag}"
44
+ dirty_template = "{tag}"
45
+
46
+ [tool.setuptools.packages.find]
47
+ where = ["src"] # list of folders that contain the packages (["."] by default)
48
+ include = ["diffpy*"] # package names should match these glob patterns (["*"] by default)
49
+ exclude = ["diffpy.utils.tests*"] # exclude packages matching these glob patterns (empty by default)
50
+ namespaces = false # to disable scanning PEP 420 namespaces (true by default)
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env python
2
+ ##############################################################################
3
+ #
4
+ # diffpy.utils by DANSE Diffraction group
5
+ # Simon J. L. Billinge
6
+ # (c) 2010 The Trustees of Columbia University
7
+ # in the City of New York. All rights reserved.
8
+ #
9
+ # File coded by: Simon Billinge
10
+ #
11
+ # See AUTHORS.txt for a list of people who contributed.
12
+ # See LICENSE_DANSE.txt for license information.
13
+ #
14
+ ##############################################################################
15
+
16
+ """Scattering objects
17
+ """
18
+
19
+ # End of file
@@ -0,0 +1,428 @@
1
+ import uuid
2
+ from copy import deepcopy
3
+
4
+ import numpy as np
5
+ from numpy import array
6
+
7
+ QQUANTITIES = ["q"]
8
+ ANGLEQUANTITIES = ["angle","tth", "twotheta", "2theta"]
9
+ DQUANTITIES = ["d", "dspace"]
10
+ XQUANTITIES = ANGLEQUANTITIES + DQUANTITIES + QQUANTITIES
11
+ XUNITS = ["degrees","radians","rad","deg","inv_angs","inv_nm","nm-1","A-1"]
12
+
13
+ class Diffraction_object():
14
+ def __init__(self, name='', wavelength=None):
15
+ self.name = name
16
+ self.wavelength = wavelength
17
+ self.scat_quantity = ""
18
+ self.on_q = [np.empty(1), np.empty(1)]
19
+ self.on_tth = [np.empty(1), np.empty(1)]
20
+ self.on_d = [np.empty(1), np.empty(1)]
21
+ self._all_arrays = [self.on_q, self.on_tth]
22
+ self.metadata = {}
23
+
24
+ def __add__(self, other):
25
+ summed = deepcopy(self)
26
+ if isinstance(other, int) or isinstance(other, float) or isinstance(other, np.ndarray):
27
+ summed.on_tth[1] = self.on_tth[1] + other
28
+ summed.on_q[1] = self.on_q[1] + other
29
+ elif not isinstance(other, Diffraction_object):
30
+ raise TypeError(f"I only know how to sum two Diffraction_object objects")
31
+ elif self.on_tth[0].all() != other.on_tth[0].all():
32
+ raise RuntimeError(f"objects are not on the same x-grid. You may add them using the self.add method and"
33
+ f"specifying how to handle the mismatch.")
34
+ else:
35
+ summed.on_tth[1] = self.on_tth[1] + other.on_tth[1]
36
+ summed.on_q[1] = self.on_q[1] + other.on_q[1]
37
+ return summed
38
+ def __radd__(self, other):
39
+ summed = deepcopy(self)
40
+ if isinstance(other, int) or isinstance(other, float) or isinstance(other, np.ndarray):
41
+ summed.on_tth[1] = self.on_tth[1] + other
42
+ summed.on_q[1] = self.on_q[1] + other
43
+ elif not isinstance(other, Diffraction_object):
44
+ raise TypeError(f"I only know how to sum two Scattering_object objects")
45
+ elif self.on_tth[0].all() != other.on_tth[0].all():
46
+ raise RuntimeError(f"objects are not on the same x-grid. You may add them using the self.add method and"
47
+ f"specifying how to handle the mismatch.")
48
+ else:
49
+ summed.on_tth[1] = self.on_tth[1] + other.on_tth[1]
50
+ summed.on_q[1] = self.on_q[1] + other.on_q[1]
51
+ return summed
52
+
53
+ def __sub__(self, other):
54
+ subtracted = deepcopy(self)
55
+ if isinstance(other, int) or isinstance(other, float) or isinstance(other, np.ndarray):
56
+ subtracted.on_tth[1] = self.on_tth[1] - other
57
+ subtracted.on_q[1] = self.on_q[1] - other
58
+ elif not isinstance(other, Diffraction_object):
59
+ raise TypeError(f"I only know how to subtract two Scattering_object objects")
60
+ elif self.on_tth[0].all() != other.on_tth[0].all():
61
+ raise RuntimeError(
62
+ f"objects are not on the same x-grid. You may subtract them using the self.add method and"
63
+ f"specifying how to handle the mismatch.")
64
+ else:
65
+ subtracted.on_tth[1] = self.on_tth[1] - other.on_tth[1]
66
+ subtracted.on_q[1] = self.on_q[1] - other.on_q[1]
67
+ return subtracted
68
+
69
+ def __rsub__(self, other):
70
+ subtracted = deepcopy(self)
71
+ if isinstance(other, int) or isinstance(other, float) or isinstance(other, np.ndarray):
72
+ subtracted.on_tth[1] = other - self.on_tth[1]
73
+ subtracted.on_q[1] = other - self.on_q[1]
74
+ elif not isinstance(other, Diffraction_object):
75
+ raise TypeError(f"I only know how to subtract two Scattering_object objects")
76
+ elif self.on_tth[0].all() != other.on_tth[0].all():
77
+ raise RuntimeError(
78
+ f"objects are not on the same x-grid. You may subtract them using the self.add method and"
79
+ f"specifying how to handle the mismatch.")
80
+ else:
81
+ subtracted.on_tth[1] = other.on_tth[1] - self.on_tth[1]
82
+ subtracted.on_q[1] = other.on_q[1] - self.on_q[1]
83
+ return subtracted
84
+
85
+ def __mul__(self, other):
86
+ multiplied = deepcopy(self)
87
+ if isinstance(other, int) or isinstance(other, float) or isinstance(other, np.ndarray):
88
+ multiplied.on_tth[1] = other * self.on_tth[1]
89
+ multiplied.on_q[1] = other * self.on_q[1]
90
+ elif not isinstance(other, Diffraction_object):
91
+ raise TypeError(f"I only know how to multiply two Scattering_object objects")
92
+ elif self.on_tth[0].all() != other.on_tth[0].all():
93
+ raise RuntimeError(
94
+ f"objects are not on the same x-grid. You may multiply them using the self.add method and"
95
+ f"specifying how to handle the mismatch.")
96
+ else:
97
+ multiplied.on_tth[1] = self.on_tth[1] * other.on_tth[1]
98
+ multiplied.on_q[1] = self.on_q[1] * other.on_q[1]
99
+ return multiplied
100
+
101
+ def __rmul__(self, other):
102
+ multiplied = deepcopy(self)
103
+ if isinstance(other, int) or isinstance(other, float) or isinstance(other, np.ndarray):
104
+ multiplied.on_tth[1] = other * self.on_tth[1]
105
+ multiplied.on_q[1] = other * self.on_q[1]
106
+ elif self.on_tth[0].all() != other.on_tth[0].all():
107
+ raise RuntimeError(
108
+ f"objects are not on the same x-grid. You may multiply them using the self.add method and"
109
+ f"specifying how to handle the mismatch.")
110
+ else:
111
+ multiplied.on_tth[1] = self.on_tth[1] * other.on_tth[1]
112
+ multiplied.on_q[1] = self.on_q[1] * other.on_q[1]
113
+ return multiplied
114
+
115
+ def __truediv__(self, other):
116
+ divided = deepcopy(self)
117
+ if isinstance(other, int) or isinstance(other, float) or isinstance(other, np.ndarray):
118
+ divided.on_tth[1] = other / self.on_tth[1]
119
+ divided.on_q[1] = other / self.on_q[1]
120
+ elif not isinstance(other, Diffraction_object):
121
+ raise TypeError(f"I only know how to multiply two Scattering_object objects")
122
+ elif self.on_tth[0].all() != other.on_tth[0].all():
123
+ raise RuntimeError(
124
+ f"objects are not on the same x-grid. You may multiply them using the self.add method and"
125
+ f"specifying how to handle the mismatch.")
126
+ else:
127
+ divided.on_tth[1] = self.on_tth[1] / other.on_tth[1]
128
+ divided.on_q[1] = self.on_q[1] / other.on_q[1]
129
+ return divided
130
+
131
+
132
+ def __rtruediv__(self, other):
133
+ divided = deepcopy(self)
134
+ if isinstance(other, int) or isinstance(other, float) or isinstance(other, np.ndarray):
135
+ divided.on_tth[1] = other / self.on_tth[1]
136
+ divided.on_q[1] = other / self.on_q[1]
137
+ elif self.on_tth[0].all() != other.on_tth[0].all():
138
+ raise RuntimeError(
139
+ f"Diffraction objects are not on the same x-grid. You may multiply them using the self.add method and"
140
+ f"specifying how to handle the mismatch.")
141
+ else:
142
+ divided.on_tth[1] = other.on_tth[1] / self.on_tth[1]
143
+ divided.on_q[1] = other.on_q[1] / self.on_q[1]
144
+ return divided
145
+
146
+
147
+ def set_angles_from_list(self, angles_list):
148
+ self.angles = angles_list
149
+ self.n_steps = len(angles_list) - 1.
150
+ self.begin_angle = self.angles[0]
151
+ self.end_angle = self.angles[-1]
152
+
153
+ def set_qs_from_range(self, begin_q, end_q, step_size=None, n_steps=None):
154
+ '''
155
+ create an array of linear spaced Q-values
156
+
157
+ Parameters
158
+ ----------
159
+ begin_q float
160
+ the beginning angle
161
+ end_q float
162
+ the ending angle
163
+ step_size float
164
+ the size of the step between points. Only specify step_size or n_steps, not both
165
+ n_steps integer
166
+ the number of steps. Odd numbers are preferred. Only specify step_size or n_steps, not both
167
+
168
+ Returns
169
+ -------
170
+ Sets self.qs
171
+ self.qs array of floats
172
+ the q values in the independent array
173
+
174
+ '''
175
+ self.qs = self._set_array_from_range(begin_q, end_q, step_size=step_size, n_steps=n_steps)
176
+
177
+
178
+ def set_angles_from_range(self, begin_angle, end_angle, step_size=None, n_steps=None):
179
+ '''
180
+ create an array of linear spaced angle-values
181
+
182
+ Parameters
183
+ ----------
184
+ begin_angle float
185
+ the beginning angle
186
+ end_angle float
187
+ the ending angle
188
+ step_size float
189
+ the size of the step between points. Only specify step_size or n_steps, not both
190
+ n_steps integer
191
+ the number of steps. Odd numbers are preferred. Only specify step_size or n_steps, not both
192
+
193
+ Returns
194
+ -------
195
+ Sets self.angles
196
+ self.angles array of floats
197
+ the q values in the independent array
198
+
199
+ '''
200
+ self.angles = self._set_array_from_range(begin_angle, end_angle, step_size=step_size, n_steps=n_steps)
201
+
202
+
203
+ def _set_array_from_range(self, begin, end, step_size=None, n_steps=None):
204
+ if step_size is not None and n_steps is not None:
205
+ print(
206
+ "WARNING: both step_size and n_steps have been given. n_steps will be used and step_size will be "
207
+ "reset.")
208
+ array = np.linspace(begin, end, n_steps)
209
+ elif step_size is not None:
210
+ array = np.arange(begin, end, step_size)
211
+ elif n_steps is not None:
212
+ array = np.linspace(begin, end, n_steps)
213
+ return array
214
+
215
+ def get_angle_index(self, angle):
216
+ count = 0
217
+ for i, target in enumerate(self.angles):
218
+ if angle == target:
219
+ return i
220
+ else:
221
+ count += 1
222
+ if count >= len(self.angles):
223
+ raise IndexError(f"WARNING: no angle {angle} found in angles list")
224
+
225
+ def insert_scattering_quantity(self, xarray, yarray, xtype, metadata={},
226
+ scat_quantity=None, name=None, wavelength=None):
227
+ f"""
228
+ insert a new scattering quantity into the scattering object
229
+
230
+ Parameters
231
+ ----------
232
+ xarray array-like of floats
233
+ the independent variable array
234
+ yarray array-like of floats
235
+ the dependent variable array
236
+ xtype string
237
+ the type of quantity for the independent variable from {*XQUANTITIES,}
238
+ metadata: dict
239
+ the metadata in the form of a dictionary of user-supplied key:value pairs
240
+
241
+ Returns
242
+ -------
243
+
244
+ """
245
+ self.input_xtype = xtype
246
+ # empty attributes have been defined in the __init__ method so only
247
+ # set the attributes that are not empty to avoid emptying them by mistake
248
+ if metadata: self.metadata = metadata
249
+ if scat_quantity is not None: self.scat_quantity = scat_quantity
250
+ if name is not None: self.name = name
251
+ if wavelength is not None: self.wavelength = wavelength
252
+ if xtype.lower() in QQUANTITIES:
253
+ self.on_q = [np.array(xarray),np.array(yarray)]
254
+ elif xtype.lower() in ANGLEQUANTITIES:
255
+ self.on_tth = [np.array(xarray),np.array(yarray)]
256
+ elif xtype.lower() in DQUANTITIES:
257
+ self.on_tth = [np.array(xarray),np.array(yarray)]
258
+ self.set_all_arrays()
259
+ def q_to_tth(self):
260
+ r"""
261
+ Helper function to convert q to two-theta.
262
+
263
+ By definition the relationship is:
264
+
265
+ .. math::
266
+
267
+ \sin\left(\frac{2\theta}{2}\right) = \frac{\lambda q}{4 \pi}
268
+
269
+ thus
270
+
271
+ .. math::
272
+
273
+ 2\theta_n = 2 \arcsin\left(\frac{\lambda q}{4 \pi}\right)
274
+
275
+ Parameters
276
+ ----------
277
+ q : array
278
+ An array of :math:`q` values
279
+
280
+ wavelength : float
281
+ Wavelength of the incoming x-rays
282
+
283
+ Function adapted from scikit-beam. Thanks to those developers
284
+
285
+ Returns
286
+ -------
287
+ two_theta : array
288
+ An array of :math:`2\theta` values in radians
289
+ """
290
+ q = self.on_q[0]
291
+ q = np.asarray(q)
292
+ wavelength = float(self.wavelength)
293
+ pre_factor = wavelength / (4 * np.pi)
294
+ return np.rad2deg(2. * np.arcsin(q * pre_factor))
295
+
296
+ def tth_to_q(self):
297
+ r"""
298
+ Helper function to convert two-theta to q
299
+
300
+ By definition the relationship is
301
+
302
+ .. math::
303
+
304
+ \sin\left(\frac{2\theta}{2}\right) = \frac{\lambda q}{4 \pi}
305
+
306
+ thus
307
+
308
+ .. math::
309
+
310
+ q = \frac{4 \pi \sin\left(\frac{2\theta}{2}\right)}{\lambda}
311
+
312
+
313
+
314
+ Parameters
315
+ ----------
316
+ two_theta : array
317
+ An array of :math:`2\theta` values in units of degrees
318
+
319
+ wavelength : float
320
+ Wavelength of the incoming x-rays
321
+
322
+ Function adapted from scikit-beam. Thanks to those developers.
323
+
324
+ Returns
325
+ -------
326
+ q : array
327
+ An array of :math:`q` values in the inverse of the units
328
+ of ``wavelength``
329
+ """
330
+ two_theta = np.asarray(np.deg2rad(self.on_tth[0]))
331
+ wavelength = float(self.wavelength)
332
+ pre_factor = (4 * np.pi) / wavelength
333
+ return pre_factor * np.sin(two_theta / 2)
334
+
335
+ def set_all_arrays(self):
336
+ master_array, xtype = self._get_original_array()
337
+ if xtype == "q":
338
+ self.on_tth[0] = self.q_to_tth()
339
+ self.on_tth[1] = master_array[1]
340
+ if xtype == "tth":
341
+ self.on_q[0] = self.tth_to_q()
342
+ self.on_q[1] = master_array[1]
343
+ self.tthmin = self.on_tth[0][0]
344
+ self.tthmax = self.on_tth[0][-1]
345
+ self.qmin = self.on_q[0][0]
346
+ self.qmax = self.on_q[0][-1]
347
+
348
+
349
+ def _get_original_array(self):
350
+ if self.input_xtype in QQUANTITIES:
351
+ return self.on_q, "q"
352
+ elif self.input_xtype in ANGLEQUANTITIES:
353
+ return self.on_tth, "tth"
354
+ elif self.input_xtype in DQUANTITIES:
355
+ return self.on_d, "d"
356
+
357
+ def scale_to(self, target_diff_object, xtype=None, xvalue=None):
358
+ f"""
359
+ returns a new diffraction object which is the current object but recaled in y to the target
360
+
361
+ Parameters
362
+ ----------
363
+ target_diff_object: Diffraction_object
364
+ the diffractoin object you want to scale the current one on to
365
+ xtype: string, optional. Default is Q
366
+ the xtype, from {XQUANTITIES}, that you will specify a point from to scale to
367
+ xvalue: float. Default is the midpoint of the array
368
+ the y-value in the target at this x-value will be used as the factor to scale to.
369
+ The entire array is scaled be the factor that places on on top of the other at that point.
370
+ xvalue does not have to be in the x-array, the point closest to this point will be used for the scaling.
371
+
372
+ Returns
373
+ -------
374
+ the rescaled Diffraction_object as a new object
375
+
376
+ """
377
+ scaled = deepcopy(self)
378
+ if xtype is None:
379
+ xtype = "q"
380
+
381
+ data = self.on_xtype(xtype)
382
+ target = target_diff_object.on_xtype(xtype)
383
+ if xvalue is None:
384
+ xvalue = data[0][0] + (data[0][-1] - data[0][0]) / 2.
385
+
386
+ xindex = (np.abs(data[0] - xvalue)).argmin()
387
+ ytarget = target[1][xindex]
388
+ yself = data[1][xindex]
389
+ scaled.on_tth[1] = data[1]*ytarget/yself
390
+ scaled.on_q[1] = data[1]*ytarget/yself
391
+ return scaled
392
+
393
+ def on_xtype(self, xtype):
394
+ '''
395
+ return a 2D np array with x in the first column and y in the second for x of type type
396
+ Parameters
397
+ ----------
398
+ xtype
399
+
400
+ Returns
401
+ -------
402
+
403
+ '''
404
+ if xtype.lower() in ANGLEQUANTITIES:
405
+ return self.on_tth
406
+ elif xtype.lower() in QQUANTITIES:
407
+ return self.on_q
408
+ elif xtype.lower() in DQUANTITIES:
409
+ return self.on_d
410
+ pass
411
+
412
+ def dump(self, filepath, xtype=None):
413
+ if xtype is None:
414
+ xtype = " q"
415
+ if xtype == "q":
416
+ data_to_save = np.column_stack((self.on_q[0], self.on_q[1]))
417
+ elif xtype == "tth":
418
+ data_to_save = np.column_stack((self.on_tth[0], self.on_tth[1]))
419
+ else:
420
+ print(f"WARNING: cannot handle the xtype '{xtype}'")
421
+
422
+ with open(filepath, 'w') as f:
423
+ f.write(f"[Diffraction_object]\nname = {self.name}\nwavelength = {self.wavelength}\n"
424
+ f"scat_quantity = {self.scat_quantity}\n")
425
+ for key, value in self.metadata.items():
426
+ f.write(f"{key} = {value}\n")
427
+ f.write("\n#### start data\n")
428
+ np.savetxt(f, data_to_save, delimiter=" ")
@@ -0,0 +1,25 @@
1
+ import numpy as np
2
+ from pathlib import Path
3
+ from diffpy.utils.scattering_objects.diffraction_objects import Diffraction_object
4
+
5
+ def test_dump(tmp_path):
6
+ x, y = np.linspace(0, 10, 11), np.linspace(0, 10, 11)
7
+ directory = Path(tmp_path)
8
+ file = directory / "testfile"
9
+ test = Diffraction_object()
10
+ test.wavelength = 1.54
11
+ test.name = "test"
12
+ test.scat_quantity = "x-ray"
13
+ test.insert_scattering_quantity(x, y, "q", metadata={"thing1": 1, "thing2": "thing2"})
14
+ test.dump(file, "q")
15
+ with open(file, "r") as f:
16
+ actual = f.read()
17
+ expected = ("[Diffraction_object]\nname = test\nwavelength = 1.54\nscat_quantity = x-ray\nthing1 = 1\n"
18
+ "thing2 = thing2\n\n#### start data\n0.000000000000000000e+00 0.000000000000000000e+00\n"
19
+ "1.000000000000000000e+00 1.000000000000000000e+00\n2.000000000000000000e+00 2.000000000000000000e+00\n"
20
+ "3.000000000000000000e+00 3.000000000000000000e+00\n4.000000000000000000e+00 4.000000000000000000e+00\n"
21
+ "5.000000000000000000e+00 5.000000000000000000e+00\n"
22
+ "6.000000000000000000e+00 6.000000000000000000e+00\n7.000000000000000000e+00 7.000000000000000000e+00\n"
23
+ "8.000000000000000000e+00 8.000000000000000000e+00\n9.000000000000000000e+00 9.000000000000000000e+00\n"
24
+ "1.000000000000000000e+01 1.000000000000000000e+01\n")
25
+ assert actual == expected
@@ -36,7 +36,7 @@ if __package__ is not None:
36
36
  with as_file(ref) as fcfg:
37
37
  if not os.path.isfile(fcfg): # pragma: no cover
38
38
  from warnings import warn
39
- warn('Package metadata not found, execute "./setup.py egg_info".')
39
+ warn('Package metadata not found.')
40
40
  fcfg = os.devnull
41
41
  with open(fcfg) as fp:
42
42
  kwords = [[w.strip() for w in line.split(' = ', 1)]
@@ -1,14 +1,12 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: diffpy.utils
3
- Version: 3.2.7
3
+ Version: 3.3.1
4
4
  Summary: Shared utilities for diffpy packages.
5
- Home-page: https://github.com/diffpy/diffpy.utils/
6
- Author: Simon J.L. Billinge group
7
- Author-email: sb2896@columbia.edu
8
- Maintainer: Simon J.L. Billinge group
9
- Maintainer-email: sb2896@columbia.edu
10
- License: BSD-style license
11
- Keywords: text data parsers wx grid
5
+ Author-email: "Simon J.L. Billinge group" <simon.billinge@gmail.com>
6
+ Maintainer-email: "Simon J.L. Billinge group" <simon.billinge@gmail.com>
7
+ Project-URL: Homepage, https://github.com/diffpy/diffpy.utils/
8
+ Project-URL: Issues, https://github.com/diffpy/diffpy.utils/issues
9
+ Keywords: text data parsers,wx grid,diffraction objects
12
10
  Classifier: Development Status :: 5 - Production/Stable
13
11
  Classifier: Environment :: Console
14
12
  Classifier: Intended Audience :: Developers
@@ -19,10 +17,12 @@ Classifier: Operating System :: Microsoft :: Windows
19
17
  Classifier: Operating System :: POSIX
20
18
  Classifier: Operating System :: Unix
21
19
  Classifier: Programming Language :: Python :: 2.7
20
+ Classifier: Programming Language :: Python :: 3.9
22
21
  Classifier: Programming Language :: Python :: 3.10
23
22
  Classifier: Programming Language :: Python :: 3.11
24
23
  Classifier: Programming Language :: Python :: 3.12
25
24
  Classifier: Topic :: Scientific/Engineering :: Physics
25
+ Requires-Python: >=3.9
26
26
  Description-Content-Type: text/x-rst
27
27
  License-File: LICENSE.txt
28
28
  License-File: LICENSE_DANSE.txt
@@ -87,7 +87,7 @@ If you prefer to install from sources, after installing the dependencies, obtain
87
87
  `GitHub <https://github.com/diffpy/diffpy.utils/>`_. Once installed, ``cd`` into your ``diffpy.utils`` directory
88
88
  and run the following ::
89
89
 
90
- pip install -e .
90
+ pip install .
91
91
 
92
92
  To check the installation integrity, if the following passes all checks, you are good! ::
93
93
 
@@ -105,9 +105,12 @@ https://github.com/diffpy/diffpy.utils.
105
105
 
106
106
  Feel free to fork the project and contribute. To install diffpy.utils
107
107
  in a development mode, with its sources being directly used by Python
108
- rather than copied to a package directory, use ::
108
+ rather than copied to a package directory, use the following in the root
109
+ directory ::
110
+
111
+ pip install -e .
109
112
 
110
- python setup.py develop --user
113
+ Note that this is only supported for `setuptools` version 62.0 and above.
111
114
 
112
115
 
113
116
  CONTACTS
@@ -3,12 +3,11 @@ LICENSE.txt
3
3
  LICENSE_DANSE.txt
4
4
  MANIFEST.in
5
5
  README.rst
6
- setup.py
6
+ pyproject.toml
7
7
  src/diffpy/__init__.py
8
8
  src/diffpy.utils.egg-info/PKG-INFO
9
9
  src/diffpy.utils.egg-info/SOURCES.txt
10
10
  src/diffpy.utils.egg-info/dependency_links.txt
11
- src/diffpy.utils.egg-info/not-zip-safe
12
11
  src/diffpy.utils.egg-info/top_level.txt
13
12
  src/diffpy/utils/__init__.py
14
13
  src/diffpy/utils/version.cfg
@@ -18,9 +17,12 @@ src/diffpy/utils/parsers/custom_exceptions.py
18
17
  src/diffpy/utils/parsers/loaddata.py
19
18
  src/diffpy/utils/parsers/resample.py
20
19
  src/diffpy/utils/parsers/serialization.py
20
+ src/diffpy/utils/scattering_objects/__init__.py
21
+ src/diffpy/utils/scattering_objects/diffraction_objects.py
21
22
  src/diffpy/utils/tests/__init__.py
22
23
  src/diffpy/utils/tests/debug.py
23
24
  src/diffpy/utils/tests/run.py
25
+ src/diffpy/utils/tests/test_diffraction_objects.py
24
26
  src/diffpy/utils/tests/test_loaddata.py
25
27
  src/diffpy/utils/tests/test_resample.py
26
28
  src/diffpy/utils/tests/test_serialization.py
@@ -1,127 +0,0 @@
1
- #!/usr/bin/env python
2
-
3
- """utils - small shared utilities for other diffpy packages
4
-
5
- Packages: diffpy.utils
6
- """
7
-
8
- import os
9
- import re
10
- import sys
11
- from setuptools import setup, find_packages
12
-
13
- # Use this version when git data are not available, like in git zip archive.
14
- # Update when tagging a new release.
15
- FALLBACK_VERSION = '3.2.4'
16
-
17
- # versioncfgfile holds version data for git commit hash and date.
18
- # It must reside in the same directory as version.py.
19
- MYDIR = os.path.dirname(os.path.abspath(__file__))
20
- versioncfgfile = os.path.join(MYDIR, 'src/diffpy/utils/version.cfg')
21
- gitarchivecfgfile = os.path.join(MYDIR, '.gitarchive.cfg')
22
-
23
- # determine if we run with Python 3.
24
- PY3 = (sys.version_info[0] == 3)
25
-
26
-
27
- def gitinfo():
28
- from subprocess import Popen, PIPE
29
- kw = dict(stdout=PIPE, cwd=MYDIR, universal_newlines=True)
30
- proc = Popen(['git', 'describe', '--tags', '--match=[v,V,[:digit:]]*'], **kw)
31
- desc = proc.stdout.read()
32
- proc = Popen(['git', 'log', '-1', '--format=%H %ct %ci'], **kw)
33
- glog = proc.stdout.read()
34
- rv = {}
35
- rv['version'] = '.post'.join(desc.strip().split('-')[:2]).lstrip('v').lstrip('V')
36
- rv['commit'], rv['timestamp'], rv['date'] = glog.strip().split(None, 2)
37
- return rv
38
-
39
-
40
- def getversioncfg():
41
- if PY3:
42
- from configparser import RawConfigParser
43
- else:
44
- from ConfigParser import RawConfigParser
45
- vd0 = dict(version=FALLBACK_VERSION, commit='', date='', timestamp=0)
46
- # first fetch data from gitarchivecfgfile, ignore if it is unexpanded
47
- g = vd0.copy()
48
- cp0 = RawConfigParser(vd0)
49
- cp0.read(gitarchivecfgfile)
50
- if len(cp0.get('DEFAULT', 'commit')) > 20:
51
- g = cp0.defaults()
52
- mx = re.search(r'\btag: [vV]?(\d[^,]*)', g.pop('refnames'))
53
- if mx:
54
- g['version'] = mx.group(1)
55
- # then try to obtain version data from git.
56
- gitdir = os.path.join(MYDIR, '.git')
57
- if os.path.exists(gitdir) or 'GIT_DIR' in os.environ:
58
- try:
59
- g = gitinfo()
60
- except OSError:
61
- pass
62
- if len(g['version']) == 0:
63
- g['version'] = FALLBACK_VERSION
64
-
65
- # finally, check and update the active version file
66
- cp = RawConfigParser()
67
- cp.read(versioncfgfile)
68
- d = cp.defaults()
69
- rewrite = not d or (g['commit'] and (
70
- g['version'] != d.get('version') or g['commit'] != d.get('commit')))
71
- if rewrite:
72
- cp.set('DEFAULT', 'version', g['version'])
73
- cp.set('DEFAULT', 'commit', g['commit'])
74
- cp.set('DEFAULT', 'date', g['date'])
75
- cp.set('DEFAULT', 'timestamp', g['timestamp'])
76
- with open(versioncfgfile, 'w') as fp:
77
- cp.write(fp)
78
- return cp
79
-
80
- versiondata = getversioncfg()
81
-
82
- with open(os.path.join(MYDIR, 'README.rst')) as fp:
83
- long_description = fp.read()
84
-
85
- # define distribution
86
- setup_args = dict(
87
- name = "diffpy.utils",
88
- version = versiondata.get('DEFAULT', 'version'),
89
- packages = find_packages(os.path.join(MYDIR, 'src')),
90
- package_dir = {'' : 'src'},
91
- test_suite = 'diffpy.utils.tests',
92
- include_package_data = True,
93
- zip_safe = False,
94
- author = 'Simon J.L. Billinge group',
95
- author_email = 'sb2896@columbia.edu',
96
- maintainer = 'Simon J.L. Billinge group',
97
- maintainer_email = 'sb2896@columbia.edu',
98
- description = "Shared utilities for diffpy packages.",
99
- long_description = long_description,
100
- long_description_content_type = 'text/x-rst',
101
- license = 'BSD-style license',
102
- url = "https://github.com/diffpy/diffpy.utils/",
103
- keywords = "text data parsers wx grid",
104
- classifiers = [
105
- # List of possible values at
106
- # http://pypi.python.org/pypi?:action=list_classifiers
107
- 'Development Status :: 5 - Production/Stable',
108
- 'Environment :: Console',
109
- 'Intended Audience :: Developers',
110
- 'Intended Audience :: Science/Research',
111
- 'License :: OSI Approved :: BSD License',
112
- 'Operating System :: MacOS :: MacOS X',
113
- 'Operating System :: Microsoft :: Windows',
114
- 'Operating System :: POSIX',
115
- 'Operating System :: Unix',
116
- 'Programming Language :: Python :: 2.7',
117
- 'Programming Language :: Python :: 3.10',
118
- 'Programming Language :: Python :: 3.11',
119
- 'Programming Language :: Python :: 3.12',
120
- 'Topic :: Scientific/Engineering :: Physics',
121
- ],
122
- )
123
-
124
- if __name__ == '__main__':
125
- setup(**setup_args)
126
-
127
- # End of file
File without changes
File without changes
File without changes
File without changes