Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# in greedy mode ('all'), choose to recompute all parameters that we can
extra = []
if greedy:
# ... let's be greedy: recompute all possible quantities. The list of
# all spectral quantities is calculated by parsing a tree in get_reachable
reachable = get_reachable(spec)
extra = [k for k, v in reachable.items() if v]
wanted = set(wanted+extra)
# There are two cases: either we are actually rescaling to another length /
# mole fraction, or we are just updating() without changing length / mole fraction
no_change = (new_mole_fraction ==
old_mole_fraction and new_path_length == old_path_length)
# Quickly stop if no change
if no_change and all_in(wanted,initial):
if __debug__:
printdbg('... rescale: no change')
# Stop here
return
# list of quantities that are needed to recompute what we want
# ... (we're just analysing how to compute them here, the actual calculation
# ... will be done laters)
try:
recompute = get_recompute(
spec, wanted, no_change, true_path_length=true_path_length)
except KeyError as err:
import sys
print(sys.exc_info())
raise KeyError('Error in get_recompute (see above). Quantity `{0}` cannot be recomputed '.format(
err.args[0])+'from available quantities in Spectrum ({0}) with '.format(spec.get_vars()) +
fixed = True
return fixed
for param in ['database', 'levelspath', 'parfuncpath', # RADIS quantities
'results_directory', 'jobName', # other quantities
]:
fixed += fix_path(param)
# Fix syntax of radis <= 0.2
# --------------------------
# Add 'thermal_equilibrium' in conditions
if 'thermal_equilibrium' not in sload['conditions']:
# Hints that the Spectrum has been calculated by a Spectral code:
if (all_in(['Tgas', 'Trot', 'Tvib', 'wstep'], sload['conditions']) # NEQ / RADIS
or all_in(['Tgas', 'Trot', 'Tvib', 'narray', 'jobName'], sload['conditions'])): # SPECAIR
def _is_at_equilibrium(conditions):
# Guess if we're at equilibrium:
# ... if at Equilibrium, more quantities can be calculated with Kirchoff's law
# ... using Spectrum.update(). Also, the Spectrum can be stored by deleting
# ... more redundant parts.
# ... if not possible to guess, assume False
try:
assert conditions['Tvib'] == conditions['Tgas']
assert conditions['Trot'] == conditions['Tgas']
if 'overpopulation' in conditions:
assert conditions['overpopulation'] is None
assert conditions['self_absorption'] # is True
return True
except AssertionError:
# Check inputs
if overpopulation is None:
overpopulation = {}
# else:
# if not returnQvibQrot:
# raise ValueError('When using overpopulation partition function '+\
# 'must be calculated with returnQvibQrot')
assert vib_distribution in ['boltzmann', 'treanor']
assert rot_distribution in ['boltzmann']
if vib_distribution == 'boltzmann':
if not 'Evib' in list(self.df.keys()):
raise ValueError('Evib must be defined to calculate non-equilibrium ' +
'partition functions')
elif vib_distribution == 'treanor':
if not all_in(['Evib1_h', 'Evib1_a', 'Evib2_h', 'Evib2_a', 'Evib3_h', 'Evib3_a'], list(self.df.keys())):
raise ValueError('Evib1_h, Evib1_a, Evib2_h, Evib2_a, Evib3_h, Evib3_a ' +
'must be defined to calculate non-equilibrium ' +
'partition functions with treanor distribution ' +
'and Tvib1, Tvib2, Tvib3')
if rot_distribution == 'boltzmann':
if not 'Erot' in list(self.df.keys()):
raise ValueError('Evib and Erot must be defined to calculate non-equilibrium ' +
'partition functions')
# Get variables
Tvib1, Tvib2, Tvib3 = Tvib
df = self.df
gvib = df.gvib
grot = df.grot
# Calculate
viblvl_l_cdsd = vib_lvl_name_cdsd_pcJN(
df.polyl, df.wangl, df.jl, df.rankl)
viblvl_u_cdsd = vib_lvl_name_cdsd_pcJN(
df.polyu, df.wangu, df.ju, df.ranku)
else:
raise ValueError(
'Unexpected level format: {0}'.format(lvlformat))
band_cdsd = viblvl_l_cdsd + '->' + viblvl_u_cdsd
df.loc[:, 'viblvl_l'] = viblvl_l_cdsd
df.loc[:, 'viblvl_u'] = viblvl_u_cdsd
df.loc[:, 'band'] = band_cdsd
# Calculate HITRAN format too (to store them))
if all_in(['v1l', 'v2l', 'l2l', 'v3l'], df):
viblvl_l_hitran = vib_lvl_name_hitran(
df.v1l, df.v2l, df.l2l, df.v3l)
viblvl_u_hitran = vib_lvl_name_hitran(
df.v1u, df.v2u, df.l2u, df.v3u)
band_hitran = viblvl_l_hitran + '->' + viblvl_u_hitran
df.loc[:, 'viblvl_htrn_l'] = viblvl_l_hitran
df.loc[:, 'viblvl_htrn_u'] = viblvl_u_hitran
df.loc[:, 'band_htrn'] = band_hitran
# 'radis' uses Dunham development based on v1v2l2v3 HITRAN convention
elif lvlformat in ['radis']:
if dbformat not in ['hitran', 'cdsd-hitemp', 'cdsd-4000']:
raise NotImplementedError('lvlformat `{0}` not supported with dbformat `{1}`'.format(
lvlformat, dbformat))
Jmax_calc = max(J, Jmax_calc)
pb.done()
df = pd.DataFrame(levels, columns=columns)
# Calculate missing energies
# --------------------------
df['Erot'] = df.E - df.Evib123
if group_energy_modes_in_2T_model == (['Evib1', 'Evib2', 'Evib3'],['Erot']):
df['Evib'] = df.Evib123 # + Evib2 + Evib3
df['Erot'] = df.Erot
elif group_energy_modes_in_2T_model == (['Evib3'],['Evib1', 'Evib2', 'Erot']):
if not all_in(['Evib1', 'Evib2', 'Evib3'], df):
raise KeyError('You need Evib1, Evib2, Evib3 calculated separately. '+\
'Use calc_Evib_per_mode=True')
df['Evib'] = df.Evib3
df['Erot'] = df.Evib1 + df.Evib2 + df.Erot
else:
raise NotImplementedError('group_energy_modes_in_2T_model: {0}'.format(
group_energy_modes_in_2T_model))
# # same as above but harder to read
# Evib_columns, Erot_columns = group_energy_modes_in_2T_model
# df['Evib20'] = pd.concat([df[k] for k in Evib_columns])
# df['Erot2'] = pd.concat([df[k] for k in Erot_columns])
assert np.allclose(df.Evib + df.Erot, df.E)
# Get Degeneracies
# ----------------
--------
:meth:`~radis.levels.partfunc.RovibPartitionFunction.at_noneq`,
:meth:`~radis.levels.partfunc.RovibPartitionFunction.at_noneq_3Tvib`
'''
if __debug__:
printdbg('called RovibPartitionFunction.at(T={0}K, '.format(T) +
'update_populations={0})'.format(update_populations))
# Check inputs, initialize
assert isinstance(update_populations, bool)
df = self.df
if 'g' in df.columns:
g = df.g
elif all_in(['gvib', 'grot'], df.columns):
g = df.gvib * df.grot
else:
raise ValueError('either g, or gvib+grot must be defined to ' +
'calculate total degeneracy. Got: {0}'.format(list(df.keys())))
# Calculate
nQ = g * exp(-hc_k*df.E/T)
Q = nQ.sum()
# Update energy level table with populations (doesnt
# cost much and can be used to plot populations afterwards)
# ... 'n'
if update_populations:
df['n'] = nQ/Q