def parse_abundance_dict_to_dataframe(abundance_dict): atomic_number_dict = dict([(element_symbol2atomic_number(symbol), abundance_dict[symbol]) for symbol in abundance_dict]) atomic_numbers = sorted(atomic_number_dict.keys()) abundances = pd.Series([atomic_number_dict[z] for z in atomic_numbers], index=atomic_numbers) abundance_norm = abundances.sum() if abs(abundance_norm - 1) > 1e-12: logger.warning('Given abundances don\'t add up to 1 (value = %g) - normalizing', abundance_norm) abundances /= abundance_norm return abundances
def parse_abundance_dict_to_dataframe(abundance_dict): atomic_number_dict = dict([(element_symbol2atomic_number(symbol), abundance_dict[symbol]) for symbol in abundance_dict]) atomic_numbers = sorted(atomic_number_dict.keys()) abundances = pd.Series([atomic_number_dict[z] for z in atomic_numbers], index=atomic_numbers) abundance_norm = abundances.sum() if abs(abundance_norm - 1) > 1e-12: logger.warn('Given abundances don\'t add up to 1 (value = %g) - normalizing', abundance_norm) abundances /= abundance_norm return abundances
def test_element_symbol2atomic_number(element_symbol, atomic_number): assert element_symbol2atomic_number(element_symbol) == atomic_number with pytest.raises(MalformedElementSymbolError): element_symbol2atomic_number('Hx')