Skip to content

Commit 9e0a4bb

Browse files
authored
Merge branch 'main' into texinfo
2 parents 2423afe + e3d6b25 commit 9e0a4bb

File tree

14 files changed

+294
-170
lines changed

14 files changed

+294
-170
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ repos:
2222
hooks:
2323
- id: black
2424
- repo: https://github.com/pycqa/flake8
25-
rev: 6.0.0
25+
rev: 6.1.0
2626
hooks:
2727
- id: flake8
2828
- repo: https://github.com/pycqa/isort

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
This program is part of the DiffPy open-source project at Columbia
22
University and is available subject to the conditions and terms laid out below.
33

4-
Copyright © 2009-2019, Trustees of Columbia University in the City of New York,
4+
Copyright © 2009-2024, Trustees of Columbia University in the City of New York,
55
all rights reserved.
66

77
For more information please visit the diffpy web-page at http://diffpy.org or

README.rst

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,24 +79,18 @@ To create and activate a conda environment to use this software, run
7979
the following command from the command line ::
8080
8181
conda create -n pdfmorph_env python=3 --yes
82-
source activate pdfmorph_env
83-
84-
If you're using Windows, replace ``source activate pdfmorph`` with
85-
``activate pdfmorph_env``.
82+
conda activate pdfmorph_env
8683

8784
When you are finished with the session, exit the environment by running ::
8885

89-
source deactivate pdfmorph_env
90-
91-
or, on Windows, ``deactivate pdfmorph_env``.
86+
conda deactivate pdfmorph_env
9287

9388
For your future sessions with the application: Make sure to run the
94-
``source activate pdfmorph_env`` or ``activate pdfmorph_env`` commands
95-
from your command line beforehand to ensure access to the software.
89+
``conda activate pdfmorph_env`` command from your command line beforehand
90+
to ensure access to the software.
9691

9792
Once in your desired conda environment, you can install from either the
98-
"diffpy" or "conda-forge" channels of Anaconda packages by running
99-
either ::
93+
"conda-forge" channel of Anaconda packages by running ::
10094

10195
conda config --add channels conda-forge
10296
conda install diffpy.pdfmorph
@@ -157,9 +151,9 @@ We welcome contributors from the community. Please consider posting issues, and
157151
To ensure code quality and to prevent accidental commits into the default branch, please set up the use of our pre-commit
158152
hooks.
159153

160-
1. Install pre-commit in your working environment by running ``conda install pre-commit``
154+
1. Install pre-commit in your working environment by running ``conda install pre-commit``.
161155

162-
2. Initialize pre-commit (one time only) ``pre-commit install``
156+
2. Initialize pre-commit (one time only) ``pre-commit install``.
163157

164158
Thereafter your code will be linted by black and isort and checked against flake8 before you can commit.
165159
If it fails by black or isort, just rerun and it should pass (black and isort will modify the files so should

doc/manual/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
project = "PDFmorph"
2323
project_full = "diffpy.pdfmorph"
24-
copyright = "2009-2019, Trustees of Columbia University in the City of New York, all rights reserved."
24+
copyright = "2009-2024, Trustees of Columbia University in the City of New York, all rights reserved"
2525
author = "Chris Farrow, Christopher J. Wright, Pavol Juhás, Chia-Hao (Timothy) Liu, S. Matthew Román, Simon J.L. Billinge"
2626

2727
# The full version, including alpha/beta/rc tags

doc/manual/source/license.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This program is part of the DiffPy open-source project at Columbia
55
University and is available subject to the conditions and terms laid out
66
below.
77

8-
Copyright © 2009-2019, Trustees of Columbia University in the City of
8+
Copyright © 2009-2024, Trustees of Columbia University in the City of
99
New York, all rights reserved.
1010

1111
For more information please visit the diffpy web-page at

doc/manual/source/quickstart.rst

Lines changed: 180 additions & 71 deletions
Large diffs are not rendered by default.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Download Tutorial Files Here
2+
############################
3+
4+
Quick start tutorial data:
5+
:download:`tutorialData.zip <../../../tutorial/tutorialData.zip>`
6+
7+
Extra tutorial data:
8+
:download:`additionalData.zip <../../../tutorial/additionalData.zip>`

src/diffpy/pdfmorph/pdfmorph_io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def multiple_morph_output(
249249
header = "# Data generated by pdfmorph\n"
250250
header += f"# from morphing {morph_path_name}\n"
251251
header += f"# with target directory {target_path_name}"
252-
reference_table = Path(save_directory).joinpath("Morph_Reference_Table.csv")
252+
reference_table = Path(save_directory).joinpath("Morph_Reference_Table.txt")
253253
with open(reference_table, "w") as reference:
254254
print(f"{header}\n{inputs}\n{verbose_outputs}{table}", file=reference)
255255

src/diffpy/pdfmorph/pdfmorphapp.py

Lines changed: 87 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ def custom_error(self, msg):
5353
"Use --help for help.",
5454
]
5555
),
56-
epilog="Please report bugs to diffpy-dev@googlegroups.com.",
56+
epilog="\n".join(
57+
[
58+
"Please report bugs to diffpy-users@googlegroups.com.",
59+
"For more information, see the PDFmorph website at https://www.diffpy.org/diffpy.pdfmorph.",
60+
]
61+
),
5762
)
5863

5964
parser.add_option("-V", "--version", action="version", help="Show program version and exit.")
@@ -90,65 +95,6 @@ def custom_error(self, msg):
9095
minimizing the residual.""",
9196
)
9297

93-
group = optparse.OptionGroup(
94-
parser,
95-
"Multiple Morphs",
96-
"""This program can morph a PDF against multiple targets in one command.
97-
See -s and Plot Options for how saving and plotting functionality changes when performing multiple morphs.""",
98-
)
99-
parser.add_option_group(group)
100-
group.add_option(
101-
"--multiple",
102-
dest="multiple",
103-
action="store_true",
104-
help=f"""Changes usage to \'{prog_short} [options] FILE DIRECTORY\'. FILE
105-
will be morphed with each file in DIRECTORY as target.
106-
Files in DIRECTORY are sorted by alphabetical order unless a field is
107-
specified by --sort-by.""",
108-
)
109-
group.add_option(
110-
"--sort-by",
111-
metavar="FIELD",
112-
dest="field",
113-
help="""Used with --multiple to sort files in DIRECTORY by FIELD from lowest to highest.
114-
FIELD must be included in the header of all the PDF files.""",
115-
)
116-
group.add_option(
117-
"--reverse",
118-
dest="reverse",
119-
action="store_true",
120-
help="""Sort from highest to lowest instead.""",
121-
)
122-
group.add_option(
123-
"--serial-file",
124-
metavar="SERIALFILE",
125-
dest="serfile",
126-
help="""Look for FIELD in a serial file instead.
127-
Must specify name of serial file SERIALFILE.""",
128-
)
129-
group.add_option(
130-
"--save-names-file",
131-
metavar="NAMESFILE",
132-
dest="snamesfile",
133-
help=f"""Used when both -s and --multiple are enabled.
134-
Specify names for each manipulated PDF when saving (see -s) using a serial file
135-
NAMESFILE. The format of NAMESFILE should be as follows: each target PDF
136-
is an entry in NAMESFILE. For each entry, there should be a key {__save_morph_as__}
137-
whose value specifies the name to save the manipulated PDF as.
138-
(See sample names files in the PDFmorph tutorial).""",
139-
)
140-
group.add_option(
141-
"--plot-parameter",
142-
metavar="PLOTPARAM",
143-
dest="plotparam",
144-
help="""Used when both plotting and --multiple are enabled.
145-
Choose a PLOTPARAM to plot for each morph (i.e. adding --pp=Pearson means the program
146-
will display a plot of the Pearson correlation coefficient for each morph-target pair).
147-
PLOTPARAM is not case sensitive, so both Pearson and pearson indicate the same parameter.
148-
When PLOTPARAM is not specified, Rw values for each morph-target pair will be plotted.
149-
PLOTPARAM will be displayed as the vertical axis label for the plot.""",
150-
)
151-
15298
# Manipulations
15399
group = optparse.OptionGroup(
154100
parser,
@@ -199,7 +145,7 @@ def custom_error(self, msg):
199145
"--qdamp",
200146
type="float",
201147
metavar="QDAMP",
202-
help="Dampen PDF by a factor QDAMP. (See PDFGui manual.)",
148+
help="Dampen PDF by a factor QDAMP.",
203149
)
204150
group.add_option(
205151
"--radius",
@@ -255,20 +201,82 @@ def custom_error(self, msg):
255201
"--mlabel",
256202
metavar="MLABEL",
257203
dest="mlabel",
258-
help="Set label for morphed data to MLABEL on plot. Ignored if using file names as labels.",
204+
help="Set label for morphed data to MLABEL on plot. Default label is FILE1.",
259205
)
260206
group.add_option(
261207
"--tlabel",
262208
metavar="TLABEL",
263209
dest="tlabel",
264-
help="Set label for target data to TLABEL on plot. Ignored if using file names as labels.",
210+
help="Set label for target data to TLABEL on plot. Default label is FILE2.",
265211
)
266212
group.add_option("--pmin", type="float", help="Minimum r-value to plot. Defaults to RMIN.")
267213
group.add_option("--pmax", type="float", help="Maximum r-value to plot. Defaults to RMAX.")
268-
group.add_option("--maglim", type="float", help="Magnify plot curves beyond MAGLIM by MAG.")
269-
group.add_option("--mag", type="float", help="Magnify plot curves beyond MAGLIM by MAG.")
214+
group.add_option("--maglim", type="float", help="Magnify plot curves beyond r=MAGLIM by MAG.")
215+
group.add_option("--mag", type="float", help="Magnify plot curves beyond r=MAGLIM by MAG.")
270216
group.add_option("--lwidth", type="float", help="Line thickness of plotted curves.")
271217

218+
# Multiple morph options
219+
group = optparse.OptionGroup(
220+
parser,
221+
"Multiple Morphs",
222+
"""This program can morph a PDF against multiple targets in one command.
223+
See -s and Plot Options for how saving and plotting functionality changes when performing multiple morphs.""",
224+
)
225+
parser.add_option_group(group)
226+
group.add_option(
227+
"--multiple",
228+
dest="multiple",
229+
action="store_true",
230+
help=f"""Changes usage to \'{prog_short} [options] FILE DIRECTORY\'. FILE
231+
will be morphed with each file in DIRECTORY as target.
232+
Files in DIRECTORY are sorted by alphabetical order unless a field is
233+
specified by --sort-by.""",
234+
)
235+
group.add_option(
236+
"--sort-by",
237+
metavar="FIELD",
238+
dest="field",
239+
help="""Used with --multiple to sort files in DIRECTORY by FIELD.
240+
If the FIELD being used has a numerical value, sort from lowest to highest.
241+
Otherwise, sort in ASCII sort order.
242+
FIELD must be included in the header of all the PDF files.""",
243+
)
244+
group.add_option(
245+
"--reverse",
246+
dest="reverse",
247+
action="store_true",
248+
help="""Sort from highest to lowest instead.""",
249+
)
250+
group.add_option(
251+
"--serial-file",
252+
metavar="SERIALFILE",
253+
dest="serfile",
254+
help="""Look for FIELD in a serial file instead.
255+
Must specify name of serial file SERIALFILE.""",
256+
)
257+
group.add_option(
258+
"--save-names-file",
259+
metavar="NAMESFILE",
260+
dest="snamesfile",
261+
help=f"""Used when both -s and --multiple are enabled.
262+
Specify names for each manipulated PDF when saving (see -s) using a serial file
263+
NAMESFILE. The format of NAMESFILE should be as follows: each target PDF
264+
is an entry in NAMESFILE. For each entry, there should be a key {__save_morph_as__}
265+
whose value specifies the name to save the manipulated PDF as. An example .json
266+
serial file is shown in the PDFmorph manual.""",
267+
)
268+
group.add_option(
269+
"--plot-parameter",
270+
metavar="PLOTPARAM",
271+
dest="plotparam",
272+
help="""Used when both plotting and --multiple are enabled.
273+
Choose a PLOTPARAM to plot for each morph (i.e. adding --plot-parameter=Pearson means the
274+
program will display a plot of the Pearson correlation coefficient for each morph-target
275+
pair). PLOTPARAM is not case sensitive, so both Pearson and pearson indicate the same
276+
parameter. When PLOTPARAM is not specified, Rw values for each morph-target pair will be
277+
plotted. PLOTPARAM will be displayed as the vertical axis label for the plot.""",
278+
)
279+
272280
# Defaults
273281
parser.set_defaults(multiple=False)
274282
parser.set_defaults(reverse=False)
@@ -330,10 +338,11 @@ def single_morph(parser, opts, pargs, stdout_flag=True):
330338
chain.append(helpers.TransformXtalRDFtoPDF())
331339
refpars.append("smear")
332340
config["smear"] = opts.smear
341+
# Set baselineslope if not given
333342
config["baselineslope"] = opts.baselineslope
334343
if opts.baselineslope is None:
335-
refpars.append("baselineslope")
336344
config["baselineslope"] = -0.5
345+
refpars.append("baselineslope")
337346
# Size
338347
radii = [opts.radius, opts.pradius]
339348
nrad = 2 - radii.count(None)
@@ -370,8 +379,7 @@ def single_morph(parser, opts, pargs, stdout_flag=True):
370379

371380
# Now remove non-refinable parameters
372381
if opts.exclude is not None:
373-
refpars = set(refpars) - set(opts.exclude)
374-
refpars = list(refpars)
382+
refpars = list(set(refpars) - set(opts.exclude))
375383

376384
# Refine or execute the morph
377385
refiner = refine.Refiner(chain, x_morph, y_morph, x_target, y_target)
@@ -387,12 +395,15 @@ def single_morph(parser, opts, pargs, stdout_flag=True):
387395
if "scale" in refpars:
388396
rptemp.append("scale")
389397
refiner.refine(*rptemp)
398+
# Adjust all parameters
390399
refiner.refine(*refpars)
391400
except ValueError as e:
392401
parser.custom_error(str(e))
393-
elif "smear" in refpars and opts.baselineslope is None:
402+
# Smear is not being refined, but baselineslope needs to refined to apply smear
403+
# Note that baselineslope is only added to the refine list if smear is applied
404+
elif "baselineslope" in refpars:
394405
try:
395-
refiner.refine("baselineslope", baselineslope=-0.5)
406+
refiner.refine("baselineslope", baselineslope=config["baselineslope"])
396407
except ValueError as e:
397408
parser.custom_error(str(e))
398409
else:
@@ -475,8 +486,13 @@ def multiple_morphs(parser, opts, pargs, stdout_flag=True):
475486
if not target_directory.is_dir():
476487
parser.custom_error(f"{target_directory} is not a directory. Go to --help for usage.")
477488

478-
# Do not morph morph_file against itself if it is in the same directory
489+
# Get list of files from target directory
479490
target_list = list(target_directory.iterdir())
491+
for target in target_list:
492+
if target.is_dir():
493+
target_list.remove(target)
494+
495+
# Do not morph morph_file against itself if it is in the same directory
480496
if morph_file in target_list:
481497
target_list.remove(morph_file)
482498

src/diffpy/pdfmorph/refine.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ def refine(self, *args, **kw):
114114
return 0.0
115115

116116
initial = [config[p] for p in self.pars]
117-
out = leastsq(self.residual, initial, full_output=1)
118-
fvec = out[2]["fvec"]
119-
if out[4] not in (1, 2, 3, 4):
120-
mesg = out[3]
121-
raise ValueError(mesg)
117+
sol, cov_sol, infodict, emesg, ier = leastsq(self.residual, initial, full_output=1)
118+
fvec = infodict["fvec"]
119+
if ier not in (1, 2, 3, 4):
120+
emesg
121+
raise ValueError(emesg)
122122

123123
# Place the fit parameters in config
124-
vals = out[0]
124+
vals = sol
125125
if not hasattr(vals, "__iter__"):
126126
vals = [vals]
127127
self.chain.config.update(zip(self.pars, vals))

0 commit comments

Comments
 (0)