Refactoring, split into more files. Add more personalisation
This commit is contained in:
@@ -12,18 +12,20 @@ def parse_exp_unit(u):
|
||||
return name_u + exp
|
||||
|
||||
|
||||
def convert_exp(number):
|
||||
splitted = "{:.4g}".format(number).split("e")
|
||||
def convert_exp(number, digits=4):
|
||||
# Split string as [coeff, exponent]
|
||||
splitted = "{num:.{digits}g}".format(num=number, digits=digits).split("e")
|
||||
# If no need of scientific notation (low number of digits)
|
||||
if len(splitted) == 1:
|
||||
return "${}$".format(splitted[0])
|
||||
else:
|
||||
coeff = float(splitted[0])
|
||||
exp = int(splitted[1])
|
||||
exp_str = "10^{" + str(exp) + "}"
|
||||
if coeff == 1.0:
|
||||
coeff = splitted[0]
|
||||
exp = splitted[1]
|
||||
exp_str = "10^{" + str(int(exp)) + "}"
|
||||
if float(coeff) == 1.0:
|
||||
return "$" + exp_str + "$"
|
||||
else:
|
||||
return "$" + str(coeff) + "\\times" + exp_str + "$"
|
||||
return "${}\\times {}$".format(coeff, exp_str)
|
||||
|
||||
|
||||
def unit_str(unit, base=None, prefix=""):
|
||||
@@ -52,20 +54,17 @@ def unit_str(unit, base=None, prefix=""):
|
||||
return r" [{}{} {}]".format(prefix, unit.coeff, base_str)
|
||||
|
||||
|
||||
cst.coldens = cst.create_unit(
|
||||
"Msun.pc^-2", base_unit=cst.Msun / cst.pc ** 2, descr="Column density"
|
||||
cst.Msun_pc3 = cst.create_unit(
|
||||
"Msun.pc^-3", base_unit=cst.Msun / cst.pc ** 3, descr="Density"
|
||||
)
|
||||
cst.km_s = cst.create_unit("km.s^-1", base_unit=cst.km / cst.s, descr="Speed")
|
||||
|
||||
cst.Msun_pc3 = cst.create_unit(
|
||||
"Msun.pc^-3", base_unit=cst.Msun / cst.pc ** 3, descr="Density"
|
||||
)
|
||||
|
||||
cst.kg_m3 = cst.create_unit("kg.m^-3", base_unit=cst.kg / cst.m ** 3, descr="Density")
|
||||
|
||||
cst.ssfr = cst.create_unit(
|
||||
"Msun.yr^-1.pc^-2",
|
||||
base_unit=cst.Msun / cst.year / cst.pc ** 2,
|
||||
descr="Surfacic SFR",
|
||||
latex="M$_{\odot}$.yr$^{-1}$.p$c^{-2}$",
|
||||
latex="M$_{\odot}$.yr$^{-1}$.pc$^{-2}$",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user