Skip to content

Commit cc6ee03

Browse files
committed
add pyproject.toml in the top directory to run pre-commit
1 parent 658ecf8 commit cc6ee03

28 files changed

+270
-605
lines changed

diffpy/srmise/applications/extract.py

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,7 @@ def main():
149149
"--pf",
150150
dest="peakfunction",
151151
metavar="PF",
152-
help="Fit peak function PF defined in "
153-
"diffpy.srmise.peaks, e.g. "
154-
"'GaussianOverR(maxwidth=0.7)'",
152+
help="Fit peak function PF defined in " "diffpy.srmise.peaks, e.g. " "'GaussianOverR(maxwidth=0.7)'",
155153
)
156154
parser.add_option(
157155
"--cres",
@@ -230,34 +228,30 @@ def main():
230228
dest="bpoly0",
231229
type="string",
232230
metavar="a0[c]",
233-
help="Use constant baseline given by y=a0. "
234-
"Append 'c' to make parameter constant.",
231+
help="Use constant baseline given by y=a0. " "Append 'c' to make parameter constant.",
235232
)
236233
group.add_option(
237234
"--bpoly1",
238235
dest="bpoly1",
239236
type="string",
240237
nargs=2,
241238
metavar="a1[c] a0[c]",
242-
help="Use baseline given by y=a1*x + a0. Append 'c' to "
243-
"make parameter constant.",
239+
help="Use baseline given by y=a1*x + a0. Append 'c' to " "make parameter constant.",
244240
)
245241
group.add_option(
246242
"--bpoly2",
247243
dest="bpoly2",
248244
type="string",
249245
nargs=3,
250246
metavar="a2[c] a1[c] a0[c]",
251-
help="Use baseline given by y=a2*x^2+a1*x + a0. Append "
252-
"'c' to make parameter constant.",
247+
help="Use baseline given by y=a2*x^2+a1*x + a0. Append " "'c' to make parameter constant.",
253248
)
254249
group.add_option(
255250
"--bseq",
256251
dest="bseq",
257252
type="string",
258253
metavar="FILE",
259-
help="Use baseline interpolated from x,y values in FILE. "
260-
"This baseline has no free parameters.",
254+
help="Use baseline interpolated from x,y values in FILE. " "This baseline has no free parameters.",
261255
)
262256
group.add_option(
263257
"--bspherical",
@@ -343,9 +337,7 @@ def main():
343337
metavar="FILE",
344338
help="Save result of extraction to FILE (.srmise " "format).",
345339
)
346-
group.add_option(
347-
"--plot", "-p", action="store_true", dest="plot", help="Plot extracted peaks."
348-
)
340+
group.add_option("--plot", "-p", action="store_true", dest="plot", help="Plot extracted peaks.")
349341
group.add_option(
350342
"--liveplot",
351343
"-l",
@@ -362,9 +354,7 @@ def main():
362354
)
363355
parser.add_option_group(group)
364356

365-
group = OptionGroup(
366-
parser, "Verbosity Options", "Control detail printed to console."
367-
)
357+
group = OptionGroup(parser, "Verbosity Options", "Control detail printed to console.")
368358
group.add_option(
369359
"--informative",
370360
"-i",
@@ -435,9 +425,7 @@ def main():
435425
options.peakfunction = eval("peaks." + options.peakfunction)
436426
except Exception as err:
437427
print(err)
438-
print(
439-
"Could not create peak function '%s'. Exiting." % options.peakfunction
440-
)
428+
print("Could not create peak function '%s'. Exiting." % options.peakfunction)
441429
return
442430

443431
if options.modelevaluator is not None:
@@ -447,9 +435,7 @@ def main():
447435
options.modelevaluator = eval("modelevaluators." + options.modelevaluator)
448436
except Exception as err:
449437
print(err)
450-
print(
451-
"Could not find ModelEvaluator '%s'. Exiting." % options.modelevaluator
452-
)
438+
print("Could not find ModelEvaluator '%s'. Exiting." % options.modelevaluator)
453439
return
454440

455441
if options.bcrystal is not None:
@@ -534,9 +520,7 @@ def main():
534520
if options.rng is not None:
535521
pdict["rng"] = list(options.rng)
536522
if options.qmax is not None:
537-
pdict["qmax"] = (
538-
options.qmax if options.qmax == "automatic" else float(options.qmax)
539-
)
523+
pdict["qmax"] = options.qmax if options.qmax == "automatic" else float(options.qmax)
540524
if options.nyquist is not None:
541525
pdict["nyquist"] = options.nyquist
542526
if options.supersample is not None:
@@ -624,10 +608,7 @@ def _format_text(self, text):
624608
# the above is still the same
625609
bits = text.split("\n")
626610
formatted_bits = [
627-
textwrap.fill(
628-
bit, text_width, initial_indent=indent, subsequent_indent=indent
629-
)
630-
for bit in bits
611+
textwrap.fill(bit, text_width, initial_indent=indent, subsequent_indent=indent) for bit in bits
631612
]
632613
result = "\n".join(formatted_bits) + "\n"
633614
return result
@@ -665,9 +646,7 @@ def format_option(self, option):
665646
help_lines.extend(textwrap.wrap(para, self.help_width))
666647
# Everything is the same after here
667648
result.append("%*s%s\n" % (indent_first, "", help_lines[0]))
668-
result.extend(
669-
["%*s%s\n" % (self.help_position, "", line) for line in help_lines[1:]]
670-
)
649+
result.extend(["%*s%s\n" % (self.help_position, "", line) for line in help_lines[1:]])
671650
elif opts[-1] != "\n":
672651
result.append("\n")
673652
return "".join(result)

diffpy/srmise/applications/plot.py

Lines changed: 11 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,7 @@ def makeplot(ppe_or_stability, ip=None, **kwds):
194194
x = ppe.x[rangeslice]
195195
y = ppe.y[rangeslice]
196196
dy = ppe.effective_dy[rangeslice]
197-
mcluster = ModelCluster(
198-
ppe.initial_peaks, ppe.baseline, x, y, dy, None, ppe.error_method, ppe.pf
199-
)
197+
mcluster = ModelCluster(ppe.initial_peaks, ppe.baseline, x, y, dy, None, ppe.error_method, ppe.pf)
200198
ext = mcluster
201199
else:
202200
ext = ppe.extracted
@@ -255,9 +253,7 @@ def makeplot(ppe_or_stability, ip=None, **kwds):
255253
# Define the various data which will be plotted
256254
r = ext.r_cluster
257255
dr = (r[-1] - r[0]) / len(r)
258-
rexpand = np.concatenate(
259-
(np.arange(r[0] - dr, xlo, -dr)[::-1], r, np.arange(r[-1] + dr, xhi + dr, dr))
260-
)
256+
rexpand = np.concatenate((np.arange(r[0] - dr, xlo, -dr)[::-1], r, np.arange(r[-1] + dr, xhi + dr, dr)))
261257
rfine = np.arange(r[0], r[-1], 0.1 * dr)
262258
gr_obs = np.array(resample(ppe.x, ppe.y, rexpand)) * scale
263259
# gr_fit = resample(r, ext.value(), rfine)
@@ -295,21 +291,10 @@ def makeplot(ppe_or_stability, ip=None, **kwds):
295291
max_res = 0.0
296292

297293
# Derive various y limits based on all the offsets
298-
rel_height = (
299-
100.0
300-
- top_offset
301-
- dg_height
302-
- cmp_height
303-
- datatop_offset
304-
- databottom_offset
305-
- bottom_offset
306-
)
294+
rel_height = 100.0 - top_offset - dg_height - cmp_height - datatop_offset - databottom_offset - bottom_offset
307295
abs_height = 100 * ((max_gr - min_gr) + (max_res - min_res)) / rel_height
308296

309-
yhi = (
310-
max_gr
311-
+ (top_offset + dg_height + cmp_height + datatop_offset) * abs_height / 100
312-
)
297+
yhi = max_gr + (top_offset + dg_height + cmp_height + datatop_offset) * abs_height / 100
313298
ylo = yhi - abs_height
314299

315300
yhi = kwds.get("yhi", yhi)
@@ -353,13 +338,7 @@ def makeplot(ppe_or_stability, ip=None, **kwds):
353338

354339
# Remove labels above where insets begin
355340
# ax_data.yaxis.set_ticklabels([str(int(loc)) for loc in ax_data.yaxis.get_majorticklocs() if loc < datatop])
356-
ax_data.yaxis.set_ticks(
357-
[
358-
loc
359-
for loc in ax_data.yaxis.get_majorticklocs()
360-
if (loc < datatop and loc >= ylo)
361-
]
362-
)
341+
ax_data.yaxis.set_ticks([loc for loc in ax_data.yaxis.get_majorticklocs() if (loc < datatop and loc >= ylo)])
363342

364343
# Dataset label
365344
if datalabel is not None:
@@ -378,9 +357,7 @@ def makeplot(ppe_or_stability, ip=None, **kwds):
378357

379358
# Create new x axis at bottom edge of compare inset
380359
ax_data.axis["top"].set_visible(False)
381-
ax_data.axis["newtop"] = ax_data.new_floating_axis(
382-
0, datatop, axis_direction="bottom"
383-
) # "top" bugged?
360+
ax_data.axis["newtop"] = ax_data.new_floating_axis(0, datatop, axis_direction="bottom") # "top" bugged?
384361
ax_data.axis["newtop"].toggle(all=False, ticks=True)
385362
ax_data.axis["newtop"].major_ticks.set_tick_out(True)
386363
ax_data.axis["newtop"].minor_ticks.set_tick_out(True)
@@ -399,9 +376,7 @@ def makeplot(ppe_or_stability, ip=None, **kwds):
399376
transform=ax_data.transAxes,
400377
)
401378
labeldict[fig] = newylabel # so we can find the correct text object
402-
fig.canvas.mpl_connect(
403-
"draw_event", on_draw
404-
) # original label invisibility and updating
379+
fig.canvas.mpl_connect("draw_event", on_draw) # original label invisibility and updating
405380

406381
# Compare extracted (and ideal, if provided) peak positions clearly.
407382
if cmp_height > 0:
@@ -610,15 +585,9 @@ def main():
610585
type="int",
611586
help="Plot given model from set. Ignored if srmise_file is not a PeakStability file.",
612587
)
613-
parser.add_option(
614-
"--show", action="store_true", help="execute pylab.show() blocking call"
615-
)
616-
parser.add_option(
617-
"-o", "--output", type="string", help="save plot to the specified file"
618-
)
619-
parser.add_option(
620-
"--format", type="string", default="eps", help="output format for plot saving"
621-
)
588+
parser.add_option("--show", action="store_true", help="execute pylab.show() blocking call")
589+
parser.add_option("-o", "--output", type="string", help="save plot to the specified file")
590+
parser.add_option("--format", type="string", default="eps", help="output format for plot saving")
622591
parser.allow_interspersed_args = True
623592
opts, args = parser.parse_args(sys.argv[1:])
624593

@@ -636,9 +605,7 @@ def main():
636605
try:
637606
toplot.load(filename)
638607
except Exception:
639-
print(
640-
"File '%s' is not a .srmise or PeakStability data file." % filename
641-
)
608+
print("File '%s' is not a .srmise or PeakStability data file." % filename)
642609
return
643610

644611
if opts.model is not None:

diffpy/srmise/basefunction.py

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,12 @@ def __init__(
116116

117117
# Check validity of default_formats
118118
self.default_formats = default_formats
119-
if not (
120-
"default_input" in self.default_formats
121-
and "default_output" in self.default_formats
122-
):
123-
emsg = (
124-
"Argument default_formats must specify 'default_input' "
125-
+ "and 'default_output' as keys."
126-
)
119+
if not ("default_input" in self.default_formats and "default_output" in self.default_formats):
120+
emsg = "Argument default_formats must specify 'default_input' " + "and 'default_output' as keys."
127121
raise ValueError(emsg)
128122
for f in self.default_formats.values():
129123
if not f in self.parformats:
130-
emsg = (
131-
"Keys of argument default_formats must map to a "
132-
+ "value within argument parformats."
133-
)
124+
emsg = "Keys of argument default_formats must map to a " + "value within argument parformats."
134125
raise ValueError()
135126

136127
# Set metadictionary
@@ -195,10 +186,7 @@ def jacobian(self, p, r, rng=None):
195186
previously calculated values instead.
196187
"""
197188
if self is not p._owner:
198-
emsg = (
199-
"Argument 'p' must be evaluated by the BaseFunction "
200-
+ "subclass which owns it."
201-
)
189+
emsg = "Argument 'p' must be evaluated by the BaseFunction " + "subclass which owns it."
202190
raise ValueError(emsg)
203191

204192
# normally r will be a sequence, but also allow single numeric values
@@ -241,18 +229,12 @@ def transform_derivatives(self, pars, in_format=None, out_format=None):
241229
out_format = self.default_formats["default_input"]
242230

243231
if not in_format in self.parformats:
244-
raise ValueError(
245-
"Argument 'in_format' must be one of %s." % self.parformats
246-
)
232+
raise ValueError("Argument 'in_format' must be one of %s." % self.parformats)
247233
if not out_format in self.parformats:
248-
raise ValueError(
249-
"Argument 'out_format' must be one of %s." % self.parformats
250-
)
234+
raise ValueError("Argument 'out_format' must be one of %s." % self.parformats)
251235
if in_format == out_format:
252236
return np.identity(self.npars)
253-
return self._transform_derivativesraw(
254-
pars, in_format=in_format, out_format=out_format
255-
)
237+
return self._transform_derivativesraw(pars, in_format=in_format, out_format=out_format)
256238

257239
def transform_parameters(self, pars, in_format=None, out_format=None):
258240
"""Return new sequence with pars converted from in_format to out_format.
@@ -282,18 +264,12 @@ def transform_parameters(self, pars, in_format=None, out_format=None):
282264
out_format = self.default_formats["default_input"]
283265

284266
if not in_format in self.parformats:
285-
raise ValueError(
286-
"Argument 'in_format' must be one of %s." % self.parformats
287-
)
267+
raise ValueError("Argument 'in_format' must be one of %s." % self.parformats)
288268
if not out_format in self.parformats:
289-
raise ValueError(
290-
"Argument 'out_format' must be one of %s." % self.parformats
291-
)
269+
raise ValueError("Argument 'out_format' must be one of %s." % self.parformats)
292270
# if in_format == out_format:
293271
# return pars
294-
return self._transform_parametersraw(
295-
pars, in_format=in_format, out_format=out_format
296-
)
272+
return self._transform_parametersraw(pars, in_format=in_format, out_format=out_format)
297273

298274
def value(self, p, r, rng=None):
299275
"""Calculate value of ModelPart over r, possibly restricted by range.
@@ -307,10 +283,7 @@ def value(self, p, r, rng=None):
307283
previously calculated values instead.
308284
"""
309285
if self is not p._owner:
310-
emsg = (
311-
"Argument 'p' must be evaluated by the BaseFunction "
312-
+ "subclass which owns it."
313-
)
286+
emsg = "Argument 'p' must be evaluated by the BaseFunction " + "subclass which owns it."
314287
raise ValueError(emsg)
315288

316289
# normally r will be a sequence, but also allow single numeric values

diffpy/srmise/baselines/arbitrary.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ def __init__(self, npars, valuef, jacobianf=None, estimatef=None, Cache=None):
9595
metadict["valuef"] = (valuef, repr)
9696
metadict["jacobianf"] = (jacobianf, repr)
9797
metadict["estimatef"] = (estimatef, repr)
98-
BaselineFunction.__init__(
99-
self, parameterdict, formats, default_formats, metadict, None, Cache
100-
)
98+
BaselineFunction.__init__(self, parameterdict, formats, default_formats, metadict, None, Cache)
10199

102100
#### Methods required by BaselineFunction ####
103101

@@ -173,17 +171,13 @@ def _transform_parametersraw(self, pars, in_format, out_format):
173171
if in_format == "internal":
174172
pass
175173
else:
176-
raise ValueError(
177-
"Argument 'in_format' must be one of %s." % self.parformats
178-
)
174+
raise ValueError("Argument 'in_format' must be one of %s." % self.parformats)
179175

180176
# Convert to specified output format from "internal" format.
181177
if out_format == "internal":
182178
pass
183179
else:
184-
raise ValueError(
185-
"Argument 'out_format' must be one of %s." % self.parformats
186-
)
180+
raise ValueError("Argument 'out_format' must be one of %s." % self.parformats)
187181
return temp
188182

189183
def _valueraw(self, pars, r):

diffpy/srmise/baselines/base.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ def __init__(
8383
additional functionality.
8484
Cache: A class (not instance) which implements caching of BaseFunction
8585
evaluations."""
86-
BaseFunction.__init__(
87-
self, parameterdict, parformats, default_formats, metadict, base, Cache
88-
)
86+
BaseFunction.__init__(self, parameterdict, parformats, default_formats, metadict, base, Cache)
8987

9088
#### "Virtual" class methods ####
9189

0 commit comments

Comments
 (0)