Skip to content

Commit 80d0f4b

Browse files
committed
setCalculationPoints
1 parent eef5741 commit 80d0f4b

6 files changed

Lines changed: 76 additions & 12 deletions

File tree

news/profile-dep.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* Added ``load_parsed_data`` in replace of ``loadParsedData`` in ``Profile`` and ``SimpleRecipe``.
44
* Added ``set_observed_profile`` in replace of ``setObservedProfile`` in ``Profile`` and ``SimpleRecipe``.
5+
* Added ``set_calculation_range`` in replace of ``setCalculationRange`` in ``Profile`` and ``SimpleRecipe``.
56

67
**Changed:**
78

@@ -11,6 +12,7 @@
1112

1213
* Deprecated ``loadParsedData`` in ``Profile`` and ``SimpleRecipe`` for removal in 4.0.0.
1314
* Deprecated ``setObservedProfile`` in ``Profile`` and ``SimpleRecipe`` for removal in 4.0.0.
15+
* Deprecated ``setCalculationRange`` in ``Profile`` and ``SimpleRecipe`` for removal in 4.0.0.
1416

1517
**Removed:**
1618

src/diffpy/srfit/fitbase/profile.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@
5757
removal_version,
5858
)
5959

60+
setCalculationPoints_dep_msg = build_deprecation_message(
61+
base,
62+
"setCalculationPoints",
63+
"set_calculation_points",
64+
removal_version,
65+
)
66+
6067

6168
class Profile(Observable, Validatable):
6269
"""Observed and calculated profile container.
@@ -202,9 +209,9 @@ def set_observed_profile(self, xobs, yobs, dyobs=None):
202209

203210
# Set the default calculation points
204211
if self.x is None:
205-
self.setCalculationPoints(self._xobs)
212+
self.set_calculation_points(self._xobs)
206213
else:
207-
self.setCalculationPoints(self.x)
214+
self.set_calculation_points(self.x)
208215

209216
return
210217

@@ -321,7 +328,7 @@ def _isobs(a):
321328
self.dy = self.dyobs[indices]
322329
else:
323330
x1 = numpy.arange(lo, hi + epshi, step)
324-
self.setCalculationPoints(x1)
331+
self.set_calculation_points(x1)
325332
return
326333

327334
@deprecated(setCalculationRange_dep_msg)
@@ -336,7 +343,7 @@ def setCalculationRange(self, xmin=None, xmax=None, dx=None):
336343
self.set_calculation_range(xmin, xmax, dx)
337344
return
338345

339-
def setCalculationPoints(self, x):
346+
def set_calculation_points(self, x):
340347
"""Set the calculation points.
341348
342349
Parameters
@@ -366,6 +373,22 @@ def setCalculationPoints(self, x):
366373

367374
return
368375

376+
@deprecated(setCalculationPoints_dep_msg)
377+
def setCalculationPoints(self, x):
378+
"""Set the calculation points.
379+
380+
Parameters
381+
----------
382+
x
383+
A non-empty numpy array containing the calculation points. If
384+
xobs exists, the bounds of x will be limited to its bounds.
385+
386+
This will create y and dy on the specified grid if xobs, yobs and
387+
dyobs exist.
388+
"""
389+
self.set_calculation_points(x)
390+
return
391+
369392
def loadtxt(self, *args, **kw):
370393
"""Use numpy.loadtxt to load data.
371394

src/diffpy/srfit/fitbase/simplerecipe.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@
4444
removal_version,
4545
)
4646

47+
setCalculationPoints_dep_msg = build_deprecation_message(
48+
base,
49+
"setCalculationPoints",
50+
"set_calculation_points",
51+
removal_version,
52+
)
53+
4754

4855
class SimpleRecipe(FitRecipe):
4956
"""SimpleRecipe class.
@@ -227,7 +234,7 @@ def setCalculationRange(self, xmin=None, xmax=None, dx=None):
227234
"""
228235
return self.set_calculation_range(xmin, xmax, dx)
229236

230-
def setCalculationPoints(self, x):
237+
def set_calculation_points(self, x):
231238
"""Set the calculation points.
232239
233240
Parameters
@@ -239,7 +246,18 @@ def setCalculationPoints(self, x):
239246
This will create y and dy on the specified grid if xobs, yobs and
240247
dyobs exist.
241248
"""
242-
return self.profile.setCalculationPoints(x)
249+
return self.profile.set_calculation_points(x)
250+
251+
@deprecated(setCalculationPoints_dep_msg)
252+
def setCalculationPoints(self, x):
253+
"""This function has been deprecated and will be removed in version
254+
4.0.0.
255+
256+
Please use
257+
diffpy.srfit.fitbase.simplerecipe.SimpleRecipe.set_calculation_points
258+
instead.
259+
"""
260+
return self.set_calculation_points(x)
243261

244262
def loadtxt(self, *args, **kw):
245263
"""Use numpy.loadtxt to load data.

src/diffpy/srfit/pdf/pdfcontribution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def setCalculationRange(self, xmin=None, xmax=None, dx=None):
164164
ValueError
165165
When xmin > xmax or if dx <= 0. Also if dx > xmax - xmin.
166166
"""
167-
return self.profile.setCalculationRange(xmin, xmax, dx)
167+
return self.profile.set_calculation_range(xmin, xmax, dx)
168168

169169
def savetxt(self, fname, **kwargs):
170170
"""Call numpy.savetxt with x, ycalc, y, dy.

tests/test_profile.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ def testSetCalculationRange(self):
206206
dy = array(x)
207207
prof = self.profile
208208
prof.set_observed_profile(x, y, dy)
209-
prof.setCalculationRange()
210209
# Test normal execution w/o arguments
211210
self.assertTrue(array_equal(x, prof.x))
212211
self.assertTrue(array_equal(y, prof.y))
@@ -217,8 +216,30 @@ def testSetCalculationRange(self):
217216
self.assertTrue(array_equal(dy, prof.dy))
218217
return
219218

219+
def test_set_calculation_points(self):
220+
"""Test the set_calculation_points method."""
221+
prof = self.profile
222+
223+
x = arange(2, 10.5, 0.5)
224+
y = array(x)
225+
dy = array(x)
226+
227+
# Test without data
228+
xcalc = arange(3, 12.2, 0.2)
229+
prof.set_calculation_points(xcalc)
230+
self.assertTrue(array_equal(xcalc, prof.x))
231+
232+
# Add the data. This should change the bounds of the calculation array.
233+
prof.set_observed_profile(x, y, dy)
234+
self.assertTrue(array_equal(arange(3, 10.1, 0.2), prof.x))
235+
236+
return
237+
220238
def testSetCalculationPoints(self):
221-
"""Test the setCalculationPoints method."""
239+
"""Test the deprecated setCalculationPoints method.
240+
241+
Remove this test when setCalculationPoints is removed in 4.0.0.
242+
"""
222243
prof = self.profile
223244

224245
x = arange(2, 10.5, 0.5)

tests/test_profilegenerator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def setUp(self):
2929
self.gen = ProfileGenerator("test")
3030
self.profile = Profile()
3131
x = arange(0, 10, 0.1)
32-
self.profile.setCalculationPoints(x)
32+
self.profile.set_calculation_points(x)
3333
self.gen.set_profile(self.profile)
3434
return
3535

@@ -55,7 +55,7 @@ def testUpdate(self):
5555
# Make sure attributes get updated with a change in the calculation
5656
# points.
5757
x = arange(0, 9, 0.1)
58-
prof.setCalculationPoints(x)
58+
prof.set_calculation_points(x)
5959
self.assertTrue(gen._value is None)
6060
val = gen.value
6161
self.assertTrue(array_equal(x, val))
@@ -68,7 +68,7 @@ def testUpdate(self):
6868
# Make sure attributes get updated with a new profile.
6969
x = arange(0, 8, 0.1)
7070
prof = Profile()
71-
prof.setCalculationPoints(x)
71+
prof.set_calculation_points(x)
7272
gen.set_profile(prof)
7373
self.assertTrue(gen._value is None)
7474
self.assertTrue(array_equal(x, gen.value))

0 commit comments

Comments
 (0)