def test_numbers(self): assert Isotope(7, 14).numbers() == (7, 14) assert Isotope(6, 12, True).numbers() == (6, 12, True) assert Isotope(6, 12, False).numbers(force_isomer=True) == (6, 12, False)
def test_decay(self): assert Isotope(9, 26).decay().numbers() == (12, 26) assert Isotope(4, 8).decay().numbers() == (2, 4) assert Isotope(14, 26).decay().numbers() == (12, 26) assert Isotope(2, 4).decay().numbers() == (2, 4) # This asserts the code is not working physically but as intended assert Isotope(20, 36).decay().numbers() == (16, 36)
def in_file(self, target: Union[str, "Isotope"]): target = Isotope.name(target) try: self.__getitem__(target) return True except Exception: return False
def __getitem__(self, target: Union[str, "Isotope"]) -> KadonisReaction: target = Isotope.name(target) try: return self.df[ (self.df["Z"] == target.charge_number) & (self.df["A"] == target.mass_number)].Reaction.iloc[0] except IndexError: raise Exception(str(target) + " Not found in file")
def test_init(self): for n, r in zip(n_captures, n_capture_reactions): reaction = KadonisReaction(n, rr=[1.0] * 12, err=[0.0] * 12) assert str(reaction) == r assert (str( KadonisReaction(Isotope(7, 14), rr=[1.0] * 12, err=[0.0] * 12)) == "n+N14 -> N15")
def test_ppn_to_numbers(self): for iso, isomer, out in zip(self.isotopes, self.isomers, self.ppn_outputs): assert Isotope.ppn_name_factory(out).numbers( force_isomer=True) == ( iso[0], iso[1], isomer, )
def get_n_gamma(self, target: Union[Isotope, str]) -> ReaclibReaction: """Gets reaction from target Isotope, matches __getitem__ method in the Kadonis class Parameters ---------- target : [Isotope, str] Returns ------- ReaclibReaction """ target = Isotope.name(target) try: return self.df[(self.df.Chapter == 4) & (self.df.E0 == "n") & (self.df.E1 == str(target).lower())].Reaction.iloc[0] except IndexError: raise Exception(str(target) + " Not found in file")
def __init__( self, target: Union[str, Isotope], rr: List[real], err: List[real], temp: Tuple[real] = (5, 8, 10, 15, 20, 25, 30, 40, 50, 60, 80, 100), temp_units: str = "KeV", label: str = "Kadonis", colour: str = "C2", ): product = copy.deepcopy(Isotope.name(target)) product.mass_number += 1 super().__init__(["n", target], [product]) self.rr = rr self.err = err self.temperature = temp self.temp_unit = temp_units self.label = label self.colour = colour
def test_str(self): assert str(Isotope(7, 14)) == "N14" assert str(Isotope(4, 9)) == "Be9" assert str(Isotope(1, 0)) == "weak"
def test_is_primordial(self): for s, j in Isotope.primordial: assert Isotope(s, j).is_primordial
def test_is_stable(self): for s, j in Isotope.stable_isotopes: assert Isotope(s, j).is_stable
def test_ppn_name_to_numbers(self): assert Isotope.ppn_name_to_numbers("NE 10") == (10, 10)
def test_full_name(self): assert Isotope.name("Ne20").full_name == "Neon-20"
def test_number_to_ppn_name_error(self): with pytest.raises(ValueError): Isotope.number_to_ppn_name(10, 10, 3)
def test_decay_isotope(self): assert Isotope.decay_isotope(10, 10) == (5, 10, False)
def test_class_re_input_to_name(self): assert str(Isotope.name(Isotope(7, 14))) == "N14"
def test_name(self): for n, n_out in zip(self.names, self.names_out): isotope = Isotope.name(n) assert str(isotope) == n_out
def test_init_to_ppn(self): for iso, isomer, out in zip(self.isotopes, self.isomers, self.ppn_outputs): assert Isotope(iso[0], iso[1], isomer).ppn_name == out
def test_init(self): with pytest.raises(ValueError): assert Isotope(119, 350) with pytest.raises(ValueError): assert Isotope(118, 351)
def read_file(file_path: Union[str, Path]) -> pd.DataFrame: """ Parameters ---------- file_path : Returns ------- """ file_path = Path(file_path) df = pd.read_csv( file_path, index_col=False, sep="\t", header=0, dtype={ "Z": np.uint8, "A": np.uint8, "Isomer": str, "Sym": str }, na_values="-", ) try: df.drop([" ; reaction rate including SEF in cm3/mole/s"], axis=1, inplace=True) version = 1.0 except KeyError: df.rename( {"100(keV); reaction rate including SEF in cm3/mole/s": "100"}, axis=1, inplace=True, ) version = 0.3 print("Warning Loading Kadonis in 0.3 format") except: raise Exception if version == 1.0: df["Reaction"] = df.apply( lambda df: KadonisReaction( target=Isotope(df.Z, df.A), label="Kadonis 1.0", rr=[ df["RR(5keV)"], df["RR(8keV)"], df["RR(10keV)"], df["RR(15keV)"], df["RR(20keV)"], df["RR(25keV)"], df["RR(30keV)"], df["RR(40keV)"], df["RR(50keV)"], df["RR(60keV)"], df["RR(80keV)"], df["RR(100keV)"], ], err=[ df["Err(5keV)"], df["Err(8keV)"], df["Err(10keV)"], df["Err(15keV)"], df["Err(20keV)"], df["Err(25keV)"], df["Err(30keV)"], df["Err(40keV)"], df["Err(50keV)"], df["Err(60keV)"], df["Err(80keV)"], df["Err(100keV)"], ], ), axis=1, ) elif version == 0.3: df["Reaction"] = df.apply( lambda df: KadonisReaction( target=Isotope(df.Z, df.A), label="Kadonis 0.3", rr=[ df["5"], df["8"], df["10"], df["15"], df["20"], df["25"], df["30"], df["40"], df["50"], df["60"], df["80"], df["100"], ], err=[0.0] * 12, ), axis=1, ) pickle_path = "{0}.temp".format(str(file_path.parent / file_path.stem)) df.to_pickle(pickle_path) return df
def test_eq(self): assert Isotope.name("Ne20") == "Ne20" and "ne20" and "20Ne" assert Isotope.name("O12") != "NE20"
def __init__(self, targets: iso_list_type, products: iso_list_type) -> None: self.targets = [Isotope.name(t) for t in targets] self.products = [Isotope.name(t) for t in products]
def test_number_to_ppn_name(self): assert Isotope.number_to_ppn_name(10, 10, 1) == "NE 10" assert Isotope.number_to_ppn_name(10, 10, 2) == "NE*10"