How to use the omas.load_omas_json 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_sample.py View on Github external
:param ods: ODS instance

    :param time_index: int

    :param add_junk_ion: bool
        Flag for adding a junk ion for testing how well functions tolerate problems. This will be missing labels, etc.

    :param include_pressure: bool
        Include pressure profiles when temperature and density are added

    :return: ODS instance with profiles added.
        Since the original is modified, it is not necessary to catch the return, but it may be convenient to do so in
        some contexts. If you do not want the original to be modified, deepcopy it first.
    """
    from omas import load_omas_json
    pr = load_omas_json(imas_json_dir + '/../samples/sample_core_profiles_ods.json', consistency_check=False)

    ods['core_profiles.profiles_1d'][time_index].update(pr['core_profiles.profiles_1d.0'])
    ods['core_profiles.vacuum_toroidal_field.r0'] = pr['core_profiles.vacuum_toroidal_field.r0']
    ods.set_time_array('core_profiles.vacuum_toroidal_field.b0', time_index, pr['core_profiles.vacuum_toroidal_field.b0'][0])

    if add_junk_ion:
        ions = ods['core_profiles.profiles_1d'][time_index]['ion']
        ions[len(ions)] = copy.deepcopy(ions[len(ions) - 1])
        for item in ions[len(ions) - 1].flat():
            ions[len(ions) - 1][item] *= 0

    if not include_pressure:
        for item in ods.physics_core_profiles_pressures(update=False).flat().keys():
            if p2l(item)[0] == 'core_profiles' and p2l(item)[-1].startswith('pres') and item in ods:
                del ods[item]
github gafusion / omas / omas / omas_sample.py View on Github external
def core_sources(ods, time_index=0):
    """
    Add sample core_profiles data

    :param ods: ODS instance

    :param time_index: int

    :return: ODS instance with sources added.
        Since the original is modified, it is not necessary to catch the return, but it may be convenient to do so in
        some contexts. If you do not want the original to be modified, deepcopy it first.
    """
    from omas import load_omas_json
    pr = load_omas_json(imas_json_dir + '/../samples/sample_core_sources_ods.json', consistency_check=False)['core_sources']

    if 'core_sources' not in ods:
        ods['core_sources'].update(pr)
    else:
        for item in pr:
            if item not in ods['core_sources']:
                ods['core_sources'][item] = pr[item]
        sources = pr['source']
        for source in sources:
            ods['core_sources.source'][source]['identifier'].update(sources[source]['identifier'])
            ods['core_sources.source'][source]['profiles_1d'][time_index].update(sources[source]['profiles_1d.0'])
    ods.set_time_array('core_sources.time', time_index, float(time_index))
    return ods
github gafusion / omas / omas / omas_sample.py View on Github external
This is in the sample set, so not including it means deleting it.

    :param include_q: bool
        Include safety factor
        This is in the sample set, so not including it means deleting it.

    :param include_xpoint: bool
        Include X-point R-Z coordinates
        This is not in the sample set, so including it means making it up

    :return: ODS instance with equilibrium data added
        Since the original is modified, it is not necessary to catch the return, but it may be convenient to do so in
        some contexts. If you do not want the original to be modified, deepcopy it first.
    """
    from omas import load_omas_json
    eq = load_omas_json(imas_json_dir + '/../samples/sample_equilibrium_ods.json', consistency_check=False)

    phi = eq['equilibrium.time_slice.0.profiles_1d.phi']
    psi = eq['equilibrium.time_slice.0.profiles_1d.psi']
    q = eq['equilibrium.time_slice.0.profiles_1d.q']

    if not include_profiles:
        del eq['equilibrium.time_slice.0.profiles_1d']

    if not include_phi:
        if 'profiles_1d' in eq['equilibrium.time_slice.0']:
            del eq['equilibrium.time_slice.0.profiles_1d.phi']
        del eq['equilibrium.time_slice.0.profiles_2d.0.phi']
    else:
        eq['equilibrium.time_slice.0.profiles_1d.phi'] = phi

    if not include_psi:
github gafusion / omas / omas / omas_sample.py View on Github external
def core_transport(ods, time_index=0):
    """
    Add sample core_profiles data

    :param ods: ODS instance

    :param time_index: int

    :return: ODS instance with sources added.
        Since the original is modified, it is not necessary to catch the return, but it may be convenient to do so in
        some contexts. If you do not want the original to be modified, deepcopy it first.
    """
    from omas import load_omas_json
    pr = load_omas_json(imas_json_dir + '/../samples/sample_core_transport_ods.json', consistency_check=False)['core_transport']

    if 'core_transport' not in ods:
        ods['core_transport'].update(pr)
    else:
        for item in pr:
            if item not in ods['core_transport']:
                ods['core_transport'][item] = pr[item]
        models = pr['model']
        for model in models:
            ods['core_transport.model'][model]['identifier'].update(models[model]['identifier'])
            ods['core_transport.model'][model]['profiles_1d'][time_index].update(models[model]['profiles_1d.0'])
    ods.set_time_array('core_sources.time', time_index, float(time_index))
    return ods