コード例 #1
0
 def test_initinvalid(self):
     with self.assertRaises(TypeError):
         ag.UnstablesInventory(data=[(10010, 1e20), (30040, 3.2e17), 8.9])
     with self.assertRaises(TypeError):
         ag.UnstablesInventory(data=[0.2, 3.5])
     with self.assertRaises(ValueError):
         ag.UnstablesInventory(data=([10010, 30040, 500461],
                                     [1e20, 3.2e17, 2.43e18]))
コード例 #2
0
    def test_avoiddirectaccess(self):
        inv = ag.UnstablesInventory(data=[(10010, 1e20)])

        with self.assertRaises(AttributeError):
            inv.zais = []
        with self.assertRaises(AttributeError):
            inv.activities = []

        self.assertEqual([10010], inv.zais, "Assert zais")
        self.assertEqual([1e20], inv.activities, "Assert activities")
コード例 #3
0
    def test_append(self):
        inv = ag.UnstablesInventory(data=[(10010, 1e20)])
        self.assertEqual([10010], inv.zais, "Assert zais")
        self.assertEqual([1e20], inv.activities, "Assert activity")
        self.assertEqual(1, len(inv), "Assert length")

        inv.append(260561, 3.5e19)
        inv.append(260570, 1.4e19)
        self.assertEqual([10010, 260561, 260570], inv.zais, "Assert zais")
        self.assertEqual([1e20, 3.5e19, 1.4e19], inv.activities,
                         "Assert activity")
        self.assertEqual(3, len(inv), "Assert length")
コード例 #4
0
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)
コード例 #5
0
 def test_findatoms(self):
     inv = ag.UnstablesInventory(
         data=[(10010, 1e20), (260571, 3e18), (30040, 1.56e17), (10010,
                                                                 2e20)])
     self.assertEqual(3e20, inv.findactivitybyzai(10010),
                      "Assert activity for zai 10010")
     self.assertEqual(0.0, inv.findactivitybyzai(-1),
                      "Assert activity for zai invalid zai")
     self.assertEqual(1.56e17, inv.findactivitybyzai(30040),
                      "Assert activity for zai 30040")
     self.assertEqual(3e18, inv.findactivitybyzai(260571),
                      "Assert activity for zai 260571")
     self.assertEqual(0.0, inv.findactivitybyzai(260570),
                      "Assert activity for zai 260570")
     self.assertEqual(3e18, inv.findactivitybyzai(260571),
                      "Assert activity for zai 260571")
     self.assertEqual(3e20, inv.findactivitybyzai(10010),
                      "Assert activity for zai 10010")
コード例 #6
0
    def test_appendsamezai(self):
        inv = ag.UnstablesInventory(data=[(10010, 1e20)])
        self.assertEqual([10010], inv.zais, "Assert zais")
        self.assertEqual([1e20], inv.activities, "Assert activities")
        self.assertEqual(1, len(inv), "Assert length")

        inv.append(260561, 3.5e19)
        inv.append(260570, 1.4e19)
        self.assertEqual([10010, 260561, 260570], inv.zais, "Assert zais")
        self.assertEqual([1e20, 3.5e19, 1.4e19], inv.activities,
                         "Assert activities")
        self.assertEqual(3, len(inv), "Assert length")

        # append the same zai - length should not increase
        inv.append(10010, 3.5e19)
        inv.append(260570, 2.4e19)
        self.assertEqual([10010, 260561, 260570], inv.zais, "Assert zais")
        self.assertEqual([1.35e20, 3.5e19, 3.8e19], inv.activities,
                         "Assert activities")
        self.assertEqual(3, len(inv), "Assert length")
コード例 #7
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)
plt.ylabel("Cumulative number of lines per bin".format(SPECTYPE), fontsize=18)

# normal hist
X, Y = ag.getplotvalues(bin_edges, hist)
fig = plt.figure(figsize=(12, 7))
plt.plot(X, Y, 'k')
コード例 #8
0
 def test_initvaliddefault(self):
     inv = ag.UnstablesInventory()
     self.assertEqual([], inv.zais, "Assert default zais")
     self.assertEqual([], inv.activities, "Assert default activity")
コード例 #9
0
 def test_initvalid(self):
     inv = ag.UnstablesInventory(data=[(10030, 38.321e4), (9202350,
                                                           3.2e17)])
     self.assertEqual([10030, 9202350], inv.zais, "Assert zais")
     self.assertEqual([38.321e4, 3.2e17], inv.activities, "Assert activity")
コード例 #10
0
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)
コード例 #11
0
ファイル: classifier.py プロジェクト: markharley12/actigamma
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 = []
    indices = []
    while len(nuclides) < nrofnuclides:
        indx = random.randrange(NNUCLIDES)
        nuclide = radionuclides[indx]
        if nuclide not in nuclides:
            nuclides.append(nuclide)
            indices.append(indx)

    inv = ag.UnstablesInventory(data=[(db.getzai(n), ACTIVITY) for n in nuclides])
    hist, _ = lc(inv, spectype=SPECTYPE)

    # use any bin > 0 = 1, else = 0
    X = [1 if bin > 0 else 0 for bin in hist ]

    datasetX.append(X)#np.array(X))
    datasetY.append(indices)#np.array(indices).astype('int'))

mlb = MultiLabelBinarizer()#classes=len(radionuclides))
datasetY = mlb.fit_transform(datasetY)

#datasetX = StandardScaler().fit_transform(datasetX)
X_train, X_test, y_train, y_test = \
    train_test_split(datasetX, datasetY, test_size=.4, random_state=42)
コード例 #12
0
    Uses the simple BinWiseNuclideIdentifer.
"""

import collections

import actigamma as ag

SPECTYPE = "gamma"

# database handle
db = ag.Decay2012Database()

# make a histogram from a dummy inventory
inv = ag.UnstablesInventory(data=[
    (db.getzai("Bi213"), 9.87e13),
    (db.getzai("Pm151"), 1.1e3),
])

# a dummy energy grid - must be fine to get anything reliable out
grid = ag.EnergyGrid(bounds=ag.linspace(0.0, 6e6, 10000))
lc = ag.LineAggregator(db, grid)
hist, _ = lc(inv, spectype=SPECTYPE)

# use the simple bin wise (brute force) identifier to
# get everything possible from the hist
ider = ag.BinWiseNuclideIdentifier(db)
id_nucs = ider(hist, grid, spectype=SPECTYPE, excludes=[])

# make one big list of all entries to count nuclide
# occurrences
nrofnonzerobins = 0