Skip to content

Commit 646b024

Browse files
[pre-commit.ci] auto fixes from pre-commit hooks
1 parent cd9415b commit 646b024

File tree

114 files changed

+2383
-1915
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+2383
-1915
lines changed

Diff for: devutils/makesdist

+22-16
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,57 @@
11
#!/usr/bin/env python
22

3-
'''Create source distribution tar.gz archive, where each file belongs
3+
"""Create source distribution tar.gz archive, where each file belongs
44
to a root user and modification time is set to the git commit time.
5-
'''
5+
"""
66

7-
import sys
7+
import glob
8+
import gzip
89
import os
910
import subprocess
10-
import glob
11+
import sys
1112
import tarfile
12-
import gzip
1313

1414
BASEDIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
1515
sys.path.insert(0, BASEDIR)
1616

17-
from setup import versiondata, FALLBACK_VERSION
18-
timestamp = versiondata.getint('DEFAULT', 'timestamp')
17+
from setup import FALLBACK_VERSION, versiondata
1918

20-
vfb = versiondata.get('DEFAULT', 'version').split('.post')[0] + '.post0'
19+
timestamp = versiondata.getint("DEFAULT", "timestamp")
20+
21+
vfb = versiondata.get("DEFAULT", "version").split(".post")[0] + ".post0"
2122
emsg = "Invalid FALLBACK_VERSION. Expected %r got %r."
2223
assert vfb == FALLBACK_VERSION, emsg % (vfb, FALLBACK_VERSION)
2324

25+
2426
def inform(s):
2527
sys.stdout.write(s)
2628
sys.stdout.flush()
2729
return
2830

31+
2932
inform('Run "setup.py sdist --formats=tar" ')
30-
cmd_sdist = [sys.executable] + 'setup.py sdist --formats=tar'.split()
31-
ec = subprocess.call(cmd_sdist, cwd=BASEDIR, stdout=open(os.devnull, 'w'))
32-
if ec: sys.exit(ec)
33+
cmd_sdist = [sys.executable] + "setup.py sdist --formats=tar".split()
34+
ec = subprocess.call(cmd_sdist, cwd=BASEDIR, stdout=open(os.devnull, "w"))
35+
if ec:
36+
sys.exit(ec)
3337
inform("[done]\n")
3438

35-
tarname = max(glob.glob(BASEDIR + '/dist/*.tar'), key=os.path.getmtime)
39+
tarname = max(glob.glob(BASEDIR + "/dist/*.tar"), key=os.path.getmtime)
3640

3741
tfin = tarfile.open(tarname)
38-
fpout = gzip.GzipFile(tarname + '.gz', 'w', mtime=0)
39-
tfout = tarfile.open(fileobj=fpout, mode='w')
42+
fpout = gzip.GzipFile(tarname + ".gz", "w", mtime=0)
43+
tfout = tarfile.open(fileobj=fpout, mode="w")
44+
4045

4146
def fixtarinfo(tinfo):
4247
tinfo.uid = tinfo.gid = 0
43-
tinfo.uname = tinfo.gname = 'root'
48+
tinfo.uname = tinfo.gname = "root"
4449
tinfo.mtime = timestamp
4550
tinfo.mode &= ~0o022
4651
return tinfo
4752

48-
inform('Filter %s --> %s.gz ' % (2 * (os.path.basename(tarname),)))
53+
54+
inform("Filter %s --> %s.gz " % (2 * (os.path.basename(tarname),)))
4955
for ti in tfin:
5056
tfout.addfile(fixtarinfo(ti), tfin.extractfile(ti))
5157

Diff for: doc/Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,3 @@ clean:
3131
rm -rf diffpy.srfitapi
3232
rm -f srfit_examples.zip
3333
$(MAKE) -C devmanual $@
34-

Diff for: doc/examples/coreshellnp.py

+30-27
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,15 @@
2222
"""
2323

2424
import numpy
25-
from scipy.optimize import leastsq
26-
2725
from pyobjcryst import loadCrystal
26+
from scipy.optimize import leastsq
2827

28+
from diffpy.srfit.fitbase import FitContribution, FitRecipe, FitResults, Profile
2929
from diffpy.srfit.pdf import PDFGenerator, PDFParser
30-
from diffpy.srfit.fitbase import Profile
31-
from diffpy.srfit.fitbase import FitContribution, FitRecipe
32-
from diffpy.srfit.fitbase import FitResults
3330

3431
####### Example Code
3532

33+
3634
def makeRecipe(stru1, stru2, datname):
3735
"""Create a fitting recipe for crystalline PDF data."""
3836

@@ -43,7 +41,7 @@ def makeRecipe(stru1, stru2, datname):
4341
parser = PDFParser()
4442
parser.parseFile(datname)
4543
profile.loadParsedData(parser)
46-
profile.setCalculationRange(xmin=1.5, xmax = 45, dx = 0.1)
44+
profile.setCalculationRange(xmin=1.5, xmax=45, dx=0.1)
4745

4846
## The ProfileGenerator
4947
# In order to fit the core and shell phases simultaneously, we must use two
@@ -66,15 +64,16 @@ def makeRecipe(stru1, stru2, datname):
6664
contribution = FitContribution("cdszns")
6765
contribution.addProfileGenerator(generator_cds)
6866
contribution.addProfileGenerator(generator_zns)
69-
contribution.setProfile(profile, xname = "r")
67+
contribution.setProfile(profile, xname="r")
7068

7169
# Set up the characteristic functions. We use a spherical CF for the core
7270
# and a spherical shell CF for the shell. Since this is set up as two
7371
# phases, we implicitly assume that the core-shell correlations contribute
7472
# very little to the PDF.
75-
from diffpy.srfit.pdf.characteristicfunctions import sphericalCF, shellCF
76-
contribution.registerFunction(sphericalCF, name = "f_CdS")
77-
contribution.registerFunction(shellCF, name = "f_ZnS")
73+
from diffpy.srfit.pdf.characteristicfunctions import shellCF, sphericalCF
74+
75+
contribution.registerFunction(sphericalCF, name="f_CdS")
76+
contribution.registerFunction(shellCF, name="f_ZnS")
7877

7978
# Write the fitting equation. We want to sum the PDFs from each phase and
8079
# multiply it by a scaling factor.
@@ -106,27 +105,28 @@ def makeRecipe(stru1, stru2, datname):
106105
# subsequent refinement.
107106
phase_cds = generator_cds.phase
108107
for par in phase_cds.sgpars.latpars:
109-
recipe.addVar(par, name = par.name + "_cds", tag = "lat")
108+
recipe.addVar(par, name=par.name + "_cds", tag="lat")
110109
for par in phase_cds.sgpars.adppars:
111-
recipe.addVar(par, 1, name = par.name + "_cds", tag = "adp")
112-
recipe.addVar(phase_cds.sgpars.xyzpars.z_1, name = "z_1_cds", tag = "xyz")
110+
recipe.addVar(par, 1, name=par.name + "_cds", tag="adp")
111+
recipe.addVar(phase_cds.sgpars.xyzpars.z_1, name="z_1_cds", tag="xyz")
113112
# Since we know these have stacking disorder, constrain the B33 adps for
114113
# each atom type.
115114
recipe.constrain("B33_1_cds", "B33_0_cds")
116-
recipe.addVar(generator_cds.delta2, name = "delta2_cds", value = 5)
115+
recipe.addVar(generator_cds.delta2, name="delta2_cds", value=5)
117116

118117
phase_zns = generator_zns.phase
119118
for par in phase_zns.sgpars.latpars:
120-
recipe.addVar(par, name = par.name + "_zns", tag = "lat")
119+
recipe.addVar(par, name=par.name + "_zns", tag="lat")
121120
for par in phase_zns.sgpars.adppars:
122-
recipe.addVar(par, 1, name = par.name + "_zns", tag = "adp")
123-
recipe.addVar(phase_zns.sgpars.xyzpars.z_1, name = "z_1_zns", tag = "xyz")
121+
recipe.addVar(par, 1, name=par.name + "_zns", tag="adp")
122+
recipe.addVar(phase_zns.sgpars.xyzpars.z_1, name="z_1_zns", tag="xyz")
124123
recipe.constrain("B33_1_zns", "B33_0_zns")
125-
recipe.addVar(generator_zns.delta2, name = "delta2_zns", value = 2.5)
124+
recipe.addVar(generator_zns.delta2, name="delta2_zns", value=2.5)
126125

127126
# Give the recipe away so it can be used!
128127
return recipe
129128

129+
130130
def plotResults(recipe):
131131
"""Plot the results contained within a refined FitRecipe."""
132132

@@ -138,10 +138,11 @@ def plotResults(recipe):
138138
diff = g - gcalc + diffzero
139139

140140
import pylab
141-
pylab.plot(r,g,'bo',label="G(r) Data")
142-
pylab.plot(r, gcalc,'r-',label="G(r) Fit")
143-
pylab.plot(r,diff,'g-',label="G(r) diff")
144-
pylab.plot(r,diffzero,'k-')
141+
142+
pylab.plot(r, g, "bo", label="G(r) Data")
143+
pylab.plot(r, gcalc, "r-", label="G(r) Fit")
144+
pylab.plot(r, diff, "g-", label="G(r) diff")
145+
pylab.plot(r, diffzero, "k-")
145146
pylab.xlabel(r"$r (\AA)$")
146147
pylab.ylabel(r"$G (\AA^{-2})$")
147148
pylab.legend(loc=1)
@@ -163,6 +164,7 @@ def main():
163164
stru2 = loadCrystal(znsciffile)
164165
recipe = makeRecipe(stru1, stru2, data)
165166
from diffpy.srfit.fitbase.fithook import PlotFitHook
167+
166168
recipe.pushFitHook(PlotFitHook())
167169
recipe.fithooks[0].verbose = 3
168170

@@ -172,23 +174,23 @@ def main():
172174
# Start with the lattice parameters. In makeRecipe, these were tagged with
173175
# "lat". Here is how we use that.
174176
recipe.free("lat")
175-
leastsq(recipe.residual, recipe.values, maxfev = 50)
177+
leastsq(recipe.residual, recipe.values, maxfev=50)
176178

177179
# Now the scale and phase fraction.
178180
recipe.free("scale", "scale_CdS")
179-
leastsq(recipe.residual, recipe.values, maxfev = 50)
181+
leastsq(recipe.residual, recipe.values, maxfev=50)
180182

181183
# The ADPs.
182184
recipe.free("adp")
183-
leastsq(recipe.residual, recipe.values, maxfev = 100)
185+
leastsq(recipe.residual, recipe.values, maxfev=100)
184186

185187
# The delta2 parameters.
186188
recipe.free("delta2_cds", "delta2_zns")
187-
leastsq(recipe.residual, recipe.values, maxfev = 50)
189+
leastsq(recipe.residual, recipe.values, maxfev=50)
188190

189191
# The shape parameters.
190192
recipe.free("radius", "thickness")
191-
leastsq(recipe.residual, recipe.values, maxfev = 50)
193+
leastsq(recipe.residual, recipe.values, maxfev=50)
192194

193195
# The positional parameters.
194196
recipe.free("xyz")
@@ -202,6 +204,7 @@ def main():
202204
plotResults(recipe)
203205
return
204206

207+
205208
if __name__ == "__main__":
206209
main()
207210

Diff for: doc/examples/crystalpdf.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,15 @@
2626
"""
2727

2828
import numpy
29+
from gaussianrecipe import scipyOptimize
2930

30-
from diffpy.structure import Structure
31+
from diffpy.srfit.fitbase import FitContribution, FitRecipe, FitResults, Profile
3132
from diffpy.srfit.pdf import PDFGenerator, PDFParser
32-
from diffpy.srfit.fitbase import Profile
33-
from diffpy.srfit.fitbase import FitContribution, FitRecipe
34-
from diffpy.srfit.fitbase import FitResults
35-
36-
from gaussianrecipe import scipyOptimize
33+
from diffpy.structure import Structure
3734

3835
####### Example Code
3936

37+
4038
def makeRecipe(ciffile, datname):
4139
"""Create a fitting recipe for crystalline PDF data."""
4240

@@ -53,7 +51,7 @@ def makeRecipe(ciffile, datname):
5351
parser = PDFParser()
5452
parser.parseFile(datname)
5553
profile.loadParsedData(parser)
56-
profile.setCalculationRange(xmax = 20)
54+
profile.setCalculationRange(xmax=20)
5755

5856
## The ProfileGenerator
5957
# The PDFGenerator is for configuring and calculating a PDF profile. Here,
@@ -72,7 +70,7 @@ def makeRecipe(ciffile, datname):
7270
# before.
7371
contribution = FitContribution("nickel")
7472
contribution.addProfileGenerator(generator)
75-
contribution.setProfile(profile, xname = "r")
73+
contribution.setProfile(profile, xname="r")
7674

7775
## Make the FitRecipe and add the FitContribution.
7876
recipe = FitRecipe()
@@ -95,6 +93,7 @@ def makeRecipe(ciffile, datname):
9593
# documentation for more details. The 'constrainAsSpaceGroup' method may
9694
# create new Parameters, which it returns in a SpaceGroupParameters object.
9795
from diffpy.srfit.structure import constrainAsSpaceGroup
96+
9897
sgpars = constrainAsSpaceGroup(phase, "Fm-3m")
9998

10099
# The SpaceGroupParameters object returned by 'constrainAsSpaceGroup' holds
@@ -124,6 +123,7 @@ def makeRecipe(ciffile, datname):
124123
# Give the recipe away so it can be used!
125124
return recipe
126125

126+
127127
def plotResults(recipe):
128128
"""Plot the results contained within a refined FitRecipe."""
129129

@@ -135,17 +135,19 @@ def plotResults(recipe):
135135
diff = g - gcalc + diffzero
136136

137137
import pylab
138-
pylab.plot(r,g,'bo',label="G(r) Data")
139-
pylab.plot(r, gcalc,'r-',label="G(r) Fit")
140-
pylab.plot(r,diff,'g-',label="G(r) diff")
141-
pylab.plot(r,diffzero,'k-')
138+
139+
pylab.plot(r, g, "bo", label="G(r) Data")
140+
pylab.plot(r, gcalc, "r-", label="G(r) Fit")
141+
pylab.plot(r, diff, "g-", label="G(r) diff")
142+
pylab.plot(r, diffzero, "k-")
142143
pylab.xlabel(r"$r (\AA)$")
143144
pylab.ylabel(r"$G (\AA^{-2})$")
144145
pylab.legend(loc=1)
145146

146147
pylab.show()
147148
return
148149

150+
149151
if __name__ == "__main__":
150152

151153
# Make the data and the recipe

0 commit comments

Comments
 (0)