@@ -53,7 +53,12 @@ def custom_error(self, msg):
53
53
"Use --help for help." ,
54
54
]
55
55
),
56
- epilog = "Please report bugs to [email protected] ." ,
56
+ epilog = "\n " .join (
57
+ [
58
+ "Please report bugs to [email protected] ." ,
59
+ "For more information, see the PDFmorph website at https://www.diffpy.org/diffpy.pdfmorph." ,
60
+ ]
61
+ ),
57
62
)
58
63
59
64
parser .add_option ("-V" , "--version" , action = "version" , help = "Show program version and exit." )
@@ -90,65 +95,6 @@ def custom_error(self, msg):
90
95
minimizing the residual.""" ,
91
96
)
92
97
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
-
152
98
# Manipulations
153
99
group = optparse .OptionGroup (
154
100
parser ,
@@ -199,7 +145,7 @@ def custom_error(self, msg):
199
145
"--qdamp" ,
200
146
type = "float" ,
201
147
metavar = "QDAMP" ,
202
- help = "Dampen PDF by a factor QDAMP. (See PDFGui manual.) " ,
148
+ help = "Dampen PDF by a factor QDAMP." ,
203
149
)
204
150
group .add_option (
205
151
"--radius" ,
@@ -255,20 +201,82 @@ def custom_error(self, msg):
255
201
"--mlabel" ,
256
202
metavar = "MLABEL" ,
257
203
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 ." ,
259
205
)
260
206
group .add_option (
261
207
"--tlabel" ,
262
208
metavar = "TLABEL" ,
263
209
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 ." ,
265
211
)
266
212
group .add_option ("--pmin" , type = "float" , help = "Minimum r-value to plot. Defaults to RMIN." )
267
213
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." )
270
216
group .add_option ("--lwidth" , type = "float" , help = "Line thickness of plotted curves." )
271
217
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
+
272
280
# Defaults
273
281
parser .set_defaults (multiple = False )
274
282
parser .set_defaults (reverse = False )
@@ -330,10 +338,11 @@ def single_morph(parser, opts, pargs, stdout_flag=True):
330
338
chain .append (helpers .TransformXtalRDFtoPDF ())
331
339
refpars .append ("smear" )
332
340
config ["smear" ] = opts .smear
341
+ # Set baselineslope if not given
333
342
config ["baselineslope" ] = opts .baselineslope
334
343
if opts .baselineslope is None :
335
- refpars .append ("baselineslope" )
336
344
config ["baselineslope" ] = - 0.5
345
+ refpars .append ("baselineslope" )
337
346
# Size
338
347
radii = [opts .radius , opts .pradius ]
339
348
nrad = 2 - radii .count (None )
@@ -370,8 +379,7 @@ def single_morph(parser, opts, pargs, stdout_flag=True):
370
379
371
380
# Now remove non-refinable parameters
372
381
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 ))
375
383
376
384
# Refine or execute the morph
377
385
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):
387
395
if "scale" in refpars :
388
396
rptemp .append ("scale" )
389
397
refiner .refine (* rptemp )
398
+ # Adjust all parameters
390
399
refiner .refine (* refpars )
391
400
except ValueError as e :
392
401
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 :
394
405
try :
395
- refiner .refine ("baselineslope" , baselineslope = - 0.5 )
406
+ refiner .refine ("baselineslope" , baselineslope = config [ "baselineslope" ] )
396
407
except ValueError as e :
397
408
parser .custom_error (str (e ))
398
409
else :
@@ -475,8 +486,13 @@ def multiple_morphs(parser, opts, pargs, stdout_flag=True):
475
486
if not target_directory .is_dir ():
476
487
parser .custom_error (f"{ target_directory } is not a directory. Go to --help for usage." )
477
488
478
- # Do not morph morph_file against itself if it is in the same directory
489
+ # Get list of files from target directory
479
490
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
480
496
if morph_file in target_list :
481
497
target_list .remove (morph_file )
482
498
0 commit comments