tardis.util.base module

exception tardis.util.base.MalformedElementSymbolError(malformed_element_symbol)[source]

Bases: MalformedError

exception tardis.util.base.MalformedError[source]

Bases: Exception

exception tardis.util.base.MalformedQuantityError(malformed_quantity_string)[source]

Bases: MalformedError

exception tardis.util.base.MalformedSpeciesError(malformed_element_symbol)[source]

Bases: MalformedError

tardis.util.base.atomic_number2element_symbol(atomic_number)[source]

Convert atomic number to string

Parameters:
atomic_numberint

Inputted atomic number

Returns:
str

Returned corresponding element symbol

tardis.util.base.calculate_luminosity(spec_fname, distance, wavelength_column=0, wavelength_unit=Unit('Angstrom'), flux_column=1, flux_unit=Unit('erg / (Angstrom s cm2)'))[source]

Calculates luminosity of star.

Parameters:
spec_fnamefile or str

File or file name to be read

distancefloat

Distance to star

wavelength_columnint, optional(default = 0)

Column index in which the wavelength is stored

wavelength_unitfloat, optional(default = u.angstrom)

Dictates units used for calculating wavelength.

flux_columnint, optional(default = 1)

Column index in which the flux is stored

flux_unitstr, optional(default = u.Unit(‘erg / (Angstrom cm2 s)’)

Dictates units used for flux

Returns:
luminosity.valuefloat

Returned luminosity value of star.

wavelength.min()float

Minimum value of wavelength of light

wavelength.max()float

Maximum value of wavelength of light

tardis.util.base.convert_abundances_format(fname, delimiter='\\s+')[source]

Changes format of file containing abundances into data frame

Parameters:
fnamefile, str

File or file name that contains abundance info

delimiterstr, optional(default = ‘s+’)

Determines the separator for splitting file

Returns:
DataFrame

Corresponding data frame

tardis.util.base.create_synpp_yaml(radial1d_mdl, fname, shell_no=0, lines_db=None)[source]

Create a yaml file that is readable from syn++

Parameters:
radial1d_mdlSimulationState

Inputted object that will be read into YAML file

fnamestr

File name for the synpp yaml

shell_noint, optional(default = 0)

Number of shells

lines_dbfile, optional(default = None)
Raises:
ValueError

If the current dataset does not contain necessary reference files

tardis.util.base.deprecated(func)[source]

A decorator to add a deprecation warning to a function that is no longer used

Parameters:
funcfunction
tardis.util.base.element_symbol2atomic_number(element_string)[source]

Takes an element symbol and returns its corresponding atomic number

Parameters:
element_stringstr

Inputted element symbol

Returns:
int

Returned atomic number

tardis.util.base.fix_bar_layout(bar, no_of_packets=None, total_iterations=None)[source]

Fix the layout of progress bars.

Parameters:
bartqdm instance

Progress bar to change the layout of.

no_of_packetsint, optional

Number of packets to be propagated.

total_iterationsint, optional

Total number of iterations.

tardis.util.base.int_to_roman(i)[source]

Convert an integer into its roman numeral representation.

Parameters:
iint

Integer to be converted into roman numerals

Returns:
str

Returns roman numeral representation of i in str format.

tardis.util.base.intensity_black_body(nu, temperature)[source]

Calculate the intensity of a black-body according to the following formula

\[I(\nu, temperature) = \frac{2h\nu^3}{c^2}\frac{1} {e^{h\nu \beta_\textrm{rad}} - 1}\]
Parameters:
nufloat

Frequency of light

temperaturefloat

Temperature in kelvin

Returns:
Intensityfloat

Returns the intensity of the black body

tardis.util.base.is_notebook()[source]

Checking the shell environment where the simulation is run is Jupyter based

Returns:
Trueif the shell environment is IPython Based
Falseif the shell environment is Terminal or anything else
tardis.util.base.is_valid_nuclide_or_elem(input_nuclide)[source]

Parses nuclide string into symbol - mass number format and returns whether the nuclide is either contained in the decay dataset or is a raw element string.

Parameters:
input_nuclidestr or int

Nuclide name string or element string.

Returns:
bool

Bool indicating if the input nuclide is contained in the decay dataset or is a valid element.

tardis.util.base.parse_quantity(quantity_string)[source]

Changes a string into it’s corresponding astropy.Quantity object.

Parameters:
quantity_stringstr

String to be converted into astropy.Quantity

Returns:
qu.Quantity

Corresponding astropy.Quantity object for passed string

Raises:
MalformedQuantityError

If string is not properly formatted for Astropy Quantity

tardis.util.base.quantity_linspace(start, stop, num, **kwargs)[source]

Essentially the same input parameters as linspace, but calculated for an astropy quantity start and stop.

Parameters:
startastropy.Quantity

Starting value of the sequence

stopastropy.Quantity

End value of the sequence

numint

Number of samples to generate

Returns:
astropy.Quantity

Returns num evenly spaced characters of type astropy.Quantity

Raises:
ValueError

If start and stop values have no unit attribute.

tardis.util.base.reformat_element_symbol(element_string)[source]
Reformat the string so the first letter is uppercase and all subsequent

letters lowercase.

Parameters:
element_stringstr

Inputted element symbol

Returns:
str

Returned reformatted element symbol

tardis.util.base.refresh_packet_pbar()[source]

Refresh packet progress bar after each iteration.

tardis.util.base.roman_to_int(roman_string)[source]

Convert a roman numeral into its corresponding integer.

Parameters:
roman_stringstr

Roman numeral to be converted into an integer

Returns:
int

Returns integer representation of roman_string

tardis.util.base.species_string_to_tuple(species_string)[source]

Convert a species string to its corresponding tuple representation

Parameters:
species_stringstr

String containing species symbol (e.g. Si II, Fe III)

Returns:
atomic_number, ion_numbertuple

Returns tuple of length 2 indicating atomic number and ion number

Raises:
MalformedSpeciesError

If the inputted string does not match the species format

tardis.util.base.species_tuple_to_string(species_tuple, roman_numerals=True)[source]

Convert a species tuple to its corresponding string representation.

Parameters:
species_tupletuple

Tuple of 2 values indicated atomic number and number of electrons missing

roman_numeralsbool, optional(default = TRUE)

Indicates whether the returned ion number is in roman numerals

Returns:
element_symbol, roman_ion_numberstr

Returns corresponding string representation of given tuple

tardis.util.base.update_iterations_pbar(i)[source]

Update progress bar for each iteration.

Parameters:
iint

Amount by which the progress bar needs to be updated.

tardis.util.base.update_packet_pbar(i, current_iteration, no_of_packets, total_iterations)[source]

Update progress bars as each packet is propagated.

Parameters:
iint

Amount by which the progress bar needs to be updated.

current_iterationint

Current iteration number.

no_of_packetsint

Total number of packets in one iteration.

total_iterationsint

Total number of iterations.