Commit 664fef3f authored by Daniel Boeckenhoff's avatar Daniel Boeckenhoff
Browse files

plot_standard_case added

parent 41dd5b70
......@@ -49,6 +49,7 @@ def measurements(program, port):
images[images < 0] = 0
if not status:
raise ValueError("Could not retrieve. Bad status")
verbose = 500
status3, mapping = IR.download_heatflux_scene_model_reference(
port, program=program, verbose=verbose)
# testmode=False)
......@@ -84,7 +85,7 @@ def measurements_projected(program, port):
measurements_projected.save(measurements_projected_path)
else:
measurements_projected = tfields.Mesh3D.load(measurements_projected_path)
return measurments_projected
return measurements_projected
def strikelines(program, port):
......@@ -99,7 +100,6 @@ def strikelines(program, port):
'{program}_port_{port}_measurements_mapped.npz'
.format(**locals())))
verbose = 500
if not os.path.exists(measurements_mapped_path):
divertor_evaluator = get_divertor_evaluator()
divertor_evaluator.measurements_projected = measurements_projected(program, port)
......@@ -137,7 +137,8 @@ def strikeline_movie(program, port):
# break
def plot_strikeline_frame(axes, program, port, time, unit='ns', **kwargs):
def plot_strikeline_frame(axes, program, port, time, unit='ns',
measurements_mapped=None, **kwargs):
# print(len(measurements_mapped.fields))
# rna.plotting.use('pyqtgraph')
# # rna.plotting.backend.set_style()
......@@ -163,36 +164,62 @@ def plot_strikeline_frame(axes, program, port, time, unit='ns', **kwargs):
# mesh.maps[0].fields[i][np.isnan(mesh.maps[0].fields[i])] = 0
# mesh.plot(map_index=45, z_index=2)
if unit == 's':
time /= 1e9
time *= 1e9
elif not unit == 'ns':
raise NotImplementedError("only nano seconds supported")
try:
measurements_mapped = strikelines(program, port)
except Exception as err:
print("Error while processing program {program}, port {port}: {err}"
.format(**locals()))
axes.set_aspect(3)
axes.axis('off')
axes.text(0.5, 0.5, str(err),
horizontalalignment='center', fontsize=4)
return None
if measurements_mapped is None:
try:
measurements_mapped = strikelines(program, port)
except Exception as err:
print("Error while processing program {program}, port {port}: {err}"
.format(**locals()))
axes.set_aspect(3)
axes.axis('off')
axes.text(0.5, 0.5, str(err),
horizontalalignment='center', fontsize=4)
return None
times = np.array(measurements_mapped.names)
idx = np.searchsorted(times, time, side="left")
print(time, idx)
values = measurements_mapped.fields[idx]
vmax = kwargs.get('vmax', None)
if isinstance(vmax, str):
if vmax == 'max':
vmax = values[~np.isnan(values)].max()
print(vmax)
else:
raise NotImplementedError()
kwargs['vmax'] = vmax
divertor_evaluator = get_divertor_evaluator()
artist = divertor_evaluator.plot(measurements_mapped.fields[idx], axes=axes,
**kwargs)
artist = divertor_evaluator.plot(values, axes=axes, **kwargs)
return artist
def plot_strikeline_frame_all_ports(program, time, **kwargs):
"""
python -c "from mapping import plot_strikeline_frame, plot_strikeline_frame_all_ports; import rna; plot_strikeline_frame_all_ports('20180927.007', 'max'); rna.plotting.show()"
Args:
time (float | str):
'max': maxima of all frames
'max_cumulative': maxima of all frames
"""
ports = [10, 11, 20, 21, 30, 31, 40, 41, 50, 51]
# ports = [10, 11]
# ports = [10, 11, 50, 51]
data = {}
for port in ports:
print(port)
try:
data[port] = strikelines(program, port)
except Exception as err:
data[port] = None
if time == 'max':
max_times = {}
for port in ports:
try:
measurements_mapped = strikelines(program, port)
except Exception as err:
measurements_mapped = data[port]
if measurements_mapped is None:
continue
frame_maxima = np.array([f[~np.isnan(f)].max()
for f in measurements_mapped.fields])
......@@ -200,8 +227,23 @@ def plot_strikeline_frame_all_ports(program, time, **kwargs):
max_times[np.max(frame_maxima[idx])] = measurements_mapped.names[idx]
q_max = max(max_times.keys())
time = max_times[q_max]
kwargs['vmin'] = 0.
kwargs['vmax'] = q_max
if time == 'max_cumulative':
max_times = {}
for port in ports:
measurements_mapped = data[port]
if measurements_mapped is None:
continue
frame_maxima = np.array([f[~np.isnan(f)].max()
for f in measurements_mapped.fields])
frame_sums = np.array([f[~np.isnan(f)].sum()
for f in measurements_mapped.fields])
idx = np.argmax(frame_sums, axis=0)
max_times[np.max(frame_sums[idx])] = measurements_mapped.names[idx]
q_cumulative_max = max(max_times.keys())
time = max_times[q_cumulative_max]
kwargs['vmin'] = 0.
# kwargs['vmax'] = q_max
artists = []
gs = mpl.gridspec.GridSpec(6, 2)
......@@ -217,10 +259,13 @@ def plot_strikeline_frame_all_ports(program, time, **kwargs):
'program {program}\n$t = t_1 + \\SI{{{time_s:3.3f}}}{{\\second}}$'.format(**locals()),
horizontalalignment='center', fontsize=14)
if 'vmin' in kwargs and 'vmax' in kwargs:
if 'vmin' in kwargs and 'vmax' in kwargs \
and not isinstance(kwargs['vmax'], str):
ax1 = plt.subplot(gs[1])
cmap = kwargs.get('cmap', plt.get_cmap())
norm = mpl.colors.Normalize(vmin=kwargs['vmin'], vmax=kwargs['vmax'])
norm = mpl.colors.Normalize(
vmin=kwargs['vmin'] * 1e-6,
vmax=kwargs['vmax'] * 1e-6)
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
axins1 = inset_axes( # inset axes
ax1,
......@@ -231,17 +276,19 @@ def plot_strikeline_frame_all_ports(program, time, **kwargs):
axins1,
cmap=cmap,
norm=norm,
orientation='horizontal')
cb.set_label(r'$q [MW/m^2]$')
orientation='horizontal',
label=r'$q [MW/m^2]$',
format=rna.plotting.backend.ScientificFormatter(None, useMathText=False)
)
else:
ax1 = plt.subplot(gs[1])
ax1.axis('off')
for i, port in enumerate(ports):
print(port)
ax = plt.subplot(gs[i + 2])
kwargs['text'] = 'port {port}'.format(**locals())
artist = plot_strikeline_frame(ax, program, port, time, **kwargs)
artist = plot_strikeline_frame(ax, program, port, time,
measurements_mapped=data[port], **kwargs)
if artist is None:
continue
artists.append(artist)
......@@ -293,7 +340,7 @@ if __name__ == '__main__':
# ports = [31]
for port in ports:
for program in programs:
for program in reversed(programs):
print("{program}\tAEF{port}".format(**locals()))
# continue
try:
......
# -*- coding: utf-8 -*-
"""
Created on Wed Mai 3 2019
@author: dboe
"""
import numpy as np
import datetime
import tfields
import mapping
import rna
import w7x
import os
import loggingTools
rna.plotting.set_style(upgrade=True)
if __name__ == '__main__':
# port = 31
# program = "20181004.012"
ports = [10, 11, 20, 21, 30, 31, 40, 41, 50, 51]
# id:XP_* AND tags.value:S53 AND tags.value:ok
programs = [
'XP_20180927.7 ID1_reference_discharge_@FTM+252_all_gyro_NBI_10s_v2_CTS',
'XP_20180927.17 ID11_2MW_ne_3.5_4s',
'XP_20180927.22 ID14_2MW_ne_3.5_4s',
'XP_20180927.34 ID26_2-4MW_ne_8_NBIblips_21s',
'XP_20180927.15 ID7+8_2MW_ne_3.5_4s',
'XP_20180927.24 ID17_2MW_ne_3.5_NBIblibs_15s',
'XP_20180927.26 ID19_X2_5.5MW_4e19_pellets_NBIblips_CTS_v2',
'XP_20180927.32 ID24_X2_5.5MW_4e19_pellets_NBIblips_CTS',
'XP_20180927.14 S43_#9_NBI-S7_TC_V2',
'XP_20180927.18 ID11_2MW_ne_3.5_4s',
'XP_20180927.16 ID9+10_2MW_ne_3.5_4s',
'XP_20180927.25 ID18_2-4MW_ne_3.5-6_16.25s',
'XP_20180927.28 ID20_2MW_ne_3.5_4s',
'XP_20180927.9 ID2_2MW_ne_3.5_NBIblips_30s',
'XP_20180927.10 ID3_1.7MW_ne_2.5_NBIblips_40s',
'XP_20180927.13 S43_#9_NBI-S7',
'XP_20180927.19 ID11_2MW_ne_3.5_4s',
'XP_20180927.27 ID20_2MW_ne_3.5_4s',
'XP_20180927.31 ID23_4MW_ne_6_3.4s_v2',
'XP_20180927.30 ID22_2MW_ne_3.5_4s',
'XP_20180927.5 ID1_reference_discharge_@FTM+252_all_gyro_NBI_10s_v2_CTS',
'XP_20180927.8 ID1_reference_discharge_@FTM+252_all_gyro_NBI_10s_v2_CTS',
'XP_20180927.23 ID16_3.5MW_ne_6_4s',
'XP_20180927.21 ID14_2MW_ne_3.5_4s',
'XP_20180927.29 ID20_2MW_ne_3.5_4s',
'XP_20180927.33 ID25_2MW_ne_3.5_NBIblips_22s',
]
for p in range(len(programs)):
value = programs[p]
value = value[3:]
value = value.split(' ')[0]
parts = value.split('.')
value = parts[0] + ".{:03d}".format(int(parts[1]))
programs[p] = value
# programs = ["20180927.034"]
# ports = [31]
for port in ports:
for program in programs:
print("{program}\tAEF{port}".format(**locals()))
# continue
try:
mapping.measurements(program, port)
except Exception as err:
print(str(err))
print("DONE ___________________")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment