Skip to content

Commit

Permalink
Merge pull request #258 from gafusion/omas_plot_w_new_EFIT_mapping
Browse files Browse the repository at this point in the history
Omas plot w new efit mapping
  • Loading branch information
AreWeDreaming authored Nov 25, 2024
2 parents 5416ea7 + fc99883 commit cc925c3
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 86 deletions.
17 changes: 10 additions & 7 deletions omas/machine_mappings/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
import glob
from omas.omas_setup import omas_dir
from omas.utilities.omas_mds import mdsvalue
from omas.utilities.omas_mds import mdsvalue, get_pulse_id

__support_files_cache__ = {}

Expand Down Expand Up @@ -47,30 +47,33 @@ def get_support_file(object_type, filename):
__MDS_gEQDSK_COCOS_identify_cache__ = {}


def MDS_gEQDSK_COCOS_identify(machine, pulse, EFIT_tree):
def MDS_gEQDSK_COCOS_identify(machine, pulse, EFIT_tree, EFIT_run_id):
"""
Python function that queries MDS+ EFIT tree to figure
out COCOS convention used for a particular reconstruction
:param machine: machine name
:param pulse: pulse
:param pulse: pulse number
:param EFIT_tree: MDS+ EFIT tree name
:param EFIT_run_id: with id extension for non-standard shot numbers. E.g. 19484401 for EFIT tree
:return: integer cocos convention
"""
if (machine, pulse, EFIT_tree) in __MDS_gEQDSK_COCOS_identify_cache__:
return __MDS_gEQDSK_COCOS_identify_cache__[(machine, pulse, EFIT_tree)]
pulse_id = get_pulse_id(pulse, EFIT_run_id)
if (machine, pulse_id, EFIT_tree) in __MDS_gEQDSK_COCOS_identify_cache__:
return __MDS_gEQDSK_COCOS_identify_cache__[(machine, pulse_id, EFIT_tree)]
TDIs = {'bt': f'mean(\\{EFIT_tree}::TOP.RESULTS.GEQDSK.BCENTR)', 'ip': f'mean(\\{EFIT_tree}::TOP.RESULTS.GEQDSK.CPASMA)'}
res = mdsvalue(machine, EFIT_tree, pulse, TDIs).raw()
res = mdsvalue(machine, EFIT_tree, pulse_id, TDIs).raw()
bt = res['bt']
ip = res['ip']
g_cocos = {(+1, +1): 1, (+1, -1): 3, (-1, +1): 5, (-1, -1): 7, (+1, 0): 1, (-1, 0): 3}
sign_Bt = int(np.sign(bt))
sign_Ip = int(np.sign(ip))
cocosio = g_cocos.get((sign_Bt, sign_Ip), None)
__MDS_gEQDSK_COCOS_identify_cache__[(machine, pulse, EFIT_tree)] = cocosio
__MDS_gEQDSK_COCOS_identify_cache__[(machine, pulse_id, EFIT_tree)] = cocosio
return cocosio


Expand Down
2 changes: 1 addition & 1 deletion omas/machine_mappings/_efit.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"__cocos_rules__": {
"EFIT_tree": {
"eval2TDI": "py2tdi(MDS_gEQDSK_COCOS_identify, 'data(\\{EFIT_tree}::TOP.RESULTS.GEQDSK.BCENTR)', 'data(\\{EFIT_tree}::TOP.RESULTS.GEQDSK.CPASMA)')",
"PYTHON": "MDS_gEQDSK_COCOS_identify({machine!r}, {pulse}, {EFIT_tree!r})"
"PYTHON": "MDS_gEQDSK_COCOS_identify({machine!r}, {pulse}, {EFIT_tree!r}, {EFIT_run_id!r})"
}
},
"equilibrium.code.name": {
Expand Down
76 changes: 39 additions & 37 deletions omas/machine_mappings/d3d.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"default_tree": "D3D",
"fast_ece": false,
"nref": 0,
"revision": "BLESSED"
"revision": "BLESSED",
"PROFILES_run_id": null,
"EFIT_run_id": null
},
"bolometer.channel.:": {
"PYTHON": "bolometer_hardware(ods, {pulse})"
Expand Down Expand Up @@ -113,36 +115,33 @@
"coils_non_axisymmetric.coil.:.name": {
"PYTHON": "coils_non_axisymmetric_hardware(ods, {pulse})"
},
"core_profiles": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
},
"core_profiles.global_quantities.v_loop": {
"COCOSIO": 11,
"PYTHON": "core_profiles_global_quantities_data(ods, {pulse})"
},
"core_profiles.ids_properties.homogeneous_time": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.e_field.radial": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.e_field.radial_error_upper": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.electrons.density_error_upper": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.electrons.density_fit.measured": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.electrons.density_fit.measured_error_upper": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.electrons.density_fit.psi_norm": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.electrons.density_thermal": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
Expand All @@ -151,28 +150,28 @@
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
},
"core_profiles.profiles_1d.:.electrons.temperature": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.electrons.temperature_error_upper": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.electrons.temperature_fit.measured": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.electrons.temperature_fit.measured_error_upper": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.electrons.temperature_fit.psi_norm": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.grid.rho_pol_norm": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.grid.rho_tor_norm": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.ion.:": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.ion.:.density_fit.measured": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
Expand All @@ -195,61 +194,64 @@
"core_profiles.profiles_1d.:.ion.:.density_thermal_fit.measured_error_upper": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
},
"core_profiles.profiles_1d.:.ion.:.density_fit.psi_norm": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.ion.:.element.:": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.ion.:.element.:.a": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.ion.:.element.:.z_n": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.ion.:.label": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.ion.:.temperature": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.ion.:.temperature_error_upper": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.ion.:.temperature_fit.measured": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.ion.:.temperature_fit.measured_error_upper": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.ion.:.temperature_fit.psi_norm": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.ion.:.velocity.toroidal": {
"COCOSIO": 11,
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.ion.:.velocity.toroidal_error_upper": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.ion.:.velocity.toroidal_fit.measured": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.ion.:.velocity.toroidal_fit.measured_error_upper": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.ion.:.velocity.toroidal_fit.psi_norm": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.j_total": {
"COCOSIO": 11,
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.pressure_perpendicular": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"core_profiles.profiles_1d.:.time": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
},
"core_profiles.time": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r}, {PROFILES_run_id!r})"
},
"ec_launchers.beam.:": {
"PYTHON": "ec_launcher_active_hardware(ods, {pulse})"
Expand Down
38 changes: 28 additions & 10 deletions omas/machine_mappings/d3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from omas.omas_core import ODS
from omas.omas_structure import add_extra_structures
from omas.omas_physics import omas_environment
import copy

__all__ = []
__regression_arguments__ = {'__all__': __all__}
Expand Down Expand Up @@ -1383,12 +1384,13 @@ def add_extra_profile_structures():
add_extra_structures(extra_structures)


@machine_mapping_function(__regression_arguments__, pulse=194842001, PROFILES_tree="OMFIT_PROFS")
def core_profiles_profile_1d(ods, pulse, PROFILES_tree="OMFIT_PROFS"):
@machine_mapping_function(__regression_arguments__, pulse=194844, PROFILES_tree="OMFIT_PROFS", PROFILES_run_id='001')
def core_profiles_profile_1d(ods, pulse, PROFILES_tree="OMFIT_PROFS", PROFILES_run_id=None):
add_extra_profile_structures()
ods["core_profiles.ids_properties.homogeneous_time"] = 1
sh = "core_profiles.profiles_1d"
if "OMFIT_PROFS" in PROFILES_tree:
pulse_id = int(str(pulse) + PROFILES_run_id)
omfit_profiles_node = '\\TOP.'
query = {
"electrons.density_thermal": "N_E",
Expand Down Expand Up @@ -1419,11 +1421,11 @@ def core_profiles_profile_1d(ods, pulse, PROFILES_tree="OMFIT_PROFS"):
query[entry] = omfit_profiles_node + query[entry]
for entry in uncertain_entries:
query[entry + "_error_upper"] = "error_of(" + query[entry] + ")"
data = mdsvalue('d3d', treename=PROFILES_tree, pulse=pulse, TDI=query).raw()
data = mdsvalue('d3d', treename=PROFILES_tree, pulse=pulse_id, TDI=query).raw()
if data is None:
print("No mds+ data")
raise ValueError(f"Could not find any data in MDS+ for {pulse} and {PROFILES_tree}")
dim_info = mdsvalue('d3d', treename=PROFILES_tree, pulse=pulse, TDI="\\TOP.n_e")
dim_info = mdsvalue('d3d', treename=PROFILES_tree, pulse=pulse_id, TDI="\\TOP.n_e")
data['time'] = dim_info.dim_of(1) * 1.e-3
psi_n = dim_info.dim_of(0)
data['grid.rho_pol_norm'] = np.zeros((data['time'].shape + psi_n.shape))
Expand Down Expand Up @@ -1469,6 +1471,8 @@ def core_profiles_profile_1d(ods, pulse, PROFILES_tree="OMFIT_PROFS"):
ods[f"{sh}[{i_time}].ion[1].element[0].a"] = 12.011
ods[f"{sh}[{i_time}].ion[0].label"] = "D"
ods[f"{sh}[{i_time}].ion[1].label"] = "C"
ods[f"{sh}[{i_time}].electrons.density_thermal"] = copy.deepcopy(ods[f"{sh}[{i_time}].electrons.density"])
ods[f"{sh}[{i_time}].electrons.density_thermal_error_upper"] = copy.deepcopy(ods[f"{sh}[{i_time}].electrons.density_error_upper"])
else:
profiles_node = '\\TOP.PROFILES.'
query = {
Expand All @@ -1483,6 +1487,14 @@ def core_profiles_profile_1d(ods, pulse, PROFILES_tree="OMFIT_PROFS"):
data = mdsvalue('d3d', treename=PROFILES_tree, pulse=pulse, TDI=query).raw()
dim_info = mdsvalue('d3d', treename=PROFILES_tree, pulse=pulse, TDI="\\TOP.PROFILES.EDENSFIT")
data['time'] = dim_info.dim_of(1) * 1.e-3
dim_info = mdsvalue('d3d', treename=PROFILES_tree, pulse=pulse, TDI="\\TOP.PROFILES.ETEMPFIT")
data['time_te'] = dim_info.dim_of(1) * 1.e-3
ods[f"core_profiles.time"] = data['time'][np.in1d(data['time'], data['time_te'])]
mask_dict = {
"electrons.density": np.in1d(data['time'], ods[f"core_profiles.time"]),
"electrons.density_thermal": np.in1d(data['time'], ods[f"core_profiles.time"]),
"electrons.temperature": np.in1d(data['time_te'], ods[f"core_profiles.time"])
}
rho_tor_norm = dim_info.dim_of(0)
data['grid.rho_tor_norm'] = np.zeros((data['time'].shape + rho_tor_norm.shape))
data['grid.rho_tor_norm'][:] = rho_tor_norm
Expand All @@ -1491,7 +1503,7 @@ def core_profiles_profile_1d(ods, pulse, PROFILES_tree="OMFIT_PROFS"):
if isinstance(data[entry], Exception):
continue
for i_time, time in enumerate(data["time"]):
ods[f"core_profiles.profiles_1d[{i_time}]."+entry] = data[entry][i_time]
ods[f"core_profiles.profiles_1d[{i_time}]."+entry] = data[entry][mask_dict[entry]][i_time]
#Needed for ion components
#for i_time, time in enumerate(data["time"]):
# ods[f"{sh}[{i_time}].ion[0].element[0].z_n"] = 1
Expand All @@ -1502,19 +1514,25 @@ def core_profiles_profile_1d(ods, pulse, PROFILES_tree="OMFIT_PROFS"):
# ods[f"{sh}[{i_time}].ion[1].label"] = "C"

# ================================
@machine_mapping_function(__regression_arguments__, pulse=133221)
def core_profiles_global_quantities_data(ods, pulse):
@machine_mapping_function(__regression_arguments__, pulse=133221, PROFILES_tree="ZIPFIT01", PROFILES_run_id=None)
def core_profiles_global_quantities_data(ods, pulse, PROFILES_tree="ZIPFIT01", PROFILES_run_id=None):
from scipy.interpolate import interp1d

ods1 = ODS()
unwrap(magnetics_hardware)(ods1, pulse)

with omas_environment(ods, cocosio=1):
cp = ods['core_profiles']
gq = ods['core_profiles.global_quantities']
if 'time' not in cp:
m = mdsvalue('d3d', pulse=pulse, TDI="\\TOP.PROFILES.EDENSFIT", treename="ZIPFIT01")
cp['time'] = m.dim_of(1) * 1e-3
if "ZIPFIT0" in PROFILES_tree:
m = mdsvalue('d3d', pulse=pulse, TDI="\\TOP.PROFILES.EDENSFIT", treename=PROFILES_tree)
cp['time'] = m.dim_of(1) * 1e-3
elif "OMFIT_PROFS" in PROFILES_tree and PROFILES_run_id is not None:
pulse_id = int(str(pulse) + PROFILES_run_id)
dim_info = mdsvalue('d3d', treename=PROFILES_tree, pulse=pulse_id, TDI="\\TOP.n_e")
cp['time'] = dim_info.dim_of(1) * 1.e-3
else:
raise ValueError(f"Trying to access global_quantities with unknown profiles tree: {PROFILES_tree}")
t = cp['time']

m = mdsvalue('d3d', pulse=pulse, TDI=f"ptdata2(\"VLOOP\",{pulse})", treename=None)
Expand Down
Loading

0 comments on commit cc925c3

Please sign in to comment.