queso-cluster 0.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- queso_cluster/addon/aia.py +103 -0
- queso_cluster/addon/logg.py +66 -0
- queso_cluster/addon/multiline.py +5 -0
- queso_cluster/addon/prep.py +36 -0
- queso_cluster/addon/products.py +403 -0
- queso_cluster/addon/style.py +185 -0
- queso_cluster/atoms/aux.py +170 -0
- queso_cluster/atoms/base.py +395 -0
- queso_cluster/atoms/mask.py +29 -0
- queso_cluster/atoms/norm.py +38 -0
- queso_cluster/atoms/scores.py +212 -0
- queso_cluster/base.py +283 -0
- queso_cluster/loaders/event.py +108 -0
- queso_cluster/loaders/fiss.py +50 -0
- queso_cluster/loaders/iris.py +13 -0
- queso_cluster/loaders/visp.py +103 -0
- queso_cluster/runners/base.py +169 -0
- queso_cluster/td.py +137 -0
- queso_cluster/ti.py +86 -0
- queso_cluster/writer.py +67 -0
- queso_cluster-0.0.0.dist-info/METADATA +36 -0
- queso_cluster-0.0.0.dist-info/RECORD +28 -0
- queso_cluster-0.0.0.dist-info/WHEEL +5 -0
- queso_cluster-0.0.0.dist-info/licenses/LICENSE +0 -0
- queso_cluster-0.0.0.dist-info/top_level.txt +2 -0
- tests/epoch.py +105 -0
- tests/evo.py +101 -0
- tests/main.py +314 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
#> file: ./QuESO/addon/aia
|
|
2
|
+
#> lang: python
|
|
3
|
+
#> synopsis:
|
|
4
|
+
#> author: <>
|
|
5
|
+
|
|
6
|
+
from scipy.io import readsav
|
|
7
|
+
import numpy as np
|
|
8
|
+
|
|
9
|
+
from .logg import loggTimer
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@loggTimer
|
|
13
|
+
def delayAIA(fname, epochDev):
|
|
14
|
+
#> detail:
|
|
15
|
+
#> param type fname:
|
|
16
|
+
#> param type epochDev:
|
|
17
|
+
#> return (type):
|
|
18
|
+
#> test-method:
|
|
19
|
+
|
|
20
|
+
eD = epochDev
|
|
21
|
+
print(eD.shape)
|
|
22
|
+
print(fname)
|
|
23
|
+
jq_delayCube = readsav(fname)
|
|
24
|
+
|
|
25
|
+
#jq_delayCube['arr'][0] --> background of pixel
|
|
26
|
+
#jq_delayCube['arr'][1] --> background noise of pixel (standard deviation)
|
|
27
|
+
#jq_delayCube['arr'][2] --> AIA brightness at ViSP slit time
|
|
28
|
+
#jq_delayCube['arr'][3] --> time of the ViSP slit
|
|
29
|
+
#jq_delayCube['arr'][4] --> xpos
|
|
30
|
+
#jq_delayCube['arr'][5] --> ypos
|
|
31
|
+
#jq_delayCube['arr'][6] --> brightness of peak (before ViSP time)
|
|
32
|
+
#jq_delayCube['arr'][7] --> time of peak before ViSP time
|
|
33
|
+
#jq_delayCube['arr'][8] --> brightness of peak (after ViSP time)
|
|
34
|
+
#jq_delayCube['arr'][9] --> time of peak after ViSP time
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
jq_AIAFrame = np.zeros((514, 295)) + np.nan
|
|
38
|
+
#momentFrame = np.zeros(len(jq_delayCube['arr'][:, 4])) + np.nan
|
|
39
|
+
|
|
40
|
+
#moment_compare = eD.dataSquare[:, eD.spectralWindow[0]:eD.spectralWindow[1]].mean(axis=-1).reshape(eD.shape[0], eD.shape[1])
|
|
41
|
+
|
|
42
|
+
#aia_correct = lambda x: x.reshape((295, 514)).T.reshape(514*295)
|
|
43
|
+
correct = lambda x: x.reshape(eD.shape[1], eD.shape[0]).T.reshape(eD.shape[0]*eD.shape[1])
|
|
44
|
+
|
|
45
|
+
jq_AIAMask = np.zeros(jq_AIAFrame.shape) + np.nan
|
|
46
|
+
jq_indxMap = np.zeros(jq_AIAFrame.shape) + np.nan
|
|
47
|
+
jq_AIABright = np.zeros(jq_AIAFrame.shape) + np.nan
|
|
48
|
+
|
|
49
|
+
#print([0.01937, eD.deltas['pxlAlongSlit']])
|
|
50
|
+
#print([0.21420, eD.deltas['pxlSlitWidth']])
|
|
51
|
+
|
|
52
|
+
dy = 0.01937
|
|
53
|
+
dx = 0.214167
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
for i in range(len(jq_delayCube['arr'][:, 4])):
|
|
57
|
+
xx = int(np.floor(jq_delayCube['arr'][int(i), 4]*dx*6))
|
|
58
|
+
yy = int(np.floor(jq_delayCube['arr'][int(i), 5]*dy*6))
|
|
59
|
+
|
|
60
|
+
if jq_delayCube['arr'][i, 7] > 0:
|
|
61
|
+
jq_AIAFrame[xx, yy] = jq_delayCube['arr'][i, 3] - jq_delayCube['arr'][i, 7]
|
|
62
|
+
jq_AIAMask[xx, yy] = 1
|
|
63
|
+
|
|
64
|
+
jq_AIABright[xx, yy] = jq_delayCube['arr'][i, 2]
|
|
65
|
+
if jq_delayCube['arr'][i, 9] > 0:
|
|
66
|
+
jq_AIAFrame[xx, yy] = jq_delayCube['arr'][i, 3] - jq_delayCube['arr'][i, 9]
|
|
67
|
+
jq_AIAMask[xx, yy] = 1
|
|
68
|
+
|
|
69
|
+
jq_AIABright[xx, yy] = jq_delayCube['arr'][i, 2]
|
|
70
|
+
|
|
71
|
+
jq_indxMap[xx, yy] = i
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
visp_jqDelayFrame = np.zeros(eD.dataSquare.shape[0]) + np.nan
|
|
75
|
+
visp_jqMaskFrame = np.zeros(eD.dataSquare.shape[0]) + np.nan
|
|
76
|
+
visp_aiaIndx = np.zeros(eD.dataSquare.shape[0]) + np.nan
|
|
77
|
+
visp_aiaBright = np.zeros(eD.dataSquare.shape[0]) + np.nan
|
|
78
|
+
for i in range(eD.dataSquare.shape[0]):
|
|
79
|
+
yy = int(np.floor((i / eD.shape[0])*dy*6))
|
|
80
|
+
xx = int(np.floor(np.mod(i, eD.shape[0])*dx*6))
|
|
81
|
+
|
|
82
|
+
if ~(np.isnan(jq_AIAMask[xx, yy])):
|
|
83
|
+
visp_jqMaskFrame[i] = jq_AIAMask[xx, yy]
|
|
84
|
+
visp_aiaIndx[i] = jq_indxMap[xx, yy]
|
|
85
|
+
visp_aiaBright[i] = jq_AIABright[xx, yy]
|
|
86
|
+
visp_jqDelayFrame[i] = jq_AIAFrame[xx, yy]
|
|
87
|
+
|
|
88
|
+
delayCube = correct(visp_jqDelayFrame)/60.#)/60.
|
|
89
|
+
aiaATvisp = correct(visp_aiaBright)
|
|
90
|
+
aiaIndxMap = correct(visp_aiaIndx)
|
|
91
|
+
|
|
92
|
+
mask_map = np.zeros(delayCube.shape)
|
|
93
|
+
mask_map[np.where(~np.isnan(delayCube))] = 1
|
|
94
|
+
|
|
95
|
+
import matplotlib.pyplot as plt
|
|
96
|
+
fig = plt.figure(layout='constrained', figsize=(10, 5), dpi=300)
|
|
97
|
+
ax = fig.add_subplot(111)
|
|
98
|
+
|
|
99
|
+
ax.imshow(mask_map.reshape(eD.shape[0], eD.shape[1]).T, cmap='Greys_r', origin='lower', extent=[0, eD.shape[0]*dx, 0, eD.shape[1]*dy])
|
|
100
|
+
fig.savefig("./maskTest.png")
|
|
101
|
+
plt.close()
|
|
102
|
+
|
|
103
|
+
return(delayCube, aiaATvisp, aiaIndxMap, mask_map.astype(bool))
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#> file: ./QuESO/addon/logg
|
|
2
|
+
#> lang: python
|
|
3
|
+
#> synopsis:
|
|
4
|
+
#> author: <>
|
|
5
|
+
import logging
|
|
6
|
+
import timeit
|
|
7
|
+
|
|
8
|
+
logger = logging.getLogger("queso_cluster")
|
|
9
|
+
logger.addHandler(logging.NullHandler())
|
|
10
|
+
|
|
11
|
+
def loggTimer(func):
|
|
12
|
+
#> detail:
|
|
13
|
+
#> param type func:
|
|
14
|
+
#> return (type):
|
|
15
|
+
#> test-method:
|
|
16
|
+
def wrapper(*args, **kwargs):
|
|
17
|
+
__log__ = logg("start", val="{}".format(func.__name__))
|
|
18
|
+
value = func(*args, **kwargs)
|
|
19
|
+
logg("stop", _log=__log__)
|
|
20
|
+
return(value)
|
|
21
|
+
return(wrapper)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def logg(tag, val=None, _time=None, _log=None):
|
|
25
|
+
#> detail:
|
|
26
|
+
#> param type tag:
|
|
27
|
+
#> param type [None] val:
|
|
28
|
+
#> param type [None] _time:
|
|
29
|
+
#> param type [None] _log:
|
|
30
|
+
#> return (type):
|
|
31
|
+
#> test-method:
|
|
32
|
+
ptag = '[' + tag.upper() + '\t]'
|
|
33
|
+
if _log is not None:
|
|
34
|
+
val, _time = _log
|
|
35
|
+
if _time is not None:
|
|
36
|
+
dur = timeit.default_timer() - _time
|
|
37
|
+
match tag:
|
|
38
|
+
case 'aloha':
|
|
39
|
+
if _log is not None:
|
|
40
|
+
log_str = ptag + '[' + duration_string(dur) + ']'
|
|
41
|
+
else:
|
|
42
|
+
#print(ptag + 'DURATION\tMESSAGES\tRUNNERS')
|
|
43
|
+
logger.info(ptag)
|
|
44
|
+
return(None, timeit.default_timer())
|
|
45
|
+
case 'start':
|
|
46
|
+
log_str = ptag + '\t\t' + val.upper()
|
|
47
|
+
logger.info(log_str)
|
|
48
|
+
return(val.upper(), timeit.default_timer())
|
|
49
|
+
case 'stop':
|
|
50
|
+
log_str = ptag + '[' + duration_string(dur) + ']\t' + val.upper()
|
|
51
|
+
case 'msg':
|
|
52
|
+
log_str = ptag + '\t\t' + val.upper()
|
|
53
|
+
case 'warn':
|
|
54
|
+
logger.warning(val.upper())
|
|
55
|
+
return None
|
|
56
|
+
case 'error':
|
|
57
|
+
logger.error(val.upper())
|
|
58
|
+
return None
|
|
59
|
+
logger.info(log_str)
|
|
60
|
+
|
|
61
|
+
def duration_string(dur):
|
|
62
|
+
#> detail:
|
|
63
|
+
#> param type dur:
|
|
64
|
+
#> return (type):
|
|
65
|
+
#> test-method:
|
|
66
|
+
return("{:02d}h {:02d}m {:02d}s".format(int(dur/3600), int(int(dur/60) % 60), int(dur % 60)))
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import matplotlib as mpl
|
|
2
|
+
import matplotlib.pyplot as plt
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
from . import style as sty
|
|
6
|
+
def figureBackup01(analysisObj, dataSquare=None):
|
|
7
|
+
ii, jj = analysisObj.spectralWindow
|
|
8
|
+
if dataSquare is None:
|
|
9
|
+
dataSquare = analysisObj.dataSquare
|
|
10
|
+
|
|
11
|
+
moment0_integrated = dataSquare[:, ii:jj+1].mean(axis=-1).compute()
|
|
12
|
+
print(moment0_integrated.shape)
|
|
13
|
+
moment0_continuum = dataSquare[:, analysisObj.continuum].compute()
|
|
14
|
+
print(moment0_continuum.shape)
|
|
15
|
+
|
|
16
|
+
i0_layerCount = len(analysisObj.clusterConfig['intrinsic'])
|
|
17
|
+
|
|
18
|
+
fig = plt.figure(layout='constrained', figsize=(5*i0_layerCount, 5), dpi=300)
|
|
19
|
+
|
|
20
|
+
moment0 = {'window': moment0_integrated, 'continuum': moment0_continuum}
|
|
21
|
+
binWidth = {'window': 0.01, 'continuum': 0.01}
|
|
22
|
+
|
|
23
|
+
for i in range(i0_layerCount):
|
|
24
|
+
label = analysisObj.config.clusterConfig['intrinsic'][i]['label']
|
|
25
|
+
bins = analysisObj.config.clusterConfig['intrinsic'][i]['layerConfig']['bins']
|
|
26
|
+
|
|
27
|
+
ax = fig.add_subplot(1, i0_layerCount, i+1)
|
|
28
|
+
histBins = np.arange(0, np.ceil(np.nanmax(moment0[label])*10)/10, step=binWidth[label])
|
|
29
|
+
ax.hist(moment0[label], bins=histBins, range=histBins, rwidth=1, fill=False, histtype='step', color='black')
|
|
30
|
+
_, color_pallet = sty._genColorPallet(len(np.diff(bins)))
|
|
31
|
+
|
|
32
|
+
for j in range(len(bins)-2):
|
|
33
|
+
ax.axvline(x = bins[j+1] , color=mpl.colors.rgb2hex(color_pallet[j+1]))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
return(fig)
|
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
#> file: ./QuESO/addon/products
|
|
2
|
+
#> lang: python
|
|
3
|
+
#> synopsis:
|
|
4
|
+
#> author: <>
|
|
5
|
+
#from ..atoms import base as baseAtom
|
|
6
|
+
|
|
7
|
+
from . import style as sty
|
|
8
|
+
from .logg import loggTimer
|
|
9
|
+
from ..atoms import aux as auxAtom
|
|
10
|
+
from ..atoms import scores as scoresAtom
|
|
11
|
+
from ..runners import base as baseRun
|
|
12
|
+
|
|
13
|
+
import numpy as np
|
|
14
|
+
import matplotlib as mpl
|
|
15
|
+
import matplotlib.pyplot as plt
|
|
16
|
+
from matplotlib.gridspec import GridSpec
|
|
17
|
+
from matplotlib.colors import LinearSegmentedColormap
|
|
18
|
+
|
|
19
|
+
from ..addon.logg import logger
|
|
20
|
+
|
|
21
|
+
class Products:
|
|
22
|
+
|
|
23
|
+
def __init__(self, quesoOut, optLabels):
|
|
24
|
+
#> detail:
|
|
25
|
+
#> param type self:
|
|
26
|
+
#> param type quesoOut:
|
|
27
|
+
#> param type optLabels:
|
|
28
|
+
#> return (type):
|
|
29
|
+
#> test-method:
|
|
30
|
+
self.quesoOut = quesoOut
|
|
31
|
+
self.config = self.quesoOut.config
|
|
32
|
+
self.keepI0 = self.config.runners.config['keepI0']
|
|
33
|
+
self.ii, self.jj = self.quesoOut.spectralWindow
|
|
34
|
+
self.lineCenter = self.quesoOut.lineCenter
|
|
35
|
+
self.continuum = self.quesoOut.continuum
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
#self.waveFit = self.quesoOut.waveFit
|
|
39
|
+
self.optLabels = optLabels
|
|
40
|
+
self.optLabels[self.optLabels == 0] = np.nan
|
|
41
|
+
self.vindx = np.where(~np.isnan(self.optLabels))#[0]
|
|
42
|
+
#print(np.where(~np.isnan(self.optLabels)))
|
|
43
|
+
|
|
44
|
+
self.mapMake = sty.mapMaker(self.quesoOut.spaceInfo, self.quesoOut.deltas)
|
|
45
|
+
|
|
46
|
+
@loggTimer
|
|
47
|
+
def clusterMapSequence(self, orientation='vertical'):
|
|
48
|
+
ncols = self.optLabels.shape[0]
|
|
49
|
+
#> Error?: Maximum number of clients reached
|
|
50
|
+
fig = plt.figure(layout='compressed', figsize=(ncols, 2*ncols), dpi=300)
|
|
51
|
+
|
|
52
|
+
if orientation == 'vertical':
|
|
53
|
+
nrows = ncols
|
|
54
|
+
ncols = 2
|
|
55
|
+
height_ratios = [1 for x in range(nrows)]
|
|
56
|
+
width_ratios = [1, 0.025]
|
|
57
|
+
else:
|
|
58
|
+
nrows = 2
|
|
59
|
+
height_ratios=[0.025, 1]
|
|
60
|
+
width_ratios = [1 for x in range(ncols)]
|
|
61
|
+
gs = GridSpec(nrows, ncols, figure=fig,
|
|
62
|
+
height_ratios=height_ratios, width_ratios=width_ratios, hspace=0, wspace=0)
|
|
63
|
+
|
|
64
|
+
#xx = (self.vindx % self.quesoOut.rasterSize)#, self.quesoOut.alongSlitSize])
|
|
65
|
+
#yy = (self.vindx // self.quesoOut.rasterSize)#, self.quesoOut.alongSlitSize])
|
|
66
|
+
|
|
67
|
+
#inset_bbox = [xx0, xx1, yy0, yy1]
|
|
68
|
+
|
|
69
|
+
xlim = np.array([self.vindx[1].min(),
|
|
70
|
+
self.vindx[1].max()])
|
|
71
|
+
ylim = np.array([self.vindx[2].min(),
|
|
72
|
+
self.vindx[2].max()])
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
labelLst = np.unique(self.optLabels[self.vindx]).astype(int)#.astype(str)
|
|
76
|
+
print(labelLst)
|
|
77
|
+
print(labelLst[~np.isnan(labelLst)])
|
|
78
|
+
# tLabels = np.unique(self.optLabels)
|
|
79
|
+
actual_bounds, bound_ticks, color_pallet = sty.cbar_bounds(list(labelLst[~np.isnan(labelLst)]))
|
|
80
|
+
cmap = mpl.colors.ListedColormap(color_pallet)
|
|
81
|
+
norm = mpl.colors.BoundaryNorm(actual_bounds, cmap.N+1)
|
|
82
|
+
|
|
83
|
+
compoundLabels = np.zeros(self.optLabels.shape[1:], dtype=str)
|
|
84
|
+
|
|
85
|
+
recountedLabels = np.zeros(self.optLabels.shape) + np.nan
|
|
86
|
+
for l in range(labelLst.size):
|
|
87
|
+
#for t in range(self.optLabels.shape[0]):
|
|
88
|
+
lindx = np.where(self.optLabels == labelLst[l])
|
|
89
|
+
recountedLabels[lindx] = l+1
|
|
90
|
+
|
|
91
|
+
for t in range(self.optLabels.shape[0]):
|
|
92
|
+
print(np.unique(self.optLabels[t, ...]))
|
|
93
|
+
kwargsDict = {'cmap': cmap, 'norm': norm}
|
|
94
|
+
ax, im = self.mapMake._mapGen(fig, gs[t, 0],
|
|
95
|
+
recountedLabels[t, ...],
|
|
96
|
+
timeAxis=True,
|
|
97
|
+
#flareContour=self.mask_map,
|
|
98
|
+
**kwargsDict)
|
|
99
|
+
ax.set_xlim(xlim* self.quesoOut.deltas['pxlSlitWidth'].magnitude)
|
|
100
|
+
ax.set_ylim(ylim* self.quesoOut.deltas['pxlAlongSlit'].magnitude)
|
|
101
|
+
|
|
102
|
+
ax.set_aspect("equal")
|
|
103
|
+
|
|
104
|
+
if not gs[t, 0].is_last_row():
|
|
105
|
+
ax.set_xticklabels([])
|
|
106
|
+
|
|
107
|
+
#cbar = fig.colorbar(im, cax=cax, ticks=bounds_ticks)#, label='Binned Intensity')
|
|
108
|
+
#
|
|
109
|
+
# cbar.ax.set_yticklabels(["{}XX".format(int(x)) for x in recountLst])
|
|
110
|
+
compoundLabels = np.char.add(compoundLabels, np.char.zfill(recountedLabels[t, ...].astype(np.uint).astype(str), 2))
|
|
111
|
+
|
|
112
|
+
cax = fig.add_subplot(gs[:, 1])
|
|
113
|
+
cbar = fig.colorbar(im, spacing='uniform',
|
|
114
|
+
ticks=bound_ticks, orientation=orientation,
|
|
115
|
+
cax=cax)
|
|
116
|
+
cbar.ax.set_yticklabels(["{}".format(int(x)) for x in np.unique(labelLst)])
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
print(np.unique(compoundLabels))
|
|
121
|
+
compoundLabels[~np.char.isalnum(compoundLabels)] = np.nan
|
|
122
|
+
|
|
123
|
+
recountedCompoundLabels = np.zeros(compoundLabels.shape) + np.nan
|
|
124
|
+
labelLst = np.unique(compoundLabels[:-1])
|
|
125
|
+
for l in range(labelLst.size):
|
|
126
|
+
#for t in range(self.optLabels.shape[0]):
|
|
127
|
+
lindx = np.where(compoundLabels == labelLst[l])
|
|
128
|
+
recountedCompoundLabels[lindx] = l+1
|
|
129
|
+
print(labelLst)
|
|
130
|
+
print(np.unique(recountedCompoundLabels))
|
|
131
|
+
fig2 = plt.figure(layout='compressed', figsize=(10, 7), dpi=300)
|
|
132
|
+
gs2 = GridSpec(1, 2, figure=fig2, width_ratios=[1, 0.025], hspace=0, wspace=0)
|
|
133
|
+
_, color_pallet = sty._genColorPallet(len(np.unique(labelLst)))
|
|
134
|
+
cmap = mpl.colors.ListedColormap(color_pallet)
|
|
135
|
+
#cmap = mpl.cm.get_cmap('rainbow_r', len(labelLst))
|
|
136
|
+
cmap.set_bad("#FFFFFF")
|
|
137
|
+
kwargsDict = {'cmap': cmap}
|
|
138
|
+
ax, im = self.mapMake._mapGen(fig2, gs2[0, 0],
|
|
139
|
+
recountedCompoundLabels.astype(int),
|
|
140
|
+
timeAxis=True,
|
|
141
|
+
#flareContour=self.mask_map,
|
|
142
|
+
**kwargsDict)
|
|
143
|
+
ax.set_xlim(xlim*self.quesoOut.deltas['pxlSlitWidth'].magnitude)
|
|
144
|
+
ax.set_ylim(ylim*self.quesoOut.deltas['pxlAlongSlit'].magnitude)
|
|
145
|
+
ax.set_aspect("equal")
|
|
146
|
+
|
|
147
|
+
cax = fig2.add_subplot(gs2[0, 1])
|
|
148
|
+
cbar = fig2.colorbar(im, spacing='uniform', orientation=orientation,
|
|
149
|
+
cax=cax)
|
|
150
|
+
return(fig, fig2)
|
|
151
|
+
|
|
152
|
+
@loggTimer
|
|
153
|
+
def figure03(self):
|
|
154
|
+
#> detail:
|
|
155
|
+
#> param type self:
|
|
156
|
+
#> return (type):
|
|
157
|
+
#> test-method:
|
|
158
|
+
|
|
159
|
+
width = [2, 0.025]
|
|
160
|
+
types = ['intensity', 'labels']
|
|
161
|
+
for t in range(len(types)):
|
|
162
|
+
|
|
163
|
+
fig = plt.figure(layout='compressed', figsize=(2*4, 3.25*4), dpi=300)
|
|
164
|
+
|
|
165
|
+
gs = GridSpec(3,2, figure=fig, width_ratios=width, height_ratios=[1, 1, 1], hspace=0, wspace=0)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
intrinsicConfig = self.config.srcLst.clusterConfig['intrinsic']
|
|
169
|
+
for i in range(len(intrinsicConfig)):
|
|
170
|
+
match intrinsicConfig[i]['label']:
|
|
171
|
+
case 'window':
|
|
172
|
+
moment0 = self.quesoOut.instrumentObj.dataSquare[:, self.ii:self.jj+1].mean(axis=-1).compute()
|
|
173
|
+
bins = intrinsicConfig[i]['layerConfig']['bins']
|
|
174
|
+
cbar_label = "Mean Window Intensity"
|
|
175
|
+
case 'continuum':
|
|
176
|
+
moment0 = self.quesoOut.instrumentObj.dataSquare[:, self.quesoOut.continuum].compute()
|
|
177
|
+
bins = intrinsicConfig[i]['layerConfig']['bins']
|
|
178
|
+
cbar_label = "Continuum Intensity"
|
|
179
|
+
|
|
180
|
+
intrinsicLayerMap = baseRun.runIntrinsic(len(np.diff(bins)), np.floor(moment0*100)/100.,
|
|
181
|
+
edgeOverride=np.array(bins).astype(float))
|
|
182
|
+
_, color_pallet = sty._genColorPallet(len(np.unique(intrinsicLayerMap)))
|
|
183
|
+
|
|
184
|
+
match types[t]:
|
|
185
|
+
case 'intensity':
|
|
186
|
+
present = moment0
|
|
187
|
+
cmap = 'Greys_r'
|
|
188
|
+
case 'labels':
|
|
189
|
+
present = intrinsicLayerMap
|
|
190
|
+
cmap = mpl.colors.ListedColormap(color_pallet)
|
|
191
|
+
norm = mpl.colors.BoundaryNorm(np.array(bins).astype(float), cmap.N)
|
|
192
|
+
|
|
193
|
+
kwargsDict = {'cmap': cmap}
|
|
194
|
+
# if i > np.inf:
|
|
195
|
+
# ax, im, tax = self.mapMake._mapGen(fig, gs[i, 0],
|
|
196
|
+
# present,
|
|
197
|
+
# timeAxis=True,
|
|
198
|
+
# #flareContour=self.mask_map,
|
|
199
|
+
# **kwargsDict)
|
|
200
|
+
|
|
201
|
+
# ax.set_xlabel("Raster Direction [arcseconds]")
|
|
202
|
+
# tax.set_xlabel('Time [hours after 20:02:42 UTC]')
|
|
203
|
+
# else:
|
|
204
|
+
ax, im = self.mapMake._mapGen(fig, gs[i, 0],
|
|
205
|
+
present,
|
|
206
|
+
#flareContour=self.mask_map,
|
|
207
|
+
**kwargsDict)
|
|
208
|
+
|
|
209
|
+
ax.set_xticklabels([])
|
|
210
|
+
ax.set_aspect("equal")
|
|
211
|
+
ax.set_ylabel("Along Slit Direction [arcseconds]")
|
|
212
|
+
|
|
213
|
+
#ax.text(20, 2250, " ({})".format(self.alphaLst[i]), va="center", ha="center", bbox=dict(facecolor='white', edgecolor='black', boxstyle='round,pad=0.25', alpha=0.3), font='monospace')
|
|
214
|
+
# ax.annotate('({})'.format(self.alphaLst[i]),
|
|
215
|
+
# xy=(0.035, 1-0.05), xycoords='axes fraction',
|
|
216
|
+
# xytext=(0.035, 1-0.05), textcoords='axes fraction', fontfamily='sans-serif',
|
|
217
|
+
# va='center', ha='center', bbox=dict(boxstyle='square', facecolor='white', edgecolor='black', alpha=0.4))
|
|
218
|
+
|
|
219
|
+
cax = fig.add_subplot(gs[i, 1])
|
|
220
|
+
match types[t]:
|
|
221
|
+
case 'intensity':
|
|
222
|
+
im_cbar = im
|
|
223
|
+
case 'labels':
|
|
224
|
+
im_cbar = mpl.cm.ScalarMappable(norm=norm, cmap=cmap)
|
|
225
|
+
cbar = fig.colorbar(im_cbar, cax=cax, spacing='uniform', label=cbar_label)
|
|
226
|
+
|
|
227
|
+
intrinsicLayerMap_oldCount = auxAtom.pick_jth_label(self.optLabels[self.vindx], 0).astype(float)
|
|
228
|
+
intrinsicLayerMap = np.zeros(self.optLabels.shape) + np.nan
|
|
229
|
+
recountLst = np.unique(intrinsicLayerMap_oldCount)
|
|
230
|
+
for rc in range(recountLst.size):
|
|
231
|
+
lindx = np.where(intrinsicLayerMap_oldCount == recountLst[rc])[0]
|
|
232
|
+
intrinsicLayerMap[self.vindx[lindx]] = rc+1
|
|
233
|
+
|
|
234
|
+
actual_bounds, bound_ticks, color_pallet = sty.cbar_bounds(list(np.unique(intrinsicLayerMap[self.vindx])))
|
|
235
|
+
cmap = mpl.colors.ListedColormap(color_pallet)
|
|
236
|
+
norm = mpl.colors.BoundaryNorm(actual_bounds, cmap.N+1)
|
|
237
|
+
|
|
238
|
+
kwargsDict = {'cmap': cmap}
|
|
239
|
+
ax, im, tax = self.mapMake._mapGen(fig, gs[-1, 0],
|
|
240
|
+
intrinsicLayerMap,
|
|
241
|
+
timeAxis=True,
|
|
242
|
+
#flareContour=self.mask_map,
|
|
243
|
+
**kwargsDict)
|
|
244
|
+
cax = fig.add_subplot(gs[-1, 1])
|
|
245
|
+
ax.set_aspect("equal")
|
|
246
|
+
|
|
247
|
+
#cbar = fig.colorbar(im, cax=cax, ticks=bounds_ticks)#, label='Binned Intensity')
|
|
248
|
+
cbar = fig.colorbar(mpl.cm.ScalarMappable(norm=norm, cmap=cmap), spacing='proportional',
|
|
249
|
+
ticks=bound_ticks,
|
|
250
|
+
cax=cax, label='Intrinsic bins')
|
|
251
|
+
cbar.ax.set_yticklabels(["{}XX".format(int(x)) for x in recountLst])
|
|
252
|
+
|
|
253
|
+
ax.set_xlabel("Raster Direction [arcseconds]")
|
|
254
|
+
tax.set_xlabel('Time [hours after 20:02:42 UTC]')
|
|
255
|
+
ax.set_ylabel("Along Slit Direction [arcseconds]")
|
|
256
|
+
|
|
257
|
+
#ax.text(20, 2250, " ({})".format(self.alphaLst[2]), va="center", ha="center", bbox=dict(facecolor='white', edgecolor='black', boxstyle='round,pad=0.25', alpha=0.3))
|
|
258
|
+
# ax.annotate('({})'.format(self.alphaLst[2]),
|
|
259
|
+
# xy=(0.035, 1-0.05), xycoords='axes fraction',
|
|
260
|
+
# xytext=(0.035, 1-0.05), textcoords='axes fraction', fontfamily='sans-serif',
|
|
261
|
+
# va='center', ha='center', bbox=dict(boxstyle='square', facecolor='white', edgecolor='black', alpha=0.4))
|
|
262
|
+
|
|
263
|
+
#print(self.figDir + 'figure03_{}.pdf'.format(types[t]))
|
|
264
|
+
fig.savefig('./figure03_{}.png'.format(types[t]))
|
|
265
|
+
#fig.savefig(self.figDir + 'figure03_{}.pdf'.format(types[t]))
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
@loggTimer
|
|
269
|
+
def clusterProfiles(self, dev=False):
|
|
270
|
+
#> detail:
|
|
271
|
+
#> param type self:
|
|
272
|
+
#> return (type):
|
|
273
|
+
#> test-method:
|
|
274
|
+
|
|
275
|
+
ii, jj = [self.ii, self.jj]
|
|
276
|
+
|
|
277
|
+
wavelambda = self.quesoOut.waveFit
|
|
278
|
+
validLabels = self.optLabels[self.vindx]
|
|
279
|
+
i0Arr = auxAtom.pick_jth_label(validLabels, 0)
|
|
280
|
+
|
|
281
|
+
i0o1Arr = auxAtom.pick_jth_label(validLabels, 0)*10 + auxAtom.pick_jth_label(validLabels, 1)
|
|
282
|
+
|
|
283
|
+
i0o1Lst = np.unique(i0o1Arr)
|
|
284
|
+
|
|
285
|
+
nrows = len(i0o1Lst)
|
|
286
|
+
ncols = 1 + auxAtom.pick_jth_label(validLabels, 2).max()
|
|
287
|
+
|
|
288
|
+
fig = plt.figure(layout='constrained', figsize=((ncols + 0.2)*3, nrows*3), dpi=300)
|
|
289
|
+
|
|
290
|
+
gs = GridSpec(nrows, ncols + 1,
|
|
291
|
+
left=0, right=1, top=1, bottom=0,
|
|
292
|
+
width_ratios=[1 for x in range(ncols)] + [0.2],
|
|
293
|
+
height_ratios=[1 for x in range(nrows)],
|
|
294
|
+
figure=fig)
|
|
295
|
+
|
|
296
|
+
raw_max = (np.ceil(self.quesoOut.prepSquare[:, ii:jj+1].max()*10)/10.).compute()
|
|
297
|
+
raw_min = (np.floor(self.quesoOut.prepSquare[:, ii:jj+1].min()*10)/10.).compute()
|
|
298
|
+
extent = (wavelambda[ii]-wavelambda[self.lineCenter]).magnitude, (wavelambda[jj]-wavelambda[self.lineCenter]).magnitude, raw_min, raw_max
|
|
299
|
+
|
|
300
|
+
color = "black"
|
|
301
|
+
panel_bounds = []
|
|
302
|
+
bounds_ticker = int(str(i0o1Lst[0])[0])
|
|
303
|
+
for j in range(len(i0o1Lst)):
|
|
304
|
+
i0_indx = np.where(i0o1Arr == i0o1Lst[j])[0]
|
|
305
|
+
|
|
306
|
+
ax0 = plt.subplot(gs[j, 0])
|
|
307
|
+
ax0 = self.spectralEntry(ax0, i0_indx, color, wavelambda.magnitude, extent)
|
|
308
|
+
if gs[j,0].is_last_row():
|
|
309
|
+
#ax0.set_xlabel(r"$\lambda-\lambda_{0}$ [$\mathrm{\AA}$]")
|
|
310
|
+
ax0.set_xlabel(r"$\lambda-\lambda_{0}$" + " [{}]".format(wavelambda.units))
|
|
311
|
+
ax0.tick_params(labelleft=True)
|
|
312
|
+
#axR0.tick_params(labelright=False)
|
|
313
|
+
if not gs[j, 0].is_last_row():
|
|
314
|
+
ax0.tick_params(labelbottom=False)
|
|
315
|
+
|
|
316
|
+
if bounds_ticker != int(str(i0o1Lst[j])[0]):
|
|
317
|
+
trans = mpl.transforms.blended_transform_factory(ax0.transData, fig.transFigure)
|
|
318
|
+
panel_bounds.append([-extent[0], ax0.get_position().bounds[2], j, trans])
|
|
319
|
+
|
|
320
|
+
bounds_ticker = int(str(i0o1Lst[j])[0])
|
|
321
|
+
|
|
322
|
+
o2Arr = auxAtom.pick_jth_label(validLabels[i0_indx], 2).astype(int)
|
|
323
|
+
o2Lst = np.unique(o2Arr).astype(int)
|
|
324
|
+
for k in range(len(o2Lst)):
|
|
325
|
+
ax = plt.subplot(gs[j, k+1])
|
|
326
|
+
o2_indx = i0_indx[np.where(o2Arr == o2Lst[k])[0]]
|
|
327
|
+
|
|
328
|
+
sArr = auxAtom.pick_jth_label(validLabels[o2_indx], 0)
|
|
329
|
+
sindx = np.where(i0Arr == sArr[0])[0]
|
|
330
|
+
|
|
331
|
+
score = 0#scoresAtom.calcSingleSilhouetteScore(self.quesoOut.prepSquare[sindx.astype(np.uint32), ii:jj+1].compute(), validLabels[sindx.astype(np.uint32)], validLabels[o2_indx[0]])
|
|
332
|
+
|
|
333
|
+
ax = self.spectralEntry(ax, o2_indx, color, wavelambda.magnitude, extent, scores=score)
|
|
334
|
+
if gs[j,k+1].is_last_row():
|
|
335
|
+
ax.set_xlabel(r"$\lambda-\lambda_{0}$" + " [{}]".format(wavelambda.units))
|
|
336
|
+
else:
|
|
337
|
+
ax.tick_params(labelbottom=False)
|
|
338
|
+
|
|
339
|
+
ax.tick_params(labelleft=False)
|
|
340
|
+
# if dev and not gs[j, k+1].is_last_col():
|
|
341
|
+
# axR.tick_params(labelright=False)
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
return(fig)
|
|
346
|
+
|
|
347
|
+
def spectralEntry(self, ax, indx, color, wavelambda, extent, scores=None, dev=False):
|
|
348
|
+
#> detail:
|
|
349
|
+
#> param type self:
|
|
350
|
+
#> param type ax:
|
|
351
|
+
#> param type indx:
|
|
352
|
+
#> param type color:
|
|
353
|
+
#> param type wavelambda:
|
|
354
|
+
#> param type extent:
|
|
355
|
+
#> param type [None] scores:
|
|
356
|
+
#> return (type):
|
|
357
|
+
#> test-method:
|
|
358
|
+
ii, jj = [self.ii, self.jj]
|
|
359
|
+
raw_dat = self.quesoOut.prepSquare[indx.astype(np.uint32), ii:jj+1].compute()
|
|
360
|
+
centroid_i = raw_dat.sum(axis=0)/raw_dat.shape[0]
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
if dev:
|
|
364
|
+
resolvingIndex = scoresAtom.calcSingleResolvingIndex(raw_dat)
|
|
365
|
+
centroid_min, centroid_max = np.quantile(raw_dat, [0.25, 0.75], axis=0)
|
|
366
|
+
axR = ax.twinx()
|
|
367
|
+
axR.set_ylim([-1, 1])
|
|
368
|
+
axR.plot(wavelambda[ii:jj+1]-wavelambda[self.lineCenter], resolvingIndex, color='red', linestyle='dashed', linewidth=0.75)
|
|
369
|
+
ax.plot(wavelambda[ii:jj+1]-wavelambda[self.lineCenter], centroid_min, color='blue', linewidth=0.75)
|
|
370
|
+
ax.plot(wavelambda[ii:jj+1]-wavelambda[self.lineCenter], centroid_max, color='blue', linewidth=0.75)
|
|
371
|
+
logger.debug("Resolving Index: {}".format(np.mean(np.abs(resolvingIndex))))
|
|
372
|
+
|
|
373
|
+
ax.plot(wavelambda[ii:jj+1]-wavelambda[self.lineCenter], centroid_i, color='black', linewidth=0.75)
|
|
374
|
+
|
|
375
|
+
# im = ax.hist2d(raw_dat, bins=[0.01, wavelambda[ii:jj+1]-wavelambda[self.lineCenter]])
|
|
376
|
+
|
|
377
|
+
temp_im = auxAtom.density_hist2d(raw_dat, 0.01, extent[3], extent[2])
|
|
378
|
+
|
|
379
|
+
ww, insty = np.meshgrid((wavelambda[ii:jj+1+1]-wavelambda[self.lineCenter]), np.arange(extent[2], extent[3], 0.01))
|
|
380
|
+
im = ax.pcolormesh(ww, insty, temp_im.T, cmap=LinearSegmentedColormap.from_list('', ['white', color]))
|
|
381
|
+
|
|
382
|
+
ax.axvline(x = 0, linestyle='dashed', color='black')
|
|
383
|
+
|
|
384
|
+
tindx = self.vindx[0][indx]
|
|
385
|
+
xindx = self.vindx[1][indx]
|
|
386
|
+
yindx = self.vindx[2][indx]
|
|
387
|
+
labelLst = np.unique(self.optLabels[tindx, xindx, yindx]).astype(int).astype(str)
|
|
388
|
+
commonLabel = [labelLst[0][j] for j in range(len(labelLst[0])) if np.unique([a[j] for a in [list(x) for x in labelLst]]).size == 1]
|
|
389
|
+
#print(commonLabel)
|
|
390
|
+
label = "{}{}".format(int("".join(commonLabel)), "X"*(len(labelLst[0]) - len(commonLabel)))
|
|
391
|
+
|
|
392
|
+
if scores == None:
|
|
393
|
+
ax.text(0.9*(wavelambda[ii]-wavelambda[self.lineCenter]), 0.8*extent[3],
|
|
394
|
+
"{}\nN={}\n".format(label, len(indx)))
|
|
395
|
+
# fontname='Times New Roman')
|
|
396
|
+
else:
|
|
397
|
+
ax.text(0.9*(wavelambda[ii]-wavelambda[self.lineCenter]), 0.8*extent[3],
|
|
398
|
+
"{}\nN={}\nS={:.3f}\n".format(label, len(indx), float(scores)))
|
|
399
|
+
# fontname='Times New Roman')
|
|
400
|
+
|
|
401
|
+
ax.xaxis.set_minor_locator(mpl.ticker.MultipleLocator(base=0.2))
|
|
402
|
+
|
|
403
|
+
return(ax)
|