def test_simple(self): grid = ag.EnergyGrid(bounds=ag.linspace(1, 2, 2)) self.assertEqual(1.0, grid.minEnergy, "Assert default min energy") self.assertEqual(2.0, grid.maxEnergy, "Assert default max energy") self.assertEqual("eV", grid.units, "Assert units") self.assertEqual(2, len(grid), "Assert length") self.assertEqual(1.0, grid[0], "Assert first") self.assertEqual(2.0, grid[-1], "Assert last") self.assertEqual(1, grid.nrofbins, "Assert nrofbins") self.assertEqual([1.5], list(grid.midpoints), "Assert mid points") self.assertEqual([1.0, 2.0], list(grid.bounds), "Assert bounds")
def getmaxcount(nrofbins): grid = ag.EnergyGrid(bounds=ag.linspace(MIN_ENERGY, MAX_ENERGY, math.floor(nrofbins) + 1)) # bin the lines appropriately lc = BinaryLineAggregator(db, grid) hist = np.zeros(grid.nrofbins) bin_edges = grid.bounds for nuclide in tqdm(db.allnuclidesoftype(spectype=SPECTYPE)): inv = ag.UnstablesInventory(data=[(db.getzai(nuclide), 1)]) h, _ = lc(inv, spectype=SPECTYPE) hist += h return np.max(hist)
bins = ag.logspace(0, 7, 30) y = [ 1707.0, 1707.0, 1680.0, 1625.0, 1499.0, 1300.0, 1116.0, 954.0, 780.0, 611.0, 448.0, 316.0, 214.0, 143.0, 101.0, 64.0, 44.0, 31.0, 26.0, 15.0, 14.0, 13.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0 ] plt.plot(bins, y, 'ko') plt.xscale('log') plt.yscale('log') plt.xlabel('Number of bins', fontsize=18) plt.ylabel('Max nr. unique nuclides', fontsize=18) # look at the lines for one type of binning. # bin the lines appropriately grid = ag.EnergyGrid(bounds=ag.linspace(MIN_ENERGY, MAX_ENERGY, 1000)) lc = BinaryLineAggregator(db, grid) hist = np.zeros(grid.nrofbins) bin_edges = grid.bounds for nuclide in tqdm(db.allnuclidesoftype(spectype=SPECTYPE)): inv = ag.UnstablesInventory(data=[(db.getzai(nuclide), 1)]) h, _ = lc(inv, spectype=SPECTYPE, include_same_nuclide=False) hist += h # make a plot of cumulative cumsum_hist = np.cumsum(hist) X, Y = ag.getplotvalues(bin_edges, cumsum_hist) fig = plt.figure(figsize=(12, 7)) plt.plot(X, Y, 'k') plt.xlabel("Energy ({})".format(grid.units), fontsize=18)
import matplotlib.pyplot as plt import actigamma as ag # normally gamma but could be something else - "alpha", "beta" if data exists! SPECTYPES = ["gamma", "x-ray"] # setup the DB db = ag.Decay2012Database() # define my unstable inventory by activities (Bq) inv = ag.UnstablesInventory(data=[ (db.getzai("Co60"), 9.87e13), ]) # define an energy grid between 0 and 4 MeV with 10,000 bins grid = ag.EnergyGrid(bounds=ag.linspace(0.0, 4e6, 10000)) # or we can do logspace between 1e3 eV and 1e7 eV with 10,000 bins # grid = ag.EnergyGrid(bounds=ag.logspace(3, 7, 10000)) # plt.xscale('log') # bin the lines appropriately lc = ag.MultiTypeLineAggregator(db, grid) hist, bin_edges = lc(inv, types=SPECTYPES) # make a plot X, Y = ag.getplotvalues(bin_edges, hist) fig = plt.figure(figsize=(12, 7)) plt.plot(X, Y, 'k') plt.xlabel("Energy ({})".format(grid.units), fontsize=18) plt.ylabel("{} per unit time (s-1)".format("+".join(SPECTYPES)), fontsize=18)
from sklearn.ensemble import RandomForestClassifier import actigamma as ag classifier = MultiOutputClassifier(RandomForestClassifier(n_estimators=100, max_features='auto', verbose=False)) # generate a dataset based on 100 bins from 0 to 4 MeV MINENERGY = 0.0 MAXENERGY = 4e6 NBINS = 1000 SPECTYPE = "gamma" # setup the DB db = ag.Decay2012Database() grid = ag.EnergyGrid(bounds=ag.linspace(MINENERGY, MAXENERGY, NBINS+1)) lc = ag.LineAggregator(db, grid) NSAMPLES = 1000 NNUCLIDES = 10 # randomly generate 100 samples based on 10 radionuclides radionuclides = db.allnuclidesoftype(spectype=SPECTYPE)[:NNUCLIDES] # ignore activity - set to 1 ACTIVITY = 1 datasetX, datasetY = [], [] for _ in range(NSAMPLES): # randomly pick between 1 and NNUCLIDIES to generate data nrofnuclides = random.randrange(1, NNUCLIDES+1) # pick nrofnuclides - must be unique nuclides = []