Skip to content

Commit 1cff7e7

Browse files
committed
[#1056] compute_diagnostic_solidangle_from_plane() operational and clean
1 parent 95dffa4 commit 1cff7e7

File tree

1 file changed

+95
-35
lines changed

1 file changed

+95
-35
lines changed

tofu/data/_class8_plane_perp_to_los.py

Lines changed: 95 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -436,12 +436,12 @@ def _check(
436436
if isinstance(margin_perp, (float, int)):
437437
margin_perp = [margin_perp, margin_perp]
438438

439-
margin_perp = float(ds._generic_check._check_flat1darray(
439+
margin_perp = ds._generic_check._check_flat1darray(
440440
margin_perp, 'margin_perp',
441-
dtype=(int, float),
441+
dtype=float,
442442
size=2,
443443
sign='>=0',
444-
))
444+
)
445445

446446
# -----------
447447
# verb
@@ -710,11 +710,11 @@ def _spectro(
710710

711711
def _plot(
712712
coll=None,
713+
key_diag=None,
714+
key_cam=None,
713715
# dout
714716
is2d=None,
715717
spectro=None,
716-
key_diag=None,
717-
key_cam=None,
718718
indch=None,
719719
indref=None,
720720
los_ref=None,
@@ -754,7 +754,7 @@ def _plot(
754754
(
755755
etend0, etend, etend_lamb,
756756
etend_plane0, etend_plane, etend_plane_lamb,
757-
sli,
757+
sli, axis,
758758
extent_cam, extent_plane,
759759
vmin_cam0, vmax_cam0,
760760
vmin_cam, vmax_cam,
@@ -788,7 +788,18 @@ def _plot(
788788
vmax_plane=vmax_plane,
789789
)
790790

791-
sang_plot = sang0['data'][sli].ravel()
791+
# --------------
792+
# prepare
793+
794+
ix1 = int(x1.size/2)
795+
# sang_plot = sang0['data'][sli].ravel()
796+
sang_tot_plot = np.sum(sang0['data'], axis=axis)
797+
798+
# tit
799+
tit = (
800+
"Solid angle subtended from points in the plasma by:\n"
801+
f"{key_diag} - {key_cam}"
802+
)
792803

793804
# --------------
794805
# prepare
@@ -824,7 +835,7 @@ def _plot(
824835
ax.scatter(
825836
np.hypot(ptsx, ptsy).ravel(),
826837
ptsz.ravel(),
827-
c=sang_plot,
838+
c=sang_tot_plot,
828839
s=4,
829840
marker='.',
830841
vmin=vmin_plane,
@@ -848,7 +859,7 @@ def _plot(
848859
ax.scatter(
849860
ptsx.ravel(),
850861
ptsy.ravel(),
851-
c=sang_plot,
862+
c=sang_tot_plot,
852863
s=4,
853864
marker='.',
854865
vmin=vmin_plane,
@@ -873,7 +884,7 @@ def _plot(
873884
ptsx.ravel(),
874885
ptsy.ravel(),
875886
ptsz.ravel(),
876-
c=sang0['data'][sli].ravel(),
887+
c=sang_tot_plot,
877888
s=4,
878889
marker='.',
879890
vmin=vmin_plane,
@@ -919,6 +930,7 @@ def _plot(
919930
lw=1.,
920931
c='k',
921932
marker='.',
933+
label='Analytical',
922934
)
923935

924936
# plane-specific etendue
@@ -928,6 +940,7 @@ def _plot(
928940
lw=1.,
929941
c='b',
930942
marker='.',
943+
label='Numerical',
931944
)
932945

933946
# ref pixel
@@ -946,6 +959,8 @@ def _plot(
946959
lw=1,
947960
)
948961

962+
ax.legend()
963+
949964
kax = 'cam_etend0'
950965
if dax.get(kax) is not None:
951966
ax = dax[kax]['handle']
@@ -1083,7 +1098,7 @@ def _plot(
10831098

10841099
# ref pixel
10851100
_add_marker(ax, indref, indplot)
1086-
plt.colorbar(im, ax=[ax, dax['cam_plane_lamb']['handle']])
1101+
plt.colorbar(im0, ax=[ax, dax['cam_plane_lamb']['handle']])
10871102

10881103
kax = 'cam_diff_lamb'
10891104
if dax.get(kax) is not None:
@@ -1114,15 +1129,23 @@ def _plot(
11141129
ax = dax[kax]['handle']
11151130

11161131
im = ax.imshow(
1117-
sang0['data'][sli].T,
1132+
sang_tot_plot.T,
1133+
# sang0['data'][sli].T,
11181134
extent=extent_plane,
11191135
origin='lower',
11201136
interpolation='nearest',
11211137
vmin=vmin_plane0,
11221138
vmax=vmax_plane0,
11231139
)
11241140

1125-
plt.colorbar(im, ax=ax, label='solid angle (sr)')
1141+
ax.axhline(x1[ix1], c='w', ls='--', lw=0.5)
1142+
1143+
plt.colorbar(
1144+
im,
1145+
ax=ax,
1146+
cax=dax.get('colorbar', {}).get('handle'),
1147+
label='solid angle (sr)',
1148+
)
11261149

11271150
kax = 'plane'
11281151
if dax.get(kax) is not None:
@@ -1139,6 +1162,18 @@ def _plot(
11391162

11401163
plt.colorbar(im, ax=ax, label='solid angle (sr)')
11411164

1165+
# -------------------------------------------
1166+
# slice through sang 2d map
1167+
1168+
kax = 'slice'
1169+
if dax.get(kax) is not None:
1170+
ax = dax[kax]['handle']
1171+
1172+
ax.plot(
1173+
x0,
1174+
sang0['data'][..., ix1].T.reshape((x0.size, -1)),
1175+
)
1176+
11421177
# ----------
11431178
# diag geom
11441179

@@ -1164,6 +1199,15 @@ def _plot(
11641199
ax = dax[kax]['handle']
11651200
plot_config.plot(lax=ax, proj=kax, dLeg=False)
11661201

1202+
# ------------
1203+
# figure title
1204+
1205+
list(dax.values())[0]['handle'].figure.suptitle(
1206+
tit,
1207+
size=14,
1208+
fontweight='bold',
1209+
)
1210+
11671211
return dax
11681212

11691213

@@ -1244,8 +1288,10 @@ def _check_plot(
12441288
if is2d:
12451289
extent_cam = None
12461290
sli = (indplot[0], indplot[1], slice(None), slice(None))
1291+
axis = (0, 1)
12471292
else:
12481293
sli = (indplot, slice(None), slice(None))
1294+
axis = 0
12491295

12501296
# extent_plane
12511297
dx0 = 0.5*(x0[1] - x0[0])
@@ -1315,7 +1361,7 @@ def _check_plot(
13151361
return (
13161362
etend0, etend, etend_lamb,
13171363
etend_plane0, etend_plane, etend_plane_lamb,
1318-
sli,
1364+
sli, axis,
13191365
extent_cam, extent_plane,
13201366
vmin_cam0, vmax_cam0,
13211367
vmin_cam, vmax_cam,
@@ -1337,13 +1383,13 @@ def _get_dax(
13371383
# check
13381384

13391385
if fs is None:
1340-
fs = (15, 9)
1386+
fs = (16, 10)
13411387

13421388
dmargin = ds._generic_check._check_var(
13431389
dmargin, 'dmargin',
13441390
types=dict,
13451391
default={
1346-
'bottom': 0.05, 'top': 0.95,
1392+
'bottom': 0.05, 'top': 0.92,
13471393
'left': 0.05, 'right': 0.95,
13481394
'wspace': 0.4, 'hspace': 0.5,
13491395
},
@@ -1452,45 +1498,57 @@ def _get_dax(
14521498
}
14531499

14541500
else:
1455-
gs = gridspec.GridSpec(ncols=5, nrows=6, **dmargin)
1501+
nn = 4
1502+
gs = gridspec.GridSpec(ncols=5*nn+1, nrows=6, **dmargin)
14561503

14571504
# --------
14581505
# create
14591506

1460-
ax0 = fig.add_subplot(gs[:3, :2], aspect='equal', adjustable='datalim')
1461-
ax0.set_xlabel('X (m)')
1462-
ax0.set_ylabel('Y (m)')
1507+
ax0 = fig.add_subplot(gs[:3, :2*nn], aspect='equal', adjustable='datalim')
1508+
ax0.set_xlabel('X (m)', size=12, fontweight='bold')
1509+
ax0.set_ylabel('Y (m)', size=12, fontweight='bold')
14631510

1464-
ax1 = fig.add_subplot(gs[3:, :2], aspect='equal', adjustable='datalim')
1465-
ax1.set_xlabel('R (m)')
1466-
ax1.set_ylabel('Z (m)')
1511+
ax1 = fig.add_subplot(gs[3:, :2*nn], aspect='equal', adjustable='datalim')
1512+
ax1.set_xlabel('R (m)', size=12, fontweight='bold')
1513+
ax1.set_ylabel('Z (m)', size=12, fontweight='bold')
14671514

1468-
ax2 = fig.add_subplot(gs[:2, 2:], projection='3d')
1469-
ax2.set_xlabel('X (m)')
1470-
ax2.set_ylabel('Y (m)')
1471-
ax2.set_ylabel('Z (m)')
1515+
ax2 = fig.add_subplot(gs[:2, 2*nn+1:3*nn+1], projection='3d')
1516+
ax2.set_xlabel('X (m)', size=12, fontweight='bold')
1517+
ax2.set_ylabel('Y (m)', size=12, fontweight='bold')
1518+
ax2.set_ylabel('Z (m)', size=12, fontweight='bold')
14721519

14731520
if is2d is True:
1474-
ax30 = fig.add_subplot(gs[2:4, 2], aspect='equal')
1521+
ax30 = fig.add_subplot(gs[2:4, 2*nn:3*nn], aspect='equal')
14751522
ax30.set_ylabel('x1 (m)')
14761523
ax30.set_xlabel('x0 (m)')
14771524
ax30.set_title('integral', size=12, fontweight='bold')
14781525

1479-
ax31 = fig.add_subplot(gs[2:4, 3], sharex=ax30, sharey=ax30)
1526+
ax31 = fig.add_subplot(gs[2:4, 3*nn:4*nn], sharex=ax30, sharey=ax30)
14801527
ax31.set_xlabel('x0 (m)')
14811528
ax31.set_title('etendue', size=12, fontweight='bold')
14821529

1483-
ax32 = fig.add_subplot(gs[2:4, 4], sharex=ax30, sharey=ax30)
1530+
ax32 = fig.add_subplot(gs[2:4, 4*nn:-1], sharex=ax30, sharey=ax30)
14841531
ax32.set_xlabel('x0 (m)')
14851532
ax32.set_title('difference', size=12, fontweight='bold')
14861533

14871534
else:
1488-
ax30 = fig.add_subplot(gs[2:4, 2:])
1489-
ax30.set_ylabel('x1 (m)')
1535+
ax30 = fig.add_subplot(gs[:2, 3*nn+2:])
1536+
ax30.set_xlabel('channel', size=12, fontweight='bold')
1537+
ax30.set_ylabel('Etendue (m2.sr)', size=12, fontweight='bold')
1538+
1539+
ax4 = fig.add_subplot(
1540+
gs[2:4, 2*nn+1:-1],
1541+
aspect='equal',
1542+
adjustable='datalim',
1543+
)
1544+
ax4.set_ylabel('x1 (m)', size=12, fontweight='bold')
1545+
ax4.set_xlabel('x0 (m)', size=12, fontweight='bold')
1546+
1547+
ax4c = fig.add_subplot(gs[2:4, -1])
14901548

1491-
ax4 = fig.add_subplot(gs[4:, 2:], aspect='equal', adjustable='datalim')
1492-
ax4.set_ylabel('x1 (m)')
1493-
ax4.set_xlabel('x0 (m)')
1549+
ax5 = fig.add_subplot(gs[4:, 2*nn+1:-1], sharex=ax4)
1550+
ax5.set_ylabel('sang (sr)', size=12, fontweight='bold')
1551+
ax5.set_xlabel('x0 (m)', size=12, fontweight='bold')
14941552

14951553
# dict
14961554
dax = {
@@ -1499,6 +1557,8 @@ def _get_dax(
14991557
'3d': {'handle': ax2, 'type': '3d'},
15001558
'cam_plane0': {'handle': ax30, 'type': 'camera'},
15011559
'plane0': {'handle': ax4, 'type': 'misc'},
1560+
'colorbar': {'handle': ax4c, 'type': 'misc'},
1561+
'slice': {'handle': ax5, 'type': 'misc'},
15021562
}
15031563
if is2d is True:
15041564
dax['cam_etend0'] = {'handle': ax31, 'type': 'camera'}

0 commit comments

Comments
 (0)