Skip to content

Commit

Permalink
Merge branch 'cherry_pick_omas_viewer_dev' into test_new_EFIT_mapping…
Browse files Browse the repository at this point in the history
…s_for_IDA
  • Loading branch information
AreWeDreaming committed Dec 12, 2023
2 parents 13c9570 + ddaf49d commit a06c7d8
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 28 deletions.
2 changes: 1 addition & 1 deletion omas/examples/omas_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# how to manipulate data that has units
ods.sample()
with omas_environment(ods, unitsio=True):
ne = ods['core_profiles.profiles_1d.0.electrons.density_thermal']
ne = ods['core_profiles.profiles_1d.0.electrons.density']
print(f'Mean density in m^-3: {numpy.mean(ne.to("m^-3").magnitude):3.3g}')
print(f'Mean density in cm^-3: {numpy.mean(ne.to("cm^-3").magnitude):3.3g}')

Expand Down
3 changes: 0 additions & 3 deletions omas/machine_mappings/d3d.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,6 @@
"core_profiles.profiles_1d.:.electrons.density_fit.psi_norm": {
"PYTHON": "core_profiles_profile_1d(ods, {pulse}, {PROFILES_tree!r})"
},
"core_profiles.profiles_1d.:.electrons.density_thermal": {
"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})"
},
Expand Down
3 changes: 1 addition & 2 deletions omas/machine_mappings/d3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,6 @@ def core_profiles_profile_1d(ods, pulse, PROFILES_tree="OMFIT_PROFS"):
query["electrons.temperature_fit.psi_norm"] = "PS_T_E"
query["ion[1].density_fit.psi_norm"] = "PS_N_C"
query["ion[1].temperature_fit.psi_norm"] = "PS_T_C"
query["ion[1].density_fit.psi_norm"] = "PS_T_C"
query["ion[1].velocity.toroidal_fit.psi_norm"]= "PS_V_TOR_C"
#query["j_total"] = "J_TOT"
#query["pressure_perpendicular"] = "P_TOT"
Expand Down Expand Up @@ -1473,7 +1472,6 @@ def core_profiles_profile_1d(ods, pulse, PROFILES_tree="OMFIT_PROFS"):
profiles_node = '\\TOP.PROFILES.'
query = {
"electrons.density": "EDENSFIT",
"electrons.density_thermal": "EDENSFIT",
"electrons.temperature": "ETEMPFIT"
}
for entry in query:
Expand All @@ -1490,6 +1488,7 @@ def core_profiles_profile_1d(ods, pulse, PROFILES_tree="OMFIT_PROFS"):
continue
for i_time, time in enumerate(data["time"]):
ods[f"core_profiles.profiles_1d[{i_time}]."+entry] = data[entry][i_time]

# ================================
@machine_mapping_function(__regression_arguments__, pulse=133221)
def core_profiles_global_quantities_data(ods, pulse):
Expand Down
2 changes: 1 addition & 1 deletion omas/machine_mappings/profiles_db_ccfe.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"core_profiles.profiles_1d.:": {
"PYTHON": "profile_db_to_ODS(ods, {pulse}, {tok!r}, {db!r}, {ngrid!r})"
},
"core_profiles.profiles_1d.:.electrons.density_thermal": {
"core_profiles.profiles_1d.:.electrons.density": {
"PYTHON": "profile_db_to_ODS(ods, {pulse}, {tok!r}, {db!r}, {ngrid!r})"
},
"core_profiles.profiles_1d.:.electrons.temperature": {
Expand Down
2 changes: 1 addition & 1 deletion omas/machine_mappings/profiles_db_ccfe.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def profile_db_to_ODS(ods, pulse, tok, db, ngrid):
"['TWOD']['Q']": 'core_profiles.profiles_1d[0].q',
"['TWOD']['TI']": 'core_profiles.profiles_1d[0].t_i_average',
"['TWOD']['TE']": 'core_profiles.profiles_1d[0].electrons.temperature',
"['TWOD']['NE']": 'core_profiles.profiles_1d[0].electrons.density_thermal',
"['TWOD']['NE']": 'core_profiles.profiles_1d[0].electrons.density',
"['TWOD']['CURTOT']": 'core_profiles.profiles_1d[0].j_tor',
"['TWOD']['QNBII']": 'q_nbi_i',
"['TWOD']['QNBIE']": 'q_nbi_e',
Expand Down
12 changes: 6 additions & 6 deletions omas/omas_physics.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ def summary_greenwald(ods, update=True):
% time_index: ods['equilibrium.time_slice.%s.profiles_1d.rho_tor_norm' % time_index]
},
):
ne = ods['core_profiles.profiles_1d.%d.electrons.density_thermal' % time_index]
ne = ods['core_profiles.profiles_1d.%d.electrons.density' % time_index]
volume = ods['equilibrium.time_slice.%d.profiles_1d.volume' % time_index]
ne_vol_avg = numpy.trapz(ne, x=volume) / volume[-1]

Expand Down Expand Up @@ -1051,11 +1051,11 @@ def summary_lineaverage_density(ods, line_grid=2000, time_index=None, update=Tru
Zgrid = ods['equilibrium']['time_slice'][time_index]['profiles_2d'][0]['grid']['dim2']

psi2d = ods['equilibrium']['time_slice'][time_index]['profiles_2d'][0]['psi']
psi_interp = scipy.interpolate.interp2d(Zgrid, Rgrid, psi2d)
psi_spl = RectBivariateSpline(Rgrid, Zgrid, psi2d)
psi_eq = ods['equilibrium']['time_slice'][time_index]['profiles_1d']['psi']
rhon_eq = ods['equilibrium']['time_slice'][time_index]['profiles_1d']['rho_tor_norm']
rhon_cp = ods['core_profiles']['profiles_1d'][time_index]['grid']['rho_tor_norm']
ne = ods['core_profiles']['profiles_1d'][time_index]['electrons']['density_thermal']
ne = ods['core_profiles']['profiles_1d'][time_index]['electrons']['density']
ne = numpy.interp(rhon_eq, rhon_cp, ne)
tck = scipy.interpolate.splrep(psi_eq, ne, k=3)

Expand Down Expand Up @@ -1105,7 +1105,7 @@ def summary_lineaverage_density(ods, line_grid=2000, time_index=None, update=Tru
i1 = zero_crossings[0]
i2 = zero_crossings[-1]

psival = [psi_interp(Zline[i], Rline[i])[0] for i in range(i1, i2, numpy.sign(i2 - i1))]
psival = [psi_spl(Rline[i], Zline[i], grid=False).item() for i in range(i1, i2, numpy.sign(i2 - i1))]
ne_interp = scipy.interpolate.splev(psival, tck)
ne_line = numpy.trapz(ne_interp)
ne_line /= abs(i2 - i1)
Expand Down Expand Up @@ -1239,7 +1239,7 @@ def summary_taue(ods, thermal=True, update=True):
with omas_environment(ods, coordsio={'equilibrium.time_slice.0.profiles_1d.psi': psi}):
volume = equilibrium_ods['profiles_1d']['volume']
kappa = volume[-1] / 2 / numpy.pi / numpy.pi / a / a / r_major
ne = ods['core_profiles']['profiles_1d'][time_index]['electrons']['density_thermal']
ne = ods['core_profiles']['profiles_1d'][time_index]['electrons']['density']
ne_vol_avg = numpy.trapz(ne, x=volume) / volume[-1]

if 'interferometer' in ods:
Expand Down Expand Up @@ -1542,7 +1542,7 @@ def core_profiles_pressures(ods, update=True):

__p__ = None
if 'density_thermal' in prof1d['electrons'] and 'temperature' in prof1d['electrons']:
__p__ = nominal_values(prof1d['electrons']['density_thermal'] * prof1d['electrons']['temperature'] * constants.e)
__p__ = nominal_values(prof1d['electrons']['density'] * prof1d['electrons']['temperature'] * constants.e)
elif 'pressure_thermal' in prof1d['electrons']:
__p__ = nominal_values(prof1d['electrons']['pressure_thermal'])

Expand Down
18 changes: 13 additions & 5 deletions omas/omas_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,10 @@ def get2d(contour_quantity):
if levels is None and value_1d is not None:
if contour_quantity == 'q':
max_q = int(numpy.round(omas_interp1d(0.95, x_value_1d, value_1d)))
levels = numpy.arange(max_q)
levels = numpy.arange(numpy.abs(max_q))
if max_q < 0:
levels *= -1
levels = levels[::-1]
else:
levels = numpy.linspace(numpy.min(value_1d), numpy.max(value_1d), 11)[1:-1]
levels = numpy.hstack((levels, levels[-1] + (levels[1] - levels[0]) * numpy.arange(100)[1:]))
Expand Down Expand Up @@ -799,8 +802,10 @@ def get2d(contour_quantity):
r = scipy.ndimage.zoom(r, sf)
z = scipy.ndimage.zoom(z, sf)
value_2d = scipy.ndimage.zoom(value_2d, sf)

cs = ax.contour(r, z, value_2d, levels, **kw)
if levels is not None:
cs = ax.contour(r, z, value_2d, levels, **kw)
else:
cs = ax.contour(r, z, value_2d, **kw)

if label_contours or ((label_contours is None) and (contour_quantity == 'q')):
ax.clabel(cs)
Expand Down Expand Up @@ -1186,7 +1191,7 @@ def core_profiles_currents_summary(ods, time_index=None, time=None, ax=None, **k

@add_to__ODS__
def core_profiles_summary(ods, time_index=None, time=None, fig=None,
ods_species=None, quantities=['density_thermal', 'temperature'],
ods_species=None, quantities=['density', 'temperature'],
x_axis = "rho_tor_norm", **kw):
"""
Plot densities and temperature profiles for electrons and all ion species
Expand Down Expand Up @@ -1280,7 +1285,8 @@ def core_profiles_summary(ods, time_index=None, time=None, fig=None,
# plotting_list.append(prof1d[specie][q]*scale * prof1d[specie]['element[0].z_n'])
# label_name_z.append(r'$\times$' + f" {int(prof1d[specie]['element[0].z_n'])}")
# else:
if len(prof1d[specie][q]) == len(prof1d[specie][q + "_error_upper"]):

if q + "_error_upper" in prof1d[specie] and len(prof1d[specie][q]) == len(prof1d[specie][q + "_error_upper"]):
plotting_list.append(unumpy.uarray(prof1d[specie][q]*scale,
prof1d[specie][q + "_error_upper"]*scale))
else:
Expand All @@ -1292,6 +1298,8 @@ def core_profiles_summary(ods, time_index=None, time=None, fig=None,
prof1d[specie][q + "_fit.measured_error_upper"]*scale])
except Exception as e:
data_list.append(None)
else:
data_list.append(None)
label_name_z.append("")
label_name.append(f'{names[index]} {q.capitalize()}')
elif "e_field.radial" not in q:
Expand Down
2 changes: 1 addition & 1 deletion omas/omas_symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
_symbols['.b_field_r'] = r'$B_{r}$'
_symbols['.b_field_tor'] = r'$B_{\phi}$'
_symbols['.b_field_z'] = r'$B_{z}$'
_symbols['.electrons.density_thermal'] = '$n_e$'
_symbols['.electrons.density'] = '$n_e$'
_symbols['.ion.:.density'] = r'$n_{i:}$'
_symbols['.n_e'] = '$n_e$'
_symbols['.potential_floating'] = r'$\phi_f'
Expand Down
2 changes: 1 addition & 1 deletion omas/samples/sample_core_profiles_ods.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"profiles_1d": [
{
"electrons": {
"density_thermal": [
"density": [
6.153301513064224e+19,
6.072762281483232e+19,
5.885729236754774e+19,
Expand Down
2 changes: 1 addition & 1 deletion omas/tests/test_omas_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ def test_latexit(self):
assert latexit['.n_e'] == '$n_e$'
assert latexit['n_e'] == '$n_e$'

assert latexit['core_profiles.profiles_1d[:].electrons.density_thermal'] == '$n_e$'
assert latexit['core_profiles.profiles_1d[:].electrons.density'] == '$n_e$'
assert latexit['barometry.gauge[:].pressure.data'] == '$P$'
assert latexit['equilibrium.time_slice[0].ggd[1].b_field_tor[0].values'] == r'$B_{\phi}$'
assert latexit['core_profiles.profiles_1d[4].ion[0].density'] == '$n_{i0}$'
Expand Down
4 changes: 2 additions & 2 deletions omas/tests/test_omas_physics.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ def test_coordsio(self):
ods5 = ODS()
ods5['core_profiles.profiles_1d[0].grid.rho_tor_norm'] = data5
with omas_environment(ods5, coordsio={'core_profiles.profiles_1d[0].grid.rho_tor_norm': data10}):
ods5['core_profiles.profiles_1d[0].electrons.density_thermal'] = data10
ods5['core_profiles.profiles_1d[0].electrons.density'] = data10
assert len(ods5['core_profiles.profiles_1d[0].grid.rho_tor_norm']) == 5
assert len(ods5['core_profiles.profiles_1d[0].electrons.density_thermal']) == 5
assert len(ods5['core_profiles.profiles_1d[0].electrons.density']) == 5

ods6 = ODS()
ods6['core_profiles.profiles_1d[0].grid.rho_tor_norm'] = data5
Expand Down
2 changes: 1 addition & 1 deletion omas/tests/test_omas_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def tearDown(self):
pyplot.close()

def test_quantity(self):
self.ods.plot_quantity('core_profiles.profiles_1d.0.electrons.density_thermal', '$n_e$', lw=2)
self.ods.plot_quantity('core_profiles.profiles_1d.0.electrons.density', '$n_e$', lw=2)
self.ods.plot_quantity('@core.*elec.*dens', '$n_e$', lw=2)
try:
self.ods.plot_quantity('@core.*')
Expand Down
2 changes: 1 addition & 1 deletion omas/tests/test_omas_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_different_ods(self):
assert isinstance(diff_prof2, list)
assert 'core_profiles' in ' '.join(diff_prof2)
ods2.sample_core_profiles()
ods2['core_profiles.profiles_1d.0.electrons.density_thermal'][0] = 1.5212
ods2['core_profiles.profiles_1d.0.electrons.density'][0] = 1.5212
diff_prof3 = ods2.diff(ods3)
assert isinstance(diff_prof3, list)
assert 'value' in ' '.join(diff_prof3)
Expand Down
4 changes: 2 additions & 2 deletions sphinx/source/how.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ The `ODS` class extends native Python dictionary and list classes with:

.. code-block:: python
ods['core_profiles.profiles_1d.0.electrons.density_thermal'].xarray()
ods['core_profiles.profiles_1d.0.electrons.density'].xarray()
14. Conveniently **plot individual quantities**:

.. code-block:: python
ods.plot_quantity('core_profiles.profiles_1d.0.electrons.density_thermal')
ods.plot_quantity('core_profiles.profiles_1d.0.electrons.density')
15. **Use regular expressions** with ``@`` construct for accessing data and plotting:

Expand Down

0 comments on commit a06c7d8

Please sign in to comment.