LabTools3 1.1.3.13__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.
@@ -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
- try:
346
- self.res = np.histogram(y, new = None, **kwargs)
347
- except:
348
- self.res = np.histogram(y, **kwargs)
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
- try:
357
- res = np.histogram(y, new = True, bins = self.res[1], **kwargs)
358
- except:
359
- res = np.histogram(y, bins = self.res[1], **kwargs)
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
@@ -1068,7 +1082,10 @@ class histo:
1068
1082
  self.bin_content = self.res[0]
1069
1083
  self.bins = self.res[1]
1070
1084
  if error is None:
1071
- self.bin_error = np.sqrt(self.bin_content)
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)
1072
1089
  else:
1073
1090
  self.bin_error = error
1074
1091
  self.__prepare_histo_plot()
@@ -1266,6 +1283,8 @@ class histo2d:
1266
1283
  xlabel Set the x-label
1267
1284
  ylabel Set the y-label
1268
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
1269
1288
  colorbar if True, plot a colorbar
1270
1289
  bad_color Set the color for plot for bins below zmin (default: w)
1271
1290
  logz if True plot content on log scale
@@ -1292,10 +1311,13 @@ class histo2d:
1292
1311
  bad_color = 'w',\
1293
1312
  colorbar = True, \
1294
1313
  logz = False,\
1314
+ calc_w2 = False,\
1295
1315
  **kwargs):
1316
+ self.has_weights = 'weights' in kwargs
1296
1317
  self.bad_color = bad_color # color for bad pixels
1297
1318
  self.colorbar = colorbar
1298
1319
  self.logz = logz
1320
+ self.calc_w2 = calc_w2
1299
1321
  # initialize fitting
1300
1322
  if (x_values is not None) and (y_values is not None):
1301
1323
  # values have been given for filling
@@ -1369,10 +1391,13 @@ class histo2d:
1369
1391
  """
1370
1392
  if not add:
1371
1393
  # a new filling
1372
- try:
1373
- self.res = np.histogram2d(x, y, new = None, **kwargs)
1374
- except:
1375
- self.res = np.histogram2d(x, y, **kwargs)
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
1376
1401
  self.__setup_bins(error = None)
1377
1402
  else:
1378
1403
  # the bins have already been defined continue
@@ -1381,8 +1406,15 @@ class histo2d:
1381
1406
  print("no binning information: try fill with add = False ")
1382
1407
  return
1383
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
1384
1415
  # add the new bin content to the old one
1385
1416
  self.res = (self.res[0] + res[0], self.res[1], self.res[2])
1417
+ self.w2 += w2
1386
1418
  # update the histogram information
1387
1419
  self.__setup_bins(error = None)
1388
1420
  # end of fill
@@ -1814,7 +1846,12 @@ class histo2d:
1814
1846
  self.x_bins = self.res[1]
1815
1847
  self.y_bins = self.res[2]
1816
1848
  if error is None:
1817
- self.bin_error = np.sqrt(self.bin_content)
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)
1818
1855
  else:
1819
1856
  self.bin_error = error
1820
1857
  self.__prepare_histo_plot()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: LabTools3
3
- Version: 1.1.3.13
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
@@ -48,3 +48,5 @@ Version 1.1.3.11: new control on title and axes labels for plotting
48
48
  Version 1.1.3.12: bug fixes, peak and background functions are available for histogram fits.
49
49
 
50
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.13
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
@@ -48,3 +48,5 @@ Version 1.1.3.11: new control on title and axes labels for plotting
48
48
  Version 1.1.3.12: bug fixes, peak and background functions are available for histogram fits.
49
49
 
50
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
@@ -33,4 +33,6 @@ Version 1.1.3.11: new control on title and axes labels for plotting
33
33
 
34
34
  Version 1.1.3.12: bug fixes, peak and background functions are available for histogram fits.
35
35
 
36
- Version 1.1.3.13: fitting of only one parameters enabled for linear fits
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
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
5
5
 
6
6
  setup(
7
7
  name = "LabTools3",
8
- version = "1.1.3.13",
8
+ version = "1.1.3.14",
9
9
  packages = find_packages(),
10
10
  # add additional files
11
11
  package_data = {'':['*.bat','*.command']},
File without changes
File without changes
File without changes