Exemple #1
0
def build_test_databases(verbose=True):
    ''' Build test databases and add them in ~/.radis. Generate the file if it 
    doesnt exist
    
    In particular:
    
    - HITRAN-CO2-TEST: CO2, HITRAN 2016, 4165-4200 nm 
    - HITRAN-CO-TEST: CO, HITRAN 2016, 2000-2300 cm-1
    
    These test databases are used to run the different test routines. They can
    obviously be used by Users to run simulations, but we suggest Users to download
    their own line databases files and add them to ~/.radis so they have more control
    on it
    
    '''

    # Get list of databases
    try:
        dbnames = getDatabankList()
    except FileNotFoundError:
        dbnames = []

    # %% Add test databases

    def add_to_parser(config, name, dic):
        for k, v in dic.items():
            config[name][k] = v
        if verbose: print("Adding '{0}' database in ~/.radis".format(name))

    for dbname, dbentries in TEST_DATABASES.items():

        if dbname in dbnames:  # Check entries are correct
            #            for k
            diff = diffDatabankEntries(getDatabankEntries(dbname),
                                       dbentries,
                                       verbose=False)
            if diff is not None:
                raise ValueError('{0}'.format(diff)+\
                                 '\nIn ~/.radis\n----------\n{0}'.format(getDatabankEntries(dbname))+\
                                 '\n\nExpected\n---------\n{0}\n\n'.format(dbentries)+\
                                 'Test Database {0} doesnt match expected '.format(dbname)+\
                                 'entries for key `{0}`. See comparison above. '.format(diff)+\
                                 'To regenerate test databases just delete the {0} '.format(dbname)+\
                                 'entry in your ~/.radis')

        else:  #  add them (create ~/.radis file if doesnt exist yet)
            addDatabankEntries(dbname, dbentries)

    return
Exemple #2
0
def setup_test_line_databases(verbose=True):
    """Build :py:data:`~radis.test.utils.TEST_DATABASES` and add them in ~/.radis.
    Generate the file if it  doesnt exist

    In particular:

    - HITRAN-CO2-TEST: CO2, HITRAN 2016, 4165-4200 nm
    - HITRAN-CO-TEST: CO, HITRAN 2016, 2000-2300 cm-1
    - HITEMP-CO2-TEST: CO2, HITEMP-2010, 2283.7-2285.1 cm-1, 3 isotopes
    - HITEMP-CO2-HAMIL-TEST: same as previous, with (some) energy levels computed
      from Tashkun effective Hamiltonian.


    These test databases are used to run the different test routines. They can
    obviously be used by Users to run simulations, but we suggest Users to download
    their own line databases files and add them to ~/.radis so they have more control
    on it

    Examples
    --------

    Initialize the Line databases::

        from radis import setup_test_line_databases
        setup_test_line_databases()

    Plot a CO2 spectrum at high temperature::

        from radis import calc_spectrum
        calc_spectrum(2284,
                      2285,
                      Tgas=2000,
                      pressure=1,
                      molecule='CO2',
                      isotope=1
                      databank='HITEMP-CO2-TEST').plot()

    Note that 'HITEMP-CO2-TEST' is defined on 2283.7-2285.1 cm-1 only, as
    can be shown by reading the Database information:

        from radis.misc.config import printDatabankEntries
        printDatabankEntries('HITEMP-CO2-TEST')

        >>> HITEMP-CO2-TEST
        >>> -------
        >>> info : HITEMP-2010, CO2, 3 main isotope (CO2-626, 636, 628), 2283.7-2285.1 cm-1
        >>> path : ['/USER/PATH/TO\\radis\\radis\\test\\files\\cdsd_hitemp_09_fragment.txt']
        >>> format : cdsd-hitemp
        >>> parfuncfmt : hapi
        >>> levelsfmt : radis


    See Also
    --------

    :ref:`Configuration file <label_lbl_config_file>`,
    :py:func:`~radis.misc.config.getDatabankList`,
    :py:func:`~radis.misc.config.printDatabankEntries`

    """
    # TODO: generate large band databases for the main species (let's say CO2,
    # H2O and CH4) and main isotopes by fetching the HITRAN 2016 database.

    # Get list of databases
    try:
        dbnames = getDatabankList()
    except FileNotFoundError:
        dbnames = []

    # %% Add test databases

    def add_to_parser(config, name, dic):
        for k, v in dic.items():
            config[name][k] = v
        if verbose:
            print("Adding '{0}' database in ~/.radis".format(name))

    for dbname, dbentries in TEST_DATABASES.items():

        if dbname in dbnames:  # Check entries are correct
            #            for k
            diff = diffDatabankEntries(getDatabankEntries(dbname),
                                       dbentries,
                                       verbose=False)
            if diff is not None:
                raise ValueError(
                    "{0}".format(diff) +
                    "\nIn ~/.radis\n----------\n{0}".format(
                        getDatabankEntries(dbname)) +
                    "\n\nExpected\n---------\n{0}\n\n".format(dbentries) +
                    "Test Database {0} doesnt match expected ".format(dbname) +
                    "entries for key `{0}`. See comparison above. ".format(
                        diff) +
                    "To regenerate test databases just delete the {0} ".format(
                        dbname) + "entry in your ~/.radis")

        else:  # add them (create ~/.radis file if doesnt exist yet)
            addDatabankEntries(dbname, dbentries)

    return
Exemple #3
0
def setup_test_line_databases(verbose=True):
    ''' Build :py:data:`~radis.test.utils.TEST_DATABASES` and add them in ~/.radis. 
    Generate the file if it  doesnt exist

    In particular:

    - HITRAN-CO2-TEST: CO2, HITRAN 2016, 4165-4200 nm 
    - HITRAN-CO-TEST: CO, HITRAN 2016, 2000-2300 cm-1
    - HITEMP-CO2-TEST: CO2, HITEMP-2010, 2283.7-2285.1 cm-1, 3 isotopes

    These test databases are used to run the different test routines. They can
    obviously be used by Users to run simulations, but we suggest Users to download
    their own line databases files and add them to ~/.radis so they have more control
    on it
    
    See Also
    --------
    
    :ref:`Configuration file <label_lbl_config_file>`

    '''
    # TODO: generate large band databases for the main species (let's say CO2,
    # H2O and CH4) and main isotopes by fetching the HITRAN 2016 database.

    # Get list of databases
    try:
        dbnames = getDatabankList()
    except FileNotFoundError:
        dbnames = []

    # %% Add test databases

    def add_to_parser(config, name, dic):
        for k, v in dic.items():
            config[name][k] = v
        if verbose:
            print("Adding '{0}' database in ~/.radis".format(name))

    for dbname, dbentries in TEST_DATABASES.items():

        if dbname in dbnames:  # Check entries are correct
            #            for k
            diff = diffDatabankEntries(getDatabankEntries(dbname),
                                       dbentries,
                                       verbose=False)
            if diff is not None:
                raise ValueError(
                    '{0}'.format(diff) +
                    '\nIn ~/.radis\n----------\n{0}'.format(
                        getDatabankEntries(dbname)) +
                    '\n\nExpected\n---------\n{0}\n\n'.format(dbentries) +
                    'Test Database {0} doesnt match expected '.format(dbname) +
                    'entries for key `{0}`. See comparison above. '.format(
                        diff) +
                    'To regenerate test databases just delete the {0} '.format(
                        dbname) + 'entry in your ~/.radis')

        else:  # add them (create ~/.radis file if doesnt exist yet)
            addDatabankEntries(dbname, dbentries)

    return
Exemple #4
0
def register_database(databank_name, path_list, molecule, wmin, wmax,
                      download_date, urlname, verbose):
    """Add to registered databases in RADIS config file.

    If database exists, assert it has the same entries.

    Parameters
    ----------
    databank_name: str
        name of the database in :ref:`~/.radis config file <label_lbl_config_file>`

    Other Parameters
    ----------------
    verbose: bool

    Returns
    -------
    None:
        adds to :ref:`~/.radis <label_lbl_config_file>` with all the input
        parameters. Also adds ::

            format : "hdf5"
            parfuncfmt : "hapi"   # TIPS-2017 for equilibrium partition functions

        And if the molecule is in :py:attr:`~radis.db.MOLECULES_LIST_NONEQUILIBRIUM`::

            levelsfmt : "radis"   # use RADIS spectroscopic constants for rovibrational energies (nonequilibrium)

    """
    dict_entries = {
        "info":
        f"HITEMP {molecule} lines ({wmin:.1f}-{wmax:.1f} cm-1) with TIPS-2017 (through HAPI) for partition functions",
        "path": path_list,
        "format": "hdf5",
        "parfuncfmt": "hapi",
        "wavenumber_min": f"{wmin}",
        "wavenumber_max": f"{wmax}",
        "download_date": download_date,
        "download_url": urlname,
    }
    if molecule in MOLECULES_LIST_NONEQUILIBRIUM:
        dict_entries[
            "info"] += " and RADIS spectroscopic constants for rovibrational energies (nonequilibrium)"
        dict_entries["levelsfmt"] = "radis"

    # Register database in ~/.radis to be able to use it with load_databank()
    try:
        addDatabankEntries(databank_name, dict_entries)
    except DatabaseAlreadyExists as err:
        # Check that the existing database had the same entries
        try:
            from radis.misc.config import getDatabankEntries

            for k, v in getDatabankEntries(databank_name).items():
                if k == "download_date":
                    continue
                assert dict_entries[k] == v
            # TODO @dev : replace once we have configfile as JSON (https://github.com/radis/radis/issues/167)
        except AssertionError:
            raise DatabaseAlreadyExists(
                f"{databank_name} already exists in your ~/.radis config file. "
                +
                "Remove it from your config file, or choose a different name "
                +
                "for the downloaded database with `fetch_hitemp(databank_name=...)`"
            ) from err
        else:  # no other error raised
            if verbose:
                print(
                    f"{databank_name} already registered in ~/.radis config file, with the same parameters."
                )