LabTools3 1.1.3.11__tar.gz → 1.1.3.14__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {LabTools3-1.1.3.11 → labtools3-1.1.3.14}/LT/box.py +105 -28
- {LabTools3-1.1.3.11 → labtools3-1.1.3.14}/LT/plotting.py +48 -37
- {LabTools3-1.1.3.11 → labtools3-1.1.3.14}/LT_Fit/linear_fit.py +16 -3
- {LabTools3-1.1.3.11 → labtools3-1.1.3.14/LabTools3.egg-info}/PKG-INFO +7 -1
- {LabTools3-1.1.3.11/LabTools3.egg-info → labtools3-1.1.3.14}/PKG-INFO +7 -1
- {LabTools3-1.1.3.11 → labtools3-1.1.3.14}/README.md +7 -1
- {LabTools3-1.1.3.11 → labtools3-1.1.3.14}/setup.py +1 -1
- {LabTools3-1.1.3.11 → labtools3-1.1.3.14}/LICENSE +0 -0
- {LabTools3-1.1.3.11 → labtools3-1.1.3.14}/LT/MCA.py +0 -0
- {LabTools3-1.1.3.11 → labtools3-1.1.3.14}/LT/__init__.py +0 -0
- {LabTools3-1.1.3.11 → labtools3-1.1.3.14}/LT/datafile.py +0 -0
- {LabTools3-1.1.3.11 → labtools3-1.1.3.14}/LT/get_precision.py +0 -0
- {LabTools3-1.1.3.11 → labtools3-1.1.3.14}/LT/parameterfile.py +0 -0
- {LabTools3-1.1.3.11 → labtools3-1.1.3.14}/LT/pdatafile.py +0 -0
- {LabTools3-1.1.3.11 → labtools3-1.1.3.14}/LT_Fit/__init__.py +0 -0
- {LabTools3-1.1.3.11 → labtools3-1.1.3.14}/LT_Fit/gen_fit.py +0 -0
- {LabTools3-1.1.3.11 → labtools3-1.1.3.14}/LT_Fit/parameters.py +0 -0
- {LabTools3-1.1.3.11 → labtools3-1.1.3.14}/LabTools3.egg-info/SOURCES.txt +0 -0
- {LabTools3-1.1.3.11 → labtools3-1.1.3.14}/LabTools3.egg-info/dependency_links.txt +0 -0
- {LabTools3-1.1.3.11 → labtools3-1.1.3.14}/LabTools3.egg-info/top_level.txt +0 -0
- {LabTools3-1.1.3.11 → labtools3-1.1.3.14}/setup.cfg +0 -0
|
@@ -247,6 +247,8 @@ class histo:
|
|
|
247
247
|
title Set the title
|
|
248
248
|
xlabel Set the x-label
|
|
249
249
|
ylabel Set the y-label
|
|
250
|
+
calc_w2 If True calccultae the sum of the square of the weights for each bin to calculate the final bin error
|
|
251
|
+
weights Array of weight to increment the histogram with
|
|
250
252
|
============ =====================================================
|
|
251
253
|
|
|
252
254
|
Additional keyword arguments are passed to the :func:`numpy.histogram` function
|
|
@@ -265,8 +267,11 @@ class histo:
|
|
|
265
267
|
title = 'my histogram', \
|
|
266
268
|
xlabel = 'x-bin', \
|
|
267
269
|
ylabel = 'content', \
|
|
270
|
+
calc_w2 = False, \
|
|
268
271
|
**kwargs):
|
|
269
272
|
self.res = None
|
|
273
|
+
self.has_weights = 'weights' in kwargs
|
|
274
|
+
self.calc_w2 = calc_w2
|
|
270
275
|
self.fit_dict = {}
|
|
271
276
|
# initialize fitting
|
|
272
277
|
self.b0 = Parameter(0., 'b0')
|
|
@@ -342,10 +347,13 @@ class histo:
|
|
|
342
347
|
"""
|
|
343
348
|
if not add:
|
|
344
349
|
# a new filling
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
350
|
+
self.res = np.histogram(y, **kwargs)
|
|
351
|
+
if self.calc_w2 and self.has_weights:
|
|
352
|
+
w_loc = kwargs['weights']**2
|
|
353
|
+
# histogram with weights squared
|
|
354
|
+
kwargs1 = copy.copy(kwargs)
|
|
355
|
+
kwargs1['weights'] = w_loc
|
|
356
|
+
self.w2 = np.histogram(y, **kwargs1)[0] # save only the bin content
|
|
349
357
|
self.__setup_bins(error = None)
|
|
350
358
|
else:
|
|
351
359
|
# the bins have already been defined continue
|
|
@@ -353,12 +361,18 @@ class histo:
|
|
|
353
361
|
if self.res is None:
|
|
354
362
|
print("no binning information: try fill with add = False ")
|
|
355
363
|
return
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
364
|
+
|
|
365
|
+
res = np.histogram(y, bins = self.res[1], **kwargs)
|
|
366
|
+
if self.calc_w2 and self.has_weights:
|
|
367
|
+
w2 = kwargs['weights']**2
|
|
368
|
+
# histogram with weights squared
|
|
369
|
+
kwargs1 = copy.copy(kwargs)
|
|
370
|
+
kwargs1['weights'] = w2
|
|
371
|
+
w2 = np.histogram(y, **kwargs1)[0] # save only the bin content
|
|
360
372
|
# add the new bin content to the old one
|
|
361
373
|
self.res = (self.res[0] + res[0], self.res[1])
|
|
374
|
+
if self.calc_w2 and self.has_weights:
|
|
375
|
+
self.w2 += w2
|
|
362
376
|
# update the histogram information
|
|
363
377
|
self.__setup_bins(error = None)
|
|
364
378
|
# end of fill
|
|
@@ -399,24 +413,24 @@ class histo:
|
|
|
399
413
|
if (xmin is None) and (xmax is None):
|
|
400
414
|
if self.window_set:
|
|
401
415
|
sel = self.window_sel
|
|
402
|
-
|
|
416
|
+
sum_v = self.bin_content[sel].sum()
|
|
403
417
|
sum_err = np.sqrt( (self.bin_error[sel]**2).sum())
|
|
404
418
|
else:
|
|
405
|
-
|
|
419
|
+
sum_v = self.bin_content.sum()
|
|
406
420
|
sum_err = np.sqrt( (self.bin_error**2).sum())
|
|
407
421
|
elif (xmin is None):
|
|
408
422
|
sel = (self.bin_center <= xmax)
|
|
409
|
-
|
|
423
|
+
sum_v = self.bin_content[sel].sum()
|
|
410
424
|
sum_err = np.sqrt( (self.bin_error[sel]**2).sum())
|
|
411
425
|
elif (xmax is None):
|
|
412
426
|
sel = (xmin <= self.bin_center)
|
|
413
|
-
|
|
427
|
+
sum_v = (self.bin_content[sel]).sum()
|
|
414
428
|
sum_err = np.sqrt( (self.bin_error[sel]**2).sum())
|
|
415
429
|
else:
|
|
416
430
|
sel = (xmin <= self.bin_center) & (self.bin_center <= xmax)
|
|
417
|
-
|
|
431
|
+
sum_v = (self.bin_content[sel]).sum()
|
|
418
432
|
sum_err = np.sqrt( (self.bin_error[sel]**2).sum())
|
|
419
|
-
return (
|
|
433
|
+
return (sum_v, sum_err)
|
|
420
434
|
|
|
421
435
|
def copy(self):
|
|
422
436
|
"""
|
|
@@ -800,7 +814,7 @@ class histo:
|
|
|
800
814
|
# is there a range given, or is a window set
|
|
801
815
|
sel_all = np.ones_like(self.bin_center, dtype = 'bool')
|
|
802
816
|
if init:
|
|
803
|
-
self.init_gauss(xmin, xmax)
|
|
817
|
+
self.init_gauss(xmin, xmax, ignore_zeros)
|
|
804
818
|
if (xmin is None) and (xmax is None):
|
|
805
819
|
# check if a window is set
|
|
806
820
|
if self.window_set:
|
|
@@ -835,9 +849,10 @@ class histo:
|
|
|
835
849
|
self.fit_indx, = np.where(sel_w)
|
|
836
850
|
else:
|
|
837
851
|
self.fit_indx, = np.where(sel)
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
852
|
+
if not ignore_zeros:
|
|
853
|
+
# set minimal error to 1
|
|
854
|
+
is_zero = np.where(self.bin_error == 0.)
|
|
855
|
+
self.bin_error[is_zero] = 1.
|
|
841
856
|
# store the limits of fit_indx
|
|
842
857
|
self.fit_index_min = self.fit_indx.min()
|
|
843
858
|
self.fit_index_max = self.fit_indx.max()
|
|
@@ -909,7 +924,7 @@ class histo:
|
|
|
909
924
|
self.sigma.set(1.)
|
|
910
925
|
self.A.set(1.)
|
|
911
926
|
|
|
912
|
-
def init_gauss(self, xmin = None, xmax = None):
|
|
927
|
+
def init_gauss(self, xmin = None, xmax = None, ignore_zeros = True):
|
|
913
928
|
"""
|
|
914
929
|
|
|
915
930
|
Calculate the initial parameter guess for a gaussian. These parameters
|
|
@@ -952,9 +967,10 @@ class histo:
|
|
|
952
967
|
self.fit_indx, = np.where(sel_w)
|
|
953
968
|
else:
|
|
954
969
|
self.fit_indx, = np.where(sel)
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
970
|
+
if not ignore_zeros:
|
|
971
|
+
# set minimal error to 1
|
|
972
|
+
s_zero = np.where(self.bin_error == 0.)
|
|
973
|
+
self.bin_error[is_zero] = 1.
|
|
958
974
|
# do the fit
|
|
959
975
|
bin_content = self.bin_content[self.fit_indx]
|
|
960
976
|
bin_center = self.bin_center[self.fit_indx]
|
|
@@ -1008,6 +1024,44 @@ class histo:
|
|
|
1008
1024
|
fit_val = (self.b2()*x + self.b1())*x + self.b0() + \
|
|
1009
1025
|
self.A()*np.exp(-0.5*((x-self.mean())/self.sigma() )**2)
|
|
1010
1026
|
return fit_val
|
|
1027
|
+
|
|
1028
|
+
def gauss(self, x):
|
|
1029
|
+
"""
|
|
1030
|
+
|
|
1031
|
+
Return the value of the gauss function using the fitted parameters at x
|
|
1032
|
+
|
|
1033
|
+
|
|
1034
|
+
Parameters
|
|
1035
|
+
----------
|
|
1036
|
+
x : float
|
|
1037
|
+
|
|
1038
|
+
Returns
|
|
1039
|
+
-------
|
|
1040
|
+
gauss(x) : float
|
|
1041
|
+
fitted gaussian at x.
|
|
1042
|
+
|
|
1043
|
+
"""
|
|
1044
|
+
g_val = self.A()*np.exp(-0.5*((x-self.mean())/self.sigma() )**2)
|
|
1045
|
+
return g_val
|
|
1046
|
+
|
|
1047
|
+
def bkg(self, x):
|
|
1048
|
+
"""
|
|
1049
|
+
|
|
1050
|
+
Return the value of the fitted background at x
|
|
1051
|
+
|
|
1052
|
+
Parameters
|
|
1053
|
+
----------
|
|
1054
|
+
x : float
|
|
1055
|
+
|
|
1056
|
+
Returns
|
|
1057
|
+
-------
|
|
1058
|
+
b_val(x) : float
|
|
1059
|
+
fitted backgound at x.
|
|
1060
|
+
|
|
1061
|
+
"""
|
|
1062
|
+
b_val = (self.b2()*x + self.b1())*x + self.b0()
|
|
1063
|
+
return b_val
|
|
1064
|
+
|
|
1011
1065
|
def apply_calibration(self, cal):
|
|
1012
1066
|
"""
|
|
1013
1067
|
|
|
@@ -1028,7 +1082,10 @@ class histo:
|
|
|
1028
1082
|
self.bin_content = self.res[0]
|
|
1029
1083
|
self.bins = self.res[1]
|
|
1030
1084
|
if error is None:
|
|
1031
|
-
self.
|
|
1085
|
+
if not self.has_weights: # no weights specified
|
|
1086
|
+
self.bin_error = np.sqrt(self.bin_content)
|
|
1087
|
+
elif self.calc_w2: # weights given and sum(weights**2) calculated for each bin
|
|
1088
|
+
self.bin_error = np.sqrt(self.w2)
|
|
1032
1089
|
else:
|
|
1033
1090
|
self.bin_error = error
|
|
1034
1091
|
self.__prepare_histo_plot()
|
|
@@ -1226,6 +1283,8 @@ class histo2d:
|
|
|
1226
1283
|
xlabel Set the x-label
|
|
1227
1284
|
ylabel Set the y-label
|
|
1228
1285
|
zlabel Set the z-label
|
|
1286
|
+
calc_w2 If True calccultae the sum of the square of the weights for each bin to calculate the final bin error
|
|
1287
|
+
weights Array of weight to increment the histogram with
|
|
1229
1288
|
colorbar if True, plot a colorbar
|
|
1230
1289
|
bad_color Set the color for plot for bins below zmin (default: w)
|
|
1231
1290
|
logz if True plot content on log scale
|
|
@@ -1252,10 +1311,13 @@ class histo2d:
|
|
|
1252
1311
|
bad_color = 'w',\
|
|
1253
1312
|
colorbar = True, \
|
|
1254
1313
|
logz = False,\
|
|
1314
|
+
calc_w2 = False,\
|
|
1255
1315
|
**kwargs):
|
|
1316
|
+
self.has_weights = 'weights' in kwargs
|
|
1256
1317
|
self.bad_color = bad_color # color for bad pixels
|
|
1257
1318
|
self.colorbar = colorbar
|
|
1258
1319
|
self.logz = logz
|
|
1320
|
+
self.calc_w2 = calc_w2
|
|
1259
1321
|
# initialize fitting
|
|
1260
1322
|
if (x_values is not None) and (y_values is not None):
|
|
1261
1323
|
# values have been given for filling
|
|
@@ -1329,10 +1391,13 @@ class histo2d:
|
|
|
1329
1391
|
"""
|
|
1330
1392
|
if not add:
|
|
1331
1393
|
# a new filling
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1394
|
+
self.res = np.histogram2d(x, y, **kwargs)
|
|
1395
|
+
if self.calc_w2 and self.has_weights:
|
|
1396
|
+
w_loc = kwargs['weights']**2
|
|
1397
|
+
# histogram with weights squared
|
|
1398
|
+
kwargs1 = copy.copy(kwargs)
|
|
1399
|
+
kwargs1['weights'] = w_loc
|
|
1400
|
+
self.w2 = np.histogram2d(x,y, **kwargs1)[0] # save only the bin content
|
|
1336
1401
|
self.__setup_bins(error = None)
|
|
1337
1402
|
else:
|
|
1338
1403
|
# the bins have already been defined continue
|
|
@@ -1341,8 +1406,15 @@ class histo2d:
|
|
|
1341
1406
|
print("no binning information: try fill with add = False ")
|
|
1342
1407
|
return
|
|
1343
1408
|
res = np.histogram2d(x, y, bins = [self.x_bins,self.y_bins], **kwargs)
|
|
1409
|
+
if self.calc_w2 and self.has_weights:
|
|
1410
|
+
w_loc = kwargs['weights']**2
|
|
1411
|
+
# histogram with weights squared
|
|
1412
|
+
kwargs1 = copy.copy(kwargs)
|
|
1413
|
+
kwargs1['weights'] = w_loc
|
|
1414
|
+
w2 = np.histogram2d(x,y, bins = [self.x_bins,self.y_bins], **kwargs1)[0] # save only the bin content
|
|
1344
1415
|
# add the new bin content to the old one
|
|
1345
1416
|
self.res = (self.res[0] + res[0], self.res[1], self.res[2])
|
|
1417
|
+
self.w2 += w2
|
|
1346
1418
|
# update the histogram information
|
|
1347
1419
|
self.__setup_bins(error = None)
|
|
1348
1420
|
# end of fill
|
|
@@ -1774,7 +1846,12 @@ class histo2d:
|
|
|
1774
1846
|
self.x_bins = self.res[1]
|
|
1775
1847
|
self.y_bins = self.res[2]
|
|
1776
1848
|
if error is None:
|
|
1777
|
-
self.
|
|
1849
|
+
if not self.has_weights: # no weights specified
|
|
1850
|
+
self.bin_error = np.sqrt(self.bin_content)
|
|
1851
|
+
elif self.calc_w2: # weights given and sum(weights**2) calculated for each bin
|
|
1852
|
+
self.bin_error = np.sqrt(self.w2)
|
|
1853
|
+
else:
|
|
1854
|
+
self.bin_error = np.sqrt(self.bin_content)
|
|
1778
1855
|
else:
|
|
1779
1856
|
self.bin_error = error
|
|
1780
1857
|
self.__prepare_histo_plot()
|
|
@@ -48,6 +48,7 @@ def plot_exp(x,\
|
|
|
48
48
|
# set general line width
|
|
49
49
|
linewidth=2,\
|
|
50
50
|
logy = False,\
|
|
51
|
+
logx = False, \
|
|
51
52
|
min_val = None,\
|
|
52
53
|
scale = 1.,\
|
|
53
54
|
# labelling
|
|
@@ -82,6 +83,7 @@ def plot_exp(x,\
|
|
|
82
83
|
marker marker type (see :func:`~matplotlib.pyplot.plot`)
|
|
83
84
|
linestyle line style (see :func:`~matplotlib.pyplot.plot`)
|
|
84
85
|
logy use log y-scale (True/False)
|
|
86
|
+
logx use log x-scale (True/False)
|
|
85
87
|
label label for data (used in :func:`~matplotlib.pyplot.legend` )
|
|
86
88
|
min_val min. values to be plotted
|
|
87
89
|
scale scale ally-values (including errrors ) by this factor
|
|
@@ -105,7 +107,9 @@ def plot_exp(x,\
|
|
|
105
107
|
axes = pl.gca()
|
|
106
108
|
if logy:
|
|
107
109
|
axes.set_yscale("log", nonpositive='clip')
|
|
108
|
-
if
|
|
110
|
+
if logx:
|
|
111
|
+
axes.set_xscale("log", nonpositive='clip')
|
|
112
|
+
if len(dy) == 0:
|
|
109
113
|
# no error bars
|
|
110
114
|
e=axes.plot(xx, yy,\
|
|
111
115
|
linestyle=linestyle,\
|
|
@@ -121,7 +125,7 @@ def plot_exp(x,\
|
|
|
121
125
|
axes.set_title(plot_title)
|
|
122
126
|
return e
|
|
123
127
|
# plot second (total) error bar behind first (statistical) one
|
|
124
|
-
if dyt !=
|
|
128
|
+
if len(dyt) != 0:
|
|
125
129
|
# in case ther are several different errors
|
|
126
130
|
et=axes.errorbar(xx, \
|
|
127
131
|
yy, \
|
|
@@ -175,6 +179,7 @@ def plot_line(x,\
|
|
|
175
179
|
y, \
|
|
176
180
|
label='_nolegend_',\
|
|
177
181
|
logy = False, \
|
|
182
|
+
logx = False, \
|
|
178
183
|
convx = 1., \
|
|
179
184
|
convy = 1., \
|
|
180
185
|
axes = None, \
|
|
@@ -195,6 +200,7 @@ def plot_line(x,\
|
|
|
195
200
|
============ =====================================================
|
|
196
201
|
label label for curve (used in :func:`~matplotlib.pyplot.legend` )
|
|
197
202
|
logy use log y-scale (True/False)
|
|
203
|
+
logx use log x-scale (True/False)
|
|
198
204
|
convx scale all x-values by this factor
|
|
199
205
|
convy scale all y-values by this factor
|
|
200
206
|
============ =====================================================
|
|
@@ -206,10 +212,11 @@ def plot_line(x,\
|
|
|
206
212
|
axes = pl.gca()
|
|
207
213
|
xx = np.array(x) * convx
|
|
208
214
|
yy = np.array(y) * convy
|
|
215
|
+
s=axes.plot(xx, yy, marker='None',label=label,**kwargs)
|
|
209
216
|
if logy:
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
217
|
+
axes.set_yscale("log", nonpositive='clip')
|
|
218
|
+
if logx:
|
|
219
|
+
axes.set_xscale("log", nonpositive='clip')
|
|
213
220
|
return s
|
|
214
221
|
|
|
215
222
|
#----------------------------------------------------------------------
|
|
@@ -225,6 +232,7 @@ def plot_spline(x, \
|
|
|
225
232
|
convx = 1., \
|
|
226
233
|
convy = 1., \
|
|
227
234
|
logy = False,\
|
|
235
|
+
logx = False, \
|
|
228
236
|
axes = None, \
|
|
229
237
|
**kwargs):
|
|
230
238
|
"""
|
|
@@ -243,6 +251,7 @@ def plot_spline(x, \
|
|
|
243
251
|
============ =====================================================
|
|
244
252
|
label label for curve (used in :func:`~matplotlib.pyplot.legend` )
|
|
245
253
|
logy use log y-scale (True/False)
|
|
254
|
+
logx use log x-scale (True/False)
|
|
246
255
|
nstep factor by which the number of interpolated data points is increased
|
|
247
256
|
convx scale all x-values by this factor
|
|
248
257
|
convy scale all y-values by this factor
|
|
@@ -266,15 +275,15 @@ def plot_spline(x, \
|
|
|
266
275
|
# now get interpolation coefficients
|
|
267
276
|
yvar_cj = splrep(xvar,yvar)
|
|
268
277
|
new_yvar = splev(new_xvar, yvar_cj)
|
|
278
|
+
s=axes.plot(new_xvar, new_yvar, marker=marker,\
|
|
279
|
+
label=label,\
|
|
280
|
+
**kwargs)
|
|
269
281
|
if logy:
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
else:
|
|
274
|
-
s=axes.plot(new_xvar, new_yvar, marker=marker,\
|
|
275
|
-
label=label,\
|
|
276
|
-
**kwargs)
|
|
282
|
+
axes.set_yscale("log", nonpositive='clip')
|
|
283
|
+
if logx:
|
|
284
|
+
axes.set_xscale("log", nonpositive='clip')
|
|
277
285
|
return s
|
|
286
|
+
|
|
278
287
|
#----------------------------------------------------------------------
|
|
279
288
|
#----------------------------------------------------------------------
|
|
280
289
|
# plot spline lines only, this has to be used carefully
|
|
@@ -287,6 +296,7 @@ def log_plot_spline(x, \
|
|
|
287
296
|
nstep = 5,\
|
|
288
297
|
conv = 1., \
|
|
289
298
|
axes = None, \
|
|
299
|
+
logx = False, \
|
|
290
300
|
**kwargs):
|
|
291
301
|
if (axes == None):
|
|
292
302
|
axes = pl.gca()
|
|
@@ -306,6 +316,8 @@ def log_plot_spline(x, \
|
|
|
306
316
|
s=axes.semilogy(new_xvar, new_yvar, marker=marker,\
|
|
307
317
|
label=label,\
|
|
308
318
|
**kwargs)
|
|
319
|
+
if logx:
|
|
320
|
+
axes.set_xscale("log", nonpositive='clip')
|
|
309
321
|
return s
|
|
310
322
|
#----------------------------------------------------------------------
|
|
311
323
|
# plot data read using data file
|
|
@@ -332,6 +344,7 @@ def datafile_plot_exp(set,\
|
|
|
332
344
|
linewidth=2,\
|
|
333
345
|
# set for semilog plot
|
|
334
346
|
logy = False,\
|
|
347
|
+
logx = False, \
|
|
335
348
|
# minimum value for semilog plot
|
|
336
349
|
min_val = None,\
|
|
337
350
|
scale = 1.,\
|
|
@@ -369,7 +382,8 @@ def datafile_plot_exp(set,\
|
|
|
369
382
|
marker marker type (see :func:`~matplotlib.pyplot.plot`)
|
|
370
383
|
linestyle line style (see :func:`~matplotlib.pyplot.plot`)
|
|
371
384
|
label label for data (used in :func:`~matplotlib.pyplot.legend` )
|
|
372
|
-
logy use log y-scale (True/False)
|
|
385
|
+
logy use log y-scale (True/False)
|
|
386
|
+
logx use log x-scale (True/False)
|
|
373
387
|
min_val min. values to be plotted
|
|
374
388
|
scale scale all y-values (including errrors ) by this factor
|
|
375
389
|
x_label label for x-axis
|
|
@@ -393,6 +407,8 @@ def datafile_plot_exp(set,\
|
|
|
393
407
|
yy = np.array(set.get_data(y))*scale
|
|
394
408
|
if logy:
|
|
395
409
|
axes.set_yscale("log", nonpositive='clip')
|
|
410
|
+
if logx:
|
|
411
|
+
axes.set_xscale("log", nonpositive='clip')
|
|
396
412
|
if dy != None:
|
|
397
413
|
dyy = np.array(set.get_data(dy))*scale
|
|
398
414
|
dyyt = []
|
|
@@ -407,7 +423,7 @@ def datafile_plot_exp(set,\
|
|
|
407
423
|
label=label, \
|
|
408
424
|
**kwargs)
|
|
409
425
|
# plot second (total) error bar behind first (statistical) one
|
|
410
|
-
elif dyyt !=
|
|
426
|
+
elif len(dyyt) != 0:
|
|
411
427
|
# in case ther are several different errors
|
|
412
428
|
et=axes.errorbar(xx, \
|
|
413
429
|
yy, \
|
|
@@ -474,6 +490,7 @@ def datafile_plot_theory(set,\
|
|
|
474
490
|
convx = 1.,\
|
|
475
491
|
convy = 1.,\
|
|
476
492
|
logy = False,\
|
|
493
|
+
logx = False, \
|
|
477
494
|
axes = None, \
|
|
478
495
|
**kwargs):
|
|
479
496
|
"""
|
|
@@ -487,19 +504,17 @@ def datafile_plot_theory(set,\
|
|
|
487
504
|
xvar = np.array(set.get_data(x) )*convx
|
|
488
505
|
yvar = np.array(set.get_data(y))*convy
|
|
489
506
|
|
|
507
|
+
s=axes.plot(xvar, yvar, marker=marker,color=color, \
|
|
508
|
+
label=label,\
|
|
509
|
+
**kwargs)
|
|
510
|
+
|
|
490
511
|
if logy:
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
s=axes.semilogy(xvar, yvar, marker=marker,color=color, \
|
|
495
|
-
label=label,\
|
|
496
|
-
**kwargs)
|
|
497
|
-
else:
|
|
498
|
-
s=axes.plot(xvar, yvar, marker=marker,color=color, \
|
|
499
|
-
label=label,\
|
|
500
|
-
**kwargs)
|
|
512
|
+
axes.set_yscale("log", nonpositive='clip')
|
|
513
|
+
if logx:
|
|
514
|
+
axes.set_xscale("log", nonpositive='clip')
|
|
501
515
|
return s
|
|
502
516
|
|
|
517
|
+
|
|
503
518
|
#----------------------------------------------------------------------
|
|
504
519
|
#plot spline lines only, this has to be used carefully
|
|
505
520
|
def datafile_spline_plot_theory(set,\
|
|
@@ -513,6 +528,7 @@ def datafile_spline_plot_theory(set,\
|
|
|
513
528
|
convx = 1.,\
|
|
514
529
|
convy = 1.,\
|
|
515
530
|
logy = False,\
|
|
531
|
+
logx = False, \
|
|
516
532
|
axes = None, \
|
|
517
533
|
**kwargs):
|
|
518
534
|
"""
|
|
@@ -528,23 +544,18 @@ def datafile_spline_plot_theory(set,\
|
|
|
528
544
|
# number of interpolation steps
|
|
529
545
|
new_xvar = np.linspace(xvar[0], xvar[-1:], int(nstep*len(xvar)) ) # create a new range with more points
|
|
530
546
|
# handle 0 and neg values for log scale
|
|
531
|
-
if logy:
|
|
532
|
-
for i in range(len(xvar)):
|
|
533
|
-
if yvar[i] <= 0. :
|
|
534
|
-
yvar[i] = min_val
|
|
535
547
|
# now get interpolation coefficients
|
|
536
548
|
yvar_cj = splrep(xvar,yvar)
|
|
537
549
|
new_yvar = splev(new_xvar, yvar_cj)
|
|
550
|
+
s=axes.plot(new_xvar, new_yvar, marker=marker,\
|
|
551
|
+
color=color,\
|
|
552
|
+
label=label,\
|
|
553
|
+
**kwargs)
|
|
538
554
|
if logy:
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
else:
|
|
544
|
-
s=axes.plot(new_xvar, new_yvar, marker=marker,\
|
|
545
|
-
color=color,\
|
|
546
|
-
label=label,\
|
|
547
|
-
**kwargs)
|
|
555
|
+
axes.set_yscale("log", nonpositive='clip')
|
|
556
|
+
if logx:
|
|
557
|
+
axes.set_xscale("log", nonpositive='clip')
|
|
558
|
+
|
|
548
559
|
return s
|
|
549
560
|
|
|
550
561
|
#----------------------------------------------------------------------
|
|
@@ -30,6 +30,7 @@ def linfit(function, y, x = None, y_err = None, nplot = 100):
|
|
|
30
30
|
if x is None: x = arange(y.shape[0])
|
|
31
31
|
#
|
|
32
32
|
# pdb.set_trace()
|
|
33
|
+
|
|
33
34
|
A = function(x).transpose()
|
|
34
35
|
if y_err is None:
|
|
35
36
|
weight = ones_like(y)
|
|
@@ -39,14 +40,21 @@ def linfit(function, y, x = None, y_err = None, nplot = 100):
|
|
|
39
40
|
# store the parameter values in a list to be passed to the fitting function
|
|
40
41
|
M = dot(Aw.transpose(),A)
|
|
41
42
|
# invert the matrix
|
|
42
|
-
|
|
43
|
+
if np.isscalar(M):
|
|
44
|
+
# check if only one parameter
|
|
45
|
+
Mi = np.expand_dims(np.array([1./M]), 0)
|
|
46
|
+
else:
|
|
47
|
+
Mi = linalg.inv(M)
|
|
43
48
|
b=dot(Aw.transpose(),y)
|
|
44
49
|
par = dot(Mi,b)
|
|
45
50
|
# for the calculation of errors
|
|
46
51
|
# sigma = sqrt( diag(Mi) )
|
|
47
52
|
# final total chi square
|
|
48
53
|
# number of degrees of freedom
|
|
49
|
-
|
|
54
|
+
fux = function(x)
|
|
55
|
+
if fux.ndim == 1:
|
|
56
|
+
fux = np.expand_dims(fux, 0)
|
|
57
|
+
yfit = dot(par,fux)
|
|
50
58
|
n_dof = len(y) - len(par)
|
|
51
59
|
diff = yfit - y
|
|
52
60
|
chi2 = sum( power(diff, 2 )*weight )
|
|
@@ -56,7 +64,12 @@ def linfit(function, y, x = None, y_err = None, nplot = 100):
|
|
|
56
64
|
# create an array with calculated values for plotting
|
|
57
65
|
if (nplot > 0):
|
|
58
66
|
xpl = linspace(x.min(), x.max(), nplot+1)
|
|
59
|
-
|
|
67
|
+
fux = function(xpl)
|
|
68
|
+
if fux.ndim ==1 :
|
|
69
|
+
fux = np.expand_dims(fux, 0)
|
|
70
|
+
ypl = np.squeeze(dot(par,fux))
|
|
71
|
+
else:
|
|
72
|
+
ypl = dot(par,fux)
|
|
60
73
|
stat = {'chisquare': chi2, \
|
|
61
74
|
'red. chisquare':chi2_red, \
|
|
62
75
|
'conf. level':CL, \
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: LabTools3
|
|
3
|
-
Version: 1.1.3.
|
|
3
|
+
Version: 1.1.3.14
|
|
4
4
|
Summary: Python 3 Package of modules for typical analysis tasks analyzing physics data
|
|
5
5
|
Home-page: http://wanda.fiu.edu/LabTools3
|
|
6
6
|
Author: Werner Boeglin
|
|
@@ -44,3 +44,9 @@ Version 1.1.3.9: Fixed a bug in *histo* where histogram window variable was not
|
|
|
44
44
|
Version 1.1.3.10: 2d histo now accepts axes as keywords. Make sure for 3d display the axes is a Axes3DSubplot.
|
|
45
45
|
|
|
46
46
|
Version 1.1.3.11: new control on title and axes labels for plotting
|
|
47
|
+
|
|
48
|
+
Version 1.1.3.12: bug fixes, peak and background functions are available for histogram fits.
|
|
49
|
+
|
|
50
|
+
Version 1.1.3.13: fitting of only one parameters enabled for linear fits
|
|
51
|
+
|
|
52
|
+
Version 1.1.3.14: error calcualtion for filling histograms with weights include sum of weight**2
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: LabTools3
|
|
3
|
-
Version: 1.1.3.
|
|
3
|
+
Version: 1.1.3.14
|
|
4
4
|
Summary: Python 3 Package of modules for typical analysis tasks analyzing physics data
|
|
5
5
|
Home-page: http://wanda.fiu.edu/LabTools3
|
|
6
6
|
Author: Werner Boeglin
|
|
@@ -44,3 +44,9 @@ Version 1.1.3.9: Fixed a bug in *histo* where histogram window variable was not
|
|
|
44
44
|
Version 1.1.3.10: 2d histo now accepts axes as keywords. Make sure for 3d display the axes is a Axes3DSubplot.
|
|
45
45
|
|
|
46
46
|
Version 1.1.3.11: new control on title and axes labels for plotting
|
|
47
|
+
|
|
48
|
+
Version 1.1.3.12: bug fixes, peak and background functions are available for histogram fits.
|
|
49
|
+
|
|
50
|
+
Version 1.1.3.13: fitting of only one parameters enabled for linear fits
|
|
51
|
+
|
|
52
|
+
Version 1.1.3.14: error calcualtion for filling histograms with weights include sum of weight**2
|
|
@@ -29,4 +29,10 @@ Version 1.1.3.9: Fixed a bug in *histo* where histogram window variable was not
|
|
|
29
29
|
|
|
30
30
|
Version 1.1.3.10: 2d histo now accepts axes as keywords. Make sure for 3d display the axes is a Axes3DSubplot.
|
|
31
31
|
|
|
32
|
-
Version 1.1.3.11: new control on title and axes labels for plotting
|
|
32
|
+
Version 1.1.3.11: new control on title and axes labels for plotting
|
|
33
|
+
|
|
34
|
+
Version 1.1.3.12: bug fixes, peak and background functions are available for histogram fits.
|
|
35
|
+
|
|
36
|
+
Version 1.1.3.13: fitting of only one parameters enabled for linear fits
|
|
37
|
+
|
|
38
|
+
Version 1.1.3.14: error calcualtion for filling histograms with weights include sum of weight**2
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|