Example #1
0
def test_decay_normalize_spectra(radioisotope):
    """Test decay_normalize_spectra()"""

    t0 = datetime.datetime.now()
    t1 = t0 + datetime.timedelta(hours=1)
    spec1 = Spectrum(np.zeros(256), start_time=t0, stop_time=t1)
    assert np.isclose(decay_normalize_spectra(radioisotope, spec1, spec1), 1)

    # avoid numerical issues with large half-lives (#65)
    # and underflow with small half-lives
    # note: 2^(-(1 day) / (85 seconds)) ~ sys.float_info.min
    if radioisotope.half_life < 90 or radioisotope.half_life > 1000 * 3.156e7:
        pass
    else:
        t2 = t0 + datetime.timedelta(days=1)
        t3 = t1 + datetime.timedelta(days=1)
        spec2 = Spectrum(np.zeros(256), start_time=t2, stop_time=t3)
        assert decay_normalize_spectra(radioisotope, spec1, spec2) > 1
        assert decay_normalize_spectra(radioisotope, spec2, spec1) < 1
Example #2
0
def test_isotopequantity_decays_during(iq):
    """Test IsotopeQuantity.*_during()"""

    if iq.half_life > 1000 * 3.156e7:
        # avoid overflow errors in test calculations
        pass
    else:
        dt_s = iq.half_life
        t0 = iq.ref_date
        t1 = t0 + datetime.timedelta(seconds=dt_s)
        spec = Spectrum(np.zeros(256), start_time=t0, stop_time=t1)

        assert np.isclose(iq.decays_during(spec), iq.atoms_at(t0) / 2)
        assert np.isclose(iq.bq_during(spec), iq.decays_during(spec) / dt_s)
        assert np.isclose(iq.uci_during(spec), iq.bq_during(spec) / UCI_TO_BQ)
import numpy as np
import matplotlib.pyplot as plt
from becquerel.tools.isotope import Isotope
from becquerel.tools.isotope_qty import IsotopeQuantity, NeutronIrradiation
import datetime
from becquerel import Spectrum
import Calibration_sources as ca
from scipy.optimize import curve_fit

"""creates efficiency data needed to calculate concetrations of
isotopes present in the measured samples"""

#create a queue of the calibration sources used
Na_22_spec = Spectrum.from_file('/Users/jackiegasca/Documents/Ca_sources/Na_22_flat_against_detector_531.Spe')
Mn_54_spec = Spectrum.from_file('/Users/jackiegasca/Documents/Ca_sources/Mn_54_flat_against_detector_1264-96-2.Spe')
Co_57_spec = Spectrum.from_file('/Users/jackiegasca/Documents/Ca_sources/Co_57_flat_against_detector_1264-96-3.Spe')
Cd_109_spec = Spectrum.from_file('/Users/jackiegasca/Documents/Ca_sources/Cd_109_flat_against_detector_1264-96-8.Spe')
Th_228_spec = Spectrum.from_file('/Users/jackiegasca/Documents/Ca_sources/Th_228_flat_against_detector_1415-83.Spe')
Eu_152_spec = Spectrum.from_file('/Users/jackiegasca/Documents/Ca_sources/Eu_152_flat_against_detector_1316-97-2.Spe')


Na_22_start = Na_22_spec.start_time
Mn_54_start = Mn_54_spec.start_time
Co_57_start = Co_57_spec.start_time
Cd_109_start = Cd_109_spec.start_time
Th_228_start = Th_228_spec.start_time
Eu_152_start = Eu_152_spec.start_time

Na_22_init_act = IsotopeQuantity('na22', date=ca.Na_22.date, uci=ca.Na_22.init_act)
Na_22_act = Na_22_init_act.bq_at(Na_22_start)
Mn_54_init_act = IsotopeQuantity('mn54', date=ca.Mn_54.date, uci=ca.Mn_54.init_act)
import numpy as np
from becquerel.tools.isotope import Isotope
from becquerel.tools.isotope_qty import IsotopeQuantity, NeutronIrradiation
import datetime
from becquerel import Spectrum
import efficiencies as ef
from bs4 import BeautifulSoup
import urllib.request
import math
import NAA_Isotopes as na
from uncertainties import ufloat



#load a spectra for testing
spec_S1 = Spectrum.from_file('/Users/jackiegasca/Documents/spectras/Sample1_30m_C.Spe')

back_spec = Spectrum.from_file('/Users/jackiegasca/Documents/2017.5.1_long_background.Spe')


#For now, just use an existing dictionary/class of isotopes
spec_S1_ener_spec = spec_S1.energies_kev[0:len(spec_S1)]
back_ener_spec = back_spec.energies_kev[0:len(back_spec)]

isotope_list = [na.Br_82, na.Na_24, na.Sb_122, na.K_42]
#Info regarding the irradiation:
irr_start = '2017-04-27 14:02:00'
irr_stop = '2017-04-27 14:12:00'
flux = 3.1e11
N_0 = 6.02e23