Skip to content

Commit

Permalink
Imporve Makefile speed for black
Browse files Browse the repository at this point in the history
  • Loading branch information
gb119 committed Dec 7, 2019
1 parent dd5693f commit 3432455
Show file tree
Hide file tree
Showing 48 changed files with 291 additions and 86 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ check:
prospector -E -0 --profile-path=. -P .landscape.yml Stoner > prospector-report.txt

black:
find Stoner -name '*.py' -exec black -l 119 {} \;
find doc/samples -name '*.py' -exec black {} \;
find scripts -name '*.py' -exec black {} \;
find Stoner -name '*.py' | xargs -d "\n" black -l 119
find doc/samples -name '*.py' | xargs -d "\n" black -l 80
find scripts -name '*.py' | xargs -d "\n" black -l 80

commit: black
$(MAKE) -C doc readme
Expand Down
3 changes: 2 additions & 1 deletion Stoner/analysis/fitting/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,7 @@ def lmfit(self, model, xcol=None, ycol=None, p0=None, sigma=None, **kargs):
replace=replace,
output=output,
residuals=residuals,
**kargs
)
else: # chi^2 mode
pn = p0
Expand All @@ -1373,7 +1374,7 @@ def lmfit(self, model, xcol=None, ycol=None, p0=None, sigma=None, **kargs):
p0, single_fit = _prep_lmfit_p0(
model, data[1], data[0], pn_i, kargs
) # model, data, params, prefix, columns, scale_covar,**kargs)
ret_val[i, :] = self.__lmfit_one(model, data, p0, prefix, _, scale_covar, output="row")
ret_val[i, :] = self.__lmfit_one(model, data, p0, prefix, _, scale_covar, output="row", **kargs)
if output == "data": # Create a data object and seet column headers etc correctly
ret = self.clone
ret.data = ret_val
Expand Down
4 changes: 3 additions & 1 deletion doc/samples/3D_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
x, y = np.meshgrid(np.linspace(-2, 2, 100), np.linspace(-2, 2, 100))
x = x.ravel()
y = y.ravel()
z = np.cos(4 * np.pi * np.sqrt(x ** 2 + y ** 2)) * np.exp(-np.sqrt(x ** 2 + y ** 2))
z = np.cos(4 * np.pi * np.sqrt(x ** 2 + y ** 2)) * np.exp(
-np.sqrt(x ** 2 + y ** 2)
)

p = Data()
p = p & x & y & z
Expand Down
16 changes: 13 additions & 3 deletions doc/samples/Fitting/BDR.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@
# Curve fit
d = Data(V, I, dI, setas="xye", column_headers=["Bias", "Current", "Noise"])

d.curve_fit(SF.bdr, p0=[2.5, 3.2, 0.3, 15.0, 1.0], result=True, header="curve_fit")
d.curve_fit(
SF.bdr, p0=[2.5, 3.2, 0.3, 15.0, 1.0], result=True, header="curve_fit"
)
d.setas = "xyey"
d.plot(fmt=["r.", "b-"])
d.annotate_fit(
SF.bdr, x=0.6, y=0.05, prefix="bdr", fontdict={"size": "x-small", "color": "blue"}
SF.bdr,
x=0.6,
y=0.05,
prefix="bdr",
fontdict={"size": "x-small", "color": "blue"},
)

# lmfit
Expand All @@ -35,7 +41,11 @@
d.setas = "x...y"
d.plot(fmt="g-")
d.annotate_fit(
fit, x=0.2, y=0.05, prefix="BDR", fontdict={"size": "x-small", "color": "green"}
fit,
x=0.2,
y=0.05,
prefix="BDR",
fontdict={"size": "x-small", "color": "green"},
)

d.ylabel = "Current"
Expand Down
4 changes: 3 additions & 1 deletion doc/samples/Fitting/FowlerNordheim.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

d = Data(V, I, dI, setas="xye", column_headers=["Bias", "Current", "Noise"])

d.curve_fit(SF.fowlerNordheim, p0=[2500, 3.2, 15.0], result=True, header="curve_fit")
d.curve_fit(
SF.fowlerNordheim, p0=[2500, 3.2, 15.0], result=True, header="curve_fit"
)
d.setas = "xyey"
d.plot(fmt=["r.", "b-"])
d.annotate_fit(
Expand Down
8 changes: 7 additions & 1 deletion doc/samples/Fitting/b_g.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
params2 = deepcopy(params)
G = SF.blochGrueneisen(T, *params) + normal(size=len(T), scale=5e-5)
dG = ones_like(T) * 5e-5
d = Data(T, G, dG, setas="xye", column_headers=["Temperature (K)", "Resistivity", "dR"])
d = Data(
T,
G,
dG,
setas="xye",
column_headers=["Temperature (K)", "Resistivity", "dR"],
)

d.curve_fit(SF.blochGrueneisen, p0=params, result=True, header="curve_fit")

Expand Down
5 changes: 4 additions & 1 deletion doc/samples/Fitting/f_s.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
d.plot(fmt=["r.", "b-", "g-"])

d.annotate_fit(
SF.fluchsSondheimer, x=0.2, y=0.6, fontdict={"size": "x-small", "color": "blue"}
SF.fluchsSondheimer,
x=0.2,
y=0.6,
fontdict={"size": "x-small", "color": "blue"},
)
d.annotate_fit(
SF.FluchsSondheimer,
Expand Down
14 changes: 12 additions & 2 deletions doc/samples/Fitting/langevin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
params = [1, 1.0e-11, 250]
G = SF.langevin(B, *params) + normal(size=len(B), scale=5e-3)
dG = ones_like(B) * 5e-3
d = Data(B, G, dG, setas="xye", column_headers=["Field $\\mu_0H (T)$", "Moment", "dM"])
d = Data(
B,
G,
dG,
setas="xye",
column_headers=["Field $\\mu_0H (T)$", "Moment", "dM"],
)

func = lambda H, M_s, m: SF.langevin(H, M_s, m, 250)

Expand All @@ -31,7 +37,11 @@
d.plot(fmt=["r.", "b-", "g-"])

d.annotate_fit(
func, x=0.1, y=0.5, fontdict={"size": "x-small", "color": "blue"}, mode="eng"
func,
x=0.1,
y=0.5,
fontdict={"size": "x-small", "color": "blue"},
mode="eng",
)
d.annotate_fit(
SF.Langevin,
Expand Down
8 changes: 6 additions & 2 deletions doc/samples/Fitting/modArrhenius.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@

# Make some data
T = linspace(200, 350, 101)
R = SF.modArrhenius(T, 1e6, 0.5, 1.5) * normal(scale=0.00005, loc=1.0, size=len(T))
R = SF.modArrhenius(T, 1e6, 0.5, 1.5) * normal(
scale=0.00005, loc=1.0, size=len(T)
)
d = Data(T, R, setas="xy", column_headers=["T", "Rate"])

# Curve_fit on its own
d.curve_fit(SF.modArrhenius, p0=[1e6, 0.5, 1.5], result=True, header="curve_fit")
d.curve_fit(
SF.modArrhenius, p0=[1e6, 0.5, 1.5], result=True, header="curve_fit"
)
d.setas = "xyy"
d.plot(fmt=["r.", "b-"])
d.annotate_fit(SF.modArrhenius, x=0.2, y=0.5)
Expand Down
4 changes: 3 additions & 1 deletion doc/samples/Fitting/weak_localisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
d.setas = "xyeyy"
d.plot(fmt=["r.", "b-", "g-"])

d.annotate_fit(SF.wlfit, x=0.05, y=0.75, fontdict={"size": "x-small", "color": "blue"})
d.annotate_fit(
SF.wlfit, x=0.05, y=0.75, fontdict={"size": "x-small", "color": "blue"}
)
d.annotate_fit(
SF.WLfit,
x=0.05,
Expand Down
6 changes: 5 additions & 1 deletion doc/samples/Vectorfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
from os import path

d = Data(path.join(__home__, "..", "sample-data", "OVF1.ovf"))
e = d.select(Z__between=(10, 11)).select(X__between=(10, 18)).select(Y__between=(5, 13))
e = (
d.select(Z__between=(10, 11))
.select(X__between=(10, 18))
.select(Y__between=(5, 13))
)
e.figure(figsize=(8, 4))

# 2D vectors on a 2D Field
Expand Down
4 changes: 3 additions & 1 deletion doc/samples/colormap_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
x, y = np.meshgrid(np.linspace(-2, 2, 100), np.linspace(-2, 2, 100))
x = x.ravel()
y = y.ravel()
z = np.cos(4 * np.pi * np.sqrt(x ** 2 + y ** 2)) * np.exp(-np.sqrt(x ** 2 + y ** 2))
z = np.cos(4 * np.pi * np.sqrt(x ** 2 + y ** 2)) * np.exp(
-np.sqrt(x ** 2 + y ** 2)
)

p = Data(np.column_stack((x, y, z)), column_headers=["X", "Y", "Z"])
p.setas = "xyz"
Expand Down
4 changes: 3 additions & 1 deletion doc/samples/contour_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
x, y = np.meshgrid(np.linspace(-2, 2, 100), np.linspace(-2, 2, 100))
x = x.ravel()
y = y.ravel()
z = np.cos(4 * np.pi * np.sqrt(x ** 2 + y ** 2)) * np.exp(-np.sqrt(x ** 2 + y ** 2))
z = np.cos(4 * np.pi * np.sqrt(x ** 2 + y ** 2)) * np.exp(
-np.sqrt(x ** 2 + y ** 2)
)

p = Data()
p = p & x & y & z
Expand Down
4 changes: 3 additions & 1 deletion doc/samples/curve_fit_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ def linear(x, m, c):

d = Data("curve_fit_data.dat", setas="xye")
d.plot(fmt="ro")
fit = d.curve_fit(linear, result=True, replace=False, header="Fit", output="report")
fit = d.curve_fit(
linear, result=True, replace=False, header="Fit", output="report"
)
d.setas = "x..y"
d.plot(fmt="b-")
d.annotate_fit(linear)
Expand Down
4 changes: 3 additions & 1 deletion doc/samples/curve_fit_plane.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def plane(coord, a, b, c):
d.plot_xyz(linewidth=0, cmap=cmap.jet)

txt = "$z=c-ax+by$\n"
txt += "\n".join([d.format("plane:{}".format(k), latex=True) for k in ["a", "b", "c"]])
txt += "\n".join(
[d.format("plane:{}".format(k), latex=True) for k in ["a", "b", "c"]]
)

ax = plt.gca(projection="3d")
ax.text(15, 5, -50, txt)
Expand Down
10 changes: 8 additions & 2 deletions doc/samples/curvefit_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@

# Make some data
x = linspace(0, 10.0, 101)
y = PowerLaw().func(x, 1e-1, 1.64) * random.normal(loc=1.0, scale=0.05, size=101)
y = PowerLaw().func(x, 1e-1, 1.64) * random.normal(
loc=1.0, scale=0.05, size=101
)
d = Data(x, y, column_headers=["Time", "Signal"], setas="xy")

# Do the fitting and plot the result
fit = d.curve_fit(
PowerLaw, result=True, header="LM-Model Fit", residuals=True, output="report"
PowerLaw,
result=True,
header="LM-Model Fit",
residuals=True,
output="report",
)

ODRModel = odr_Model(PowerLaw, p0=(1, 1))
Expand Down
7 changes: 6 additions & 1 deletion doc/samples/decompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
str_coeffs = [format_val(c, mode="eng") for c in coeffs.ravel()]
str_coeffs = reshape(array(str_coeffs), coeffs.shape)
d.plot()
d.text(-6, -800, "Coefficients\n{}".format(str_coeffs), fontdict={"size": "x-small"})
d.text(
-6,
-800,
"Coefficients\n{}".format(str_coeffs),
fontdict={"size": "x-small"},
)
d.ylabel = "Data"
d.title = "Decompose Example"
d.tight_layout()
9 changes: 8 additions & 1 deletion doc/samples/differential_evolution_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@

# Do the fitting and plot the result
fit = d.differential_evolution(
func, result=True, header="Fit", A=1, B=1, C=1, prefix="Model", residuals=True
func,
result=True,
header="Fit",
A=1,
B=1,
C=1,
prefix="Model",
residuals=True,
)

# Reset labels
Expand Down
20 changes: 16 additions & 4 deletions doc/samples/extrapolate-demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
x = linspace(1, 10, 101)
d = Data(
column_stack(
[x, (2 * x ** 2 - x + 2) + normal(size=len(x), scale=2.0), ones_like(x) * 2]
[
x,
(2 * x ** 2 - x + 2) + normal(size=len(x), scale=2.0),
ones_like(x) * 2,
]
),
setas="xye",
column_headers=["x", "y"],
Expand All @@ -24,8 +28,16 @@
d.title = "Extrapolation Demo"

errorfill(
extra_x, y2[:, 0], color="green", yerr=y2[:, 1], label="Quadratic Extrapolation"
extra_x,
y2[:, 0],
color="green",
yerr=y2[:, 1],
label="Quadratic Extrapolation",
)
errorfill(
extra_x, y3[:, 0], color="red", yerr=y3[:, 1], label="Cubic Extrapolation"
)
errorfill(
extra_x, y1[:, 0], color="blue", yerr=y1[:, 1], label="Linear Extrapolation"
)
errorfill(extra_x, y3[:, 0], color="red", yerr=y3[:, 1], label="Cubic Extrapolation")
errorfill(extra_x, y1[:, 0], color="blue", yerr=y1[:, 1], label="Linear Extrapolation")
plt.legend(loc=2)
4 changes: 3 additions & 1 deletion doc/samples/folder_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
# Have the amended results replace the existing data files
fldr.each.odr(Quadratic, output="data")
# Now take a slice through the metadata to get the files we want.
result_2 = fldr.metadata.slice(["y", "Quadratic:b", "Quadratic:b err"], output="Data")
result_2 = fldr.metadata.slice(
["y", "Quadratic:b", "Quadratic:b err"], output="Data"
)

# Set the columns assignments and plot
result_2.setas = "xye"
Expand Down
5 changes: 4 additions & 1 deletion doc/samples/image/STXMIMage_Demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
thisdir = dirname(__file__)

imgs = ImageFolder(type=STXMImage)
for fname in ["Sample_Image_2017-10-15_100.hdf5", "Sample_Image_2017-10-15_101.hdf5"]:
for fname in [
"Sample_Image_2017-10-15_100.hdf5",
"Sample_Image_2017-10-15_101.hdf5",
]:
# Load the image
img = STXMImage(join(thisdir, "..", "..", "..", "sample-data", fname))
img.gridimage().crop(5, -15, 5, -5, _=True) # regularise grid and crop
Expand Down
1 change: 1 addition & 0 deletions doc/samples/lmfit_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
datafile = join(__home__, "..", "sample-data", "PCAR Co Data.csv")

d = cfg_data_from_ini(config, datafile)
d.x += 0.244
model, p0 = cfg_model_from_ini(config, data=d)

fit = d.lmfit(model, result=True, header="lmfit", output="report")
Expand Down
9 changes: 8 additions & 1 deletion doc/samples/lmfit_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
# Do the fitting and plot the result
func = lambda x, A, B, C: A + B * exp(-x / C)
fit = d.lmfit(
func, result=True, header="Fit", A=1, B=1, C=1, residuals=True, output="report"
func,
result=True,
header="Fit",
A=1,
B=1,
C=1,
residuals=True,
output="report",
)

# Reset labels
Expand Down
4 changes: 3 additions & 1 deletion doc/samples/matrix_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import numpy as np

x, y = np.meshgrid(np.linspace(-2, 2, 101), np.linspace(-2, 2, 101))
z = np.cos(4 * np.pi * np.sqrt(x ** 2 + y ** 2)) * np.exp(-np.sqrt(x ** 2 + y ** 2))
z = np.cos(4 * np.pi * np.sqrt(x ** 2 + y ** 2)) * np.exp(
-np.sqrt(x ** 2 + y ** 2)
)

p = Data()
p = p & np.linspace(-2, 2, 101) & z
Expand Down
10 changes: 8 additions & 2 deletions doc/samples/odr_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@
d.setas = "x.yyy"
d.plot(fmt=["b-", "g-", "m-"], label=["lmfit", "odr", "diff.ev."])

d.annotate_fit(model, x=0.05, y=0.75, fontdict={"size": "x-small", "color": "blue"})
d.annotate_fit(
model, x=0.05, y=0.5, fontdict={"size": "x-small", "color": "green"}, prefix="odr"
model, x=0.05, y=0.75, fontdict={"size": "x-small", "color": "blue"}
)
d.annotate_fit(
model,
x=0.05,
y=0.5,
fontdict={"size": "x-small", "color": "green"},
prefix="odr",
)
d.annotate_fit(
model,
Expand Down

0 comments on commit 3432455

Please sign in to comment.