Skip to content

Commit bdd82f1

Browse files
committed
deprecate Profile.setObservedProfile and SimpleRecipe.setObservedProfile
1 parent a8fb488 commit bdd82f1

8 files changed

Lines changed: 97 additions & 24 deletions

File tree

docs/examples/debyemodel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def makeRecipe():
9393
# data into the profile.
9494
xydy = numpy.array(data.split(), dtype=float).reshape(-1, 3)
9595
x, y, dy = xydy.T
96-
profile.setObservedProfile(x, y, dy)
96+
profile.set_observed_profile(x, y, dy)
9797

9898
# The FitContribution
9999
# The FitContribution associates the profile with the Debye function.

docs/source/extending.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ customized Profile is the ``SASProfile`` class in the
185185

186186
The ``__init__`` method sets the ``xobs``, ``yobs`` and ``dyobs`` attributes of
187187
the ``SASProfile`` to the associated arrays within the ``_datainfo`` attribute.
188-
The ``setObservedProfile`` method is overloaded to modify the ``_datainfo``
188+
The ``set_observed_profile`` method is overloaded to modify the ``_datainfo``
189189
arrays when their corresponding attributes are modified. This keeps the arrays
190190
in sync.
191191

src/diffpy/srfit/fitbase/profile.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@
4343
removal_version,
4444
)
4545

46+
setObservedProfile_dep_msg = build_deprecation_message(
47+
base,
48+
"setObservedProfile",
49+
"set_observed_profile",
50+
removal_version,
51+
)
52+
4653

4754
class Profile(Observable, Validatable):
4855
"""Observed and calculated profile container.
@@ -142,7 +149,7 @@ def load_parsed_data(self, parser):
142149
"""
143150
x, y, junk, dy = parser.getData()
144151
self.meta = dict(parser.getMetaData())
145-
self.setObservedProfile(x, y, dy)
152+
self.set_observed_profile(x, y, dy)
146153
return
147154

148155
@deprecated(loadParsedData_dep_msg)
@@ -156,7 +163,7 @@ def loadParsedData(self, parser):
156163
self.load_parsed_data(parser)
157164
return
158165

159-
def setObservedProfile(self, xobs, yobs, dyobs=None):
166+
def set_observed_profile(self, xobs, yobs, dyobs=None):
160167
"""Set the observed profile.
161168
162169
Parameters
@@ -194,6 +201,18 @@ def setObservedProfile(self, xobs, yobs, dyobs=None):
194201

195202
return
196203

204+
@deprecated(setObservedProfile_dep_msg)
205+
def setObservedProfile(self, xobs, yobs, dyobs=None):
206+
"""This function has been deprecated and will be removed in version
207+
4.0.0.
208+
209+
Please use
210+
diffpy.srfit.fitbase.profile.Profile.set_observed_profile
211+
instead.
212+
"""
213+
self.set_observed_profile(xobs, yobs, dyobs)
214+
return
215+
197216
def setCalculationRange(self, xmin=None, xmax=None, dx=None):
198217
"""Set epsilon-inclusive calculation range.
199218
@@ -335,7 +354,7 @@ def loadtxt(self, *args, **kw):
335354
enforced. The first two arrays returned by numpy.loadtxt are
336355
assumed to be x and y. If there is a third array, it is assumed
337356
to by dy. Any other arrays are ignored. These are passed to
338-
setObservedProfile.
357+
set_observed_profile.
339358
340359
Raises ValueError if the call to numpy.loadtxt returns fewer
341360
than 2 arrays.
@@ -366,7 +385,7 @@ def loadtxt(self, *args, **kw):
366385
if len(cols) > 2:
367386
dy = cols[2]
368387

369-
self.setObservedProfile(x, y, dy)
388+
self.set_observed_profile(x, y, dy)
370389
return x, y, dy
371390

372391
def savetxt(self, fname, **kwargs):

src/diffpy/srfit/fitbase/simplerecipe.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030
removal_version,
3131
)
3232

33+
setObservedProfile_dep_msg = build_deprecation_message(
34+
base,
35+
"setObservedProfile",
36+
"set_observed_profile",
37+
removal_version,
38+
)
39+
3340

3441
class SimpleRecipe(FitRecipe):
3542
"""SimpleRecipe class.
@@ -138,7 +145,7 @@ def loadParsedData(self, parser):
138145
"""
139146
return self.load_parsed_data(parser)
140147

141-
def setObservedProfile(self, xobs, yobs, dyobs=None):
148+
def set_observed_profile(self, xobs, yobs, dyobs=None):
142149
"""Set the observed profile.
143150
144151
Parameters
@@ -158,6 +165,17 @@ def setObservedProfile(self, xobs, yobs, dyobs=None):
158165
"""
159166
return self.profile.setObservedProfile(xobs, yobs, dyobs)
160167

168+
@deprecated(setObservedProfile_dep_msg)
169+
def setObservedProfile(self, xobs, yobs, dyobs=None):
170+
"""This function has been deprecated and will be removed in version
171+
4.0.0.
172+
173+
Please use
174+
diffpy.srfit.fitbase.simplerecipe.SimpleRecipe.set_observed_profile
175+
instead.
176+
"""
177+
return self.set_observed_profile(xobs, yobs, dyobs)
178+
161179
def setCalculationRange(self, xmin=None, xmax=None, dx=None):
162180
"""Set epsilon-inclusive calculation range.
163181
@@ -213,7 +231,7 @@ def loadtxt(self, *args, **kw):
213231
enforced. The first two arrays returned by numpy.loadtxt are
214232
assumed to be x and y. If there is a third array, it is assumed
215233
to by dy. Any other arrays are ignored. These are passed to
216-
setObservedProfile.
234+
set_observed_profile.
217235
218236
Raises ValueError if the call to numpy.loadtxt returns fewer
219237
than 2 arrays.

tests/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def build_recipe_one_contribution():
152152
profile = Profile()
153153
x = linspace(0, pi, 10)
154154
y = sin(x)
155-
profile.setObservedProfile(x, y)
155+
profile.set_observed_profile(x, y)
156156
contribution = FitContribution("c1")
157157
contribution.set_profile(profile)
158158
contribution.set_equation("A*sin(k*x + c)")
@@ -170,14 +170,14 @@ def build_recipe_two_contributions():
170170
profile1 = Profile()
171171
x = linspace(0, pi, 10)
172172
y1 = sin(x)
173-
profile1.setObservedProfile(x, y1)
173+
profile1.set_observed_profile(x, y1)
174174
contribution1 = FitContribution("c1")
175175
contribution1.set_profile(profile1)
176176
contribution1.set_equation("A*sin(k*x + c)")
177177

178178
profile2 = Profile()
179179
y2 = 0.5 * sin(2 * x)
180-
profile2.setObservedProfile(x, y2)
180+
profile2.set_observed_profile(x, y2)
181181
contribution2 = FitContribution("c2")
182182
contribution2.set_profile(profile2)
183183
contribution2.set_equation("B*sin(m*x + d)")

tests/test_contribution.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def testInteraction(self):
101101
# create some data
102102
xobs = arange(0, 10, 0.5)
103103
yobs = xobs
104-
profile.setObservedProfile(xobs, yobs)
104+
profile.set_observed_profile(xobs, yobs)
105105

106106
# Make sure this is where it's supposed to be
107107
self.assertTrue(gen.profile.xobs is xobs)
@@ -123,11 +123,11 @@ def testReplacements(self):
123123
xobs = arange(0, 10, 0.5)
124124
yobs = xobs
125125
profile = self.profile
126-
profile.setObservedProfile(xobs, yobs)
126+
profile.set_observed_profile(xobs, yobs)
127127
xobs2 = arange(0, 10, 0.8)
128128
yobs2 = 0.5 * xobs2
129129
profile2 = Profile()
130-
profile2.setObservedProfile(xobs2, yobs2)
130+
profile2.set_observed_profile(xobs2, yobs2)
131131
gen = self.gen
132132

133133
# Validate equations
@@ -217,7 +217,7 @@ def testResidual(noObserversInGlobalBuilders):
217217
# Let's create some data)
218218
xobs = arange(0, 10, 0.5)
219219
yobs = xobs
220-
profile.setObservedProfile(xobs, yobs)
220+
profile.set_observed_profile(xobs, yobs)
221221

222222
# Check our fitting equation.
223223
assert np.array_equal(fc._eq(), gen(xobs))
@@ -249,7 +249,7 @@ def testResidual(noObserversInGlobalBuilders):
249249
assert fc._reseq._value is None
250250
xobs = arange(0, 10, 0.5)
251251
yobs = 9 * sin(xobs)
252-
profile.setObservedProfile(xobs, yobs)
252+
profile.set_observed_profile(xobs, yobs)
253253
assert fc._eq._value is None
254254
assert fc._reseq._value is None
255255

tests/test_fitrecipe.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def setUp(self):
4141
self.profile = Profile()
4242
x = linspace(0, pi, 10)
4343
y = sin(x)
44-
self.profile.setObservedProfile(x, y)
44+
self.profile.set_observed_profile(x, y)
4545

4646
# Set up the FitContribution
4747
self.fitcontribution = FitContribution("cont")
@@ -258,7 +258,7 @@ def testPrintFitHook(capturestdout):
258258
profile = Profile()
259259
x = linspace(0, pi, 10)
260260
y = sin(x)
261-
profile.setObservedProfile(x, y)
261+
profile.set_observed_profile(x, y)
262262

263263
# Set up the FitContribution
264264
fitcontribution = FitContribution("cont")
@@ -306,7 +306,7 @@ def test_add_contribution(capturestdout):
306306
profile = Profile()
307307
x = linspace(0, pi, 10)
308308
y = sin(x)
309-
profile.setObservedProfile(x, y)
309+
profile.set_observed_profile(x, y)
310310

311311
# Set up the FitContribution
312312
fitcontribution = FitContribution("cont")

tests/test_profile.py

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,52 @@ def testInit(self):
4343
self.assertEqual(profile.meta, {})
4444
return
4545

46+
def test_set_observed_profile(self):
47+
"""Test the set_observed_profile method."""
48+
# Make a profile with defined dy
49+
50+
x = arange(0, 10, 0.1)
51+
y = x
52+
dy = x
53+
54+
prof = self.profile
55+
prof.set_observed_profile(x, y, dy)
56+
57+
self.assertTrue(array_equal(x, prof.xobs))
58+
self.assertTrue(array_equal(y, prof.yobs))
59+
self.assertTrue(array_equal(dy, prof.dyobs))
60+
61+
# Make a profile with undefined dy
62+
x = arange(0, 10, 0.1)
63+
y = x
64+
dy = None
65+
66+
self.profile.set_observed_profile(x, y, dy)
67+
68+
self.assertTrue(array_equal(x, prof.xobs))
69+
self.assertTrue(array_equal(y, prof.yobs))
70+
self.assertTrue(array_equal(ones_like(prof.xobs), prof.dyobs))
71+
72+
# Get the ranged profile to make sure its the same
73+
self.assertTrue(array_equal(x, prof.x))
74+
self.assertTrue(array_equal(y, prof.y))
75+
self.assertTrue(array_equal(ones_like(prof.xobs), prof.dy))
76+
77+
return
78+
4679
def testSetObservedProfile(self):
47-
"""Test the setObservedProfile method."""
80+
"""Test the deprecated setObservedProfile method.
81+
82+
Remove this test when setObservedProfile is removed in 4.0.0.
83+
"""
4884
# Make a profile with defined dy
4985

5086
x = arange(0, 10, 0.1)
5187
y = x
5288
dy = x
5389

5490
prof = self.profile
55-
prof.setObservedProfile(x, y, dy)
91+
prof.set_observed_profile(x, y, dy)
5692

5793
self.assertTrue(array_equal(x, prof.xobs))
5894
self.assertTrue(array_equal(y, prof.yobs))
@@ -88,7 +124,7 @@ def testSetCalculationRange(self):
88124
self.assertRaises(AttributeError, prof.setCalculationRange, 0, 5)
89125
self.assertRaises(AttributeError, prof.setCalculationRange, 0, 5, 0.2)
90126
# assign data
91-
prof.setObservedProfile(x, y, dy)
127+
prof.set_observed_profile(x, y, dy)
92128
# Test normal execution w/o arguments
93129
self.assertTrue(array_equal(x, prof.x))
94130
self.assertTrue(array_equal(y, prof.y))
@@ -172,7 +208,7 @@ def testSetCalculationPoints(self):
172208
self.assertTrue(array_equal(xcalc, prof.x))
173209

174210
# Add the data. This should change the bounds of the calculation array.
175-
prof.setObservedProfile(x, y, dy)
211+
prof.set_observed_profile(x, y, dy)
176212
self.assertTrue(array_equal(arange(3, 10.1, 0.2), prof.x))
177213

178214
return
@@ -183,7 +219,7 @@ def test_savetxt(self):
183219
self.assertRaises(SrFitError, prof.savetxt, "foo")
184220
xobs = arange(-2, 3.01, 0.25)
185221
yobs = xobs**2
186-
prof.setObservedProfile(xobs, yobs)
222+
prof.set_observed_profile(xobs, yobs)
187223
prof.ycalc = yobs.copy()
188224
fp = io.BytesIO()
189225
prof.savetxt(fp)

0 commit comments

Comments
 (0)