How to use the radis.misc.printer.printr function in radis

To help you get started, we’ve selected a few radis examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github radis / radis / radis / tools / database.py View on Github external
sload['conditions']['isotope'] = sload['conditions'].pop(
            'isotope_identifier')
        fixed = True

    if 'air_pressure_mbar' in sload['conditions']:
        printr("File {0}".format(basename(file))+" has a deprecrated structure (key " +
             "air_pressure_mbar replaced with pressure_mbar). Fixed this time, but regenerate " +
             "database ASAP.") #, DeprecationWarning)
        sload['conditions']['pressure_mbar'] = sload['conditions'].pop(
            'air_pressure_mbar')
        fixed = True
        
    if 'isotope' in sload['conditions']:
        isotope = sload['conditions']['isotope']
        if not isinstance(isotope, string_types):
            printr("File {0}".format(basename(file))+" has a deprecrated structure (key " +
                 "isotope is now a string). Fixed this time, but regenerate " +
                 "database ASAP.") #, DeprecationWarning)
            # Fix it:
            sload['conditions']['isotope'] = ','.join([str(k) for k in
                                                       list_if_float(isotope)])
            fixed = True

    if 'dbpath' in sload['conditions']:
        dbpath = sload['conditions']['dbpath']
        if not isinstance(dbpath, string_types):
            printr("File {0}".format(basename(file))+" has a deprecrated structure (key " +
                 "dbpath is now a string). Fixed this time, but regenerate " +
                 "database ASAP.") #, DeprecationWarning)
            # Fix it:
            sload['conditions']['dbpath'] = ','.join([str(k).replace('\\', '/') for k in
                                                      list_if_float(dbpath)])  # list_if_float or just list??
github radis / radis / radis / misc / cache_files.py View on Github external
return None
    # 4. File is not not deprecated: read the content.
    else:
        df = None
        if verbose>=2:
            printm('Reading cache file ({0})'.format(cachefile))
        try:
            df = pd.read_hdf(cachefile, 'df')
        except KeyError as err:  # An error happened during file reading.
            # Fail safe by deleting cache file (unless we explicitely wanted it
            # with 'force')
            if use_cached == 'force':
                raise
            else:
                if verbose:
                    printr('An error happened during cache file reading ' +
                           '{0}:\n{1}\n'.format(cachefile, str(err)) +
                           'Deleting cache file to regenerate it')
                os.remove(cachefile)
                df = None

    return df
github radis / radis / radis / misc / cache_files.py View on Github external
pass    # just use the file as is

    # If file is still here, test if it is deprecated:
    # (we just read the attributes, the file is never fully read)
    if exists(fcache):
        if verbose:
            print(('Using cache file: {0}'.format(fcache)))
        try:
            check_not_deprecated(fcache, metadata=metadata, current_version=radis.__version__,
                                 last_compatible_version=OLDEST_COMPATIBLE_VERSION)
        except DeprecatedFileError as err:
            if use_cached == 'force':
                raise
            else:   # delete file to regenerate it in the end of the script
                if verbose:
                    printr('File {0} deprecated:\n{1}\nDeleting it!'.format(
                        fcache, str(err)))
                os.remove(fcache)

    return
github radis / radis / radis / tools / database.py View on Github external
add to the start of your script::
        
        import radis
        radis.AUTO_UPDATE_SPEC = True
    '''
    
    import radis
    if radis.AUTO_UPDATE_SPEC:
        
        assert exists(file)
        
        
        s.store(file, compress=binary, if_exists_then='replace', discard=[])
        
        printr('File {0} auto-updated to latest RADIS format'.format(file))
        
        return
github radis / radis / radis / misc / cache_files.py View on Github external
if use_cached == 'force':
            raise ValueError('Cache file {0} doesnt exist'.format(cachefile))
        else:
            return None   # File doesn't exist. It's okay. 
        
    # 3. read file attributes to know if it's deprecated
    try:
        check_not_deprecated(cachefile, metadata, current_version=current_version,
                             last_compatible_version=last_compatible_version)
    # ... if deprecated, raise an error only if 'force'
    except DeprecatedFileError as err:
        if use_cached == 'force':
            raise err
        else:
            if verbose:
                printr('File {0} deprecated:\n{1}\nDeleting it!'.format(
                    cachefile, str(err)))
            os.remove(cachefile)
            return None
    # 4. File is not not deprecated: read the content.
    else:
        df = None
        if verbose>=2:
            printm('Reading cache file ({0})'.format(cachefile))
        try:
            df = pd.read_hdf(cachefile, 'df')
        except KeyError as err:  # An error happened during file reading.
            # Fail safe by deleting cache file (unless we explicitely wanted it
            # with 'force')
            if use_cached == 'force':
                raise
            else:
github radis / radis / radis / tools / database.py View on Github external
equilibrium = _is_at_equilibrium(sload['conditions'])
            
            if equilibrium is not None:
                sload['conditions']['thermal_equilibrium'] = equilibrium
                fixed = True
                printr("File {0}".format(basename(file))+" has a deprecrated structure (" +
                     "thermal_equilibrium not defined). Fixed it this time (guessed {0})".format(
                             equilibrium)+", but regenerate file ASAP.") #, DeprecationWarning)

    # Fix lines format HITRAN_CLASS_1 molecules
    if 'lines' in sload and sload['lines'] is not None:
        lines = sload['lines']
        from radis.io.hitran import get_molecule, HITRAN_CLASS1
        if 'v1u' in lines and get_molecule(lines.id.iloc[0]) in HITRAN_CLASS1:
            printr("File {0}".format(basename(file))+" has a deprecrated structure " +\
                 "(v1u in lines is now called vu). Fixed this time, but regenerate " +\
                 "database ASAP.")
            # Fix it:
            lines.rename(columns={'v1u':'vu', 'v1l':'vl'}, inplace=True)
        
    return sload, fixed
github radis / radis / radis / tools / database.py View on Github external
return True
                except AssertionError:
                     return False
                except KeyError as err:
                    # Not all keys necessary to decide. Assume False
                    warn('Missing keys to tell if Spectrum {0} is at equilibrium'.format(file)+\
                         '. Update spectrum manually')
                    return None
            
            equilibrium = _is_at_equilibrium(sload['conditions'])
            
            if equilibrium is not None:
                sload['conditions']['thermal_equilibrium'] = equilibrium
                fixed = True
                printr("File {0}".format(basename(file))+" has a deprecrated structure (" +
                     "thermal_equilibrium not defined). Fixed it this time (guessed {0})".format(
                             equilibrium)+", but regenerate file ASAP.") #, DeprecationWarning)

    # Fix lines format HITRAN_CLASS_1 molecules
    if 'lines' in sload and sload['lines'] is not None:
        lines = sload['lines']
        from radis.io.hitran import get_molecule, HITRAN_CLASS1
        if 'v1u' in lines and get_molecule(lines.id.iloc[0]) in HITRAN_CLASS1:
            printr("File {0}".format(basename(file))+" has a deprecrated structure " +\
                 "(v1u in lines is now called vu). Fixed this time, but regenerate " +\
                 "database ASAP.")
            # Fix it:
            lines.rename(columns={'v1u':'vu', 'v1l':'vl'}, inplace=True)
        
    return sload, fixed
github radis / radis / radis / tools / database.py View on Github external
# manually converted to jsonable)
    sjson = {}
    for attr in s.__slots__:
        sjson[attr] = s.__getattribute__(attr)

    # Discard some entries
    for k in discard:
        if k in sjson:
            del sjson[k]
            
    # Check that all conditions are jsonable, discard if not
    for k in list(sjson['conditions'].keys()):
        v = sjson['conditions'][k]
        if not is_jsonable(v):
            if verbose:
                printr('Discarded {0} from conditions as not jsonable ({1})'.format(
                        k, type(v)))
            del sjson['conditions'][k]

    # if compress>=2, remove unecessary spectral quantities (that can be recomputed
    # from the rest)
    if compress>=2:
        sjson['_q'] = sjson['_q'].copy()
        sjson['_q_conv'] = sjson['_q_conv'].copy()
        sjson = _compress(s, sjson)

    return sjson
github radis / radis / radis / tools / database.py View on Github external
if sload['conditions']['waveunit'] == 'cm-1':
            pass   # does not change anything, no need to report
        else: # wavelength is in air or vacuum. 
            assert sload['conditions']['waveunit'] == 'nm'
            if sload['conditions']['medium'] == 'air':
                sload['conditions']['waveunit'] = 'nm'
            elif sload['conditions']['medium'] == 'vacuum':
                sload['conditions']['waveunit'] = 'nm_vac'
            else:
                raise ValueError(sload['conditions']['medium'])
        # fix: delete medium key
        del sload['conditions']['medium']
        fixed = True

    if 'isotope_identifier' in sload['conditions']:
        printr("File {0}".format(basename(file))+" has a deprecrated structure (key " +
             "isotope_identifier replaced with isotope). Fixed this time, but regenerate " +
             "database ASAP.") #, DeprecationWarning)
        sload['conditions']['isotope'] = sload['conditions'].pop(
            'isotope_identifier')
        fixed = True

    if 'air_pressure_mbar' in sload['conditions']:
        printr("File {0}".format(basename(file))+" has a deprecrated structure (key " +
             "air_pressure_mbar replaced with pressure_mbar). Fixed this time, but regenerate " +
             "database ASAP.") #, DeprecationWarning)
        sload['conditions']['pressure_mbar'] = sload['conditions'].pop(
            'air_pressure_mbar')
        fixed = True
        
    if 'isotope' in sload['conditions']:
        isotope = sload['conditions']['isotope']