def get_convention(coefficients): """Returns if we're using the Herzberg or Dunham convention for spectrosopic coefficients, and returns the associated coefficients Parameters ---------- coefficients: list Returns ------- convention: str 'dunham' or 'herzberg' coefficients: dict list of coefficient names """ from radis.db.utils import ignore_trailing_number from radis.misc.basics import partition assert len(coefficients) > 0 herzberg_coeffs, non_herzberg_coeffs = partition( lambda x: ignore_trailing_number(x) in herzberg_coefficients, coefficients ) for k in non_herzberg_coeffs: if not k.startswith("Y"): raise ValueError("Unexpected Spectroscopic coefficient: {0}".format(k)) dunham_coeffs = non_herzberg_coeffs if len(dunham_coeffs) > 0 and len(herzberg_coeffs) > 0: raise ValueError( "Both Dunham ({0}) and Herzberg ({1}) conventions used".format( dunham_coeffs, herzberg_coeffs ) + ". Choose one only" ) if len(dunham_coeffs) > 0: return "dunham" else: return "herzberg"
def print_conditions( conditions, units, phys_param_list=PHYSICAL_PARAMS, info_param_list=INFORMATIVE_PARAMS, ): """Print all Spectrum calculation parameters. Parameters ---------- phys_param_list: list These parameters are shown below "Physical Conditions" rather than "Computation Parameters. See :data:`~radis.spectrum.utils.PHYSICAL_PARAMS` for more information. info_param_list: list These parameters are shown below "Information" rather than "Computation Parameters. See :data:`~radis.spectrum.utils.INFORMATIVE_PARAMS` for more information. See Also -------- :data:`~radis.spectrum.utils.PHYSICAL_PARAMS`, :data:`~radis.spectrum.utils.INFORMATIVE_PARAMS` """ def align(a, space=20): """fix alignement.""" return a + " " * max(1, (space - len(str(a)))) def print_param(k): """Special formatting for nicely printing conditions.""" v_k = conditions[k] # Add extra arguments based on arbitrary conditions args = [] if k in units: args.append(units[k]) # ... fill here for other args # Special formatting try: if k in [ "wavenum_max_calc", "wavenum_min_calc", "wavelength_max", "wavelength_min", "wavenum_max", "wavenum_min", ]: v_k_str = "{0:.4f}".format(v_k) elif k in [ "lines_calculated", "lines_in_continuum", "lines_cutoff" ]: # Add comma separator for thousands v_k_str = "{0:,d}".format(v_k) else: # Default to printing str v_k_str = "{0}".format(v_k) except ValueError: # Default to printing str v_k_str = "{0}".format(v_k) # Crop if len(v_k_str) > 102: # cut if too long v_k_str = v_k_str[:100] + "..." print(" " * 2, align(k), v_k_str, *args) phys_param, non_phys_param = partition(lambda x: x in phys_param_list, conditions) info_param, non_phys_param = partition(lambda x: x in info_param_list, non_phys_param) print("Physical Conditions") print("-" * 40) for k in sorted(phys_param): print_param(k) print("Computation Parameters") print("-" * 40) for k in sorted(non_phys_param): print_param(k) if len(info_param) > 0: print("Information") print("-" * 40) for k in sorted(info_param): print_param(k) print("-" * 40) # print gas_inp (information on each gas slab) if exists (specifically # for Specair output) if "gas_inp" in conditions: try: for slab in conditions["gas_inp"]: print("Slab", slab) slab.print_conditions() except: pass return None
def print_conditions(conditions, units, phys_param_list=PHYSICAL_PARAMS, info_param_list=INFORMATIVE_PARAMS): ''' Print all Spectrum calculation parameters Parameters ---------- phys_param_list: list These parameters are shown below "Physical Conditions" rather than "Computation Parameters info_param_list: list These parameters are shown below "Information" rather than "Computation Parameters ''' def align(a, space=20): ''' fix alignement ''' return a + ' ' * max(1, (space - len(str(a)))) def print_param(k): v_k = conditions[k] # Add extra arguments based on arbitrary conditions args = [] if k in units: args.append(units[k]) # ... fill here for other args # Print v_k_str = '{0}'.format(v_k) if len(v_k_str) > 102: # cut if too long v_k_str = v_k_str[:100] + '...' print(' ' * 2, align(k), v_k_str, *args) phys_param, non_phys_param = partition(lambda x: x in phys_param_list, conditions) info_param, non_phys_param = partition(lambda x: x in info_param_list, non_phys_param) print('Physical Conditions') print('-' * 40) for k in sorted(phys_param): print_param(k) print('Computation Parameters') print('-' * 40) for k in sorted(non_phys_param): print_param(k) if len(info_param) > 0: print('Information') print('-' * 40) for k in sorted(info_param): print_param(k) print('-' * 40) # print gas_inp (information on each gas slab) if exists (specifically # for Specair output) if 'gas_inp' in conditions: try: for slab in conditions['gas_inp']: print('Slab', slab) slab.print_conditions() except: pass return None
def print_conditions(conditions, units, phys_param_list=PHYSICAL_PARAMS, info_param_list=INFORMATIVE_PARAMS): ''' Print all Spectrum calculation parameters Parameters ---------- phys_param_list: list These parameters are shown below "Physical Conditions" rather than "Computation Parameters. See :data:`~radis.spectrum.utils.PHYSICAL_PARAMS` for more information. info_param_list: list These parameters are shown below "Information" rather than "Computation Parameters. See :data:`~radis.spectrum.utils.INFORMATIVE_PARAMS` for more information. See Also -------- :data:`~radis.spectrum.utils.PHYSICAL_PARAMS`, :data:`~radis.spectrum.utils.INFORMATIVE_PARAMS` ''' def align(a, space=20): ''' fix alignement ''' return a + ' ' * max(1, (space - len(str(a)))) def print_param(k): ''' Special formatting for nicely printing conditions ''' v_k = conditions[k] # Add extra arguments based on arbitrary conditions args = [] if k in units: args.append(units[k]) # ... fill here for other args # Special formatting try: if k in ['wavenum_max_calc', 'wavenum_min_calc', 'wavelength_max', 'wavelength_min', 'wavenum_max', 'wavenum_min']: v_k_str = '{0:.4f}'.format(v_k) elif k in ['lines_calculated', 'lines_in_continuum', 'lines_cutoff']: # Add comma separator for thousands v_k_str = '{0:,d}'.format(v_k) else: # Default to printing str v_k_str = '{0}'.format(v_k) except ValueError: # Default to printing str v_k_str = '{0}'.format(v_k) # Crop if len(v_k_str) > 102: # cut if too long v_k_str = v_k_str[:100] + '...' print(' '*2, align(k), v_k_str, *args) phys_param, non_phys_param = partition(lambda x: x in phys_param_list, conditions) info_param, non_phys_param = partition(lambda x: x in info_param_list, non_phys_param) print('Physical Conditions') print('-'*40) for k in sorted(phys_param): print_param(k) print('Computation Parameters') print('-'*40) for k in sorted(non_phys_param): print_param(k) if len(info_param) > 0: print('Information') print('-'*40) for k in sorted(info_param): print_param(k) print('-'*40) # print gas_inp (information on each gas slab) if exists (specifically # for Specair output) if 'gas_inp' in conditions: try: for slab in conditions['gas_inp']: print('Slab', slab) slab.print_conditions() except: pass return None