cubevis 0.5.19__py3-none-any.whl → 0.5.20__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.
Potentially problematic release.
This version of cubevis might be problematic. Click here for more details.
- cubevis/__init__.py +24 -2
- cubevis/__version__.py +1 -1
- cubevis/exe/__init__.py +4 -0
- cubevis/exe/_context.py +126 -0
- cubevis/exe/_mode.py +7 -0
- cubevis/exe/_setting.py +4 -0
- cubevis/exe/_task.py +230 -0
- cubevis/private/apps/_interactiveclean.mustache +17 -1435
- cubevis/private/apps/_interactiveclean.py +17 -1435
- cubevis/toolbox/__init__.py +1 -0
- cubevis/toolbox/_interactive_clean_ui.mustache +1499 -0
- cubevis/toolbox/_interactive_clean_ui.py +1498 -0
- {cubevis-0.5.19.dist-info → cubevis-0.5.20.dist-info}/METADATA +1 -1
- {cubevis-0.5.19.dist-info → cubevis-0.5.20.dist-info}/RECORD +17 -10
- /cubevis/{private/apps → toolbox}/_interactiveclean_wrappers.py +0 -0
- {cubevis-0.5.19.dist-info → cubevis-0.5.20.dist-info}/WHEEL +0 -0
- {cubevis-0.5.19.dist-info → cubevis-0.5.20.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
########################################################################
|
|
2
2
|
#
|
|
3
3
|
#TASK XML> tclean -argfilter=interactive,fullsummary -argfilter:initParams=vis,imagename
|
|
4
|
-
# Copyright (C) 2022,2023,2024
|
|
4
|
+
# Copyright (C) 2022,2023,2024,2025
|
|
5
5
|
# Associated Universities, Inc. Washington DC, USA.
|
|
6
6
|
#
|
|
7
7
|
# This script is free software; you can redistribute it and/or modify it
|
|
@@ -29,137 +29,24 @@
|
|
|
29
29
|
'''implementation of the ``InteractiveClean`` application for interactive control
|
|
30
30
|
of tclean'''
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
### Useful for debugging
|
|
34
|
-
###
|
|
35
|
-
###from cubevis.bokeh.state import initialize_bokeh
|
|
36
|
-
###initialize_bokeh( bokehjs_subst=".../bokeh-3.2.2.js" )
|
|
37
|
-
###
|
|
38
|
-
import os
|
|
39
|
-
import copy
|
|
40
|
-
import asyncio
|
|
41
|
-
import shutil
|
|
42
|
-
import websockets
|
|
43
|
-
from os.path import basename, abspath, exists
|
|
44
|
-
from uuid import uuid4
|
|
45
|
-
from html import escape as html_escape
|
|
46
|
-
from contextlib import asynccontextmanager
|
|
47
|
-
from bokeh.models import Button, TextInput, Checkbox, Div, LinearAxis, CustomJS, Spacer, Span, HoverTool, DataRange1d, Step, InlineStyleSheet
|
|
48
|
-
from bokeh.events import ModelEvent, MouseEnter
|
|
49
|
-
from bokeh.models import TabPanel, Tabs
|
|
50
|
-
from bokeh.plotting import ColumnDataSource, figure, show
|
|
51
|
-
from bokeh.layouts import column, row, layout
|
|
52
|
-
from bokeh.io import reset_output as reset_bokeh_output, output_notebook
|
|
53
|
-
from bokeh.models.dom import HTML
|
|
54
|
-
|
|
55
|
-
from bokeh.models.ui.tooltips import Tooltip
|
|
56
|
-
from cubevis.bokeh.models import TipButton, Tip, EvTextInput
|
|
57
|
-
from cubevis.utils import resource_manager, reset_resource_manager, is_interactive_jupyter, find_pkg, load_pkg
|
|
58
|
-
from cubevis.utils import ContextMgrChain as CMC
|
|
59
|
-
|
|
60
|
-
# pylint: disable=no-name-in-module
|
|
61
|
-
from casatasks.private.imagerhelpers.imager_return_dict import ImagingDict
|
|
32
|
+
from pprint import pprint
|
|
62
33
|
|
|
34
|
+
import sys
|
|
35
|
+
from os.path import exists
|
|
63
36
|
from casatasks.private.imagerhelpers.input_parameters import ImagerParameters
|
|
64
|
-
# pylint: enable=no-name-in-module
|
|
65
|
-
|
|
66
|
-
from cubevis.utils import find_ws_address, convert_masks
|
|
67
|
-
from cubevis.toolbox import CubeMask, AppContext
|
|
68
|
-
from cubevis.bokeh.utils import svg_icon
|
|
69
|
-
from cubevis.bokeh.sources import DataPipe
|
|
70
|
-
from cubevis.utils import DocEnum
|
|
71
|
-
|
|
72
|
-
from ._interactiveclean_wrappers import SharedWidgets
|
|
73
37
|
|
|
74
|
-
|
|
38
|
+
from cubevis.utils import find_pkg, load_pkg
|
|
39
|
+
from cubevis.toolbox import InteractiveCleanUI
|
|
40
|
+
from cubevis import exe
|
|
75
41
|
|
|
76
42
|
class InteractiveClean:
|
|
77
43
|
'''InteractiveClean(...) implements interactive clean using Bokeh
|
|
78
44
|
{{docstring}}
|
|
79
45
|
'''
|
|
80
|
-
def __stop( self, _=None ):
|
|
81
|
-
self.__result_future.set_result(self.__retrieve_result( ))
|
|
82
|
-
|
|
83
|
-
def _abort_handler( self, err ):
|
|
84
|
-
self._error_result = err
|
|
85
|
-
self.__stop( )
|
|
86
|
-
|
|
87
|
-
def __reset( self ):
|
|
88
|
-
if self.__pipes_initialized:
|
|
89
|
-
self._pipe = { 'control': None }
|
|
90
|
-
self._clean = { 'converge': { 'state': { } }, 'last-success': None }
|
|
91
|
-
reset_bokeh_output( )
|
|
92
|
-
reset_resource_manager( )
|
|
93
|
-
|
|
94
|
-
###
|
|
95
|
-
### reset asyncio result future
|
|
96
|
-
###
|
|
97
|
-
self.__result_future = None
|
|
98
|
-
|
|
99
|
-
###
|
|
100
|
-
### used by data pipe (websocket) initialization function
|
|
101
|
-
###
|
|
102
|
-
self.__pipes_initialized = False
|
|
103
|
-
|
|
104
|
-
###
|
|
105
|
-
### error or exception result
|
|
106
|
-
###
|
|
107
|
-
self._error_result = None
|
|
108
|
-
|
|
109
|
-
###
|
|
110
|
-
### iclean results
|
|
111
|
-
###
|
|
112
|
-
self.__result = None
|
|
113
|
-
self.__result_from_gui = None
|
|
114
|
-
|
|
115
|
-
'''
|
|
116
|
-
_gen_port_fwd_cmd()
|
|
117
|
-
|
|
118
|
-
Create an SSH port-forwarding command to create the tunnels necessary for remote connection.
|
|
119
|
-
NOTE: This assumes that the same remote ports are also available locally - which may
|
|
120
|
-
NOT always be true.
|
|
121
|
-
'''
|
|
122
|
-
def _gen_port_fwd_cmd(self):
|
|
123
|
-
hostname = os.uname()[1]
|
|
124
|
-
|
|
125
|
-
###
|
|
126
|
-
### need to add extra cube ports here for multifield imaging
|
|
127
|
-
###
|
|
128
|
-
ports = [ self._pipe['control'].address[1], self._clean['converge']['pipe'].address[1] ]
|
|
129
|
-
|
|
130
|
-
for imid, imdetails in self._clean_targets.items( ):
|
|
131
|
-
ports.append( imdetails['gui']['cube']._pipe['image'].address[1] )
|
|
132
|
-
ports.append( imdetails['gui']['cube']._pipe['control'].address[1] )
|
|
133
|
-
|
|
134
|
-
# Also forward http port if serving webpage
|
|
135
|
-
if not self._is_notebook:
|
|
136
|
-
ports.append(self._http_port)
|
|
137
|
-
|
|
138
|
-
cmd = 'ssh'
|
|
139
|
-
for port in ports:
|
|
140
|
-
cmd += (' -L ' + str(port) + ':localhost:' + str(port))
|
|
141
|
-
|
|
142
|
-
cmd += ' ' + str(hostname)
|
|
143
|
-
return cmd
|
|
144
|
-
|
|
145
|
-
def _residual_path( self, gclean, imid ):
|
|
146
|
-
if self._clean['gclean_paths'] is None:
|
|
147
|
-
raise RuntimeError( f'''gclean paths are not available for {imid}''' )
|
|
148
|
-
for p in self._clean['gclean_paths']:
|
|
149
|
-
if p['name'] == imid:
|
|
150
|
-
return f"{p['imagepath']}/{p['residualname']}"
|
|
151
|
-
raise RuntimeError( f'''gclean residual path not found for {imid}''' )
|
|
152
|
-
|
|
153
|
-
def _mask_path( self, gclean, imid ):
|
|
154
|
-
if self._clean['gclean_paths'] is None:
|
|
155
|
-
raise RuntimeError( f'''gclean paths are not available for {imid}''' )
|
|
156
|
-
for p in self._clean['gclean_paths']:
|
|
157
|
-
if p['name'] == imid:
|
|
158
|
-
return f"{p['imagepath']}/{p['maskname']}"
|
|
159
|
-
raise RuntimeError( f'''gclean mask path not found for {imid}''' )
|
|
160
46
|
|
|
161
47
|
def __init__( self, vis, imagename{{# initParams}}, {{name}}={{default}}{{/ initParams}}, iclean_backend="PROD" ):
|
|
162
48
|
|
|
49
|
+
|
|
163
50
|
###
|
|
164
51
|
### iclean_backend can be used to select alternate backends for interactive clean. This could be used
|
|
165
52
|
### to enable a backend with extended features or it could be used to select a stub backend designed
|
|
@@ -177,815 +64,14 @@ class InteractiveClean:
|
|
|
177
64
|
else:
|
|
178
65
|
raise ImportError(f"Could not locate {iclean_backend} kind of iclean backend")
|
|
179
66
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
###
|
|
186
|
-
self._conv_spect_plot_width = 450
|
|
187
|
-
###
|
|
188
|
-
### Create application context (which includes a temporary directory).
|
|
189
|
-
### This sets the title of the plot.
|
|
190
|
-
###
|
|
191
|
-
self._app_state = AppContext( 'Interactive Clean' )
|
|
192
|
-
|
|
193
|
-
###
|
|
194
|
-
### Whether or not the Interactive Clean session is running remotely
|
|
195
|
-
###
|
|
196
|
-
#self._is_remote = remote
|
|
197
|
-
self._is_remote = False
|
|
198
|
-
|
|
199
|
-
###
|
|
200
|
-
### whether or not the session is being run from a jupyter notebook or script
|
|
201
|
-
###
|
|
202
|
-
self._is_notebook = is_interactive_jupyter()
|
|
203
|
-
|
|
204
|
-
##
|
|
205
|
-
## the http port for serving GUI in webpage if not running in script
|
|
206
|
-
##
|
|
207
|
-
self._http_port = None
|
|
208
|
-
|
|
209
|
-
###
|
|
210
|
-
### the asyncio future that is used to transmit the result from interactive clean
|
|
211
|
-
###
|
|
212
|
-
self.__result_future = None
|
|
213
|
-
|
|
214
|
-
###
|
|
215
|
-
### This is used to tell whether the websockets have been initialized, but also to
|
|
216
|
-
### indicate if __call__ is being called multiple times to allow for resetting Bokeh
|
|
217
|
-
###
|
|
218
|
-
self.__pipes_initialized = False
|
|
219
|
-
|
|
220
|
-
###
|
|
221
|
-
### State required to manage iteration control
|
|
222
|
-
###
|
|
223
|
-
self._control = { 'iteration': { } }
|
|
224
|
-
|
|
225
|
-
###
|
|
226
|
-
### color specs
|
|
227
|
-
###
|
|
228
|
-
self._converge_color = { 'residual': 'black',
|
|
229
|
-
'flux': 'forestgreen' }
|
|
230
|
-
|
|
231
|
-
###
|
|
232
|
-
### widgets shared across image tabs (multifield imaging)
|
|
233
|
-
###
|
|
234
|
-
self._cube_palette = None
|
|
235
|
-
self._image_bitmask_controls = None
|
|
236
|
-
|
|
237
|
-
###
|
|
238
|
-
### String which indicates the changes applied to the mask to indicte when
|
|
239
|
-
### the mask has changed... however, THIS IS NO LONGER USED
|
|
240
|
-
### It could be removed, but it adds minor overhead and would be
|
|
241
|
-
### DIFFICULT to add back in the future
|
|
242
|
-
###
|
|
243
|
-
self._last_mask_breadcrumbs = ''
|
|
244
|
-
|
|
245
|
-
###
|
|
246
|
-
### Set up dictionary of javascript code snippets
|
|
247
|
-
###
|
|
248
|
-
self._initialize_javascript( )
|
|
249
|
-
|
|
250
|
-
# Create folder for the generated html webpage - needs its own folder to not name conflict (must be 'index.html')
|
|
251
|
-
webpage_dirname = imagename + '_webpage'
|
|
252
|
-
### Directory is created when an HTTP server is running
|
|
253
|
-
### (MAX)
|
|
254
|
-
# if not os.path.isdir(webpage_dirname):
|
|
255
|
-
# os.makedirs(webpage_dirname)
|
|
256
|
-
self._webpage_path = os.path.abspath(webpage_dirname)
|
|
257
|
-
|
|
258
|
-
self._pipe = { 'control': None }
|
|
259
|
-
self._clean = { 'converge': { 'state': { } }, 'last-success': None }
|
|
260
|
-
|
|
261
|
-
self._clean_targets = { imagename: { 'args': {{forwDict}} } }
|
|
262
|
-
self._initial_clean_params = { }
|
|
263
|
-
|
|
264
|
-
self._parameters = ImagerParameters( **{ k:v for k,v in self._clean_targets[imagename]['args'].items( )
|
|
265
|
-
if k in ImagerParameters.__init__.__code__.co_varnames[1:] } )
|
|
266
|
-
|
|
267
|
-
###
|
|
268
|
-
### For 6.6.5, outliers are not yet completely implemented so the
|
|
269
|
-
### 'outlierfile' parameter may not be present.
|
|
270
|
-
###
|
|
271
|
-
if 'outlierfile' in locals( ) and outlierfile and exists(outlierfile):
|
|
272
|
-
outliers, err = self._parameters.parseOutlierFile(outlierfile)
|
|
273
|
-
if err: raise RuntimeError( f'''outlierfile error: {err}''' )
|
|
274
|
-
for image in outliers:
|
|
275
|
-
if 'impars' in image and 'imagename' in image['impars']:
|
|
276
|
-
name = image['impars']['imagename']
|
|
277
|
-
self._clean_targets[name] = { }
|
|
278
|
-
args = {{forwDict}}
|
|
279
|
-
args['outlierfile'] = '' ### >>HERE>> outlierfile TEMPORARILY handled in _interactiveclean.py
|
|
280
|
-
for _,arg_mods in image.items( ):
|
|
281
|
-
for k,v in arg_mods.items( ):
|
|
282
|
-
if k in args:
|
|
283
|
-
args[k] = v
|
|
284
|
-
self._clean_targets[name]['args'] = args
|
|
285
|
-
|
|
286
|
-
###
|
|
287
|
-
### create clean interface -- final version will have only one gclean object
|
|
288
|
-
###
|
|
289
|
-
self._init_values = { "deconvolver": deconvolver, ### used by _residual_path( )
|
|
290
|
-
"cycleniter": cycleniter, ### used by _setup( )
|
|
291
|
-
"threshold": threshold, ### used by _setup( )
|
|
292
|
-
"cyclefactor": cyclefactor, ### used by _setup( )
|
|
293
|
-
"gain": gain, ### used by _setup( )
|
|
294
|
-
"nsigma": nsigma, ### used by _setup( )
|
|
295
|
-
"convergence_state": { 'convergence': {}, ### shares state between
|
|
296
|
-
'cyclethreshold': {} } } ### __init__( ) and _setup( )
|
|
297
|
-
|
|
298
|
-
self._clean['gclean'] = None
|
|
299
|
-
self._clean['gclean_paths'] = None
|
|
300
|
-
self._clean['imid'] = [ ]
|
|
301
|
-
self._clean['gclean_rest'] = [ ]
|
|
302
|
-
for imid, imdetails in self._clean_targets.items( ):
|
|
303
|
-
self._clean['imid'].append(imid)
|
|
304
|
-
|
|
305
|
-
###
|
|
306
|
-
### Residual path...
|
|
307
|
-
###
|
|
308
|
-
if 'path' not in imdetails: imdetails['path'] = { }
|
|
309
|
-
if self._clean['gclean'] is None:
|
|
310
|
-
|
|
311
|
-
self._clean['gclean'] = self._gclean_module.gclean( **imdetails['args'] )
|
|
312
|
-
self._clean['gclean_paths'] = self._clean['gclean'].image_products( )
|
|
313
|
-
|
|
314
|
-
imdetails['path']['residual'] = self._residual_path(self._clean['gclean'],imid)
|
|
315
|
-
imdetails['path']['mask'] = self._mask_path(self._clean['gclean'],imid)
|
|
316
|
-
|
|
317
|
-
else:
|
|
318
|
-
|
|
319
|
-
imdetails['path']['residual'] = self._residual_path(self._clean['gclean'],imid)
|
|
320
|
-
imdetails['path']['mask'] = self._mask_path(self._clean['gclean'],imid)
|
|
321
|
-
|
|
322
|
-
for idx, (imid, imdetails) in enumerate(self._clean_targets.items( )):
|
|
323
|
-
imdetails['gui'] = { }
|
|
324
|
-
|
|
325
|
-
imdetails['gui'] = { 'params': { 'iteration': { }, 'automask': { } },
|
|
326
|
-
'image': { },
|
|
327
|
-
'image-adjust': { } }
|
|
328
|
-
|
|
329
|
-
###
|
|
330
|
-
### Only the first image should initialize the initial convergence state
|
|
331
|
-
###
|
|
332
|
-
imdetails['gui']['cube'] = CubeMask( imdetails['path']['residual'], mask=imdetails['path']['mask'], abort=self._abort_handler,
|
|
333
|
-
init_script=CustomJS( args=dict( initial_convergence_state=self._init_values["convergence_state"],
|
|
334
|
-
name=imid ),
|
|
335
|
-
code='''document._casa_convergence_data = initial_convergence_state''' )
|
|
336
|
-
if idx == 0 else None )
|
|
337
|
-
|
|
338
|
-
###
|
|
339
|
-
### Auto Masking Parameters
|
|
340
|
-
###
|
|
341
|
-
imdetails['params'] = { }
|
|
342
|
-
imdetails['params']['am'] = { }
|
|
343
|
-
imdetails['params']['am']['usemask'] = usemask
|
|
344
|
-
imdetails['params']['am']['noisethreshold'] = noisethreshold
|
|
345
|
-
imdetails['params']['am']['sidelobethreshold'] = sidelobethreshold
|
|
346
|
-
imdetails['params']['am']['lownoisethreshold'] = lownoisethreshold
|
|
347
|
-
imdetails['params']['am']['minbeamfrac'] = minbeamfrac
|
|
348
|
-
imdetails['params']['am']['negativethreshold'] = negativethreshold
|
|
349
|
-
imdetails['params']['am']['dogrowprune'] = dogrowprune
|
|
350
|
-
imdetails['params']['am']['fastnoise'] = fastnoise
|
|
351
|
-
|
|
352
|
-
def _init_pipes( self ):
|
|
353
|
-
if not self.__pipes_initialized:
|
|
354
|
-
self.__pipes_initialized = True
|
|
355
|
-
self._pipe['control'] = DataPipe( address=find_ws_address( ), abort=self._abort_handler )
|
|
356
|
-
###
|
|
357
|
-
### One pipe for updating the convergence plots.
|
|
358
|
-
###
|
|
359
|
-
self._clean['converge'] = { 'state': None }
|
|
360
|
-
self._clean['converge']['pipe'] = DataPipe( address=find_ws_address( ), abort=self._abort_handler )
|
|
361
|
-
self._clean['converge']['id'] = str(uuid4( ))
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
# Get port for serving HTTP server if running in script
|
|
366
|
-
self._http_port = find_ws_address("")[1]
|
|
367
|
-
for imid, imdetails in self._clean_targets.items( ):
|
|
368
|
-
imdetails['gui']['cube']._init_pipes( )
|
|
369
|
-
|
|
370
|
-
def _create_convergence_gui( self, imdetails, orient='horizontal', sizing_mode='stretch_width', **kw ):
|
|
371
|
-
TOOLTIPS='''<div>
|
|
372
|
-
<div>
|
|
373
|
-
<span style="font-weight: bold;">@type</span>
|
|
374
|
-
<span>@values</span>
|
|
375
|
-
</div>
|
|
376
|
-
<div>
|
|
377
|
-
<span style="font-weight: bold; font-size: 10px">cycle threshold</span>
|
|
378
|
-
<span>@cyclethreshold</span>
|
|
379
|
-
</div>
|
|
380
|
-
<div>
|
|
381
|
-
<span style="font-weight: bold; font-size: 10px">stop</span>
|
|
382
|
-
<span>@stopDesc</span>
|
|
383
|
-
</div>
|
|
384
|
-
</div>'''
|
|
385
|
-
|
|
386
|
-
hover = HoverTool( tooltips=TOOLTIPS )
|
|
387
|
-
imdetails['gui']['convergence'] = figure( sizing_mode=sizing_mode, y_axis_location="right",
|
|
388
|
-
tools=[ hover ], toolbar_location=None, **kw )
|
|
389
|
-
|
|
390
|
-
if orient == 'vertical':
|
|
391
|
-
imdetails['gui']['convergence'].yaxis.axis_label='Iteration (cycle threshold dotted red)'
|
|
392
|
-
imdetails['gui']['convergence'].xaxis.axis_label='Peak Residual'
|
|
393
|
-
imdetails['gui']['convergence'].extra_x_ranges = { 'residual_range': DataRange1d( follow='end' ),
|
|
394
|
-
'flux_range': DataRange1d( follow='end' ) }
|
|
395
|
-
|
|
396
|
-
imdetails['gui']['convergence'].step( 'values', 'iterations', source=imdetails['converge-data']['cyclethreshold'],
|
|
397
|
-
line_color='red', x_range_name='residual_range', line_dash='dotted', line_width=2 )
|
|
398
|
-
imdetails['gui']['convergence'].line( 'values', 'iterations', source=imdetails['converge-data']['residual'],
|
|
399
|
-
line_color=self._converge_color['residual'], x_range_name='residual_range' )
|
|
400
|
-
imdetails['gui']['convergence'].scatter( 'values', 'iterations', source=imdetails['converge-data']['residual'],
|
|
401
|
-
color=self._converge_color['residual'], x_range_name='residual_range',size=10 )
|
|
402
|
-
imdetails['gui']['convergence'].line( 'values', 'iterations', source=imdetails['converge-data']['flux'],
|
|
403
|
-
line_color=self._converge_color['flux'], x_range_name='flux_range' )
|
|
404
|
-
imdetails['gui']['convergence'].scatter( 'values', 'iterations', source=imdetails['converge-data']['flux'],
|
|
405
|
-
color=self._converge_color['flux'], x_range_name='flux_range', size=10 )
|
|
406
|
-
|
|
407
|
-
imdetails['gui']['convergence'].add_layout( LinearAxis( x_range_name='flux_range', axis_label='Total Flux',
|
|
408
|
-
axis_line_color=self._converge_color['flux'],
|
|
409
|
-
major_label_text_color=self._converge_color['flux'],
|
|
410
|
-
axis_label_text_color=self._converge_color['flux'],
|
|
411
|
-
major_tick_line_color=self._converge_color['flux'],
|
|
412
|
-
minor_tick_line_color=self._converge_color['flux'] ), 'above')
|
|
413
|
-
|
|
414
|
-
else:
|
|
415
|
-
imdetails['gui']['convergence'].xaxis.axis_label='Iteration (cycle threshold dotted red)'
|
|
416
|
-
imdetails['gui']['convergence'].yaxis.axis_label='Peak Residual'
|
|
417
|
-
imdetails['gui']['convergence'].extra_y_ranges = { 'residual_range': DataRange1d( follow='end' ),
|
|
418
|
-
'flux_range': DataRange1d( follow='end' ) }
|
|
419
|
-
|
|
420
|
-
imdetails['gui']['convergence'].step( 'iterations', 'values', source=imdetails['converge-data']['cyclethreshold'],
|
|
421
|
-
line_color='red', y_range_name='residual_range', line_dash='dotted', line_width=2 )
|
|
422
|
-
imdetails['gui']['convergence'].line( 'iterations', 'values', source=imdetails['converge-data']['residual'],
|
|
423
|
-
line_color=self._converge_color['residual'], y_range_name='residual_range' )
|
|
424
|
-
imdetails['gui']['convergence'].scatter( 'iterations', 'values', source=imdetails['converge-data']['residual'],
|
|
425
|
-
color=self._converge_color['residual'], y_range_name='residual_range',size=10 )
|
|
426
|
-
imdetails['gui']['convergence'].line( 'iterations', 'values', source=imdetails['converge-data']['flux'],
|
|
427
|
-
line_color=self._converge_color['flux'], y_range_name='flux_range' )
|
|
428
|
-
imdetails['gui']['convergence'].scatter( 'iterations', 'values', source=imdetails['converge-data']['flux'],
|
|
429
|
-
color=self._converge_color['flux'], y_range_name='flux_range', size=10 )
|
|
430
|
-
|
|
431
|
-
imdetails['gui']['convergence'].add_layout( LinearAxis( y_range_name='flux_range', axis_label='Total Flux',
|
|
432
|
-
axis_line_color=self._converge_color['flux'],
|
|
433
|
-
major_label_text_color=self._converge_color['flux'],
|
|
434
|
-
axis_label_text_color=self._converge_color['flux'],
|
|
435
|
-
major_tick_line_color=self._converge_color['flux'],
|
|
436
|
-
minor_tick_line_color=self._converge_color['flux'] ), 'right')
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
def _launch_gui( self ):
|
|
440
|
-
'''create and show GUI
|
|
441
|
-
'''
|
|
442
|
-
###
|
|
443
|
-
### Will contain the top level GUI
|
|
444
|
-
###
|
|
445
|
-
self._fig = { }
|
|
446
|
-
|
|
447
|
-
###
|
|
448
|
-
### Python-side handler for events from the interactive clean control buttons
|
|
449
|
-
###
|
|
450
|
-
async def clean_handler( msg, self=self ):
|
|
451
|
-
if msg['action'] == 'next' or msg['action'] == 'finish':
|
|
452
|
-
|
|
453
|
-
if 'mask' in msg['value']:
|
|
454
|
-
###
|
|
455
|
-
### >>HERE>> breadcrumbs must be specific to the field they are related to...
|
|
456
|
-
###
|
|
457
|
-
if 'breadcrumbs' in msg['value'] and msg['value']['breadcrumbs'] is not None and msg['value']['breadcrumbs'] != self._last_mask_breadcrumbs:
|
|
458
|
-
self._last_mask_breadcrumbs = msg['value']['breadcrumbs']
|
|
459
|
-
mask_dir = "%s.mask" % self._imagename
|
|
460
|
-
shutil.rmtree(mask_dir)
|
|
461
|
-
new_mask = imdetails['gui']['cube'].jsmask_to_raw(msg['value']['mask'])
|
|
462
|
-
self._mask_history.append(new_mask)
|
|
463
|
-
|
|
464
|
-
msg['value']['mask'] = convert_masks(masks=new_mask, coord='pixel', cdesc=imdetails['gui']['cube'].coorddesc())
|
|
465
|
-
|
|
466
|
-
else:
|
|
467
|
-
##### seemingly the mask path used to be spliced in?
|
|
468
|
-
#msg['value']['mask'] = self._mask_path
|
|
469
|
-
pass
|
|
470
|
-
else:
|
|
471
|
-
##### seemingly the mask path used to be spliced in?
|
|
472
|
-
#msg['value']['mask'] = self._mask_path
|
|
473
|
-
pass
|
|
474
|
-
|
|
475
|
-
###
|
|
476
|
-
### In the final implementation, there will only be one gclean object...
|
|
477
|
-
###
|
|
478
|
-
convergence_state={ 'convergence': {}, 'cyclethreshold': {} }
|
|
479
|
-
err,errmsg = self._clean['gclean'].update( dict( **msg['value']['iteration'],
|
|
480
|
-
**msg['value']['automask'] ) )
|
|
481
|
-
|
|
482
|
-
iteration_limit = int(msg['value']['iteration']['niter'])
|
|
483
|
-
stopdesc, stopcode, majordone, majorleft, iterleft, self._convergence_data = await self._clean['gclean'].__anext__( )
|
|
484
|
-
|
|
485
|
-
clean_cmds = self._clean['gclean']._log( )
|
|
486
|
-
|
|
487
|
-
for key, value in self._convergence_data.items( ):
|
|
488
|
-
|
|
489
|
-
if len(value['chan']) == 0 or stopcode[0] == -1:
|
|
490
|
-
### stopcode[0] == -1 indicates an error condition within gclean
|
|
491
|
-
return dict( result='error', stopcode=stopcode, cmd=clean_cmds,
|
|
492
|
-
convergence=None, majordone=majordone,
|
|
493
|
-
majorleft=majorleft, iterleft=iterleft, stopdesc=stopdesc )
|
|
494
|
-
|
|
495
|
-
convergence_state['convergence'][key] = value['chan']
|
|
496
|
-
convergence_state['cyclethreshold'][key] = value['major']['cyclethreshold']
|
|
497
|
-
|
|
498
|
-
### stopcode[0] != 0 indicates that some stopping criteria has been reached
|
|
499
|
-
### this will also catch errors as well as convergence
|
|
500
|
-
### (so 'converged' isn't quite right...)
|
|
501
|
-
self._clean['last-success'] = dict( result='converged' if stopcode[0] else 'update', stopcode=stopcode, cmd=clean_cmds,
|
|
502
|
-
convergence=convergence_state['convergence'],
|
|
503
|
-
iterdone=iteration_limit - iterleft, iterleft=iterleft,
|
|
504
|
-
majordone=majordone, majorleft=majorleft, cyclethreshold=convergence_state['cyclethreshold'], stopdesc=stopdesc )
|
|
505
|
-
return self._clean['last-success']
|
|
506
|
-
|
|
507
|
-
elif msg['action'] == 'stop':
|
|
508
|
-
self.__stop( )
|
|
509
|
-
return dict( result='stopped', update=dict( ) )
|
|
510
|
-
elif msg['action'] == 'status':
|
|
511
|
-
return dict( result="ok", update=dict( ) )
|
|
512
|
-
else:
|
|
513
|
-
print( "got something else: '%s'" % msg['action'] )
|
|
514
|
-
|
|
515
|
-
###
|
|
516
|
-
### set up websockets which will be used for control and convergence updates
|
|
517
|
-
###
|
|
518
|
-
self._init_pipes( )
|
|
519
|
-
|
|
520
|
-
###
|
|
521
|
-
### Setup id that will be used for messages from each button
|
|
522
|
-
###
|
|
523
|
-
self._clean_ids = { }
|
|
524
|
-
for btn in "continue", 'finish', 'stop':
|
|
525
|
-
self._clean_ids[btn] = str(uuid4( ))
|
|
526
|
-
#print("%s: %s" % ( btn, self._clean_ids[btn] ) )
|
|
527
|
-
self._pipe['control'].register( self._clean_ids[btn], clean_handler )
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
###
|
|
531
|
-
### There is one set of tclean controls for all images/outlier/etc. because
|
|
532
|
-
### in the final version gclean will handle the iterations for all fields...
|
|
533
|
-
###
|
|
534
|
-
cwidth = 64
|
|
535
|
-
cheight = 40
|
|
536
|
-
self._control['iteration'] = { }
|
|
537
|
-
self._control['iteration']['continue'] = TipButton( max_width=cwidth, max_height=cheight, name='continue',
|
|
538
|
-
icon=svg_icon(icon_name="iclean-continue", size=18),
|
|
539
|
-
tooltip=Tooltip( content=HTML( '''Stop after <b>one major cycle</b> or when any stopping criteria is met.''' ), position='left') )
|
|
540
|
-
self._control['iteration']['finish'] = TipButton( max_width=cwidth, max_height=cheight, name='finish',
|
|
541
|
-
icon=svg_icon(icon_name="iclean-finish", size=18),
|
|
542
|
-
tooltip=Tooltip( content=HTML( '''<b>Continue</b> until some stopping criteria is met.''' ), position='left') )
|
|
543
|
-
self._control['iteration']['stop'] = TipButton( button_type="danger", max_width=cwidth, max_height=cheight, name='stop',
|
|
544
|
-
icon=svg_icon(icon_name="iclean-stop", size=18),
|
|
545
|
-
tooltip=Tooltip( content=HTML( '''<p>Clicking a <font color="red">red</font> stop button will cause this tab to close and control will return to Python.<p>Clicking an <font color="orange">orange</font> stop button will cause <tt>tclean</tt> to stop after the current major cycle.''' ), position='left' ) )
|
|
546
|
-
|
|
547
|
-
###
|
|
548
|
-
### The single SHARED help button will be supplied by the first CubeMask...
|
|
549
|
-
###
|
|
550
|
-
help_button = None
|
|
551
|
-
###
|
|
552
|
-
### First status line will be reused...
|
|
553
|
-
###
|
|
554
|
-
status_line = None
|
|
555
|
-
|
|
556
|
-
###
|
|
557
|
-
### Manage the widgets which are shared between tabs...
|
|
558
|
-
###
|
|
559
|
-
icw = SharedWidgets( )
|
|
560
|
-
toolbars = [ ]
|
|
561
|
-
for imid, imdetails in self._clean_targets.items( ):
|
|
562
|
-
imdetails['gui']['stats'] = imdetails['gui']['cube'].statistics( )
|
|
563
|
-
imdetails['image-channels'] = imdetails['gui']['cube'].shape( )[3]
|
|
564
|
-
|
|
565
|
-
status_line = imdetails['gui']['stopcode'] = imdetails['gui']['cube'].status_text( "<p>initial residual image</p>" if imdetails['image-channels'] > 1 else "<p>initial <b>single-channel</b> residual image</p>", width=230, reuse=status_line )
|
|
566
|
-
|
|
567
|
-
###
|
|
568
|
-
### Retrieve convergence information
|
|
569
|
-
###
|
|
570
|
-
def convergence_handler( msg, self=self, imid=imid ):
|
|
571
|
-
if msg['action'] == 'retrieve':
|
|
572
|
-
return { 'result': self._clean['last-success'] }
|
|
573
|
-
else:
|
|
574
|
-
return { 'result': None, 'error': 'unrecognized action' }
|
|
575
|
-
|
|
576
|
-
self._clean['converge']['pipe'].register( self._clean['converge']['id'], convergence_handler )
|
|
577
|
-
|
|
578
|
-
###
|
|
579
|
-
### Data source that will be used for updating the convergence plot
|
|
580
|
-
###
|
|
581
|
-
stokes = 0
|
|
582
|
-
convergence = imdetails['converge']['chan'][0][stokes]
|
|
583
|
-
imdetails['converge-data'] = { }
|
|
584
|
-
imdetails['converge-data']['flux'] = ColumnDataSource( data=dict( values=convergence['modelFlux'], iterations=convergence['iterations'],
|
|
585
|
-
cyclethreshold=convergence['cycleThresh'],
|
|
586
|
-
stopDesc=list( map( ImagingDict.get_summaryminor_stopdesc, convergence['stopCode'] ) ),
|
|
587
|
-
type=['flux'] * len(convergence['iterations']) ) )
|
|
588
|
-
imdetails['converge-data']['residual'] = ColumnDataSource( data=dict( values=convergence['peakRes'], iterations=convergence['iterations'],
|
|
589
|
-
cyclethreshold=convergence['cycleThresh'],
|
|
590
|
-
stopDesc=list( map( ImagingDict.get_summaryminor_stopdesc, convergence['stopCode'] ) ),
|
|
591
|
-
type=['residual'] * len(convergence['iterations'])) )
|
|
592
|
-
imdetails['converge-data']['cyclethreshold'] = ColumnDataSource( data=dict( values=convergence['cycleThresh'], iterations=convergence['iterations'] ) )
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
###
|
|
596
|
-
### help page for cube interactions
|
|
597
|
-
###
|
|
598
|
-
if help_button is None:
|
|
599
|
-
help_button = imdetails['gui']['cube'].help( rows=[ '<tr><td><i><b>red</b> stop button</i></td><td>clicking the stop button (when red) will close the dialog and control to python</td></tr>',
|
|
600
|
-
'<tr><td><i><b>orange</b> stop button</i></td><td>clicking the stop button (when orange) will return control to the GUI after the currently executing tclean run completes</td></tr>' ], position='right' )
|
|
601
|
-
|
|
602
|
-
self._create_convergence_gui( imdetails, orient='horizontal', sizing_mode='stretch_height', width=self._conv_spect_plot_width )
|
|
603
|
-
|
|
604
|
-
imdetails['gui']['params']['iteration']['nmajor'] = icw.nmajor( title='nmajor', value="%s" % self._initial_clean_params['nmajor'], width=90 )
|
|
605
|
-
imdetails['gui']['params']['iteration']['niter'] = icw.niter( title='niter', value="%s" % self._initial_clean_params['niter'], width=90 )
|
|
606
|
-
imdetails['gui']['params']['iteration']['cycleniter'] = icw.cycleniter( title="cycleniter", value="%s" % self._initial_clean_params['cycleniter'], width=90 )
|
|
607
|
-
imdetails['gui']['params']['iteration']['threshold'] = icw.threshold( title="threshold", value="%s" % self._initial_clean_params['threshold'], width=90 )
|
|
608
|
-
imdetails['gui']['params']['iteration']['cyclefactor'] = icw.cyclefactor( value="%s" % self._initial_clean_params['cyclefactor'], title="cyclefactor", width=90 )
|
|
609
|
-
imdetails['gui']['params']['iteration']['gain'] = icw.gain( title='gain', value="%s" % self._initial_clean_params['gain'], width=90 )
|
|
610
|
-
imdetails['gui']['params']['iteration']['nsigma'] = icw.nsigma( title='nsigma', value="%s" % self._initial_clean_params['nsigma'], width=90 )
|
|
611
|
-
|
|
612
|
-
if imdetails['params']['am']['usemask'] == 'auto-multithresh':
|
|
613
|
-
###
|
|
614
|
-
### Currently automasking tab is only available when the user selects 'auto-multithresh'
|
|
615
|
-
###
|
|
616
|
-
imdetails['gui']['params']['automask']['active'] = True
|
|
617
|
-
imdetails['gui']['params']['automask']['noisethreshold'] = icw.noisethreshold( title='noisethreshold', value="%s" % imdetails['params']['am']['noisethreshold'], margin=( 5, 25, 5, 5 ), width=90 )
|
|
618
|
-
imdetails['gui']['params']['automask']['sidelobethreshold'] = icw.sidelobethreshold( title='sidelobethreshold', value="%s" % imdetails['params']['am']['sidelobethreshold'], margin=( 5, 25, 5, 5 ), width=90 )
|
|
619
|
-
imdetails['gui']['params']['automask']['lownoisethreshold'] = icw.lownoisethreshold( title='lownoisethreshold', value="%s" % imdetails['params']['am']['lownoisethreshold'], margin=( 5, 25, 5, 5 ), width=90 )
|
|
620
|
-
imdetails['gui']['params']['automask']['minbeamfrac'] = icw.minbeamfrac( title='minbeamfrac', value="%s" % imdetails['params']['am']['minbeamfrac'], width=90 )
|
|
621
|
-
imdetails['gui']['params']['automask']['negativethreshold'] = icw.negativethreshold( title='negativethreshold', value="%s" % imdetails['params']['am']['negativethreshold'], margin=( 5, 25, 5, 5 ), width=90 )
|
|
622
|
-
imdetails['gui']['params']['automask']['dogrowprune'] = icw.dogrowprune( label='dogrowprune', active=imdetails['params']['am']['dogrowprune'], margin=( 15, 25, 5, 5 ) )
|
|
623
|
-
imdetails['gui']['params']['automask']['fastnoise'] = icw.fastnoise( label='fastnoise', active=imdetails['params']['am']['fastnoise'], margin=( 15, 25, 5, 5 ) )
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
imdetails['gui']['image']['src'] = imdetails['gui']['cube'].js_obj( )
|
|
627
|
-
imdetails['gui']['image']['fig'] = imdetails['gui']['cube'].image( grid=False, height_policy='max', width_policy='max',
|
|
628
|
-
channelcb=CustomJS( args=dict( img_state={ 'src': imdetails['gui']['image']['src'],
|
|
629
|
-
'flux': imdetails['converge-data']['flux'],
|
|
630
|
-
'residual': imdetails['converge-data']['residual'],
|
|
631
|
-
'cyclethreshold': imdetails['converge-data']['cyclethreshold'] },
|
|
632
|
-
imid=imid,
|
|
633
|
-
ctrl={ 'converge': self._clean['converge'] },
|
|
634
|
-
stopdescmap=ImagingDict.get_summaryminor_stopdesc( ) ),
|
|
635
|
-
code=self._js['update-converge'] +
|
|
636
|
-
'''update_convergence_single( img_state, document._casa_convergence_data.convergence[imid] )''' ) )
|
|
637
|
-
|
|
638
|
-
###
|
|
639
|
-
### collect toolbars for syncing selection
|
|
640
|
-
###
|
|
641
|
-
toolbars.append(imdetails['gui']['image']['fig'].toolbar)
|
|
642
|
-
|
|
643
|
-
###
|
|
644
|
-
### spectrum plot must be disabled during iteration due to "tap to change channel" functionality
|
|
645
|
-
###
|
|
646
|
-
if imdetails['image-channels'] > 1:
|
|
647
|
-
imdetails['gui']['spectrum'] = imdetails['gui']['cube'].spectrum( orient='vertical', sizing_mode='stretch_height', width=self._conv_spect_plot_width )
|
|
648
|
-
imdetails['gui']['slider'] = imdetails['gui']['cube'].slider( show_value=False, title='', margin=(14,5,5,5), sizing_mode="scale_width" )
|
|
649
|
-
imdetails['gui']['goto'] = imdetails['gui']['cube'].goto( )
|
|
650
|
-
else:
|
|
651
|
-
imdetails['gui']['spectrum'] = None
|
|
652
|
-
imdetails['gui']['slider'] = None
|
|
653
|
-
imdetails['gui']['goto'] = None
|
|
654
|
-
|
|
655
|
-
imdetails['gui']['channel-ctrl'] = imdetails['gui']['cube'].channel_ctrl( )
|
|
656
|
-
|
|
657
|
-
imdetails['gui']['cursor-pixel-text'] = imdetails['gui']['cube'].pixel_tracking_text( margin=(-3, 5, 3, 30) )
|
|
658
|
-
|
|
659
|
-
self._image_bitmask_controls = imdetails['gui']['cube'].bitmask_ctrl( reuse=self._image_bitmask_controls, button_type='light' )
|
|
660
|
-
|
|
661
|
-
if imdetails['params']['am']['usemask'] == 'auto-multithresh':
|
|
662
|
-
imdetails['gui']['auto-masking-panel'] = [ TabPanel( child=column( row( Tip( imdetails['gui']['params']['automask']['noisethreshold'],
|
|
663
|
-
tooltip=Tooltip( content=HTML( 'sets the signal-to-noise threshold above which significant emission is masked during the initial round of mask creation' ),
|
|
664
|
-
position='bottom' ) ),
|
|
665
|
-
Tip( imdetails['gui']['params']['automask']['sidelobethreshold'],
|
|
666
|
-
tooltip=Tooltip( content=HTML( 'sets a threshold based on the sidelobe level above which significant emission is masked during the initial round of mask creation' ),
|
|
667
|
-
position='bottom' ) ),
|
|
668
|
-
Tip( imdetails['gui']['params']['automask']['minbeamfrac'],
|
|
669
|
-
tooltip=Tooltip( content=HTML( 'sets the minimum size a region must be to be retained in the mask' ),
|
|
670
|
-
position='bottom' ) ) ),
|
|
671
|
-
row( Tip( imdetails['gui']['params']['automask']['lownoisethreshold'],
|
|
672
|
-
tooltip=Tooltip( content=HTML( 'sets the threshold into which the initial mask (which is determined by either noisethreshold or sidelobethreshold) is expanded in order to include low signal-to-noise regions in the mask' ),
|
|
673
|
-
position='bottom' ) ),
|
|
674
|
-
Tip( imdetails['gui']['params']['automask']['negativethreshold'],
|
|
675
|
-
tooltip=Tooltip( content=HTML( 'sets the signal-to-noise threshold for absorption features to be masked' ),
|
|
676
|
-
position='bottom' ) ) ),
|
|
677
|
-
row( Tip( imdetails['gui']['params']['automask']['dogrowprune'],
|
|
678
|
-
tooltip=Tooltip( content=HTML( 'allows you to turn off the pruning of the low signal-to-noise mask, which speeds up masking for images and cubes with complex low signal-to-noise emission' ),
|
|
679
|
-
position='bottom' ) ),
|
|
680
|
-
Tip( imdetails['gui']['params']['automask']['fastnoise'],
|
|
681
|
-
tooltip=Tooltip( content=HTML( 'When set to True, a simpler but faster noise calucation is used' ),
|
|
682
|
-
position='bottom' ) ) ) ),
|
|
683
|
-
title='Automask' ) ]
|
|
684
|
-
else:
|
|
685
|
-
imdetails['gui']['auto-masking-panel'] = [ ]
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
###
|
|
689
|
-
### synchronize toolbar selections among figures
|
|
690
|
-
###
|
|
691
|
-
if toolbars:
|
|
692
|
-
for tb in toolbars:
|
|
693
|
-
tb.js_on_change( 'active_changed',
|
|
694
|
-
###
|
|
695
|
-
### toolbars must filter out 'tb' to avoid circular references
|
|
696
|
-
###
|
|
697
|
-
CustomJS( args=dict(toolbars=[t for t in toolbars if t.id != tb.id]),
|
|
698
|
-
code='''casalib.map( (gest,tool) => {
|
|
699
|
-
if ( tool.active ) {
|
|
700
|
-
// a tool which belongs to the toolbar that signaled a change
|
|
701
|
-
// is active for this gesture...
|
|
702
|
-
toolbars.forEach( (other_tb) => {
|
|
703
|
-
let new_active = other_tb.gestures[gest].tools.find(
|
|
704
|
-
(t) => t.name == tool.active.name )
|
|
705
|
-
if ( ! other_tb.gestures[gest].active ) {
|
|
706
|
-
if ( new_active ) {
|
|
707
|
-
other_tb.gestures[gest].active = new_active
|
|
708
|
-
new_active.active = true
|
|
709
|
-
}
|
|
710
|
-
} else if ( other_tb.gestures[gest].active.name != tool.active.name ) {
|
|
711
|
-
if ( new_active ) {
|
|
712
|
-
other_tb.gestures[gest].active.active = false
|
|
713
|
-
new_active.active = true
|
|
714
|
-
other_tb.gestures[gest].active = new_active
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
} )
|
|
718
|
-
} else {
|
|
719
|
-
// a tool which belongs to the toolbar that signaled a change
|
|
720
|
-
// is NOT active for this gesture...
|
|
721
|
-
toolbars.forEach( (other_tb) => {
|
|
722
|
-
if ( other_tb.gestures[gest] && other_tb.gestures[gest].active ) {
|
|
723
|
-
other_tb.gestures[gest].active.active = false
|
|
724
|
-
other_tb.gestures[gest].active = null
|
|
725
|
-
}
|
|
726
|
-
} )
|
|
727
|
-
}
|
|
728
|
-
}, cb_obj.gestures )''' ) )
|
|
67
|
+
self._args = {{forwDict}}
|
|
68
|
+
self._gclean = self._gclean_module.gclean( **self._args )
|
|
69
|
+
self._gclean_paths = self._gclean.image_products( )
|
|
70
|
+
#self._residual_path = self._residual_path(self._clean['gclean'],imid)
|
|
71
|
+
#self._mask_path = self._mask_path(self._clean['gclean'],imid)
|
|
729
72
|
|
|
730
|
-
|
|
731
|
-
### button to display the tclean log -- in the final implmentation, outliers and other multifield imaging should be handled by gclean
|
|
732
|
-
###
|
|
733
|
-
self._log_button = TipButton( max_width=help_button.width, max_height=help_button.height, name='log',
|
|
734
|
-
icon=svg_icon(icon_name="bp-application-sm", size=25),
|
|
735
|
-
tooltip=Tooltip( content=HTML('''click here to see the <pre>tclean</pre> execution log'''), position="right" ),
|
|
736
|
-
margin=(-1, 0, -10, 0), button_type='light',
|
|
737
|
-
stylesheets=[ InlineStyleSheet( css='''.bk-btn { border: 0px solid #ccc; padding: 0 var(--padding-vertical) var(--padding-horizontal); margin-top: 3px; }''' ) ] )
|
|
738
|
-
|
|
739
|
-
self._control['iteration']['cb'] = CustomJS( args=dict( images_state={ k: { 'status': v['gui']['stopcode'],
|
|
740
|
-
'automask': v['gui']['params']['automask'],
|
|
741
|
-
'iteration': v['gui']['params']['iteration'],
|
|
742
|
-
'img': v['gui']['image']['fig'],
|
|
743
|
-
'src': v['gui']['cube'].js_obj( ),
|
|
744
|
-
'spectrum': v['gui']['spectrum'],
|
|
745
|
-
'src': v['gui']['image']['src'],
|
|
746
|
-
'flux': v['converge-data']['flux'],
|
|
747
|
-
'cyclethreshold': v['converge-data']['cyclethreshold'],
|
|
748
|
-
'residual': v['converge-data']['residual'],
|
|
749
|
-
'navi': { 'slider': v['gui']['slider'],
|
|
750
|
-
'goto': v['gui']['goto'],
|
|
751
|
-
## it doesn't seem like pixel tracking must be disabled
|
|
752
|
-
##'tracking': v['gui']['cursor-pixel-text'],
|
|
753
|
-
'stokes': v['gui']['channel-ctrl'][1] } }
|
|
754
|
-
for k,v in self._clean_targets.items( ) },
|
|
755
|
-
ctrl={ 'converge': self._clean['converge'] },
|
|
756
|
-
clean_ctrl=self._control['iteration'],
|
|
757
|
-
state=dict( mode='interactive', stopped=False, awaiting_stop=False, mask="" ),
|
|
758
|
-
ctrl_pipe=self._pipe['control'],
|
|
759
|
-
ids=self._clean_ids,
|
|
760
|
-
logbutton=self._log_button,
|
|
761
|
-
stopdescmap=ImagingDict.get_summaryminor_stopdesc( )
|
|
762
|
-
),
|
|
763
|
-
code=self._js['update-converge'] + self._js['clean-refresh'] + self._js['clean-disable'] +
|
|
764
|
-
self._js['clean-enable'] + self._js['clean-status-update'] +
|
|
765
|
-
self._js['iter-gui-update'] + self._js['clean-wait'] +
|
|
766
|
-
'''function invalid_niter( s ) {
|
|
767
|
-
let v = parseInt( s )
|
|
768
|
-
if ( v > 0 ) return ''
|
|
769
|
-
if ( v == 0 ) return 'niter is zero'
|
|
770
|
-
if ( v < 0 ) return 'niter cannot be negative'
|
|
771
|
-
if ( isNaN(v) ) return 'niter must be an integer'
|
|
772
|
-
}
|
|
773
|
-
const itobj = Object.entries(images_state)[0][1].iteration
|
|
774
|
-
if ( ! state.stopped && cb_obj.origin.name == 'finish' ) {
|
|
775
|
-
let invalid = invalid_niter(itobj.niter.value)
|
|
776
|
-
if ( invalid ) update_status( invalid )
|
|
777
|
-
else {
|
|
778
|
-
state.mode = 'continuous'
|
|
779
|
-
update_status( 'Running multiple iterations' )
|
|
780
|
-
disable( false )
|
|
781
|
-
clean_ctrl.stop.button_type = "warning"
|
|
782
|
-
const thevalue = get_update_dictionary( )
|
|
783
|
-
ctrl_pipe.send( ids[cb_obj.origin.name],
|
|
784
|
-
{ action: 'finish',
|
|
785
|
-
value: thevalue },
|
|
786
|
-
update_gui )
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
if ( ! state.stopped && state.mode === 'interactive' &&
|
|
790
|
-
cb_obj.origin.name === 'continue' ) {
|
|
791
|
-
let invalid = invalid_niter(itobj.niter.value)
|
|
792
|
-
if ( invalid ) update_status( invalid )
|
|
793
|
-
else {
|
|
794
|
-
update_status( 'Running one set of deconvolution iterations' )
|
|
795
|
-
disable( true )
|
|
796
|
-
// only send message for button that was pressed
|
|
797
|
-
// it's unclear whether 'this.origin.' or 'cb_obj.origin.' should be used
|
|
798
|
-
// (or even if 'XXX.origin.' is public)...
|
|
799
|
-
ctrl_pipe.send( ids[cb_obj.origin.name],
|
|
800
|
-
{ action: 'next',
|
|
801
|
-
value: get_update_dictionary( ) },
|
|
802
|
-
update_gui )
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
if ( state.mode === 'interactive' && cb_obj.origin.name === 'stop' ) {
|
|
806
|
-
if ( confirm( "Are you sure you want to end this interactive clean session and close the GUI?" ) ) {
|
|
807
|
-
disable( true )
|
|
808
|
-
//ctrl_pipe.send( ids[cb_obj.origin.name],
|
|
809
|
-
// { action: 'stop',
|
|
810
|
-
// value: { } },
|
|
811
|
-
// update_gui )
|
|
812
|
-
document._casa_window_closed = true
|
|
813
|
-
/*** this will close the tab >>>>---------+ ***/
|
|
814
|
-
/*** | ***/
|
|
815
|
-
/*** vvvvv----------------------------+ ***/
|
|
816
|
-
document._cube_done( Object.entries(images_state).reduce((acc,[k,v]) => ({ ...acc, [k]: v.src.masks( ) }),{ } ) )
|
|
817
|
-
}
|
|
818
|
-
} else if ( state.mode === 'continuous' &&
|
|
819
|
-
cb_obj.origin.name === 'stop' &&
|
|
820
|
-
! state.awaiting_stop ) {
|
|
821
|
-
disable( true )
|
|
822
|
-
state.awaiting_stop = true
|
|
823
|
-
ctrl_pipe.send( ids[cb_obj.origin.name],
|
|
824
|
-
{ action: 'status',
|
|
825
|
-
value: { } },
|
|
826
|
-
wait_for_tclean_stop )
|
|
827
|
-
}''' )
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
self._control['iteration']['continue'].js_on_click( self._control['iteration']['cb'] )
|
|
831
|
-
self._control['iteration']['finish'].js_on_click( self._control['iteration']['cb'] )
|
|
832
|
-
self._control['iteration']['stop'].js_on_click( self._control['iteration']['cb'] )
|
|
833
|
-
|
|
834
|
-
self._log_button.js_on_click( CustomJS( args=dict( logbutton=self._log_button ),
|
|
835
|
-
code='''function format_log( elem ) {
|
|
836
|
-
return `<html>
|
|
837
|
-
<head>
|
|
838
|
-
<style type="text/css">
|
|
839
|
-
body {
|
|
840
|
-
counter-reset: section;
|
|
841
|
-
}
|
|
842
|
-
p:not([no-num]):before {
|
|
843
|
-
font-weight: bold;
|
|
844
|
-
counter-increment: section;
|
|
845
|
-
content: "" counter(section) ": ";
|
|
846
|
-
}
|
|
847
|
-
</style>
|
|
848
|
-
</head>
|
|
849
|
-
<body>
|
|
850
|
-
<h1>Interactive Clean History</h1>
|
|
851
|
-
` + elem.map((x) => x.startsWith('#') ? `<p no-num>${x}</p>` : `<p>${x}</p>`).join('\\n') + '</body>\\n</html>'
|
|
852
|
-
}
|
|
853
|
-
let b = cb_obj.origin
|
|
854
|
-
if ( ! b._window || b._window.closed ) {
|
|
855
|
-
b._window = window.open("about:blank","Interactive Clean Log")
|
|
856
|
-
b._window.document.write(format_log(b._log))
|
|
857
|
-
b._window.document.close( )
|
|
858
|
-
}''' ) )
|
|
859
|
-
|
|
860
|
-
###
|
|
861
|
-
### Setup script that will be called when the user closes the
|
|
862
|
-
### browser tab that is running interactive clean
|
|
863
|
-
###
|
|
864
|
-
initial_log = self._clean['gclean']._log( )
|
|
865
|
-
|
|
866
|
-
self._pipe['control'].init_script=CustomJS( args=dict( ctrl_pipe=self._pipe['control'],
|
|
867
|
-
ids=self._clean_ids,
|
|
868
|
-
logbutton=self._log_button,
|
|
869
|
-
log=initial_log,
|
|
870
|
-
initial_image=list(self._clean_targets.items( ))[0][0]
|
|
871
|
-
),
|
|
872
|
-
code=self._js['initialize'] +
|
|
873
|
-
'''if ( ! logbutton._log ) {
|
|
874
|
-
/*** store log list with log button for access in other callbacks ***/
|
|
875
|
-
logbutton._log = log
|
|
876
|
-
}''' )
|
|
877
|
-
|
|
878
|
-
tab_panels = list( map( self._create_image_panel, self._clean_targets.items( ) ) )
|
|
879
|
-
|
|
880
|
-
for imid, imdetails in self._clean_targets.items( ):
|
|
881
|
-
imdetails['gui']['cube'].connect( )
|
|
73
|
+
self._ui = InteractiveCleanUI(self._gclean, self._args)
|
|
882
74
|
|
|
883
|
-
image_tabs = Tabs( tabs=tab_panels, tabs_location='below', height_policy='max', width_policy='max' )
|
|
884
|
-
|
|
885
|
-
self._fig['layout'] = column(
|
|
886
|
-
row( help_button,
|
|
887
|
-
self._log_button,
|
|
888
|
-
Spacer( height=self._control['iteration']['stop'].height, sizing_mode="scale_width" ),
|
|
889
|
-
Div( text="<div><b>status:</b></div>" ),
|
|
890
|
-
status_line,
|
|
891
|
-
self._control['iteration']['stop'], self._control['iteration']['continue'], self._control['iteration']['finish'], sizing_mode="scale_width" ),
|
|
892
|
-
row( image_tabs, height_policy='max', width_policy='max' ),
|
|
893
|
-
height_policy='max', width_policy='max' )
|
|
894
|
-
|
|
895
|
-
###
|
|
896
|
-
### Keep track of which image is currently active in document._casa_image_name (which is
|
|
897
|
-
### initialized in self._js['initialize']). Also, update the current control sub-tab
|
|
898
|
-
### when the field main-tab is changed. An attempt to manage this all within the
|
|
899
|
-
### control sub-tabs using a reference to self._image_control_tab_groups from
|
|
900
|
-
### each control sub-tab failed with:
|
|
901
|
-
###
|
|
902
|
-
### bokeh.core.serialization.SerializationError: circular reference
|
|
903
|
-
###
|
|
904
|
-
image_tabs.js_on_change( 'active', CustomJS( args=dict( names=[ t[0] for t in self._clean_targets.items( ) ],
|
|
905
|
-
itergroups=self._image_control_tab_groups ),
|
|
906
|
-
code='''if ( ! hasprop(document,'_casa_last_control_tab') ) {
|
|
907
|
-
document._casa_last_control_tab = 0
|
|
908
|
-
}
|
|
909
|
-
document._casa_image_name = names[cb_obj.active]
|
|
910
|
-
itergroups[document._casa_image_name].active = document._casa_last_control_tab''' ) )
|
|
911
|
-
|
|
912
|
-
# Change display type depending on runtime environment
|
|
913
|
-
if self._is_notebook:
|
|
914
|
-
output_notebook()
|
|
915
|
-
else:
|
|
916
|
-
### Directory is created when an HTTP server is running
|
|
917
|
-
### (MAX)
|
|
918
|
-
### output_file(self._imagename+'_webpage/index.html')
|
|
919
|
-
pass
|
|
920
|
-
|
|
921
|
-
show(self._fig['layout'])
|
|
922
|
-
|
|
923
|
-
def _create_colormap_adjust( self, imdetails ):
|
|
924
|
-
palette = imdetails['gui']['cube'].palette( reuse=self._cube_palette )
|
|
925
|
-
return column( row( Div(text="<div><b>Colormap:</b></div>",margin=(5,2,5,25)), palette ),
|
|
926
|
-
imdetails['gui']['cube'].colormap_adjust( ), sizing_mode='stretch_both' )
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
def _create_control_image_tab( self, imid, imdetails ):
|
|
930
|
-
result = Tabs( tabs=[ TabPanel(child=column( row( Tip( imdetails['gui']['params']['iteration']['nmajor'],
|
|
931
|
-
tooltip=Tooltip( content=HTML( 'maximum number of major cycles to run before stopping'),
|
|
932
|
-
position='bottom' ) ),
|
|
933
|
-
Tip( imdetails['gui']['params']['iteration']['niter'],
|
|
934
|
-
tooltip=Tooltip( content=HTML( 'number of clean iterations to run' ),
|
|
935
|
-
position='bottom' ) ),
|
|
936
|
-
Tip( imdetails['gui']['params']['iteration']['threshold'],
|
|
937
|
-
tooltip=Tooltip( content=HTML( 'stopping threshold' ),
|
|
938
|
-
position='bottom' ) ) ),
|
|
939
|
-
row( Tip( imdetails['gui']['params']['iteration']['nsigma'],
|
|
940
|
-
tooltip=Tooltip( content=HTML( 'multiplicative factor for rms-based threshold stopping'),
|
|
941
|
-
position='bottom' ) ),
|
|
942
|
-
Tip( imdetails['gui']['params']['iteration']['gain'],
|
|
943
|
-
tooltip=Tooltip( content=HTML( 'fraction of the source flux to subtract out of the residual image'),
|
|
944
|
-
position='bottom' ) ) ),
|
|
945
|
-
row( Tip( imdetails['gui']['params']['iteration']['cycleniter'],
|
|
946
|
-
tooltip=Tooltip( content=HTML( 'maximum number of <b>minor-cycle</b> iterations' ),
|
|
947
|
-
position='bottom' ) ),
|
|
948
|
-
Tip( imdetails['gui']['params']['iteration']['cyclefactor'],
|
|
949
|
-
tooltip=Tooltip( content=HTML( 'scaling on PSF sidelobe level to compute the minor-cycle stopping threshold' ),
|
|
950
|
-
position='bottom_left' ) ), background="lightgray" ),
|
|
951
|
-
imdetails['gui']['convergence'], sizing_mode='stretch_height' ),
|
|
952
|
-
title='Iteration' ) ] +
|
|
953
|
-
( [ TabPanel( child=imdetails['gui']['spectrum'],
|
|
954
|
-
title='Spectrum' ) ] if imdetails['image-channels'] > 1 else [ ] ) +
|
|
955
|
-
[ TabPanel( child=self._create_colormap_adjust(imdetails),
|
|
956
|
-
title='Colormap' ),
|
|
957
|
-
TabPanel( child=column( *imdetails['gui']['stats'] ),
|
|
958
|
-
title='Statistics' ) ] + imdetails['gui']['auto-masking-panel'],
|
|
959
|
-
width=500, sizing_mode='stretch_height', tabs_location='below' )
|
|
960
|
-
|
|
961
|
-
if not hasattr(self,'_image_control_tab_groups'):
|
|
962
|
-
self._image_control_tab_groups = { }
|
|
963
|
-
|
|
964
|
-
self._image_control_tab_groups[imid] = result
|
|
965
|
-
result.js_on_change( 'active', CustomJS( args=dict( ),
|
|
966
|
-
code='''document._casa_last_control_tab = cb_obj.active''' ) )
|
|
967
|
-
return result
|
|
968
|
-
|
|
969
|
-
def _create_image_panel( self, imagetuple ):
|
|
970
|
-
imid, imdetails = imagetuple
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
return TabPanel( child=column( row( *imdetails['gui']['channel-ctrl'], imdetails['gui']['cube'].coord_ctrl( ),
|
|
975
|
-
*self._image_bitmask_controls,
|
|
976
|
-
#Spacer( height=5, height_policy="fixed", sizing_mode="scale_width" ),
|
|
977
|
-
imdetails['gui']['cursor-pixel-text'],
|
|
978
|
-
row( Spacer( sizing_mode='stretch_width' ),
|
|
979
|
-
imdetails['gui']['cube'].tapedeck( size='20px' ) if imdetails['image-channels'] > 1 else Div( ),
|
|
980
|
-
Spacer( height=5, width=350 ), width_policy='max' ),
|
|
981
|
-
width_policy='max' ),
|
|
982
|
-
row( imdetails['gui']['image']['fig'],
|
|
983
|
-
column( row( imdetails['gui']['goto'],
|
|
984
|
-
imdetails['gui']['slider'],
|
|
985
|
-
width_policy='max' ) if imdetails['image-channels'] > 1 else Div( ),
|
|
986
|
-
self._create_control_image_tab(imid, imdetails), height_policy='max' ),
|
|
987
|
-
height_policy='max', width_policy='max' ),
|
|
988
|
-
height_policy='max', width_policy='max' ), title=imid )
|
|
989
75
|
|
|
990
76
|
def __call__( self ):
|
|
991
77
|
'''Display GUI and process events until the user stops the application.
|
|
@@ -998,510 +84,6 @@ class InteractiveClean:
|
|
|
998
84
|
cell='12.0arcsec', specmode='cube',
|
|
999
85
|
interpolation='nearest', ... )( ) )
|
|
1000
86
|
'''
|
|
1001
|
-
|
|
1002
|
-
self.
|
|
1003
|
-
|
|
1004
|
-
# If Interactive Clean is being run remotely, print helper info for port tunneling
|
|
1005
|
-
if self._is_remote:
|
|
1006
|
-
# Tunnel ports for Jupyter kernel connection
|
|
1007
|
-
print("\nImportant: Copy the following line and run in your local terminal to establish port forwarding.\
|
|
1008
|
-
You may need to change the last argument to align with your ssh config.\n")
|
|
1009
|
-
print(self._gen_port_fwd_cmd())
|
|
1010
|
-
|
|
1011
|
-
# TODO: Include?
|
|
1012
|
-
# VSCode will auto-forward ports that appear in well-formatted addresses.
|
|
1013
|
-
# Printing this line will cause VSCode to autoforward the ports
|
|
1014
|
-
# print("Cmd: " + str(repr(self.auto_fwd_ports_vscode())))
|
|
1015
|
-
input("\nPress enter when port forwarding is setup...")
|
|
1016
|
-
|
|
1017
|
-
async def _run_( ):
|
|
1018
|
-
async with self.serve( ) as s:
|
|
1019
|
-
await s
|
|
1020
|
-
|
|
1021
|
-
if self._is_notebook:
|
|
1022
|
-
ic_task = asyncio.create_task(_run_())
|
|
1023
|
-
else:
|
|
1024
|
-
asyncio.run(_run_( ))
|
|
1025
|
-
return self.result( )
|
|
1026
|
-
|
|
1027
|
-
def _setup( self ):
|
|
1028
|
-
self.__reset( )
|
|
1029
|
-
|
|
1030
|
-
def initialize_tclean( gclean ):
|
|
1031
|
-
|
|
1032
|
-
stopdesc, stopcode, majordone, majorleft, iterleft, all_converge = next(gclean)
|
|
1033
|
-
|
|
1034
|
-
for imid, converge in all_converge.items( ):
|
|
1035
|
-
#######################################################################################################
|
|
1036
|
-
### gclean seems to return its internal state making it succeptable to modification... so we'll at ###
|
|
1037
|
-
### least start out with unique dictionaries. ###
|
|
1038
|
-
#######################################################################################################
|
|
1039
|
-
converge = copy.deepcopy(converge)
|
|
1040
|
-
|
|
1041
|
-
imdetails = self._clean_targets[imid]
|
|
1042
|
-
imdetails['converge'] = converge
|
|
1043
|
-
|
|
1044
|
-
if imdetails['converge'] is None or len(imdetails['converge'].keys()) == 0 or \
|
|
1045
|
-
imdetails['converge']['major'] is None or imdetails['converge']['chan'] is None:
|
|
1046
|
-
###
|
|
1047
|
-
### gclean should provide argument checking (https://github.com/casangi/casagui/issues/33)
|
|
1048
|
-
### but currently gclean can be initialized with bad arguments and it is not known until
|
|
1049
|
-
### the initial calls to tclean/deconvolve
|
|
1050
|
-
###
|
|
1051
|
-
raise RuntimeError(f'''gclean failure "%s" not returned: {imdetails["converge"]}''' % ('major' if imdetails['converge']['major'] is None else 'chan'))
|
|
1052
|
-
|
|
1053
|
-
self._clean['cmds'].extend(self._clean['gclean']._log( ))
|
|
1054
|
-
|
|
1055
|
-
self._initial_clean_params['nmajor'] = majorleft
|
|
1056
|
-
self._initial_clean_params['niter'] = iterleft
|
|
1057
|
-
self._initial_clean_params['cycleniter'] = self._init_values["cycleniter"]
|
|
1058
|
-
self._initial_clean_params['threshold'] = self._init_values["threshold"]
|
|
1059
|
-
self._initial_clean_params['cyclefactor'] = self._init_values["cyclefactor"]
|
|
1060
|
-
self._initial_clean_params['gain'] = self._init_values["gain"]
|
|
1061
|
-
self._initial_clean_params['nsigma'] = self._init_values["nsigma"]
|
|
1062
|
-
|
|
1063
|
-
self._init_values["convergence_state"]['convergence'][imid] = imdetails['converge']['chan']
|
|
1064
|
-
self._init_values["convergence_state"]['cyclethreshold'][imid] = imdetails['converge']['major']['cyclethreshold']
|
|
1065
|
-
|
|
1066
|
-
return (stopdesc, stopcode, majordone, majorleft, iterleft)
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
self._clean['cmds'] = []
|
|
1070
|
-
|
|
1071
|
-
stopdesc, stopcode, majordone, majorleft, iterleft = initialize_tclean(self._clean['gclean'])
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
self._clean['last-success'] = dict( result='converged' if stopcode[0] else 'update', stopcode=stopcode, cmd=self._clean['cmds'],
|
|
1075
|
-
convergence=self._init_values["convergence_state"]['convergence'],
|
|
1076
|
-
iterdone=0, iterleft=iterleft,
|
|
1077
|
-
majordone=majordone, majorleft=majorleft,
|
|
1078
|
-
cyclethreshold=self._init_values["convergence_state"]['cyclethreshold'],
|
|
1079
|
-
stopdesc=stopdesc )
|
|
1080
|
-
|
|
1081
|
-
### Must occur AFTER initial "next" call to gclean(s)
|
|
1082
|
-
self._init_pipes()
|
|
1083
|
-
|
|
1084
|
-
@asynccontextmanager
|
|
1085
|
-
async def serve( self ):
|
|
1086
|
-
'''This function is intended for developers who would like to embed interactive
|
|
1087
|
-
clean as a part of a larger GUI. This embedded use of interactive clean is not
|
|
1088
|
-
currently supported and would require the addition of parameters to this function
|
|
1089
|
-
as well as changes to the interactive clean implementation. However, this function
|
|
1090
|
-
does expose the ``asyncio.Future`` that is used to signal completion of the
|
|
1091
|
-
interactive cleaning operation, and it provides the coroutines which must be
|
|
1092
|
-
managed by asyncio to make the interactive clean GUI responsive.
|
|
1093
|
-
|
|
1094
|
-
Example:
|
|
1095
|
-
Create ``iclean`` object, process events and retrieve result::
|
|
1096
|
-
|
|
1097
|
-
ic = iclean( vis='refim_point_withline.ms', imagename='test', imsize=512,
|
|
1098
|
-
cell='12.0arcsec', specmode='cube', interpolation='nearest', ... )
|
|
1099
|
-
async def process_events( ):
|
|
1100
|
-
async with ic.serve( ) as state:
|
|
1101
|
-
await state[0]
|
|
1102
|
-
|
|
1103
|
-
asyncio.run(process_events( ))
|
|
1104
|
-
print( "Result:", ic.result( ) )
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
Returns
|
|
1108
|
-
-------
|
|
1109
|
-
(asyncio.Future, dictionary of coroutines)
|
|
1110
|
-
'''
|
|
1111
|
-
def start_http_server():
|
|
1112
|
-
import http.server
|
|
1113
|
-
import socketserver
|
|
1114
|
-
PORT = self._http_port
|
|
1115
|
-
DIRECTORY=self._webpage_path
|
|
1116
|
-
|
|
1117
|
-
class Handler(http.server.SimpleHTTPRequestHandler):
|
|
1118
|
-
def __init__(self, *args, **kwargs):
|
|
1119
|
-
super().__init__(*args, directory=DIRECTORY, **kwargs)
|
|
1120
|
-
|
|
1121
|
-
with socketserver.TCPServer(("", PORT), Handler) as httpd:
|
|
1122
|
-
print("\nServing Interactive Clean webpage from local directory: ", DIRECTORY)
|
|
1123
|
-
print("Use Control-C to stop Interactive clean.\n")
|
|
1124
|
-
print("Copy and paste one of the below URLs into your browser (Chrome or Firefox) to view:")
|
|
1125
|
-
print("http://localhost:"+str(PORT))
|
|
1126
|
-
print("http://127.0.0.1:"+str(PORT))
|
|
1127
|
-
|
|
1128
|
-
httpd.serve_forever()
|
|
1129
|
-
|
|
1130
|
-
self._launch_gui( )
|
|
1131
|
-
|
|
1132
|
-
async with CMC( *( [ ctx for img in self._clean_targets.keys( ) for ctx in
|
|
1133
|
-
[
|
|
1134
|
-
self._clean_targets[img]['gui']['cube'].serve(self.__stop),
|
|
1135
|
-
]
|
|
1136
|
-
] + [ websockets.serve( self._pipe['control'].process_messages,
|
|
1137
|
-
self._pipe['control'].address[0],
|
|
1138
|
-
self._pipe['control'].address[1] ),
|
|
1139
|
-
websockets.serve( self._clean['converge']['pipe'].process_messages,
|
|
1140
|
-
self._clean['converge']['pipe'].address[0],
|
|
1141
|
-
self._clean['converge']['pipe'].address[1] ) ]
|
|
1142
|
-
) ):
|
|
1143
|
-
self.__result_future = asyncio.Future( )
|
|
1144
|
-
yield self.__result_future
|
|
1145
|
-
|
|
1146
|
-
def __retrieve_result( self ):
|
|
1147
|
-
'''If InteractiveClean had a return value, it would be filled in as part of the
|
|
1148
|
-
GUI dialog between Python and JavaScript and this function would return it'''
|
|
1149
|
-
if isinstance(self._error_result,Exception):
|
|
1150
|
-
raise self._error_result
|
|
1151
|
-
elif self._error_result is not None:
|
|
1152
|
-
return self._error_result
|
|
1153
|
-
return { k: v['converge'] for k,v in self._clean_targets.items( ) }
|
|
1154
|
-
|
|
1155
|
-
def result( self ):
|
|
1156
|
-
'''If InteractiveClean had a return value, it would be filled in as part of the
|
|
1157
|
-
GUI dialog between Python and JavaScript and this function would return it'''
|
|
1158
|
-
if self.__result_future is None:
|
|
1159
|
-
raise RuntimeError( 'no interactive clean result is available' )
|
|
1160
|
-
|
|
1161
|
-
if self.__result is None:
|
|
1162
|
-
### restore returns full return dictionary
|
|
1163
|
-
self.__result_from_gui = self.__result_future.result( )
|
|
1164
|
-
self.__result = self._clean['gclean'].restore( )
|
|
1165
|
-
|
|
1166
|
-
return self.__result
|
|
1167
|
-
|
|
1168
|
-
def masks( self ):
|
|
1169
|
-
'''Retrieves the masks which were used with interactive clean.
|
|
1170
|
-
|
|
1171
|
-
Returns
|
|
1172
|
-
-------
|
|
1173
|
-
The standard ``cubevis`` cube region dictionary which contains two elements
|
|
1174
|
-
``masks`` and ``polys``.
|
|
1175
|
-
|
|
1176
|
-
The value of the ``masks`` element is a dictionary that is indexed by
|
|
1177
|
-
tuples of ``(stokes,chan)`` and the value of each element is a list
|
|
1178
|
-
whose elements describe the polygons drawn on the channel represented
|
|
1179
|
-
by ``(stokes,chan)``. Each polygon description in this list has a
|
|
1180
|
-
polygon index (``p``) and a x/y translation (``d``).
|
|
1181
|
-
|
|
1182
|
-
The value of the ``polys`` element is a dictionary that is indexed by
|
|
1183
|
-
polygon indexes. The value of each polygon index is a dictionary containing
|
|
1184
|
-
``type`` (whose value is either ``'rect'`` or ``'poly``) and ``geometry``
|
|
1185
|
-
(whose value is a dictionary containing ``'xs'`` and ``'ys'`` (which are
|
|
1186
|
-
the x and y coordinates that define the polygon).
|
|
1187
|
-
|
|
1188
|
-
This can be converted to other formats with ``cubevis.utils.convert_masks``.
|
|
1189
|
-
'''
|
|
1190
|
-
return copy.deepcopy(self._mask_history) ## don't allow users to change history
|
|
1191
|
-
|
|
1192
|
-
def history( self ):
|
|
1193
|
-
'''Retrieves the commands used during the interactive clean session.
|
|
1194
|
-
|
|
1195
|
-
Returns
|
|
1196
|
-
-------
|
|
1197
|
-
list[str] tclean calls made during the interactive clean session.
|
|
1198
|
-
'''
|
|
1199
|
-
return self._clean['gclean']._log( True )
|
|
1200
|
-
|
|
1201
|
-
def _initialize_javascript( self ):
|
|
1202
|
-
self._js = { ### initialize state
|
|
1203
|
-
### --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
|
|
1204
|
-
### -- document is used storing state --
|
|
1205
|
-
### --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
|
|
1206
|
-
'initialize': '''if ( ! document._casa_initialized ) {
|
|
1207
|
-
document._casa_image_name = initial_image
|
|
1208
|
-
document._casa_initialized = true
|
|
1209
|
-
document._casa_window_closed = false
|
|
1210
|
-
window.addEventListener( 'beforeunload',
|
|
1211
|
-
function (e) {
|
|
1212
|
-
// if the window is already closed this message is never
|
|
1213
|
-
// delivered (unless interactive clean is called again then
|
|
1214
|
-
// the event shows up in the newly created control pipe
|
|
1215
|
-
if ( document._casa_window_closed == false ) {
|
|
1216
|
-
ctrl_pipe.send( ids['stop'],
|
|
1217
|
-
{ action: 'stop', value: { } },
|
|
1218
|
-
undefined ) } } )
|
|
1219
|
-
}''',
|
|
1220
|
-
|
|
1221
|
-
### --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
|
|
1222
|
-
### -- flux_src._convergence_data is used to store the complete --
|
|
1223
|
-
### -- --
|
|
1224
|
-
### -- The "Insert here ..." code seems to be called when when the stokes plane is changed --
|
|
1225
|
-
### -- but there have been no tclean iterations yet... --
|
|
1226
|
-
### --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
|
|
1227
|
-
'update-converge': '''function update_convergence_single( target, data ) {
|
|
1228
|
-
const pos = target.src.cur_chan
|
|
1229
|
-
const imdata = data.get(pos[1]).get(pos[0])
|
|
1230
|
-
// chan----------------^^^^^^ ^^^^^^----stokes
|
|
1231
|
-
const iterations = imdata.iterations
|
|
1232
|
-
const peakRes = imdata.peakRes
|
|
1233
|
-
const cyclethreshold = imdata.cycleThresh
|
|
1234
|
-
const modelFlux = imdata.modelFlux
|
|
1235
|
-
const stopCode = imdata.stopCode
|
|
1236
|
-
const stopDesc = imdata.stopCode.map( code => stopdescmap.has(code) ? stopdescmap.get(code): "" )
|
|
1237
|
-
target.residual.data = { iterations, cyclethreshold, stopDesc, values: peakRes, type: Array(iterations.length).fill('residual') }
|
|
1238
|
-
target.flux.data = { iterations, cyclethreshold, stopDesc, values: modelFlux, type: Array(iterations.length).fill('flux') }
|
|
1239
|
-
target.cyclethreshold.data = { iterations, values: cyclethreshold }
|
|
1240
|
-
}
|
|
1241
|
-
|
|
1242
|
-
function update_convergence( recurse=false ) {
|
|
1243
|
-
let convdata
|
|
1244
|
-
if ( hasprop(document,'_casa_convergence_data') ) {
|
|
1245
|
-
convdata = document._casa_convergence_data
|
|
1246
|
-
} else {
|
|
1247
|
-
if ( ! recurse ) {
|
|
1248
|
-
ctrl.converge.pipe.send( ctrl.converge.id, { action: 'retrieve' },
|
|
1249
|
-
(msg) => { if ( hasprop( msg.result, 'convergence' ) ) {
|
|
1250
|
-
document._casa_convergence_data = { convergence: msg.result.convergence,
|
|
1251
|
-
cyclethreshold: msg.result.cyclethreshold }
|
|
1252
|
-
update_convergence(true)
|
|
1253
|
-
} } )
|
|
1254
|
-
} else { console.log( 'INTERNAL ERROR: fetching convergence data failed' ) }
|
|
1255
|
-
return
|
|
1256
|
-
}
|
|
1257
|
-
|
|
1258
|
-
Object.entries(images_state).map(
|
|
1259
|
-
([k,v],i) => { update_convergence_single(v,convdata.convergence[k]) } )
|
|
1260
|
-
}''',
|
|
1261
|
-
|
|
1262
|
-
'clean-refresh': '''function refresh( clean_msg ) {
|
|
1263
|
-
const itobj = Object.entries(images_state)[0][1].iteration
|
|
1264
|
-
let stokes = 0 // later we will receive the polarity
|
|
1265
|
-
// from some widget mechanism...
|
|
1266
|
-
if ( clean_msg !== undefined ) {
|
|
1267
|
-
if ( 'iterleft' in clean_msg ) {
|
|
1268
|
-
itobj.niter.value = '' + clean_msg['iterleft']
|
|
1269
|
-
} else if ( clean_msg !== undefined && 'iterdone' in clean_msg ) {
|
|
1270
|
-
const remaining = parseInt(itobj.niter.value) - parseInt(clean_msg['iterdone'])
|
|
1271
|
-
itobj.niter.value = '' + (remaining < 0 ? 0 : remaining)
|
|
1272
|
-
}
|
|
1273
|
-
|
|
1274
|
-
if ( 'majorleft' in clean_msg ) {
|
|
1275
|
-
itobj.nmajor.value = '' + clean_msg['majorleft']
|
|
1276
|
-
} else if ( 'majordone' in clean_msg ) {
|
|
1277
|
-
const nm = parseInt(itobj.nmajor.value)
|
|
1278
|
-
if ( nm != -1 ) {
|
|
1279
|
-
const remaining = nm - parseInt(clean_msg['majordone'])
|
|
1280
|
-
itobj.nmajor.value = '' + (remaining < 0 ? 0 : remaining)
|
|
1281
|
-
} else itobj.nmajor.value = '' + nm // nmajor == -1 implies do not consider nmajor in stop decision
|
|
1282
|
-
}
|
|
1283
|
-
|
|
1284
|
-
if ( hasprop(clean_msg,'convergence') && clean_msg.convergence != null ) {
|
|
1285
|
-
document._casa_convergence_data = { convergence: clean_msg.convergence,
|
|
1286
|
-
cyclethreshold: clean_msg.cyclethreshold }
|
|
1287
|
-
}
|
|
1288
|
-
}
|
|
1289
|
-
|
|
1290
|
-
// All images must be updated... without this no images are updated
|
|
1291
|
-
casalib.map( (im,state) => state.src.refresh( msg => {
|
|
1292
|
-
if ( 'stats' in msg ) state.src.update_statistics( msg.stats )
|
|
1293
|
-
} ), images_state )
|
|
1294
|
-
// Update convergence plot...
|
|
1295
|
-
update_convergence( )
|
|
1296
|
-
}''',
|
|
1297
|
-
|
|
1298
|
-
###
|
|
1299
|
-
### enabling/disabling tools in imdetails['gui']['image']['fig'].toolbar.tools does not seem to not work
|
|
1300
|
-
### imdetails['gui']['image']['fig'].toolbar.tools.tool_name (e.g. "Box Select", "Lasso Select")
|
|
1301
|
-
###
|
|
1302
|
-
### By design, images_state[*].automask.*/images_state[*].iteration.* are singletons which only need
|
|
1303
|
-
### to be disabled once...
|
|
1304
|
-
###
|
|
1305
|
-
'clean-disable': '''function disable( with_stop ) {
|
|
1306
|
-
const amobj = Object.entries(images_state)[0][1].automask
|
|
1307
|
-
Object.entries(amobj).map(
|
|
1308
|
-
([k,v],i) => { if ( hasprop(v,'disabled') ) v.disabled = true } )
|
|
1309
|
-
const itobj = Object.entries(images_state)[0][1].iteration
|
|
1310
|
-
Object.entries(itobj).map(
|
|
1311
|
-
([k,v],i) => { if ( hasprop(v,'disabled') ) v.disabled = true } )
|
|
1312
|
-
Object.entries(images_state).map(
|
|
1313
|
-
([k,v],i) => {
|
|
1314
|
-
v.img.disabled = true
|
|
1315
|
-
if ( v.spectrum ) v.spectrum.disabled = true
|
|
1316
|
-
v.src.disable_masking( )
|
|
1317
|
-
v.src.disable_pixel_update( )
|
|
1318
|
-
Object.entries(v.navi).map(
|
|
1319
|
-
([k1,v1],i1) => { if ( hasprop(v1,'disabled') ) v1.disabled = true }
|
|
1320
|
-
)
|
|
1321
|
-
}
|
|
1322
|
-
)
|
|
1323
|
-
clean_ctrl.continue.disabled = true
|
|
1324
|
-
clean_ctrl.finish.disabled = true
|
|
1325
|
-
clean_ctrl.stop.disabled = with_stop
|
|
1326
|
-
}''',
|
|
1327
|
-
|
|
1328
|
-
'clean-enable': '''function enable( only_stop ) {
|
|
1329
|
-
const amobj = Object.entries(images_state)[0][1].automask
|
|
1330
|
-
Object.entries(amobj).map(
|
|
1331
|
-
([k,v],i) => { if ( hasprop(v,'disabled') ) v.disabled = false } )
|
|
1332
|
-
const itobj = Object.entries(images_state)[0][1].iteration
|
|
1333
|
-
Object.entries(itobj).map(
|
|
1334
|
-
([k,v],i) => { if ( hasprop(v,'disabled') ) v.disabled = false } )
|
|
1335
|
-
Object.entries(images_state).map(
|
|
1336
|
-
([k,v],i) => {
|
|
1337
|
-
v.img.disabled = false
|
|
1338
|
-
if ( v.spectrum ) v.spectrum.disabled = false
|
|
1339
|
-
v.src.enable_masking( )
|
|
1340
|
-
v.src.enable_pixel_update( )
|
|
1341
|
-
Object.entries(v.navi).map(
|
|
1342
|
-
([k1,v1],i) => { if ( hasprop(v1,'disabled') ) v1.disabled = false } )
|
|
1343
|
-
} )
|
|
1344
|
-
|
|
1345
|
-
clean_ctrl.stop.disabled = false
|
|
1346
|
-
if ( ! only_stop ) {
|
|
1347
|
-
clean_ctrl.continue.disabled = false
|
|
1348
|
-
clean_ctrl.finish.disabled = false
|
|
1349
|
-
}
|
|
1350
|
-
}''',
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
'clean-status-update': '''function update_status( status ) {
|
|
1354
|
-
const stopstr = [ 'Zero stop code',
|
|
1355
|
-
'Iteration limit hit',
|
|
1356
|
-
'Force stop',
|
|
1357
|
-
'No change in peak residual across two major cycles',
|
|
1358
|
-
'Peak residual increased by 3x from last major cycle',
|
|
1359
|
-
'Peak residual increased by 3x from the minimum',
|
|
1360
|
-
'Zero mask found',
|
|
1361
|
-
'No mask found',
|
|
1362
|
-
'N-sigma or other valid exit criterion',
|
|
1363
|
-
'Stopping criteria encountered',
|
|
1364
|
-
'Unrecognized stop code' ]
|
|
1365
|
-
if ( typeof status === 'number' ) {
|
|
1366
|
-
images_state[document._casa_image_name]['status'].text =
|
|
1367
|
-
'<p>' +
|
|
1368
|
-
stopstr[ status < 0 || status >= stopstr.length ?
|
|
1369
|
-
stopstr.length - 1 : status ] +
|
|
1370
|
-
'</p>'
|
|
1371
|
-
} else {
|
|
1372
|
-
images_state[document._casa_image_name]['status'].text = `<p>${status}</p>`
|
|
1373
|
-
}
|
|
1374
|
-
}''',
|
|
1375
|
-
|
|
1376
|
-
'iter-gui-update': '''function get_update_dictionary( ) {
|
|
1377
|
-
//const amste = images_state[document._casa_image_name]['automask']
|
|
1378
|
-
//const clste = images_state[document._casa_image_name]['iteration']
|
|
1379
|
-
// Assumption is that there is ONE set of iteration and automask updates
|
|
1380
|
-
// for ALL imaging fields...
|
|
1381
|
-
const amobj = Object.entries(images_state)[0][1].automask
|
|
1382
|
-
const automask = amobj.active ?
|
|
1383
|
-
Object.entries(amobj).reduce(
|
|
1384
|
-
(acc,[k1,v1]) => { if ( hasprop(v1,'value') ) acc[k1] = v1.value; return acc },
|
|
1385
|
-
{ dogrowprune: amobj.dogrowprune.active,
|
|
1386
|
-
fastnoise: amobj.fastnoise.active,
|
|
1387
|
-
active: true }
|
|
1388
|
-
) : { }
|
|
1389
|
-
const itobj = Object.entries(images_state)[0][1].iteration
|
|
1390
|
-
const iteration = Object.entries(itobj).reduce(
|
|
1391
|
-
(acc,[k1,v1]) => { if ( hasprop(v1,'value') ) acc[k1] = v1.value; return acc },
|
|
1392
|
-
{ }
|
|
1393
|
-
)
|
|
1394
|
-
|
|
1395
|
-
const masks = Object.entries(images_state).reduce( (acc,[k,v]) => { acc[k] = v.src.masks( ); return acc }, { } )
|
|
1396
|
-
const breadcrumbs = Object.entries(images_state).reduce( (acc,[k,v]) => { acc[k] = v.src.breadcrumbs( ); return acc }, { } )
|
|
1397
|
-
return { iteration, automask, masks, breadcrumbs, current_image: document._casa_image_name }
|
|
1398
|
-
}
|
|
1399
|
-
function update_log( log_lines ) {
|
|
1400
|
-
let b = logbutton
|
|
1401
|
-
b._log = b._log.concat( log_lines )
|
|
1402
|
-
if ( b._window && ! b._window.closed ) {
|
|
1403
|
-
for ( const line of log_lines ) {
|
|
1404
|
-
const p = b._window.document.createElement('p')
|
|
1405
|
-
p.appendChild( b._window.document.createTextNode(line) )
|
|
1406
|
-
b._window.document.body.appendChild(p)
|
|
1407
|
-
}
|
|
1408
|
-
}
|
|
1409
|
-
}
|
|
1410
|
-
function update_gui( msg ) {
|
|
1411
|
-
const itobj = Object.entries(images_state)[0][1].iteration
|
|
1412
|
-
if ( msg.result === 'error' ) {
|
|
1413
|
-
// ************************************************************************************
|
|
1414
|
-
// ******** error occurs and is signaled by _gclean, e.g. exception in gclean ********
|
|
1415
|
-
// ************************************************************************************
|
|
1416
|
-
state.mode = 'interactive'
|
|
1417
|
-
clean_ctrl.stop.button_type = "danger"
|
|
1418
|
-
enable(false)
|
|
1419
|
-
state.stopped = false
|
|
1420
|
-
update_status( msg.stopdesc ? msg.stopdesc : 'An internal error has occurred' )
|
|
1421
|
-
if ( 'cmd' in msg ) {
|
|
1422
|
-
update_log( msg.cmd )
|
|
1423
|
-
}
|
|
1424
|
-
} else if ( msg.result === 'no-action' ) {
|
|
1425
|
-
update_status( msg.stopdesc ? msg.stopdesc : 'nothing done' )
|
|
1426
|
-
enable( false )
|
|
1427
|
-
if ( 'cmd' in msg ) {
|
|
1428
|
-
update_log( msg.cmd )
|
|
1429
|
-
}
|
|
1430
|
-
} else if ( msg.result == 'converged' ) {
|
|
1431
|
-
state.mode = 'interactive'
|
|
1432
|
-
clean_ctrl.stop.button_type = "danger"
|
|
1433
|
-
enable(false)
|
|
1434
|
-
state.stopped = false
|
|
1435
|
-
update_status( msg.stopdesc ? msg.stopdesc : 'stopping criteria reached' )
|
|
1436
|
-
if ( 'cmd' in msg ) {
|
|
1437
|
-
update_log( msg.cmd )
|
|
1438
|
-
}
|
|
1439
|
-
refresh( msg )
|
|
1440
|
-
} else if ( msg.result === 'update' ) {
|
|
1441
|
-
if ( 'cmd' in msg ) {
|
|
1442
|
-
update_log( msg.cmd )
|
|
1443
|
-
}
|
|
1444
|
-
refresh( msg )
|
|
1445
|
-
// stopcode[0] == 1: iteration limit hit
|
|
1446
|
-
// stopcode[0] == 9: major cycle limit hit
|
|
1447
|
-
// *******************************************************************************************
|
|
1448
|
-
// ******** perhaps the user should not be locked into exiting after the limit is hit ********
|
|
1449
|
-
// *******************************************************************************************
|
|
1450
|
-
//state.stopped = state.stopped || (msg.stopcode[0] > 1 && msg.stopcode[0] < 9) || msg.stopcode[0] == 0
|
|
1451
|
-
state.stopped = false
|
|
1452
|
-
if ( state.mode === 'interactive' && ! state.awaiting_stop ) {
|
|
1453
|
-
clean_ctrl.stop.button_type = "danger"
|
|
1454
|
-
update_status( msg.stopdesc ? msg.stopdesc : 'stopcode' in msg ? msg.stopcode[0] : -1 )
|
|
1455
|
-
if ( ! state.stopped ) {
|
|
1456
|
-
enable( false )
|
|
1457
|
-
} else {
|
|
1458
|
-
disable( false )
|
|
1459
|
-
}
|
|
1460
|
-
} else if ( state.mode === 'continuous' && ! state.awaiting_stop ) {
|
|
1461
|
-
if ( ! state.stopped && itobj.niter.value > 0 && (itobj.nmajor.value > 0 || itobj.nmajor.value == -1) ) {
|
|
1462
|
-
// *******************************************************************************************
|
|
1463
|
-
// ******** 'niter.value > 0 so continue with one more iteration ********
|
|
1464
|
-
// ******** 'nmajor.value' == -1 implies do not consider nmajor in stop consideration ********
|
|
1465
|
-
// *******************************************************************************************
|
|
1466
|
-
ctrl_pipe.send( ids[cb_obj.origin.name],
|
|
1467
|
-
{ action: 'finish',
|
|
1468
|
-
value: get_update_dictionary( ) },
|
|
1469
|
-
update_gui )
|
|
1470
|
-
} else if ( ! state.stopped ) {
|
|
1471
|
-
// *******************************************************************************************
|
|
1472
|
-
// ******** 'niter.value <= 0 so iteration should stop ********
|
|
1473
|
-
// *******************************************************************************************
|
|
1474
|
-
state.mode = 'interactive'
|
|
1475
|
-
clean_ctrl.stop.button_type = "danger"
|
|
1476
|
-
enable(false)
|
|
1477
|
-
state.stopped = false
|
|
1478
|
-
update_status( msg.stopdesc ? msg.stopdesc : 'stopping criteria reached' )
|
|
1479
|
-
} else {
|
|
1480
|
-
state.mode = 'interactive'
|
|
1481
|
-
clean_ctrl.stop.button_type = "danger"
|
|
1482
|
-
enable(false)
|
|
1483
|
-
state.stopped = false
|
|
1484
|
-
update_status( msg.stopdesc ? msg.stopdesc : 'stopcode' in msg ? msg.stopcode[0] : -1 )
|
|
1485
|
-
}
|
|
1486
|
-
}
|
|
1487
|
-
} else if ( msg.result === 'error' ) {
|
|
1488
|
-
img_src.drop_breadcrumb('E')
|
|
1489
|
-
if ( 'cmd' in msg ) {
|
|
1490
|
-
update_log( msg.cmd )
|
|
1491
|
-
}
|
|
1492
|
-
state.mode = 'interactive'
|
|
1493
|
-
clean_ctrl.stop.button_type = "danger"
|
|
1494
|
-
state.stopped = false
|
|
1495
|
-
update_status( 'stopcode' in msg ? msg.stopcode[0] : -1 )
|
|
1496
|
-
enable( false )
|
|
1497
|
-
}
|
|
1498
|
-
}''',
|
|
1499
|
-
|
|
1500
|
-
'clean-wait': '''function wait_for_tclean_stop( msg ) {
|
|
1501
|
-
state.mode = 'interactive'
|
|
1502
|
-
clean_ctrl.stop.button_type = "danger"
|
|
1503
|
-
enable( false )
|
|
1504
|
-
state.awaiting_stop = false
|
|
1505
|
-
update_status( 'user requested stop' )
|
|
1506
|
-
}''',
|
|
1507
|
-
}
|
|
87
|
+
context = exe.Context( exe.Mode.SYNC )
|
|
88
|
+
exec_task = self._ui( exe.Setting.CLI, context, "interactive-clean" )
|
|
89
|
+
return context.execute( exec_task, "interactive-clean" )
|