How to use the radis.misc.basics.compare_dict 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 / spectrum / compare.py View on Github external
error*100)+' average {0:.3f}%)'.format(avgerr*100))
            b *= b1

            if plot:
                try:
                    plot_diff(first, other, var=k, wunit=wunit,
                              normalize=normalize, verbose=verbose,
                              **kwargs)
                except:
                    print('... there was an error while plotting {0}'.format(k))

        # Compare conditions and units
        # -----------
        verbose_dict = 'if_different' if verbose else False
        b1 = (compare_dict(first.conditions, other.conditions, verbose=verbose_dict) == 1)
        b2 = (compare_dict(first.cond_units, other.cond_units, verbose=verbose_dict) == 1)
        b3 = (compare_dict(first.units, other.units, verbose=verbose_dict) == 1)
        if not b1 and verbose:
            print("... conditions don't match")
        if not b2 and verbose:
            print("... conditions units don't match")
        if not b3 and verbose:
            print("... units don't match")
        b *= b1 * b2 * b3

        # Compare lines
        # -----------
        if first.lines is None and other.lines is None:
            b4 = True
        elif first.lines is None:
            b4 = False
        elif other.lines is None:
github radis / radis / radis / spectrum / compare.py View on Github external
b *= b1

            if plot:
                try:
                    plot_diff(first, other, var=k, wunit=wunit,
                              normalize=normalize, verbose=verbose,
                              **kwargs)
                except:
                    print('... there was an error while plotting {0}'.format(k))

        # Compare conditions and units
        # -----------
        verbose_dict = 'if_different' if verbose else False
        b1 = (compare_dict(first.conditions, other.conditions, verbose=verbose_dict) == 1)
        b2 = (compare_dict(first.cond_units, other.cond_units, verbose=verbose_dict) == 1)
        b3 = (compare_dict(first.units, other.units, verbose=verbose_dict) == 1)
        if not b1 and verbose:
            print("... conditions don't match")
        if not b2 and verbose:
            print("... conditions units don't match")
        if not b3 and verbose:
            print("... units don't match")
        b *= b1 * b2 * b3

        # Compare lines
        # -----------
        if first.lines is None and other.lines is None:
            b4 = True
        elif first.lines is None:
            b4 = False
        elif other.lines is None:
            b4 = False
github radis / radis / radis / misc / cache_files.py View on Github external
if current_version > file_version:
        warn(DeprecationWarning('File {0} has been generated in '.format(file) +
                                'a deprecated version ({0}) compared to current ({1})'.format(
            file_version, current_version) +
            '. Delete it to regenerate it on next run'))
        out = False
    elif current_version == file_version:
        out = True
    else:
        raise ValueError('Cache file ({0}) generated with a future version ({1} > {2})? '.format(
                            file, file_version, current_version)+\
                         "Do you own a DeLorean? Delete the file manually if you understand what happened")

    # Compare metadata
    metadata = _h5_compatible(metadata)
    out, compare_string = compare_dict(
        metadata, attrs, verbose=False, return_string=True)
    if out != 1:
        raise DeprecatedFileError('Metadata in file {0} dont match '.format(file) +
                                  'expected values. See comparison below:' +
                                  '\n\tExpected\tFile\n{0}'.format(compare_string))

    return out
github radis / radis / radis / misc / config.py View on Github external
try:
        verbose_compare = 'if_different' if verbose else False
        assert len(dict_entries1) == len(dict_entries2)
        assert compare_lists(list(dict_entries1.keys()), list(dict_entries2.keys()),
                             verbose=verbose_compare) == 1
        for k in dict_entries1.keys():
            v1 = dict_entries1[k]
            v2 = dict_entries2[k]
            if k in ['info', 'format', 'parfuncfmt', 'levelsfmt']:
                assert v1 == v2
            elif k in ['path']:
                assert compare_lists([stdpath(path1) for path1 in v1],
                                     [stdpath(path2) for path2 in v2],
                                     verbose=verbose_compare) == 1
            elif k in ['levels']:
                assert compare_dict(v1, v2, compare_as_paths=list(v1.keys()),
                                    verbose=verbose_compare) == 1
            else:
                raise ValueError('Unexpected key:', k)

        return None

    except AssertionError:
        if verbose:
            print('Key doesnt match:', k)
        return k
github radis / radis / radis / lbl / loader.py View on Github external
for s in self.SpecDatabase.get():
                        sc = compare_dict(
                            conditions, s.conditions, verbose=False)
                        if sc > score:
                            score = sc
                            best = s
                    return best

                best = get_best_match()
                if best is None:
                    raise ValueError("No spectrum found in database. Do not use " +
                                     "autoretrieve='force'")
                else:
                    # Print comparison with best
                    print('Differences in best case :')
                    compare_dict(conditions, best.conditions)

                    raise ValueError('No spectrum found in database that matched ' +
                                     'given conditions. See best case found above')
            else:
                # just a print, then calculate
                if self.verbose:
                    print('No spectrum found in database that ' +
                          'matched given conditions.')
                return None
github radis / radis / radis / lbl / loader.py View on Github external
def get_best_match():
                    ''' Returns the Spectrum that matches the input conditions
                    better. Used to give a better error message in case no
                    Spectrum was found '''
                    best = None
                    score = 0
                    for s in self.SpecDatabase.get():
                        sc = compare_dict(
                            conditions, s.conditions, verbose=False)
                        if sc > score:
                            score = sc
                            best = s
                    return best
github radis / radis / radis / spectrum / compare.py View on Github external
print('...', k, "don't match (up to {0:.3}% diff.,".format(
                        error*100)+' average {0:.3f}%)'.format(avgerr*100))
            b *= b1

            if plot:
                try:
                    plot_diff(first, other, var=k, wunit=wunit,
                              normalize=normalize, verbose=verbose,
                              **kwargs)
                except:
                    print('... there was an error while plotting {0}'.format(k))

        # Compare conditions and units
        # -----------
        verbose_dict = 'if_different' if verbose else False
        b1 = (compare_dict(first.conditions, other.conditions, verbose=verbose_dict) == 1)
        b2 = (compare_dict(first.cond_units, other.cond_units, verbose=verbose_dict) == 1)
        b3 = (compare_dict(first.units, other.units, verbose=verbose_dict) == 1)
        if not b1 and verbose:
            print("... conditions don't match")
        if not b2 and verbose:
            print("... conditions units don't match")
        if not b3 and verbose:
            print("... units don't match")
        b *= b1 * b2 * b3

        # Compare lines
        # -----------
        if first.lines is None and other.lines is None:
            b4 = True
        elif first.lines is None:
            b4 = False