Skip to content

Commit 4e9ef91

Browse files
Refactor away from PDF language (#261)
* Refactor away from pdf language * [pre-commit.ci] auto fixes from pre-commit hooks * Add news --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent de41950 commit 4e9ef91

30 files changed

+255
-227
lines changed

README.rst

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,34 +35,35 @@
3535
.. |Tracking| image:: https://img.shields.io/badge/issue_tracking-github-blue
3636
:target: https://github.com/diffpy/diffpy.morph/issues
3737

38-
Python package for manipulating and comparing PDF profiles
38+
Python package for manipulating and comparing diffraction data
3939

4040
``diffpy.morph`` is a Python software package designed to increase the insight
41-
researchers can obtain from measured atomic pair distribution functions
41+
researchers can obtain from measured diffraction data
42+
and atomic pair distribution functions
4243
(PDFs) in a model-independent way. The program was designed to help a
4344
researcher answer the question: "Has my material undergone a phase
4445
transition between these two measurements?"
4546

46-
One approach is to compare the two PDFs in a plot and view the difference
47-
curve underneath. However, significant signal can be seen in the
48-
difference curve from benign effects such as thermal expansion (peak
49-
shifts) and increased thermal motion (peak broadening) or a change in
47+
One approach is to compare the two diffraction patterns in a plot
48+
and view the difference curve underneath. However, significant signal can
49+
be seen in the difference curve from benign effects such as thermal expansion
50+
(peak shifts) and increased thermal motion (peak broadening) or a change in
5051
scale due to differences in incident flux, for example. ``diffpy.morph`` will
5152
do its best to correct for these benign effects before computing and
52-
plotting the difference curve. One measured PDF (typically that collected
53-
at higher temperature) is identified as the target PDF and the second
54-
PDF is then morphed by "stretching" (changing the r-axis to simulate a
53+
plotting the difference curve. One measured function (typically that collected
54+
at higher temperature) is identified as the target function and the second
55+
function is then morphed by "stretching" (changing the r-axis to simulate a
5556
uniform lattice expansion), "smearing" (broadening peaks through a
5657
uniform convolution to simulate increased thermal motion), and "scaling"
5758
(self-explanatory). ``diffpy.morph`` will vary the amplitude of the morphing
5859
transformations to obtain the best fit between the morphed and the target
59-
PDFs, then plot them on top of each other with the difference plotted
60+
functions, then plot them on top of each other with the difference plotted
6061
below.
6162

6263
There are also a few other morphing transformations in the program.
6364

64-
Finally, we note that ``diffpy.morph`` should work on other spectra that are not
65-
PDFs, though it has not been extensively tested beyond the PDF.
65+
Finally, we note that ``diffpy.morph`` should work on other spectra,
66+
though it has not been extensively tested beyond spectral data and the PDF.
6667

6768

6869
For more information about the diffpy.morph library, please consult our `online documentation <https://diffpy.github.io/diffpy.morph>`_.
@@ -153,9 +154,9 @@ If installed correctly, this last command should return the version
153154
of ``diffpy.morph`` that you have installed on your system. To begin using
154155
``diffpy.morph``, run a command like ::
155156

156-
diffpy.morph <target PDF file> <morphed PDF file>
157+
diffpy.morph <morph file> <target file>
157158

158-
where both PDFs file are text files which contain PDF data, such as ``.gr``
159+
where both files are text files which contain two-column data, such as ``.gr``
159160
or ``.cgr`` files that are produced by ``PDFgetX2``, ``PDFgetX3``,
160161
or ``PDFgui``. File extensions other than ``.gr`` or ``.cgr``,
161162
but with the same content structure, also work with ``diffpy.morph``.

TUTORIAL.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ Basic diffpy.morph Workflow
132132
superficial and in most cases can be ignored.
133133

134134
We see that this has had hardly any effect on our PDF. To see
135-
an effect, we restrict the ``rmin`` and ``rmax`` values to
135+
an effect, we restrict the ``xmin`` and ``xmax`` values to
136136
reflect relevant data range by typing ::
137137

138-
diffpy.morph --scale=0.8 --smear=0.5 --rmin=1.5 --rmax=30 darkSub_rh20_C_01.gr darkSub_rh20_C_44.gr
138+
diffpy.morph --scale=0.8 --smear=0.5 --xmin=1.5 --xmax=30 darkSub_rh20_C_01.gr darkSub_rh20_C_44.gr
139139

140140
Now, we see that the difference Rw = 0.204 and that the optimized
141141
``smear=-0.084138``.
@@ -151,7 +151,7 @@ Basic diffpy.morph Workflow
151151
8. Finally, we will examine the stretch factor. Provide an initial
152152
guess by typing ::
153153

154-
diffpy.morph --scale=0.8 --smear=-0.08 --stretch=0.5 --rmin=1.5 --rmax=30 -a darkSub_rh20_C_01.gr darkSub_rh20_C_44.gr
154+
diffpy.morph --scale=0.8 --smear=-0.08 --stretch=0.5 --xmin=1.5 --xmax=30 -a darkSub_rh20_C_01.gr darkSub_rh20_C_44.gr
155155

156156
And noting that the difference has increased. Before continuing,
157157
see if you can see which direction (higher or lower) our initial
@@ -160,7 +160,7 @@ Basic diffpy.morph Workflow
160160

161161
If you cannot, type ::
162162

163-
diffpy.morph --scale=0.8 --smear=-0.08 --stretch=0.005 --rmin=1.5 --rmax=30 -a darkSub_rh20_C_01.gr darkSub_rh20_C_44.gr
163+
diffpy.morph --scale=0.8 --smear=-0.08 --stretch=0.005 --xmin=1.5 --xmax=30 -a darkSub_rh20_C_01.gr darkSub_rh20_C_44.gr
164164

165165
to observe decreased difference and then remove ``-a`` to see
166166
the optimized ``--stretch=0.001762``. We have now reached

news/refactor_pdf.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
**Added:**
2+
3+
* <news item>
4+
5+
**Changed:**
6+
7+
* Changed tutorial language away from PDF-specific names
8+
* Names of rmin, rmax, rstep renamed to xmin, xmax, xstep
9+
* Removed PDF-specific labels from plotting functions
10+
11+
**Deprecated:**
12+
13+
* <news item>
14+
15+
**Removed:**
16+
17+
* <news item>
18+
19+
**Fixed:**
20+
21+
* <news item>
22+
23+
**Security:**
24+
25+
* <news item>

src/diffpy/morph/morph_api.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ def morph(
8686
y_morph,
8787
x_target,
8888
y_target,
89-
rmin=None,
90-
rmax=None,
91-
rstep=None,
89+
xmin=None,
90+
xmax=None,
91+
xstep=None,
9292
pearson=False,
9393
add_pearson=False,
9494
fixed_operations=None,
@@ -112,12 +112,12 @@ def morph(
112112
y_morph: numpy.array
113113
An array of target y values, i.e., those will be kept constant by
114114
morphing.
115-
rmin: float, optional
116-
A value to specify lower r-limit of morph operations.
117-
rmax: float, optional
118-
A value to specify upper r-limit of morph operations.
119-
rstep: float, optional
120-
A value to specify rstep of morph operations.
115+
xmin: float, optional
116+
A value to specify lower x-limit of morph operations.
117+
xmax: float, optional
118+
A value to specify upper x-limit of morph operations.
119+
xstep: float, optional
120+
A value to specify xstep of morph operations.
121121
pearson: Bool, optional
122122
Option to include Pearson coefficient as a minimizing target
123123
during morphing. Default to False.
@@ -191,9 +191,9 @@ def morph(
191191
for k, v in rv_cfg.items()
192192
if (v is not None) and k in _morph_step_dict
193193
]
194-
rv_cfg["rmin"] = rmin
195-
rv_cfg["rmax"] = rmax
196-
rv_cfg["rstep"] = rstep
194+
rv_cfg["xmin"] = xmin
195+
rv_cfg["xmax"] = xmax
196+
rv_cfg["xstep"] = xstep
197197
# configure smear, guess baselineslope when it is not provided
198198
if rv_cfg.get("smear") is not None and rv_cfg.get("baselineslope") is None:
199199
rv_cfg["baselineslope"] = -0.5
@@ -295,9 +295,9 @@ def plot_morph(chain, ax=None, **kwargs):
295295
rdat, grdat = chain.xy_target_out
296296
l_list = ax.plot(rfit, grfit, label="morph", **kwargs)
297297
l_list += ax.plot(rdat, grdat, label="target", **kwargs)
298-
ax.set_xlim([chain.config["rmin"], chain.config["rmax"]])
298+
ax.set_xlim([chain.config["xmin"], chain.config["xmax"]])
299299
ax.legend()
300-
ax.set_xlabel(r"r ($\mathrm{\AA}$)")
301-
ax.set_ylabel(r"G ($\mathrm{\AA}^{-2}$)")
300+
# ax.set_xlabel(r"r ($\mathrm{\AA}$)")
301+
# ax.set_ylabel(r"G ($\mathrm{\AA}^{-2}$)")
302302

303303
return l_list

src/diffpy/morph/morphapp.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,16 @@ def custom_error(self, msg):
110110
help="Print additional header details to saved files.",
111111
)
112112
parser.add_option(
113-
"--rmin",
113+
"--xmin",
114114
type="float",
115-
help="Minimum r-value (abscissa) to use for function comparisons.",
115+
metavar="XMIN",
116+
help="Minimum x-value (abscissa) to use for function comparisons.",
116117
)
117118
parser.add_option(
118-
"--rmax",
119+
"--xmax",
119120
type="float",
120-
help="Maximum r-value (abscissa) to use for function comparisons.",
121+
metavar="XMAX",
122+
help="Maximum x-value (abscissa) to use for function comparisons.",
121123
)
122124
parser.add_option(
123125
"--tolerance",
@@ -343,12 +345,12 @@ def custom_error(self, msg):
343345
group.add_option(
344346
"--pmin",
345347
type="float",
346-
help="Minimum r-value to plot. Defaults to RMIN.",
348+
help="Minimum x-value to plot. Defaults to XMIN.",
347349
)
348350
group.add_option(
349351
"--pmax",
350352
type="float",
351-
help="Maximum r-value to plot. Defaults to RMAX.",
353+
help="Maximum x-value to plot. Defaults to XMAX.",
352354
)
353355
group.add_option(
354356
"--maglim",
@@ -505,13 +507,13 @@ def single_morph(
505507
smear_in = "None"
506508
hshift_in = "None"
507509
vshift_in = "None"
508-
config = {"rmin": opts.rmin, "rmax": opts.rmax, "rstep": None}
510+
config = {"xmin": opts.xmin, "xmax": opts.xmax, "xstep": None}
509511
if (
510-
opts.rmin is not None
511-
and opts.rmax is not None
512-
and opts.rmax <= opts.rmin
512+
opts.xmin is not None
513+
and opts.xmax is not None
514+
and opts.xmax <= opts.xmin
513515
):
514-
e = "rmin must be less than rmax"
516+
e = "xmin must be less than xmax"
515517
parser.custom_error(e)
516518

517519
# Set up the morphs
@@ -765,7 +767,7 @@ def single_morph(
765767
xy_save = [chain.x_morph_out, chain.y_morph_out]
766768
if opts.get_diff is not None:
767769
diff_chain = morphs.MorphChain(
768-
{"rmin": None, "rmax": None, "rstep": None}
770+
{"xmin": None, "xmax": None, "xstep": None}
769771
)
770772
diff_chain.append(morphs.MorphRGrid())
771773
diff_chain(
@@ -804,16 +806,16 @@ def single_morph(
804806
labels[0] = opts.tlabel
805807

806808
# Plot extent defaults to calculation extent
807-
pmin = opts.pmin if opts.pmin is not None else opts.rmin
808-
pmax = opts.pmax if opts.pmax is not None else opts.rmax
809+
pmin = opts.pmin if opts.pmin is not None else opts.xmin
810+
pmax = opts.pmax if opts.pmax is not None else opts.xmax
809811
maglim = opts.maglim
810812
mag = opts.mag
811813
l_width = opts.lwidth
812814
plot.compare_funcs(
813815
pairlist,
814816
labels,
815-
rmin=pmin,
816-
rmax=pmax,
817+
xmin=pmin,
818+
xmax=pmax,
817819
maglim=maglim,
818820
mag=mag,
819821
rw=rw,

src/diffpy/morph/morphs/morphrgrid.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ class MorphRGrid(Morph):
2828
2929
Configuration Variables
3030
-----------------------
31-
rmin
32-
The lower-bound on the r-range.
33-
rmax
34-
The upper-bound on the r-range (exclusive within tolerance of 1e-8).
35-
rstep
36-
The r-spacing.
31+
xmin
32+
The lower-bound on the x-range.
33+
xmax
34+
The upper-bound on the x-range (exclusive within tolerance of 1e-8).
35+
xstep
36+
The x-spacing.
3737
3838
Notes
3939
-----
@@ -49,47 +49,47 @@ class MorphRGrid(Morph):
4949
yinlabel = LABEL_GR
5050
xoutlabel = LABEL_RA
5151
youtlabel = LABEL_GR
52-
parnames = ["rmin", "rmax", "rstep"]
52+
parnames = ["xmin", "xmax", "xstep"]
5353

54-
# Define rmin rmax holders for adaptive x-grid refinement
54+
# Define xmin xmax holders for adaptive x-grid refinement
5555
# Without these, the program r-grid can only decrease in interval size
56-
rmin_origin = None
57-
rmax_origin = None
58-
rstep_origin = None
56+
xmin_origin = None
57+
xmax_origin = None
58+
xstep_origin = None
5959

6060
def morph(self, x_morph, y_morph, x_target, y_target):
6161
"""Resample arrays onto specified grid."""
62-
if self.rmin is not None:
63-
self.rmin_origin = self.rmin
64-
if self.rmax is not None:
65-
self.rmax_origin = self.rmax
66-
if self.rstep is not None:
67-
self.rstep_origin = self.rstep
62+
if self.xmin is not None:
63+
self.xmin_origin = self.xmin
64+
if self.xmax is not None:
65+
self.xmax_origin = self.xmax
66+
if self.xstep is not None:
67+
self.xstep_origin = self.xstep
6868

6969
Morph.morph(self, x_morph, y_morph, x_target, y_target)
70-
rmininc = max(min(self.x_target_in), min(self.x_morph_in))
71-
r_step_target = (max(self.x_target_in) - min(self.x_target_in)) / (
70+
xmininc = max(min(self.x_target_in), min(self.x_morph_in))
71+
x_step_target = (max(self.x_target_in) - min(self.x_target_in)) / (
7272
len(self.x_target_in) - 1
7373
)
74-
r_step_morph = (max(self.x_morph_in) - min(self.x_morph_in)) / (
74+
x_step_morph = (max(self.x_morph_in) - min(self.x_morph_in)) / (
7575
len(self.x_morph_in) - 1
7676
)
77-
rstepinc = max(r_step_target, r_step_morph)
78-
rmaxinc = min(
79-
max(self.x_target_in) + r_step_target,
80-
max(self.x_morph_in) + r_step_morph,
77+
xstepinc = max(x_step_target, x_step_morph)
78+
xmaxinc = min(
79+
max(self.x_target_in) + x_step_target,
80+
max(self.x_morph_in) + x_step_morph,
8181
)
82-
if self.rmin_origin is None or self.rmin_origin < rmininc:
83-
self.rmin = rmininc
84-
if self.rmax_origin is None or self.rmax_origin > rmaxinc:
85-
self.rmax = rmaxinc
86-
if self.rstep_origin is None or self.rstep_origin < rstepinc:
87-
self.rstep = rstepinc
82+
if self.xmin_origin is None or self.xmin_origin < xmininc:
83+
self.xmin = xmininc
84+
if self.xmax_origin is None or self.xmax_origin > xmaxinc:
85+
self.xmax = xmaxinc
86+
if self.xstep_origin is None or self.xstep_origin < xstepinc:
87+
self.xstep = xstepinc
8888
# roundoff tolerance for selecting bounds on arrays.
89-
epsilon = self.rstep / 2
90-
# Make sure that rmax is exclusive
89+
epsilon = self.xstep / 2
90+
# Make sure that xmax is exclusive
9191
self.x_morph_out = numpy.arange(
92-
self.rmin, self.rmax - epsilon, self.rstep
92+
self.xmin, self.xmax - epsilon, self.xstep
9393
)
9494
self.y_morph_out = numpy.interp(
9595
self.x_morph_out, self.x_morph_in, self.y_morph_in

src/diffpy/morph/plot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ def compare_funcs(
212212
plt.ylim(ymin, ymax)
213213

214214
# Make labels and legends
215-
plt.xlabel(r"r ($\mathrm{\AA})$")
216-
plt.ylabel(r"G $(\mathrm{\AA}^{-1})$")
215+
# plt.xlabel(r"r ($\mathrm{\AA})$")
216+
# plt.ylabel(r"G $(\mathrm{\AA}^{-1})$")
217217
if legend:
218218
plt.legend(
219219
bbox_to_anchor=(0.005, 1.02, 0.99, 0.10),

tests/test_morphapp.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def test_parser_numerical(self, setup_parser):
5252

5353
# Check values parsed correctly
5454
n_names = [
55-
"--rmin",
56-
"--rmax",
55+
"--xmin",
56+
"--xmax",
5757
"--scale",
5858
"--smear",
5959
"--stretch",
@@ -134,14 +134,14 @@ def test_parser_systemexits(self, capsys, setup_parser):
134134
in err
135135
)
136136

137-
# Make sure rmax greater than rmin
137+
# Make sure xmax greater than xmin
138138
(opts, pargs) = self.parser.parse_args(
139-
[f"{nickel_PDF}", f"{nickel_PDF}", "--rmin", "10", "--rmax", "1"]
139+
[f"{nickel_PDF}", f"{nickel_PDF}", "--xmin", "10", "--xmax", "1"]
140140
)
141141
with pytest.raises(SystemExit):
142142
single_morph(self.parser, opts, pargs, stdout_flag=False)
143143
_, err = capsys.readouterr()
144-
assert "rmin must be less than rmax" in err
144+
assert "xmin must be less than xmax" in err
145145

146146
# ###Tests exclusive to multiple morphs###
147147
# Make sure we save to a directory that exists

0 commit comments

Comments
 (0)