How to use the omas.omas_utils._extra_structures function in omas

To help you get started, we’ve selected a few omas 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 gafusion / omas / omas / omas_physics.py View on Github external
f.write(str('\n'.join(csig)))
        else:
            # check that omas_cocos.py file is up-to-date
            with open(filename, 'r') as f:
                original = str(f.read())
            new = str('\n'.join(csig))
            import difflib
            diff = difflib.unified_diff(original, new)
            assert original == new, 'COCOS signals are not up-to-date! Run `make cocos` to update the omas_cocos.py file.\n' + ''.join(diff)

        return out

    finally:
        _structures.clear()
        _structures.update(_structures_bkp)
        _extra_structures.clear()
        _extra_structures.update(_extra_structures_bkp)
github gafusion / omas / omas / omas_core.py View on Github external
continue
                else:
                    consistency_value_propagate = consistency_value
                    if consistency_value:
                        if isinstance(self.getraw(item), ODS) and not self.structure:
                            if not self.location:
                                # load the json structure file
                                structure = load_structure(item, imas_version=self.imas_version)[1][item]
                            else:
                                raise RuntimeError('When switching from False to True .consistency_check=True must be set at the top-level ODS')
                        elif self.location.endswith('.ids_properties') and item == 'occurrence':
                            continue
                        else:
                            structure_key = item if not isinstance(item, int) else ':'
                            strict_fail = False
                            if isinstance(consistency_value, str) and 'strict' in consistency_value and structure_key in self.structure and p2l(self.location + '.%s' % item)[0] in _extra_structures and o2i(o2u(self.location + '.%s' % item)) in _extra_structures[p2l(self.location + '.%s' % item)[0]]:
                                strict_fail = True
                            if not strict_fail and structure_key in self.structure:
                                structure = self.structure[structure_key]
                            else:
                                options = list(self.structure.keys())
                                if len(options) == 1 and options[0] == ':':
                                    options = 'A numerical index is needed with n>=0'
                                else:
                                    options = 'Did you mean: %s' % options
                                txt = 'IMAS %s location: %s' % (self.imas_version, self.location + '.' + structure_key)
                                if isinstance(consistency_value, str) and ('warn' in consistency_value or 'drop' in consistency_value):
                                    if 'warn' in consistency_value:
                                        if 'drop' in consistency_value:
                                            printe(f'Dropping invalid {txt}')
                                        else:
                                            printe(f'Invalid {txt}')
github gafusion / omas / omas / omas_physics.py View on Github external
if isinstance(structures, str):
        structures = [structures]
    structures += cocos_structures
    structures = numpy.unique(structures)

    from .omas_utils import _structures, _extra_structures
    from .omas_utils import i2o
    from .omas_core import ODS

    # if generate_cocos_signals is run after omas has been used for something else
    # (eg. when running test_examples) it may be that _extra_structures is not empty
    # Thus, we clear _structures and _extra_structures to make sure that
    # dict_structures() is not polluted by _extra_structures
    _structures_bkp = copy.deepcopy(_structures)
    _extra_structures_bkp = copy.deepcopy(_extra_structures)
    try:
        _structures.clear()
        _extra_structures.clear()

        ods = ODS()
        out = {}
        text = []
        csig = ["""
'''List of automatic COCOS transformations

-------
'''
# COCOS signals candidates are generated by running utilities/generate_cocos_signals.py
# Running this script is useful to keep track of new signals that IMAS adds in new data structure releases
#
# In this file you are only allowed to edit/add entries to the `_cocos_signals` dictionary