Skip to content

Commit 0951113

Browse files
committed
style
1 parent 818bc12 commit 0951113

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

pyobs/misc/plotter.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@
1919
#
2020
#################################################################################
2121

22+
2223
class empty_plt:
2324
def figure(*args, **kwargs):
2425
pass
25-
26+
2627
def plot(*args, **kwargs):
2728
pass
2829

2930
def pie(*args, **kwargs):
3031
pass
31-
32+
3233
def hist(*args, **kwargs):
3334
pass
3435

@@ -40,10 +41,10 @@ def fill_between(*args, **kwargs):
4041

4142
def xlabel(*args, **kwargs):
4243
pass
43-
44+
4445
def ylabel(*args, **kwargs):
4546
pass
46-
47+
4748
def title(*args, **kwargs):
4849
pass
4950

@@ -56,10 +57,12 @@ def ylim(*args, **kwargs):
5657
def legend(*args, **kwargs):
5758
pass
5859

60+
5961
try:
6062
import matplotlib.pyplot as plt
63+
6164
MATPLOTLIB = True
6265
except ImportError:
6366
MATPLOTLIB = False
6467

65-
plt = plt if MATPLOTLIB else empty_plt
68+
plt = plt if MATPLOTLIB else empty_plt

pyobs/optimize/chisquare.py

+21-21
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def chiexp(self, yobs, pdict, p0, plot, errinfo):
163163

164164
w, v = numpy.linalg.eig(self.Hmat(pdict, p0))
165165
mask = w != 0
166-
pyobs.assertion(sum(numpy.abs(w)>1e-16) == len(w), "Badly conditioned system")
166+
pyobs.assertion(sum(numpy.abs(w) > 1e-16) == len(w), "Badly conditioned system")
167167
winv = w
168168
winv[mask] = 1 / w[mask]
169169
Hinv = v @ numpy.diag(winv) @ v.T
@@ -175,8 +175,8 @@ def chiexp(self, yobs, pdict, p0, plot, errinfo):
175175
chiexp = yobs @ v
176176
_, ce, dce = chiexp.error_core(plot=plot, errinfo=errinfo, pfile=None)
177177
return w @ ce, w @ dce
178-
179-
178+
179+
180180
class mfit:
181181
r"""
182182
Class to perform fits to multiple observables, via the minimization
@@ -277,7 +277,6 @@ def __add__(self, mf):
277277
n += 1
278278
return res
279279

280-
281280
def check_yobs(self, yobs):
282281
if len(self.csq) > 1:
283282
pyobs.check_type(yobs, "yobs", list)
@@ -289,11 +288,11 @@ def check_yobs(self, yobs):
289288
f"Unexpected number of observables for {len(self.csq)} fits",
290289
)
291290
return yobs
292-
291+
293292
@pyobs.log_timer("mfit")
294293
def __call__(self, yobs, p0=None, min_search=None):
295294
yobs = self.check_yobs(yobs)
296-
295+
297296
if p0 is None:
298297
p0 = [1.0] * len(self.pdict)
299298
if min_search is None:
@@ -349,43 +348,44 @@ def chisquared(self, pars):
349348

350349
def chiexp(self, yobs, pars, plot=False, errinfo={}):
351350
yobs = self.check_yobs(yobs)
352-
351+
353352
ce, dce = 0, 0
354353
for i in range(len(self.csq)):
355354
tmp = self.csq[i].chiexp(yobs[i], self.pdict, pars.mean, plot, errinfo)
356355
ce += tmp[0]
357356
dce += tmp[1] ** 2
358357
return ce, dce**0.5
359358

360-
361359
def pvalue(self, rng, yobs, errinfo, plot=False, nmc=10000):
362-
yobs = self.check_yobs(yobs)
360+
yobs = self.check_yobs(yobs)
363361

364362
cexp = numpy.zeros(nmc)
365363
for i in range(len(self.csq)):
366364
n = self.csq[i].n
367-
365+
368366
C = yobs[i].covariance_matrix(errinfo)[0]
369367
w, _ = numpy.linalg.eig(C @ self.csq[i].PP)
370368
w -= self.c2 / n
371-
372-
cexp += rng.sample_normal(n*nmc).reshape(nmc,n)**2 @ w
373-
369+
370+
cexp += rng.sample_normal(n * nmc).reshape(nmc, n) ** 2 @ w
371+
374372
th = numpy.array(cexp) < 0.0
375373
p = 1.0 - numpy.mean(th)
376-
dp = numpy.std(th,ddof=1)/(nmc)**0.5
377-
374+
dp = numpy.std(th, ddof=1) / (nmc) ** 0.5
375+
378376
if plot:
379377
plt.figure()
380-
plt.title(f'p-value = {p:.2f} +- {dp:.2f}')
381-
h = plt.hist(cexp + self.c2, density=True, bins=40, label='MC')
378+
plt.title(f"p-value = {p:.2f} +- {dp:.2f}")
379+
h = plt.hist(cexp + self.c2, density=True, bins=40, label="MC")
382380
if h:
383-
plt.plot([self.c2,self.c2], [0,max(h[0])], label=r'$\chi^2$')
384-
plt.plot([self.ce,self.ce], [0,max(h[0])], label=r'$\chi_\mathrm{exp}$')
381+
plt.plot([self.c2, self.c2], [0, max(h[0])], label=r"$\chi^2$")
382+
plt.plot(
383+
[self.ce, self.ce], [0, max(h[0])], label=r"$\chi_\mathrm{exp}$"
384+
)
385385
plt.legend()
386-
386+
387387
return [p, dp, cexp]
388-
388+
389389
def eval(self, xax, pars):
390390
"""
391391
Evaluates the function on a list of coordinates using the parameters

0 commit comments

Comments
 (0)