Skip to content

Commit 773e6f4

Browse files
authored
Merge pull request #74 from Sparks29032/rework_documentation
Change objective and reference naming
2 parents 71e52e5 + fb534ef commit 773e6f4

34 files changed

+453
-427
lines changed

TUTORIAL.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ Basic PDFmorph Workflow
7575
will get morphed, while the second PDF file argument you
7676
provide (here, ``darkSub_rh20_C_44.gr``) is the PDF which
7777
acts as the model and does not get morphed. Hereinafter,
78-
we will refer to the first PDF argument as the "objective"
79-
and the second as the "reference", as the PDFmorph display
78+
we will refer to the first PDF argument as the "morph"
79+
and the second as the "target", as the PDFmorph display
8080
does.
8181

8282
6. Now, we will start the morphing process, which requires us to

diffpy/pdfmorph/morphs/morph.py

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424

2525

2626
class Morph(object):
27-
'''Base class for implementing a morph on an objective given a reference.
27+
'''Base class for implementing a morph given a target.
2828
2929
Adapted from diffpy.pdfgetx to include two sets of arrays that get passed
30-
through. In most cases, the objective is modified by a morph, but it is
31-
acceptable for morph the reference as well, such as to change the range of
30+
through. In most cases, only the morph is modified, but it is
31+
acceptable for morph the target as well, such as to change the range of
3232
the array.
3333
3434
Note that attributes are taken from config when not found locally. The
@@ -47,22 +47,22 @@ class Morph(object):
4747
Instance attributes:
4848
4949
config -- dictionary that contains all configuration variables
50-
xobjin -- last objective input x data
51-
yobjin -- last objective input y data
52-
xobjout -- last objective result x data
53-
yobjout -- last objective result y data
54-
xrefin -- last reference input x data
55-
yrefin -- last reference input y data
56-
xrefout -- last reference result x data
57-
yrefout -- last reference result y data
50+
x_morph_in -- last morph input x data
51+
y_morph_in -- last morph input y data
52+
x_morph_out -- last morph result x data
53+
y_morph_out -- last morph result y data
54+
x_target_in -- last target input x data
55+
y_target_in -- last target input y data
56+
x_target_out -- last target result x data
57+
y_target_out -- last target result y data
5858
5959
Properties:
6060
61-
xyobjin -- tuple of (xobjin, yobjin)
62-
xyobjout -- tuple of (xobjout, yobjout)
63-
xyrefin -- tuple of (xrefin, yrefin)
64-
xyrefout -- tuple of (xrefout, yrefout)
65-
xyallout -- tuple of (xobjout, yobjout, xrefout, yrefout)
61+
xy_morph_in -- tuple of (x_morph_in, y_morph_in)
62+
xy_morph_out -- tuple of (x_morph_out, y_morph_out)
63+
xy_target_in -- tuple of (x_target_in, y_target_in)
64+
xy_target_out -- tuple of (x_target_out, y_target_out)
65+
xyallout -- tuple of (x_morph_out, y_morph_out, x_target_out, y_target_out)
6666
'''
6767

6868
# Class variables
@@ -76,24 +76,24 @@ class Morph(object):
7676

7777
# Properties
7878

79-
xyobjin = property(
80-
lambda self: (self.xobjin, self.yobjin),
81-
doc='Return a tuple of objective input arrays',
79+
xy_morph_in = property(
80+
lambda self: (self.x_morph_in, self.y_morph_in),
81+
doc='Return a tuple of morph input arrays',
8282
)
83-
xyobjout = property(
84-
lambda self: (self.xobjout, self.yobjout),
85-
doc='Return a tuple of objective output arrays',
83+
xy_morph_out = property(
84+
lambda self: (self.x_morph_out, self.y_morph_out),
85+
doc='Return a tuple of morph output arrays',
8686
)
87-
xyrefin = property(
88-
lambda self: (self.xrefin, self.yrefin),
89-
doc='Return a tuple of reference input arrays',
87+
xy_target_in = property(
88+
lambda self: (self.x_target_in, self.y_target_in),
89+
doc='Return a tuple of target input arrays',
9090
)
91-
xyrefout = property(
92-
lambda self: (self.xrefout, self.yrefout),
93-
doc='Return a tuple of reference output arrays',
91+
xy_target_out = property(
92+
lambda self: (self.x_target_out, self.y_target_out),
93+
doc='Return a tuple of target output arrays',
9494
)
9595
xyallout = property(
96-
lambda self: (self.xobjout, self.yobjout, self.xrefout, self.yrefout),
96+
lambda self: (self.x_morph_out, self.y_morph_out, self.x_target_out, self.y_target_out),
9797
doc='Return a tuple of all output arrays',
9898
)
9999

@@ -105,43 +105,43 @@ def __init__(self, config=None):
105105
# declare empty attributes
106106
if config is None:
107107
config = {}
108-
self.xobjin = None
109-
self.yobjin = None
110-
self.xobjout = None
111-
self.yobjout = None
112-
self.xrefin = None
113-
self.yrefin = None
114-
self.xrefout = None
115-
self.yrefout = None
108+
self.x_morph_in = None
109+
self.y_morph_in = None
110+
self.x_morph_out = None
111+
self.y_morph_out = None
112+
self.x_target_in = None
113+
self.y_target_in = None
114+
self.x_target_out = None
115+
self.y_target_out = None
116116
# process arguments
117117
self.applyConfig(config)
118118
return
119119

120-
def morph(self, xobj, yobj, xref, yref):
121-
'''Morph arrays objective or reference.
120+
def morph(self, x_morph, y_morph, x_target, y_target):
121+
'''Morph arrays morphed or target.
122122
123-
xobj, yobj -- Objective arrays.
124-
xref, yref -- Reference arrays.
123+
x_morph, y_morph -- Morphed arrays.
124+
x_target, y_target -- Target arrays.
125125
126126
Identity operation. This method should be overloaded in a derived
127127
class.
128128
129-
Return a tuple of numpy arrays (xobjout, yobjout, xrefout, yrefout)
129+
Return a tuple of numpy arrays (x_morph_out, y_morph_out, x_target_out, y_target_out)
130130
'''
131-
self.xobjin = xobj
132-
self.yobjin = yobj
133-
self.xrefin = xref
134-
self.yrefin = yref
135-
self.xobjout = xobj.copy()
136-
self.yobjout = yobj.copy()
137-
self.xrefout = xref.copy()
138-
self.yrefout = yref.copy()
131+
self.x_morph_in = x_morph
132+
self.y_morph_in = y_morph
133+
self.x_target_in = x_target
134+
self.y_target_in = y_target
135+
self.x_morph_out = x_morph.copy()
136+
self.y_morph_out = y_morph.copy()
137+
self.x_target_out = x_target.copy()
138+
self.y_target_out = y_target.copy()
139139
self.checkConfig()
140140
return self.xyallout
141141

142-
def __call__(self, xobj, yobj, xref, yref):
142+
def __call__(self, x_morph, y_morph, x_target, y_target):
143143
'''Alias for morph.'''
144-
return self.morph(xobj, yobj, xref, yref)
144+
return self.morph(x_morph, y_morph, x_target, y_target)
145145

146146
def applyConfig(self, config):
147147
'''Process any configuration data from a dictionary.
@@ -163,14 +163,14 @@ def checkConfig(self):
163163
def plotInputs(self, xylabels=True):
164164
'''Plot input arrays using matplotlib.pyplot
165165
166-
xylabels -- flag for updating x and y axis labels
166+
xylabels -- flag for updating x and y axes labels
167167
168168
Return a list of matplotlib line objects.
169169
'''
170170
from matplotlib.pyplot import plot, xlabel, ylabel
171171

172-
rv = plot(self.xrefin, self.yrefin, label="reference")
173-
rv = plot(self.xobjin, self.yobjin, label="objective")
172+
rv = plot(self.x_target_in, self.y_target_in, label="target")
173+
rv = plot(self.x_morph_in, self.y_morph_in, label="morph")
174174
if xylabels:
175175
xlabel(self.xinlabel)
176176
ylabel(self.yinlabel)
@@ -179,7 +179,7 @@ def plotInputs(self, xylabels=True):
179179
def plotOutputs(self, xylabels=True, **plotargs):
180180
'''Plot output arrays using matplotlib.pyplot
181181
182-
xylabels -- flag for updating x and y axis labels
182+
xylabels -- flag for updating x and y axes labels
183183
plotargs -- arguments passed to the pylab plot function. Note that
184184
"label" will be ignored.
185185
@@ -189,8 +189,8 @@ def plotOutputs(self, xylabels=True, **plotargs):
189189

190190
pargs = dict(plotargs)
191191
pargs.pop("label", None)
192-
rv = plot(self.xrefout, self.yrefout, label="reference", **pargs)
193-
rv = plot(self.xobjout, self.yobjout, label="objective", **pargs)
192+
rv = plot(self.x_target_out, self.y_target_out, label="target", **pargs)
193+
rv = plot(self.x_morph_out, self.y_morph_out, label="morph", **pargs)
194194
if xylabels:
195195
xlabel(self.xoutlabel)
196196
ylabel(self.youtlabel)

diffpy/pdfmorph/morphs/morphchain.py

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -33,40 +33,39 @@ class MorphChain(list):
3333
Properties:
3434
3535
These return tuples of None if there are no morphs.
36-
xobjin -- last objective input x data
37-
yobjin -- last objective input y data
38-
xobjout -- last objective result x data
39-
yobjout -- last objective result y data
40-
xrefin -- last reference input x data
41-
yrefin -- last reference input y data
42-
xrefout -- last reference result x data
43-
yrefout -- last reference result y data
44-
xyobjin -- tuple of (xobjin, yobjin) from first morph
45-
xyobjout -- tuple of (xobjout, yobjout) from last morph
46-
xyrefin -- tuple of (xrefin, yrefin) from first morph
47-
xyrefout -- tuple of (xrefout, yrefout) from last morph
48-
xyallout -- tuple of (xobjout, yobjout, xrefout, yrefout) from last
49-
morph
36+
x_morph_in -- last morph input x data
37+
y_morph_in -- last morph input y data
38+
x_morph_out -- last morph result x data
39+
y_morph_out -- last morph result y data
40+
x_target_in -- last target input x data
41+
y_target_in -- last target input y data
42+
x_target_out -- last target result x data
43+
y_target_out -- last target result y data
44+
xy_morph_in -- tuple of (x_morph_in, y_morph_in) from first morph
45+
xy_morph_out -- tuple of (x_morph_out, y_morph_out) from last morph
46+
xy_target_in -- tuple of (x_target_in, y_target_in) from first morph
47+
xy_target_out -- tuple of (x_target_out, y_target_out) from last morph
48+
xyallout -- tuple of (x_morph_out, y_morph_out, x_target_out, y_target_out) from last morph
5049
5150
parnames -- Names of parameters collected from morphs (Read only).
5251
5352
'''
5453

55-
xobjin = property(lambda self: None if len(self) == 0 else self[0].xobjin)
56-
yobjin = property(lambda self: None if len(self) == 0 else self[0].yobjin)
57-
xrefin = property(lambda self: None if len(self) == 0 else self[0].xrefin)
58-
yrefin = property(lambda self: None if len(self) == 0 else self[0].yrefin)
59-
xobjout = property(lambda self: None if len(self) == 0 else self[-1].xobjout)
60-
yobjout = property(lambda self: None if len(self) == 0 else self[-1].yobjout)
61-
xrefout = property(lambda self: None if len(self) == 0 else self[-1].xrefout)
62-
yrefout = property(lambda self: None if len(self) == 0 else self[-1].yrefout)
63-
xyobjin = property(lambda self: (None, None) if len(self) == 0 else self[0].xyobjin)
64-
xyobjout = property(
65-
lambda self: (None, None) if len(self) == 0 else self[-1].xyobjout
54+
x_morph_in = property(lambda self: None if len(self) == 0 else self[0].x_morph_in)
55+
y_morph_in = property(lambda self: None if len(self) == 0 else self[0].y_morph_in)
56+
x_target_in = property(lambda self: None if len(self) == 0 else self[0].x_target_in)
57+
y_target_in = property(lambda self: None if len(self) == 0 else self[0].y_target_in)
58+
x_morph_out = property(lambda self: None if len(self) == 0 else self[-1].x_morph_out)
59+
y_morph_out = property(lambda self: None if len(self) == 0 else self[-1].y_morph_out)
60+
x_target_out = property(lambda self: None if len(self) == 0 else self[-1].x_target_out)
61+
y_target_out = property(lambda self: None if len(self) == 0 else self[-1].y_target_out)
62+
xy_morph_in = property(lambda self: (None, None) if len(self) == 0 else self[0].xy_morph_in)
63+
xy_morph_out = property(
64+
lambda self: (None, None) if len(self) == 0 else self[-1].xy_morph_out
6665
)
67-
xyrefin = property(lambda self: (None, None) if len(self) == 0 else self[0].xyrefin)
68-
xyrefout = property(
69-
lambda self: (None, None) if len(self) == 0 else self[-1].xyrefout
66+
xy_target_in = property(lambda self: (None, None) if len(self) == 0 else self[0].xy_target_in)
67+
xy_target_out = property(
68+
lambda self: (None, None) if len(self) == 0 else self[-1].xy_target_out
7069
)
7170
xyallout = property(
7271
lambda self: (None, None, None, None) if len(self) == 0 else self[-1].xyallout
@@ -85,26 +84,26 @@ def __init__(self, config, *args):
8584
self.extend(args)
8685
return
8786

88-
def morph(self, xobj, yobj, xref, yref):
87+
def morph(self, x_morph, y_morph, x_target, y_target):
8988
'''Apply the chain of morphs to the input data.
9089
9190
Note that config may be altered by the morphs.
9291
93-
xobj, yobj -- Objective arrays.
94-
xref, yref -- Reference arrays.
92+
x_morph, y_morph -- Morphed arrays.
93+
x_target, y_target -- Target arrays.
9594
96-
Return a tuple of numpy arrays (xobjout, yobjout, xrefout, yrefout)
95+
Return a tuple of numpy arrays (x_morph_out, y_morph_out, x_target_out, y_target_out)
9796
9897
'''
99-
xyall = (xobj, yobj, xref, yref)
98+
xyall = (x_morph, y_morph, x_target, y_target)
10099
for morph in self:
101100
morph.applyConfig(self.config)
102101
xyall = morph(*xyall)
103102
return xyall
104103

105-
def __call__(self, xobj, yobj, xref, yref):
104+
def __call__(self, x_morph, y_morph, x_target, y_target):
106105
'''Alias for morph.'''
107-
return self.morph(xobj, yobj, xref, yref)
106+
return self.morph(x_morph, y_morph, x_target, y_target)
108107

109108
def __getattr__(self, name):
110109
'''Obtain the value from self.config, when normal lookup fails.

diffpy/pdfmorph/morphs/morphishape.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class MorphISpheroid -- apply inverse spheroidal shape function
2424

2525

2626
class MorphISphere(Morph):
27-
'''Apply inverse spherical characteristic function to the objective
27+
'''Apply inverse spherical characteristic function to the morph
2828
2929
Configuration variables:
3030
@@ -33,27 +33,27 @@ class MorphISphere(Morph):
3333
'''
3434

3535
# Define input output types
36-
summary = 'Apply inverse spherical characteristic function to objective'
36+
summary = 'Apply inverse spherical characteristic function to morph'
3737
xinlabel = LABEL_RA
3838
yinlabel = LABEL_GR
3939
xoutlabel = LABEL_RA
4040
youtlabel = LABEL_GR
4141
parnames = ["iradius"]
4242

43-
def morph(self, xobj, yobj, xref, yref):
43+
def morph(self, x_morph, y_morph, x_target, y_target):
4444
"""Apply a scale factor."""
45-
Morph.morph(self, xobj, yobj, xref, yref)
46-
f = _sphericalCF(xobj, 2 * self.iradius)
47-
self.yobjout /= f
48-
self.yobjout[f == 0] = 0
45+
Morph.morph(self, x_morph, y_morph, x_target, y_target)
46+
f = _sphericalCF(x_morph, 2 * self.iradius)
47+
self.y_morph_out /= f
48+
self.y_morph_out[f == 0] = 0
4949
return self.xyallout
5050

5151

5252
# End of class MorphISphere
5353

5454

5555
class MorphISpheroid(Morph):
56-
'''Apply inverse spherical characteristic function to the objective
56+
'''Apply inverse spherical characteristic function to the morph
5757
5858
Configuration variables:
5959
@@ -63,19 +63,19 @@ class MorphISpheroid(Morph):
6363
'''
6464

6565
# Define input output types
66-
summary = 'Apply inverse spheroidal characteristic function to objective'
66+
summary = 'Apply inverse spheroidal characteristic function to morph'
6767
xinlabel = LABEL_RA
6868
yinlabel = LABEL_GR
6969
xoutlabel = LABEL_RA
7070
youtlabel = LABEL_GR
7171
parnames = ["iradius", "ipradius"]
7272

73-
def morph(self, xobj, yobj, xref, yref):
73+
def morph(self, x_morph, y_morph, x_target, y_target):
7474
"""Apply a scale factor."""
75-
Morph.morph(self, xobj, yobj, xref, yref)
76-
f = _spheroidalCF(xobj, self.iradius, self.ipradius)
77-
self.yobjout /= f
78-
self.yobjout[f == 0] == 0
75+
Morph.morph(self, x_morph, y_morph, x_target, y_target)
76+
f = _spheroidalCF(x_morph, self.iradius, self.ipradius)
77+
self.y_morph_out[f != 0] /= f # Divide non-zero entries
78+
self.y_morph_out[f == 0] = 0 # Set zero entries to zero
7979
return self.xyallout
8080

8181

0 commit comments

Comments
 (0)