def test_irradiation_activate_extended(activation_pair): """Test NeutronIrradiation.activate() with decay""" start = datetime.datetime.now() t_irr = 3600 * 12 stop = start + datetime.timedelta(seconds=t_irr) n_cm2_s = 1e11 iso0, iso1 = activation_pair barns = 1 iq0 = IsotopeQuantity(iso0, date=start, atoms=1e24) expected_atoms = (n_cm2_s * barns * 1e-24 * iq0.ref_atoms * (1 - np.exp(-iso1.decay_const * t_irr))) ni = NeutronIrradiation(start, stop, n_cm2_s=n_cm2_s) # forward calculation iq1 = ni.activate(barns, initial=iq0, activated=iso1) assert iq1.ref_date == stop assert np.isclose(iq1.bq_at(iq1.ref_date), expected_atoms) # backward calculation iq0a = ni.activate(barns, initial=iso0, activated=iq1) assert iq0a.ref_date == start assert np.isclose(iq0a.ref_atoms, iq0.ref_atoms)
def test_irradiation_activate_errors(): """Test NeutronIrradiation.activate() bad args""" iso0 = Isotope("Na-23") iso1 = Isotope("Na-24") iq0 = IsotopeQuantity(iso0, atoms=1e24) iq1 = IsotopeQuantity(iso1, atoms=1e24) start = datetime.datetime.now() stop = start n_cm2 = 1e15 ni = NeutronIrradiation(start, stop, n_cm2=n_cm2) barns = 10 with pytest.raises(NeutronIrradiationError): ni.activate(barns, initial=iq0, activated=iq1) with pytest.raises(NeutronIrradiationError): ni.activate(barns, initial=iso0, activated=iso1) with pytest.raises(TypeError): ni.activate(barns, initial=iq0, activated="asdf") iso2 = Isotope("Na-25") with pytest.raises(NotImplementedError): ni.activate(barns, initial=iq1, activated=iso2)
def test_irradiation_nan_g(): """Regression test for https://github.com/lbl-anp/becquerel/issues/325. From examples/isotopes.ipynb """ iso = Isotope("Na-23") iso2 = Isotope("Na-24") barns = 2.3 # making this up for now irradiation_start = "2017-04-30 10:32:00" irradiation_stop = "2017-04-30 11:32:00" flux = 3.1e11 ni = NeutronIrradiation(irradiation_start, irradiation_stop, n_cm2_s=flux) activated_qty = IsotopeQuantity(iso2, date="2017-05-01", bq=103.2) na23_qty = ni.activate(barns, initial=iso, activated=activated_qty) assert not np.isnan(na23_qty.g_at())
def test_irradiation_activate_pulse(activation_pair): """Test NeutronIrradiation.activate() for duration = 0""" start = datetime.datetime.now() stop = start n_cm2 = 1e15 iso0, iso1 = activation_pair barns = 1 iq0 = IsotopeQuantity(iso0, date=start, atoms=1e24) expected_atoms = n_cm2 * barns * 1e-24 * iq0.ref_atoms ni = NeutronIrradiation(start, stop, n_cm2=n_cm2) # forward calculation iq1 = ni.activate(barns, initial=iq0, activated=iso1) assert iq1.ref_date == stop assert np.isclose(iq1.ref_atoms, expected_atoms) # backward calculation iq0a = ni.activate(barns, activated=iq1, initial=iso0) assert iq0a.ref_date == start assert np.isclose(iq0a.ref_atoms, iq0.ref_atoms)
def test_irradiation_str(start, stop, n_cm2, n_cm2_s): """Test NeutronIrradiation string representation""" ni = NeutronIrradiation(start, stop, n_cm2=n_cm2, n_cm2_s=n_cm2_s) print(str(ni))
def test_irradiation_bad_init(start, stop, n_cm2, n_cm2_s, error): """Test invalid inits for NeutronIrradiation""" with pytest.raises(error): NeutronIrradiation(start, stop, n_cm2=n_cm2, n_cm2_s=n_cm2_s)
def test_irradiation_init(start, stop, n_cm2, n_cm2_s): """Test valid inits for NeutronIrradiation""" ni = NeutronIrradiation(start, stop, n_cm2=n_cm2, n_cm2_s=n_cm2_s) assert hasattr(ni, "n_cm2")
def Concentration(): conc = [] for i in range(len(iso_name)): c = iso_name[i].split('_') abb = c[0] A = int(c[1]) A_0 = A - 1 iso_2 = '{0}-{1}'.format(abb, A_0) iso_1 = '{0}-{1}'.format(abb, A) nuclide = Isotope(iso_1) def urlcreator(abb, A_0): A_num = str(A_0) if len(A_num) == 1: A_num = '00' + A_num elif len(A_num) == 2: A_num = '0' + A_num else: A_num = A_num url = 'http://wwwndc.jaea.go.jp/cgi-bin/Tab80WWW.cgi?/data' \ + '/JENDL/JENDL-4-prc/intern/' + abb + A_num + '.intern' html = urllib.request.urlopen(url) bslink = BeautifulSoup(html, 'lxml') return(bslink) bslink = urlcreator(abb, A_0) def tabledata(bslink): '''extracts data from the jaea website''' table = bslink.table table_rows = table.find_all('tr') for tr in table_rows: td = tr.find_all('td') row = [i.text for i in td] if len(row) == 7: if row[0] == 'total ': x_sec = row[1] x_sec_s = x_sec.split(' ') x_val = float(x_sec_s[0]) barn = x_sec_s[1] if barn[1] == 'k': x_val = 10**(3) * x_val return(x_val) elif barn[1] == 'm': x_val = 10**(-3) * x_val return(x_val) elif barn[1] == '&': x_val = 10**(-6) * x_val return(x_val) else: x_val = x_val return(x_val) else: pass else: pass return(x_val) x_val = tabledata(bslink) #print(x_val) quantity = IsotopeQuantity(nuclide, date=spec_S1.start_time, bq=isotope_activities[i]) unc_quantity = IsotopeQuantity(nuclide, date=spec_S1.start_time, bq=stat_uncertainties[i]) irrad_quan = quantity.bq_at(irr_stop) unc_irrad_quan = unc_quantity.bq_at(irr_stop) irrad_act = IsotopeQuantity(nuclide, date=irr_stop, bq=irrad_quan) unc_irrad_act = IsotopeQuantity(nuclide, date=irr_stop, bq=unc_irrad_quan) ni = NeutronIrradiation(irr_start, irr_stop, n_cm2_s=flux) init_comp = ni.activate(x_val, initial=Isotope(iso_2), activated=irrad_act) unc_init_comp = ni.activate(x_val, initial=Isotope(iso_2), activated=unc_irrad_act) init_comp.is_stable = True unc_init_comp.is_stable = True sinit_comp = str(init_comp) sunc_init_comp = str(unc_init_comp) #print(sinit_comp, sunc_init_comp) s2 = sinit_comp.split(' ') s0 = s2[0] sunc2 = sunc_init_comp.split(' ') sunc0 = sunc2[0] isotope_type = ' ' + s2[1] + ' ' + s2[2] + ' ' + s2[3] print(s0+' +/- '+sunc0 +isotope_type)