cubevis 0.5.2__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.
Files changed (132) hide show
  1. cubevis/LICENSE.rst +500 -0
  2. cubevis/__icons__/20px/fast-backward.svg +13 -0
  3. cubevis/__icons__/20px/fast-forward.svg +13 -0
  4. cubevis/__icons__/20px/step-backward.svg +12 -0
  5. cubevis/__icons__/20px/step-forward.svg +12 -0
  6. cubevis/__icons__/add-chan.png +0 -0
  7. cubevis/__icons__/add-chan.svg +84 -0
  8. cubevis/__icons__/add-cube.png +0 -0
  9. cubevis/__icons__/add-cube.svg +186 -0
  10. cubevis/__icons__/drag.png +0 -0
  11. cubevis/__icons__/drag.svg +109 -0
  12. cubevis/__icons__/mask-selected.png +0 -0
  13. cubevis/__icons__/mask.png +0 -0
  14. cubevis/__icons__/mask.svg +1 -0
  15. cubevis/__icons__/new-layer-sm-selected.png +0 -0
  16. cubevis/__icons__/new-layer-sm-selected.svg +88 -0
  17. cubevis/__icons__/new-layer-sm.png +0 -0
  18. cubevis/__icons__/new-layer-sm.svg +15 -0
  19. cubevis/__icons__/reset.png +0 -0
  20. cubevis/__icons__/reset.svg +11 -0
  21. cubevis/__icons__/sub-chan.png +0 -0
  22. cubevis/__icons__/sub-chan.svg +71 -0
  23. cubevis/__icons__/sub-cube.png +0 -0
  24. cubevis/__icons__/sub-cube.svg +95 -0
  25. cubevis/__icons__/zoom-to-fit.png +0 -0
  26. cubevis/__icons__/zoom-to-fit.svg +21 -0
  27. cubevis/__init__.py +58 -0
  28. cubevis/__js__/bokeh-3.6.1.min.js +728 -0
  29. cubevis/__js__/bokeh-tables-3.6.1.min.js +119 -0
  30. cubevis/__js__/bokeh-widgets-3.6.1.min.js +141 -0
  31. cubevis/__js__/casalib.min.js +1 -0
  32. cubevis/__js__/cubevisjs.min.js +62 -0
  33. cubevis/__version__.py +1 -0
  34. cubevis/apps/__init__.py +44 -0
  35. cubevis/apps/_createmask.py +461 -0
  36. cubevis/apps/_createregion.py +513 -0
  37. cubevis/apps/_interactiveclean.py +3260 -0
  38. cubevis/apps/_interactiveclean_wrappers.py +130 -0
  39. cubevis/apps/_ms_raster.py +815 -0
  40. cubevis/apps/_plotants.py +286 -0
  41. cubevis/apps/_plotbandpass.py +7 -0
  42. cubevis/bokeh/__init__.py +29 -0
  43. cubevis/bokeh/annotations/__init__.py +1 -0
  44. cubevis/bokeh/annotations/_ev_poly_annotation.py +6 -0
  45. cubevis/bokeh/components/__init__.py +28 -0
  46. cubevis/bokeh/format/__init__.py +31 -0
  47. cubevis/bokeh/format/_time_ticks.py +44 -0
  48. cubevis/bokeh/format/_wcs_ticks.py +45 -0
  49. cubevis/bokeh/models/__init__.py +4 -0
  50. cubevis/bokeh/models/_edit_span.py +7 -0
  51. cubevis/bokeh/models/_ev_text_input.py +6 -0
  52. cubevis/bokeh/models/_tip.py +37 -0
  53. cubevis/bokeh/models/_tip_button.py +50 -0
  54. cubevis/bokeh/sources/__init__.py +35 -0
  55. cubevis/bokeh/sources/_data_pipe.py +258 -0
  56. cubevis/bokeh/sources/_image_data_source.py +83 -0
  57. cubevis/bokeh/sources/_image_pipe.py +581 -0
  58. cubevis/bokeh/sources/_spectra_data_source.py +55 -0
  59. cubevis/bokeh/sources/_updatable_data_source.py +189 -0
  60. cubevis/bokeh/state/__init__.py +34 -0
  61. cubevis/bokeh/state/_initialize.py +164 -0
  62. cubevis/bokeh/state/_javascript.py +53 -0
  63. cubevis/bokeh/state/_palette.py +58 -0
  64. cubevis/bokeh/state/_session.py +44 -0
  65. cubevis/bokeh/state/js/bokeh-2.4.1.min.js +596 -0
  66. cubevis/bokeh/state/js/bokeh-gl-2.4.1.min.js +74 -0
  67. cubevis/bokeh/state/js/bokeh-tables-2.4.1.min.js +132 -0
  68. cubevis/bokeh/state/js/bokeh-widgets-2.4.1.min.js +118 -0
  69. cubevis/bokeh/state/js/casaguijs-v0.0.4.0-b2.4.min.js +49 -0
  70. cubevis/bokeh/state/js/casaguijs-v0.0.5.0-b2.4.min.js +49 -0
  71. cubevis/bokeh/state/js/casaguijs-v0.0.6.0-b2.4.min.js +49 -0
  72. cubevis/bokeh/state/js/casalib-v0.0.1.min.js +1 -0
  73. cubevis/bokeh/tools/__init__.py +31 -0
  74. cubevis/bokeh/tools/_cbreset_tool.py +52 -0
  75. cubevis/bokeh/tools/_drag_tool.py +61 -0
  76. cubevis/bokeh/utils/__init__.py +35 -0
  77. cubevis/bokeh/utils/_axes_labels.py +94 -0
  78. cubevis/bokeh/utils/_svg_icon.py +136 -0
  79. cubevis/data/__init__.py +1 -0
  80. cubevis/data/casaimage/__init__.py +114 -0
  81. cubevis/data/measurement_set/__init__.py +7 -0
  82. cubevis/data/measurement_set/_ms_data.py +178 -0
  83. cubevis/data/measurement_set/processing_set/__init__.py +30 -0
  84. cubevis/data/measurement_set/processing_set/_ps_concat.py +98 -0
  85. cubevis/data/measurement_set/processing_set/_ps_coords.py +78 -0
  86. cubevis/data/measurement_set/processing_set/_ps_data.py +213 -0
  87. cubevis/data/measurement_set/processing_set/_ps_io.py +55 -0
  88. cubevis/data/measurement_set/processing_set/_ps_raster_data.py +154 -0
  89. cubevis/data/measurement_set/processing_set/_ps_select.py +91 -0
  90. cubevis/data/measurement_set/processing_set/_ps_stats.py +218 -0
  91. cubevis/data/measurement_set/processing_set/_xds_data.py +149 -0
  92. cubevis/plot/__init__.py +1 -0
  93. cubevis/plot/ms_plot/__init__.py +29 -0
  94. cubevis/plot/ms_plot/_ms_plot.py +242 -0
  95. cubevis/plot/ms_plot/_ms_plot_constants.py +22 -0
  96. cubevis/plot/ms_plot/_ms_plot_selectors.py +348 -0
  97. cubevis/plot/ms_plot/_raster_plot.py +292 -0
  98. cubevis/plot/ms_plot/_raster_plot_inputs.py +116 -0
  99. cubevis/plot/ms_plot/_xds_plot_axes.py +110 -0
  100. cubevis/private/__java__/xml-casa-assembly-1.86.jar +0 -0
  101. cubevis/private/_gclean.py +798 -0
  102. cubevis/private/casashell/createmask.py +332 -0
  103. cubevis/private/casashell/iclean.py +4432 -0
  104. cubevis/private/casatasks/__init__.py +140 -0
  105. cubevis/private/casatasks/createmask.py +86 -0
  106. cubevis/private/casatasks/createregion.py +83 -0
  107. cubevis/private/casatasks/iclean.py +1831 -0
  108. cubevis/readme.rst +16 -0
  109. cubevis/remote/__init__.py +10 -0
  110. cubevis/remote/_gclean.py +61 -0
  111. cubevis/remote/_local.py +287 -0
  112. cubevis/remote/_remote_kernel.py +80 -0
  113. cubevis/toolbox/__init__.py +32 -0
  114. cubevis/toolbox/_app_context.py +74 -0
  115. cubevis/toolbox/_cube.py +3457 -0
  116. cubevis/toolbox/_region_list.py +197 -0
  117. cubevis/utils/_ResourceManager.py +86 -0
  118. cubevis/utils/__init__.py +620 -0
  119. cubevis/utils/_contextmgrchain.py +84 -0
  120. cubevis/utils/_conversion.py +93 -0
  121. cubevis/utils/_copydoc.py +55 -0
  122. cubevis/utils/_docenum.py +25 -0
  123. cubevis/utils/_import_protected_module.py +35 -0
  124. cubevis/utils/_logging.py +85 -0
  125. cubevis/utils/_pkgs.py +77 -0
  126. cubevis/utils/_regions.py +40 -0
  127. cubevis/utils/_static.py +66 -0
  128. cubevis/utils/_tiles.py +167 -0
  129. cubevis-0.5.2.dist-info/METADATA +151 -0
  130. cubevis-0.5.2.dist-info/RECORD +132 -0
  131. cubevis-0.5.2.dist-info/WHEEL +4 -0
  132. cubevis-0.5.2.dist-info/licenses/LICENSE +504 -0
@@ -0,0 +1,3260 @@
1
+ ########################################################################
2
+ #
3
+ # Copyright (C) 2022,2023,2024
4
+ # Associated Universities, Inc. Washington DC, USA.
5
+ #
6
+ # This script is free software; you can redistribute it and/or modify it
7
+ # under the terms of the GNU Library General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or (at your
9
+ # option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful, but WITHOUT
12
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14
+ # License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Library General Public License
17
+ # along with this library; if not, write to the Free Software Foundation,
18
+ # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
19
+ #
20
+ # Correspondence concerning AIPS++ should be adressed as follows:
21
+ # Internet email: casa-feedback@nrao.edu.
22
+ # Postal address: AIPS++ Project Office
23
+ # National Radio Astronomy Observatory
24
+ # 520 Edgemont Road
25
+ # Charlottesville, VA 22903-2475 USA
26
+ #
27
+ ########################################################################
28
+ '''implementation of the ``InteractiveClean`` application for interactive control
29
+ of tclean'''
30
+
31
+ ###
32
+ ### Useful for debugging
33
+ ###
34
+ ###from cubevis.bokeh.state import initialize_bokeh
35
+ ###initialize_bokeh( bokehjs_subst=".../bokeh-3.2.2.js" )
36
+ ###
37
+ import os
38
+ import copy
39
+ import asyncio
40
+ import shutil
41
+ import websockets
42
+ from os.path import basename, abspath, exists
43
+ from uuid import uuid4
44
+ from html import escape as html_escape
45
+ from contextlib import asynccontextmanager
46
+ from bokeh.models import Button, TextInput, Checkbox, Div, LinearAxis, CustomJS, Spacer, Span, HoverTool, DataRange1d, Step, InlineStyleSheet
47
+ from bokeh.events import ModelEvent, MouseEnter
48
+ from bokeh.models import TabPanel, Tabs
49
+ from bokeh.plotting import ColumnDataSource, figure, show
50
+ from bokeh.layouts import column, row, layout
51
+ from bokeh.io import reset_output as reset_bokeh_output, output_notebook
52
+ from bokeh.models.dom import HTML
53
+
54
+ from bokeh.models.ui.tooltips import Tooltip
55
+ from ..bokeh.models import TipButton, Tip, EvTextInput
56
+ from ..utils import resource_manager, reset_resource_manager, is_notebook, find_pkg, load_pkg
57
+ from ..utils import ContextMgrChain as CMC
58
+
59
+ # pylint: disable=no-name-in-module
60
+ from casatasks.private.imagerhelpers.imager_return_dict import ImagingDict
61
+
62
+ from casatasks.private.imagerhelpers.input_parameters import ImagerParameters
63
+ # pylint: enable=no-name-in-module
64
+
65
+ from cubevis.utils import find_ws_address, convert_masks
66
+ from cubevis.toolbox import CubeMask, AppContext
67
+ from cubevis.bokeh.utils import svg_icon
68
+ from cubevis.bokeh.sources import DataPipe
69
+ from ..utils import DocEnum
70
+
71
+ from ._interactiveclean_wrappers import SharedWidgets
72
+
73
+ USE_MULTIPLE_GCLEAN_HACK=False
74
+
75
+ class InteractiveClean:
76
+ '''InteractiveClean(...) implements interactive clean using Bokeh
77
+ tclean ---- Radio Interferometric Image Reconstruction
78
+
79
+ Form images from visibilities and reconstruct a sky model.
80
+ This task handles continuum images and spectral line cubes,
81
+ supports outlier fields, contains standard clean based algorithms
82
+ along with algorithms for multi-scale and wideband image
83
+ reconstruction, widefield imaging correcting for the w-term,
84
+ full primary-beam imaging and joint mosaic imaging (with
85
+ heterogeneous array support for ALMA).
86
+
87
+ --------- parameter descriptions ---------------------------------------------
88
+
89
+ vis Name(s) of input visibility file(s)
90
+ default: none;
91
+ example: vis='ngc5921.ms'
92
+ vis=['ngc5921a.ms','ngc5921b.ms']; multiple MSs
93
+ selectdata Enable data selection parameters.
94
+ field to image or mosaic. Use field id(s) or name(s).
95
+ ['go listobs' to obtain the list id's or names]
96
+ default: ''= all fields.
97
+ If field string is a non-negative integer, it is assumed to
98
+ be a field index, otherwise it is assumed to be a
99
+ field name.
100
+ field='0~2'; field ids 0,1,2.
101
+ field='0,4,5~7'; field ids 0,4,5,6,7.
102
+ field='3C286,3C295'; field names 3C286 and 3C295.
103
+ field = '3,4C\*'; field id 3, all names starting with 4C.
104
+ For multiple MS input, a list of field strings can be used:
105
+ field = ['0~2','0~4']; field ids 0-2 for the first MS and 0-4
106
+ for the second.
107
+ field = '0~2'; field ids 0-2 for all input MSs.
108
+ spw l window/channels.
109
+ NOTE: channels not selected here will contain all zeros if
110
+ selected by other subparameters.
111
+ default: ''=all spectral windows and channels.
112
+ spw='0~2,4'; spectral windows 0,1,2,4 (all channels).
113
+ spw='0:5~61'; spw 0, channels 5 to 61.
114
+ spw='<2'; spectral windows less than 2 (i.e. 0,1).
115
+ spw='0,10,3:3~45'; spw 0,10 all channels, and spw 3
116
+ channels 3 to 45.
117
+ spw='0~2:2~6'; spw 0,1,2 with channels 2 through 6 in each.
118
+ For multiple MS input, a list of spw strings can be used:
119
+ spw=['0','0~3']; spw ids 0 for the first MS and 0-3 for the second.
120
+ spw='0~3' spw ids 0-3 for all input MS.
121
+ spw='3:10~20;50~60' for multiple channel ranges within spw id 3.
122
+ spw='3:10~20;50~60,4:0~30' for different channel ranges for spw ids 3 and 4.
123
+ spw='0:0~10,1:20~30,2:1;2;3'; spw 0, channels 0-10,
124
+ spw 1, channels 20-30, and spw 2, channels, 1,2 and 3.
125
+ spw='1~4;6:15~48' for channels 15 through 48 for spw ids 1,2,3,4 and 6.
126
+ timerange Range of time to select from data
127
+
128
+ default: '' (all); examples,
129
+ timerange = 'YYYY/MM/DD/hh:mm:ss~YYYY/MM/DD/hh:mm:ss'
130
+ Note: if YYYY/MM/DD is missing date defaults to first
131
+ day in data set.
132
+ timerange='09:14:0~09:54:0' picks 40 min on first day.
133
+ timerange='25:00:00~27:30:00' picks 1 hr to 3 hr
134
+ 30min on NEXT day.
135
+ timerange='09:44:00' pick data within one integration
136
+ of time.
137
+ timerange='> 10:24:00' data after this time.
138
+ For multiple MS input, a list of timerange strings can be
139
+ used:
140
+ timerange=['09:14:0~09:54:0','> 10:24:00'].
141
+ timerange='09:14:0~09:54:0''; apply the same timerange for
142
+ all input MSs.
143
+ uvrange Select data within uvrange (default unit is meters)
144
+ default: '' (all); example:
145
+ uvrange='0~1000klambda'; uvrange from 0-1000 kilo-lambda.
146
+ uvrange='> 4klambda';uvranges greater than 4 kilo lambda.
147
+ For multiple MS input, a list of uvrange strings can be
148
+ used:
149
+ uvrange=['0~1000klambda','100~1000klamda'].
150
+ uvrange='0~1000klambda'; apply 0-1000 kilo-lambda for all
151
+ input MSs.
152
+ uvrange='0~1000'; apply 0-1000 meter for all input MSs.
153
+ antenna Select data based on antenna/baseline
154
+
155
+ default: '' (all)
156
+ If antenna string is a non-negative integer, it is
157
+ assumed to be an antenna index, otherwise, it is
158
+ considered an antenna name.
159
+ antenna='5\&6'; baseline between antenna index 5 and
160
+ index 6.
161
+ antenna='VA05\&VA06'; baseline between VLA antenna 5
162
+ and 6.
163
+ antenna='5\&6;7\&8'; baselines 5-6 and 7-8.
164
+ antenna='5'; all baselines with antenna index 5.
165
+ antenna='05'; all baselines with antenna number 05
166
+ (VLA old name).
167
+ antenna='5,6,9'; all baselines with antennas 5,6,9
168
+ index number.
169
+ For multiple MS input, a list of antenna strings can be
170
+ used:
171
+ antenna=['5','5\&6'];
172
+ antenna='5'; antenna index 5 for all input MSs.
173
+ antenna='!DV14'; use all antennas except DV14.
174
+ scan Scan number range
175
+
176
+ default: '' (all).
177
+ example: scan='1~5'.
178
+ For multiple MS input, a list of scan strings can be used:
179
+ scan=['0~100','10~200'].
180
+ scan='0~100; scan ids 0-100 for all input MSs.
181
+ observation Observation ID range
182
+ default: '' (all).
183
+ example: observation='1~5'.
184
+ intent Scan Intent(s)
185
+
186
+ default: '' (all).
187
+ example: intent='TARGET_SOURCE'.
188
+ example: intent='TARGET_SOURCE1,TARGET_SOURCE2'.
189
+ example: intent='TARGET_POINTING\*'.
190
+ datacolumn Data column to image (data or observed, corrected)
191
+ default:'corrected'
192
+ ( If 'corrected' does not exist, it will use 'data' instead )
193
+ imagename Pre-name of output images
194
+
195
+ example : imagename='try'
196
+
197
+ Output images will be (a subset of) :
198
+
199
+ try.psf - Point Spread Function (PSF).
200
+ try.residual - Residual image.
201
+ try.image - Restored image.
202
+ try.model - Model image (contains only flux components).
203
+ try.sumwt - Single pixel image containing sum-of-weights.
204
+ (for natural weighting, sensitivity=1/sqrt(sumwt)).
205
+ try.pb - Primary Beam (PB) model (values depend on the gridder used).
206
+
207
+ A-projection algorithms (gridder=mosaic,awproject, awp2) will
208
+ compute the following images too.
209
+
210
+ try.weight - FT of gridded weights or the
211
+ un-normalized sum of PB-square (for all pointings).
212
+ Here, PB = sqrt(weight) normalized to a maximum of 1.0.
213
+
214
+ For multi-term wideband imaging, all relevant images above will
215
+ have additional .tt0,.tt1, etc suffixes to indicate Taylor terms,
216
+ plus the following extra output images.
217
+ try.alpha - spectral index.
218
+ try.alpha.error - estimate of error on spectral index.
219
+ try.beta - spectral curvature (if nterms \> 2).
220
+
221
+ Tip : Include a directory name in 'imagename' for all
222
+ output images to be sent there instead of the
223
+ current working directory : imagename='mydir/try'.
224
+
225
+ Tip : Restarting an imaging run without changing 'imagename'
226
+ implies continuation from the existing model image on disk.
227
+ - If 'startmodel' was initially specified it needs to be set to ""
228
+ for the restart run (or tclean will exit with an error message).
229
+ - By default, the residual image and psf will be recomputed
230
+ but if no changes were made to relevant parameters between
231
+ the runs, set calcres=False, calcpsf=False to resume directly from
232
+ the minor cycle without the (unnecessary) first major cycle.
233
+ To automatically change 'imagename' with a numerical
234
+ increment, set restart=False (see tclean docs for 'restart').
235
+
236
+ Note : All imaging runs will by default produce restored images.
237
+ For a niter=0 run, this will be redundant and can optionally
238
+ be turned off via the 'restoration=T/F' parameter.
239
+ imsize Number of pixels
240
+ example:
241
+
242
+ imsize = [350,250].
243
+ imsize = 500 is equivalent to [500,500].
244
+
245
+ To take proper advantage of internal optimized FFT routines, the
246
+ number of pixels must be even and factorizable by 2,3,5 only.
247
+ To find the nearest optimal imsize to that desired by the user, please use the following tool method:
248
+
249
+ from casatools import synthesisutils
250
+ su = synthesisutils()
251
+ su.getOptimumSize(345)
252
+ Output : 360
253
+ cell Cell size
254
+ example: cell=['0.5arcsec,'0.5arcsec'] or
255
+ cell=['1arcmin', '1arcmin'].
256
+ cell = '1arcsec' is equivalent to ['1arcsec','1arcsec'].
257
+ phasecenter Phase center of the image (string or field id); if the phasecenter is the name known major solar system object ('MERCURY', 'VENUS', 'MARS', 'JUPITER', 'SATURN', 'URANUS', 'NEPTUNE', 'PLUTO', 'SUN', 'MOON') or is an ephemerides table then that source is tracked and the background sources get smeared. There is a special case, when phasecenter='TRACKFIELD', which will use the ephemerides or polynomial phasecenter in the FIELD table of the MS's as the source center to track.
258
+
259
+ Note : If unspecified, tclean will use the phase-center from the first data field of the MS (or list of MSs) selected for imaging.
260
+
261
+ example: phasecenter='6'.
262
+ phasecenter='J2000 19h30m00 -40d00m00'.
263
+ phasecenter='J2000 292.5deg -40.0deg'.
264
+ phasecenter='J2000 5.105rad -0.698rad'.
265
+ phasecenter='ICRS 13:05:27.2780 -049.28.04.458'.
266
+ phasecenter='myComet_ephem.tab'.
267
+ phasecenter='MOON'.
268
+ phasecenter='TRACKFIELD'.
269
+ stokes Stokes Planes to make
270
+ default='I'; example: stokes='IQUV';
271
+ Options: 'I','Q','U','V','IV','QU','IQ','UV','IQUV','RR','LL','XX','YY','RRLL','XXYY','pseudoI'
272
+
273
+ Note : Due to current internal code constraints, if any correlation pair
274
+ is flagged, by default, no data for that row in the MS will be used.
275
+ So, in an MS with XX,YY, if only YY is flagged, neither a
276
+ Stokes I image nor an XX image can be made from those data points.
277
+ In such a situation, please split out only the unflagged correlation into
278
+ a separate MS, or use the option 'pseudoI'.
279
+
280
+ Note : The 'pseudoI' option is a partial solution, allowing Stokes I imaging
281
+ when either of the parallel-hand correlations are unflagged.
282
+
283
+ The remaining constraints shall be removed (where logical) in a future release.
284
+ projection Coordinate projection
285
+ Examples : SIN, NCP.
286
+ A list of supported (but untested) projections can be found here :
287
+ http://casa.nrao.edu/active/docs/doxygen/html/classcasa_1_1Projection.html#a3d5f9ec787e4eabdce57ab5edaf7c0cd
288
+ startmodel Name of starting model image
289
+
290
+ The contents of the supplied starting model image will be
291
+ copied to the imagename.model before the run begins.
292
+
293
+ example : startmodel = 'singledish.im'.
294
+
295
+ For deconvolver='mtmfs', one image per Taylor term must be provided.
296
+ example : startmodel = ['try.model.tt0', 'try.model.tt1'].
297
+ startmodel = ['try.model.tt0'] will use a starting model only
298
+ for the zeroth order term.
299
+ startmodel = ['','try.model.tt1'] will use a starting model only
300
+ for the first order term.
301
+
302
+ This starting model can be of a different image shape and size from
303
+ what is currently being imaged. If so, an image regrid is first triggered
304
+ to resample the input image onto the target coordinate system.
305
+
306
+ A common usage is to set this parameter equal to a single dish image.
307
+
308
+ Negative components in the model image will be included as is.
309
+
310
+ Note : If an error occurs during image resampling/regridding,
311
+ please try using task imregrid to resample the starting model
312
+ image onto a CASA image with the target shape and
313
+ coordinate system before supplying it via startmodel.
314
+ specmode Spectral definition mode (mfs,cube,cubedata, cubesource, mvc)
315
+
316
+ specmode='mfs' : Continuum imaging with only one output image channel.
317
+ (mode='cont' can also be used here)
318
+
319
+ specmode='cube' : Spectral line imaging with one or more channels.
320
+ Parameters start, width,and nchan define the spectral
321
+ coordinate system and can be specified either in terms
322
+ of channel numbers, frequency or velocity in whatever
323
+ spectral frame is specified in 'outframe'.
324
+ All internal and output images are made with outframe as the
325
+ base spectral frame. However imaging code internally uses the fixed
326
+ spectral frame, LSRK for automatic internal software
327
+ Doppler correction, so that a spectral line observed over an
328
+ extended time range will line up appropriately.
329
+ Therefore the output images have additional spectral frame conversion
330
+ layer in LSRK on the top the base frame.
331
+
332
+
333
+
334
+
335
+ specmode='cubedata' : Spectral line imaging with one or more channels.
336
+ There is no internal software Doppler correction, so
337
+ a spectral line observed over an extended time range
338
+ may be smeared out in frequency. There is strictly
339
+ no valid spectral frame with which to associate with the
340
+ output images, thus the image spectral frame will
341
+ be labelled "Undefined".
342
+
343
+
344
+ specmode='cubesource': Spectral line imaging while
345
+ tracking moving source (near field or solar system
346
+ objects). The velocity of the source is accounted
347
+ and the frequency reported is in the source frame.
348
+ As there is no "SOURCE" frame defined in CASA,
349
+ the frame in the image will be labelled "REST" (but do note the
350
+ velocity of a given line reported may be different from the rest frame
351
+ velocity if the emission region is moving w.r.t the systemic
352
+ velocity frame of the source).
353
+
354
+ specmode='mvc' : Multiterm continuum imaging with cube major cycles.
355
+ This mode requires deconvolver='mtmfs' with nterms>1
356
+ and user-set choices of 'reffreq' and 'nchan'.
357
+
358
+ The output images and minor cycle are similar to specmode='mfs'
359
+ with deconvolver='mtmfs', but the major cycles are done in
360
+ cube mode (and require a setting of 'reffreq' and 'nchan').
361
+ By default, frequency-dependent primary beam correction is
362
+ applied to each channel, before being combined across frequency
363
+ to make the inputs to the 'mtmfs' deconvolver. This results in
364
+ implicit wideband pb-correction, with the deconvolver seeing only
365
+ the sky spectral structure.
366
+
367
+ Note : There is currently no option to turn off wideband pb correction
368
+ as part of the flat-sky normalization between the major and minor cycles.
369
+ Therefore, 'mvc' with the 'standard' and 'wproject' gridders will also apply
370
+ pblimits per channel, masking all regions outside of pblimit.
371
+ An option to retain sources outside the pblimit will be added in a future release.
372
+
373
+ Note : Below is some guidance for choosing 'nchan' and 'reffreq' :
374
+
375
+ The cube produced by the major cycle is used in a linear least square fits for Taylor
376
+ polynomials per pixel. Therefore, one only needs as many channels in the cube, as
377
+ required for an accurate polynomial fit for sources that have the strongest
378
+ spectral structure.
379
+
380
+ In general, 'nchan' needs to be greater than or equal to 'nterms', and the
381
+ frequency range selected by the data will be evenly split into nchan channels.
382
+ For a low-order polynomial fit, only a small number (around 10)
383
+ channels are typically needed (for VLA/ALMA bandwidth ratios).
384
+ 'nchan=-1' applies a heuristic that results in a default of 10 cube channels
385
+ for a 2:1 bandwidth ratio.
386
+
387
+ nchan = MAX( bandwidth/(0.1*startfreq) , nterms+1 )
388
+
389
+ Note: When running in parallel, the nchan selected may limit the speedup if it
390
+ is smaller than the number of processes used.
391
+
392
+ The 'reffreq' is the reference frequency used for the Taylor polynomial expansion.
393
+ By default, in specmode='mvc', reffreq is set to the middle of the selected
394
+ frequency range.
395
+ reffreq Reference frequency of the output image coordinate system.
396
+
397
+ Example : reffreq='1.5GHz' as a string with units.
398
+
399
+ By default, it is calculated as the middle of the selected frequency range.
400
+
401
+ For deconvolver='mtmfs' the Taylor expansion is also done about
402
+ this specified reference frequency.
403
+ nchan Number of channels in the output image.
404
+ For default (=-1), the number of channels will be automatically determined
405
+ based on data selected by 'spw' with 'start' and 'width'.
406
+ It is often easiest to leave nchan at the default value.
407
+ example: nchan=100
408
+ start First channel (e.g. start=3,start=\'1.1GHz\',start=\'15343km/s\')
409
+ of output cube images specified by data channel number (integer),
410
+ velocity (string with a unit), or frequency (string with a unit).
411
+ Default:''; The first channel is automatically determined based on
412
+ the 'spw' channel selection and 'width'.
413
+ channels in 'spw'.
414
+ Since the integer number in 'start' represents the data channel number,
415
+ when the channel number is used along with the spectral window id selection
416
+ in 'spw', 'start' specified as an integer should be carefully set otherwise
417
+ it may result in the blank image channels if the 'start' channel (i.e. absolute
418
+ channel number) is outside of the channel range specified in 'spw'.
419
+ In such a case, 'start' can be left as a default (='') to ensure
420
+ matching with the data spectral channel selection.
421
+ For specmode='cube', when velocity or frequency is used it is
422
+ interpreted with the frame defined in outframe. [The parameters of
423
+ the desired output cube can be estimated by using the 'transform'
424
+ functionality of 'plotms'].
425
+ examples: start='5.0km/s'; 1st channel, 5.0km/s in outframe.
426
+ start='22.3GHz'; 1st channel, 22.3GHz in outframe.
427
+ width Channel width (e.g. width=2,width=\'0.1MHz\',width=\'10km/s\') of output cube images
428
+ specified by data channel number (integer), velocity (string with a unit), or
429
+ or frequency (string with a unit).
430
+ Default:''; data channel width.
431
+ The sign of width defines the direction of the channels to be incremented.
432
+ For width specified in velocity or frequency with '-' in front gives image channels in
433
+ decreasing velocity or frequency, respectively.
434
+ For specmode='cube', when velocity or frequency is used it is interpreted with
435
+ the reference frame defined in outframe.
436
+ examples: width='2.0km/s'; results in channels with increasing velocity.
437
+ width='-2.0km/s'; results in channels with decreasing velocity.
438
+ width='40kHz'; results in channels with increasing frequency.
439
+ width=-2; results in channels averaged of 2 data channels incremented from
440
+ high to low channel numbers.
441
+ outframe Spectral reference frame in which to interpret \'start\' and \'width\'
442
+ Options: '','LSRK','LSRD','BARY','GEO','TOPO','GALACTO','LGROUP','CMB'
443
+ example: outframe='bary' for Barycentric frame.
444
+
445
+ REST -- Rest frequency.
446
+ LSRD -- Local Standard of Rest (J2000).
447
+ -- as the dynamical definition (IAU, [9,12,7] km/s in galactic coordinates).
448
+ LSRK -- LSR as a kinematical (radio) definition.
449
+ -- 20.0 km/s in direction ra,dec = [270,+30] deg (B1900.0).
450
+ BARY -- Barycentric (J2000).
451
+ GEO --- Geocentric.
452
+ TOPO -- Topocentric.
453
+ GALACTO -- Galacto centric (with rotation of 220 km/s in direction l,b = [90,0] deg.
454
+ LGROUP -- Local group velocity -- 308km/s towards l,b = [105,-7] deg (F. Ghigo).
455
+ CMB -- CMB velocity -- 369.5km/s towards l,b = [264.4, 48.4] deg (F. Ghigo).
456
+ DEFAULT = LSRK.
457
+ veltype Velocity type (radio, z, ratio, beta, gamma, optical)
458
+ For 'start' and/or 'width' specified in velocity, specifies the velocity definition
459
+ Options: 'radio','optical','z','beta','gamma','optical'
460
+ NOTE: the viewer always defaults to displaying the 'radio' frame,
461
+ but that can be changed in the position tracking pull down.
462
+
463
+ The different types (with F = f/f0, the frequency ratio), are:
464
+
465
+ Z = (-1 + 1/F).
466
+ RATIO = (F) \*.
467
+ RADIO = (1 - F).
468
+ OPTICAL == Z.
469
+ BETA = ((1 - F^2)/(1 + F^2)).
470
+ GAMMA = ((1 + F^2)/2F) \*.
471
+ RELATIVISTIC == BETA (== v/c).
472
+ DEFAULT == RADIO.
473
+ Note that the ones with an '\*' have no real interpretation
474
+ (although the calculation will proceed) if given as a velocity.
475
+ restfreq List of rest frequencies or a rest frequency in a string.
476
+ Specify rest frequency to use for output image.
477
+
478
+ Currently it uses the first rest frequency in the list for translation of
479
+ velocities. The list will be stored in the output images.
480
+ Default: []; look for the rest frequency stored in the MS, if not available,
481
+ use center frequency of the selected channels.
482
+ examples: restfreq=['1.42GHz'].
483
+ restfreq='1.42GHz'.
484
+ interpolation Spectral interpolation (nearest,linear,cubic)
485
+
486
+ Interpolation rules to use when binning data channels onto image channels
487
+ and evaluating visibility values at the centers of image channels.
488
+
489
+ Note : 'linear' and 'cubic' interpolation requires data points on both sides of
490
+ each image frequency. Errors are therefore possible at edge channels, or near
491
+ flagged data channels. When image channel width is much larger than the data
492
+ channel width there is nothing much to be gained using linear or cubic thus
493
+ not worth the extra computation involved.
494
+ perchanweightdensity When calculating weight density for Briggs
495
+ style weighting in a cube, this parameter
496
+ determines whether to calculate the weight
497
+ density for each channel independently
498
+ (the default, True)
499
+ or a common weight density for all of the selected
500
+ data. This parameter has no
501
+ meaning for continuum (specmode='mfs') imaging
502
+ or for natural and radial weighting schemes.
503
+ For cube imaging
504
+ perchanweightdensity=True is a recommended
505
+ option that provides more uniform
506
+ sensitivity per channel for cubes, but with
507
+ generally larger psfs than the
508
+ perchanweightdensity=False (prior behavior)
509
+ option. When using Briggs style weight with
510
+ perchanweightdensity=True, the imaging weight
511
+ density calculations use only the weights of
512
+ data that contribute specifically to that
513
+ channel. On the other hand, when
514
+ perchanweightdensity=False, the imaging
515
+ weight density calculations sum all of the
516
+ weights from all of the data channels
517
+ selected whose (u,v) falls in a given uv cell
518
+ on the weight density grid. Since the
519
+ aggregated weights, in any given uv cell,
520
+ will change depending on the number of
521
+ channels included when imaging, the psf
522
+ calculated for a given frequency channel will
523
+ also necessarily change, resulting in
524
+ variability in the psf for a given frequency
525
+ channel when perchanweightdensity=False. In
526
+ general, perchanweightdensity=False results
527
+ in smaller psfs for the same value of
528
+ robustness compared to
529
+ perchanweightdensity=True, but the rms noise
530
+ as a function of channel varies and increases
531
+ toward the edge channels;
532
+ perchanweightdensity=True provides more
533
+ uniform sensitivity per channel for
534
+ cubes. This may make it harder to find
535
+ estimates of continuum when
536
+ perchanweightdensity=False. If you intend to
537
+ image a large cube in many smaller subcubes
538
+ and subsequently concatenate, it is advisable
539
+ to use perchanweightdensity=True to avoid
540
+ surprisingly varying sensitivity and psfs
541
+ across the concatenated cube.
542
+ gridder Gridding options (standard, wproject, widefield, mosaic, awproject, awp2, awphpg)
543
+
544
+
545
+ The following options choose different gridding convolution
546
+ functions for the process of convolutional resampling of the measured
547
+ visibilities onto a regular uv-grid prior to an inverse FFT.
548
+ Model prediction (degridding) also uses these same functions.
549
+ Several wide-field effects can be accounted for via careful choices of
550
+ convolution functions. Gridding (degridding) runtime will rise in
551
+ proportion to the support size of these convolution functions (in uv-pixels).
552
+
553
+ standard : Prolate Spheroid with 7x7 uv pixel support size.
554
+
555
+ [ This mode can also be invoked using 'ft' or 'gridft' ]
556
+
557
+ wproject : W-Projection algorithm to correct for the widefield
558
+ non-coplanar baseline effect. [Cornwell et.al 2008]
559
+
560
+ wprojplanes is the number of distinct w-values at
561
+ which to compute and use different gridding convolution
562
+ functions (see help for wprojplanes).
563
+ Convolution function support size can range
564
+ from 5x5 to few 100 x few 100.
565
+
566
+ [ This mode can also be invoked using 'wprojectft' ]
567
+
568
+ widefield : Facetted imaging with or without W-Projection per facet.
569
+
570
+ A set of facets x facets subregions of the specified image
571
+ are gridded separately using their respective phase centers
572
+ (to minimize max W). Deconvolution is done on the joint
573
+ full size image, using a PSF from the first subregion.
574
+
575
+ wprojplanes=1 : standard prolate spheroid gridder per facet.
576
+ wprojplanes > 1 : W-Projection gridder per facet.
577
+ nfacets=1, wprojplanes > 1 : Pure W-Projection and no facetting.
578
+ nfacets=1, wprojplanes=1 : Same as standard,ft,gridft.
579
+
580
+ A combination of facetting and W-Projection is relevant only for
581
+ very large fields of view. (In our current version of tclean, this
582
+ combination runs only with parallel=False.
583
+
584
+ mosaic : A-Projection with azimuthally symmetric beams without
585
+ sidelobes, beam rotation or squint correction.
586
+ Gridding convolution functions per visibility are computed
587
+ from FTs of PB models per antenna.
588
+ This gridder can be run on single fields as well as mosaics.
589
+
590
+ VLA : PB polynomial fit model (Napier and Rots, 1982).
591
+ EVLA : PB polynomial fit model (Perley, 2015).
592
+ ALMA : Airy disks for a 10.7m dish (for 12m dishes) and
593
+ 6.25m dish (for 7m dishes) each with 0.75m
594
+ blockages (Hunter/Brogan 2011). Joint mosaic
595
+ imaging supports heterogeneous arrays for ALMA.
596
+
597
+ Typical gridding convolution function support sizes are
598
+ between 7 and 50 depending on the desired
599
+ accuracy (given by the uv cell size or image field of view).
600
+
601
+ [ This mode can also be invoked using 'mosaicft' or 'ftmosaic' ]
602
+
603
+ awproject : A-Projection with azimuthally asymmetric beams and
604
+ including beam rotation, squint correction,
605
+ conjugate frequency beams and W-projection.
606
+ [Bhatnagar et.al, 2008]
607
+
608
+ Gridding convolution functions are computed from
609
+ aperture illumination models per antenna and optionally
610
+ combined with W-Projection kernels and a prolate spheroid.
611
+ This gridder can be run on single fields as well as mosaics.
612
+
613
+ VLA : Uses ray traced model (VLA and EVLA) including feed
614
+ leg and subreflector shadows, off-axis feed location
615
+ (for beam squint and other polarization effects), and
616
+ a Gaussian fit for the feed beams (Brisken 2009)
617
+ ALMA : Similar ray-traced model as above (but the correctness
618
+ of its polarization properties remains un-verified).
619
+
620
+ Typical gridding convolution function support sizes are
621
+ between 7 and 50 depending on the desired
622
+ accuracy (given by the uv cell size or image field of view).
623
+ When combined with W-Projection they can be significantly larger.
624
+
625
+ [ This mode can also be invoked using 'awprojectft' ]
626
+
627
+
628
+ awp2 : A-Projection with azimuthally asymmetric beams and
629
+ including beam rotation, squint correction and W-projection.
630
+ [Bhatnagar et.al, 2008]
631
+
632
+ Gridding convolution functions are computed from
633
+ aperture illumination models (assuming similar antennas) and optionally
634
+ combined with W-Projection kernels.
635
+ This gridder can be run on single fields as well as mosaics.
636
+ The other sub-parameters that are of significance when using this gridder
637
+ are wprojplanes, computepastep, mosweight, usepointing, pblimit and normtype.
638
+
639
+ Only supports VLA : Uses ray traced model (VLA and EVLA) including feed
640
+ leg and subreflector shadows, off-axis feed location
641
+ (for beam squint and other polarization effects), and
642
+ a Gaussian fit for the feed beams (Ref: Brisken 2009)
643
+
644
+ For squint correction the value passed in computepastep has to be smaller than 180.
645
+ Anything larger awp2 will use an average of LL and RR beams. If computepastep=5, for
646
+ e.g., PB every 5 degrees, over the range of parallactic angle covered by the data, will be calculated
647
+ and the nearest beam to every integration will be used to correct for the squint between the L and R beams.
648
+
649
+ NOTE : For mtmfs with nterms >1 and using awp2 gridder, for accurate results always use specmode="mvc"
650
+ as awp2 with specmode="mfs" does not use conjugate beams to remove the spectral
651
+ index of the primary beam.
652
+
653
+ awphpg : Implementation of the high performance gridder (HPG; Pokorny, ngVLA Computing Memo #5).
654
+ For CASA 6.7.0 this mode is only available on the internal VLASS release of CASA.
655
+ It will be made available for general use in a future CASA release.
656
+
657
+
658
+ imagemosaic : (untested implementation).
659
+
660
+ Grid and iFT each pointing separately and combine the
661
+ images as a linear mosaic (weighted by a PB model) in
662
+ the image domain before a joint minor cycle.
663
+
664
+ VLA/ALMA PB models are same as for gridder='mosaicft'.
665
+
666
+ ------ Notes on PB models :
667
+
668
+ (1) Several different sources of PB models are used in the modes
669
+ listed above. This is partly for reasons of algorithmic flexibility
670
+ and partly due to the current lack of a common beam model
671
+ repository or consensus on what beam models are most appropriate.
672
+
673
+ (2) For ALMA and gridder='mosaic', ray-traced (TICRA) beams
674
+ are also available via the vpmanager tool.
675
+ For example, call the following before the tclean run.
676
+ vp.setpbimage(telescope="ALMA",
677
+ compleximage='/home/casa/data/trunk/alma/responses/ALMA_0_DV__0_0_360_0_45_90_348.5_373_373_GHz_ticra2007_VP.im',
678
+ antnames=['DV'+'%02d'%k for k in range(25)])
679
+ vp.saveastable('mypb.tab')
680
+ Then, supply vptable='mypb.tab' to tclean.
681
+ ( Currently this will work only for non-parallel runs )
682
+
683
+
684
+ ------ Note on PB masks :
685
+
686
+ In tclean, A-Projection gridders (mosaic, awproject, and awp2) produce a
687
+ .pb image and use the 'pblimit' subparameter to decide normalization
688
+ cutoffs and construct an internal T/F mask in the .pb and .image images.
689
+ However, this T/F mask cannot directly be used during deconvolution
690
+ (which needs a 1/0 mask). There are two options for making a pb based
691
+ deconvolution mask.
692
+ -- Run tclean with niter=0 to produce the .pb, construct a 1/0 image
693
+ with the desired threshold (using ia.open('newmask.im');
694
+ ia.calc('iif("xxx.pb">0.3,1.0,0.0)');ia.close() for example),
695
+ and supply it via the 'mask' parameter in a subsequent run
696
+ (with calcres=F and calcpsf=F to restart directly from the minor cycle).
697
+ -- Run tclean with usemask='pb' for it to automatically construct
698
+ a 1/0 mask from the internal T/F mask from .pb at a fixed 0.2 threshold.
699
+
700
+
701
+ ----- Making PBs for gridders other than mosaic, awproject, awp2
702
+
703
+ After the PSF generation, a PB is constructed using the same
704
+ models used in gridder='mosaic' but just evaluated in the image
705
+ domain without consideration to weights.
706
+ facets Number of facets on a side
707
+
708
+ A set of (facets x facets) subregions of the specified image
709
+ are gridded separately using their respective phase centers
710
+ (to minimize max W). Deconvolution is done on the joint
711
+ full size image, using a PSF from the first subregion/facet.
712
+
713
+ In our current version of tclean, facets>1 may be used only
714
+ with parallel=False.
715
+ psfphasecenter For mosaic use psf centered on this
716
+ optional direction. You may need to use
717
+ this if for example the mosaic does not
718
+ have any pointing in the center of the
719
+ image. Another reason; as the psf is
720
+ approximate for a mosaic, this may help
721
+ to deconvolve a non central bright source
722
+ well and quickly.
723
+
724
+ example:
725
+
726
+ psfphasecenter='6' #center psf on field 6.
727
+ psfphasecenter='J2000 19h30m00 -40d00m00'.
728
+ psfphasecenter='J2000 292.5deg -40.0deg'.
729
+ psfphasecenter='J2000 5.105rad -0.698rad'.
730
+ psfphasecenter='ICRS 13:05:27.2780 -049.28.04.458'.
731
+ wprojplanes Number of distinct w-values at which to compute and use different
732
+ gridding convolution functions for W-Projection
733
+
734
+ An appropriate value of wprojplanes depends on the presence/absence
735
+ of a bright source far from the phase center, the desired dynamic
736
+ range of an image in the presence of a bright far out source,
737
+ the maximum w-value in the measurements, and the desired trade off
738
+ between accuracy and computing cost.
739
+
740
+ As a (rough) guide, VLA L-Band D-config may require a
741
+ value of 128 for a source 30arcmin away from the phase
742
+ center. A-config may require 1024 or more. To converge to an
743
+ appropriate value, try starting with 128 and then increasing
744
+ it if artifacts persist. W-term artifacts (for the VLA) typically look
745
+ like arc-shaped smears in a synthesis image or a shift in source
746
+ position between images made at different times. These artifacts
747
+ are more pronounced the further the source is from the phase center.
748
+
749
+ There is no harm in simply always choosing a large value (say, 1024)
750
+ but there will be a significant performance cost to doing so, especially
751
+ for gridder='awproject' where it is combined with A-Projection.
752
+
753
+ wprojplanes=-1 is an option for gridder='widefield' or 'wproject'
754
+ in which the number of planes is automatically computed.
755
+ vptable vpmanager
756
+
757
+ vptable="" : Choose default beams for different telescopes.
758
+ ALMA : Airy disks.
759
+ EVLA : old VLA models.
760
+
761
+ Other primary beam models can be chosen via the vpmanager tool.
762
+
763
+ Step 1 : Set up the vpmanager tool and save its state in a table.
764
+
765
+ vp.setpbpoly(telescope='EVLA', coeff=[1.0, -1.529e-3, 8.69e-7, -1.88e-10])
766
+ vp.saveastable('myvp.tab')
767
+
768
+ Step 2 : Supply the name of that table in tclean.
769
+
770
+ tclean(....., vptable='myvp.tab',....)
771
+
772
+ Please see the documentation for the vpmanager for more details on how to
773
+ choose different beam models. Work is in progress to update the defaults
774
+ for EVLA and ALMA.
775
+
776
+ Note : AWProjection currently does not use this mechanism to choose
777
+ beam models. It instead uses ray-traced beams computed from
778
+ parameterized aperture illumination functions, which are not
779
+ available via the vpmanager. So, gridder='awproject' does not allow
780
+ the user to set this parameter.
781
+ mosweight When doing Brigg's style weighting (including uniform) to perform the weight density calculation for each field indepedently if True. If False the weight density is calculated from the average uv distribution of all the fields.
782
+ aterm Use aperture illumination functions during gridding.
783
+
784
+ This parameter turns on the A-term of the AW-Projection gridder.
785
+ Gridding convolution functions are constructed from aperture illumination
786
+ function models of each antenna.
787
+ psterm Include the Prolate Spheroidal (PS) funtion as the anti-aliasing
788
+ operator in the gridding convolution functions used for gridding.
789
+
790
+ Setting this parameter to true is necessary when aterm is set to
791
+ false. It can be set to false when aterm is set to true, though
792
+ with this setting effects of aliasing may be there in the image,
793
+ particularly near the edges.
794
+
795
+ When set to true, the .pb images will contain the fourier transform
796
+ of the of the PS funtion.
797
+
798
+ For more information on the functional
799
+ effects of the psterm, aterm and wprojplanes settings, see the
800
+ 'Wide-field Imaging' pages in CASA Docs (https://casadocs.readthedocs.io).
801
+ wbawp Use frequency dependent A-terms.
802
+ Scale aperture illumination functions appropriately with frequency
803
+ when gridding and combining data from multiple channels.
804
+ conjbeams Use conjugate frequency for wideband A-terms.
805
+
806
+ While gridding data from one frequency channel, choose a convolution
807
+ function from a 'conjugate' frequency such that the resulting baseline
808
+ primary beam is approximately constant across frequency. For a system in
809
+ which the primary beam scales with frequency, this step will eliminate
810
+ instrumental spectral structure from the measured data and leave only the
811
+ sky spectrum for the minor cycle to model and reconstruct [Bhatnagar et al., ApJ, 2013].
812
+
813
+ As a rough guideline for when this is relevant, a source at the half power
814
+ point of the PB at the center frequency will see an artificial spectral
815
+ index of -1.4 due to the frequency dependence of the PB [Sault and Wieringa, 1994].
816
+ If left uncorrected during gridding, this spectral structure must be modeled
817
+ in the minor cycle (using the mtmfs algorithm) to avoid dynamic range limits
818
+ (of a few hundred for a 2:1 bandwidth).
819
+ This works for specmode='mfs' and its value is ignored for cubes.
820
+ cfcache Convolution function cache directory name.
821
+
822
+ Name of a directory in which to store gridding convolution functions.
823
+ This cache is filled at the beginning of an imaging run. This step can be time
824
+ consuming but the cache can be reused across multiple imaging runs that
825
+ use the same image parameters (cell size, image size , spectral data
826
+ selections, wprojplanes, wbawp, psterm, aterm). The effect of the wbawp,
827
+ psterm and aterm settings is frozen-in in the cfcache. Using an existing cfcache
828
+ made with a different setting of these parameters will not reflect the current
829
+ settings.
830
+
831
+ In a parallel execution, the construction of the cfcache is also parallelized
832
+ and the time to compute scales close to linearly with the number of compute
833
+ cores used. With the re-computation of Convolution Functions (CF) due to PA
834
+ rotation turned-off (the computepastep parameter), the total number of in the
835
+ cfcache can be computed as [No. of wprojplanes x No. of selected spectral windows x 4]
836
+
837
+ By default, cfcache = imagename + '.cf'
838
+ usepointing The usepointing flag informs the gridder that it should utilize the pointing table
839
+ to use the correct direction in which the antenna is pointing with respect to the pointing phasecenter.
840
+ computepastep Parallactic angle interval after the AIFs are recomputed (deg).
841
+
842
+ This parameter controls the accuracy of the aperture illumination function
843
+ used with AProjection for alt-az mount dishes where the AIF rotates on the
844
+ sky as the synthesis image is built up. Once the PA in the data changes by
845
+ the given interval, AIFs are re-computed at the new PA.
846
+
847
+ A value of 360.0 deg (the default) implies no re-computation due to PA rotation.
848
+ AIFs are computed for the PA value of the first valid data received and used for
849
+ all of the data.
850
+
851
+ For gridder=awp2 a value of 180.0 deg or larger implies no squint correction will be
852
+ attempted i.e an average beam of the left hand and right hand polarization will be calculated
853
+ rotatepastep Parallactic angle interval after which the nearest AIF is rotated (deg)
854
+
855
+ Instead of recomputing the AIF for every timestep's parallactic angle,
856
+ the nearest existing AIF is used and rotated
857
+ after the PA changed by rotatepastep value.
858
+
859
+ A value of 360.0 deg (the default) disables rotation of the AIF.
860
+
861
+ For example, computepastep=360.0 and rotatepastep=5.0 will compute
862
+ the AIFs at only the starting parallactic angle and all other timesteps will
863
+ use a rotated version of that AIF at the nearest 5.0 degree point.
864
+ pointingoffsetsigdev Corrections for heterogenous and time-dependent pointing
865
+ offsets via AWProjection are controlled by this parameter.
866
+ It is a vector of 2 ints or doubles each of which is interpreted
867
+ in units of arcsec. Based on the first threshold, a clustering
868
+ algorithm is applied to entries from the POINTING subtable
869
+ of the MS to determine how distinct antenna groups for which
870
+ the pointing offset must be computed separately. The second
871
+ number controls how much a pointing change across time can
872
+ be ignored and after which an antenna rebinning is required.
873
+
874
+
875
+ Note : The default value of this parameter is [], due a programmatic constraint.
876
+ If run with this value, it will internally pick [600,600] and exercise the
877
+ option of using large tolerances (10arcmin) on both axes. Please choose
878
+ a setting explicitly for runs that need to use this parameter.
879
+
880
+ Note : This option is available only for gridder='awproject' and usepointing=True and
881
+ and has been validated primarily with VLASS on-the-fly mosaic data
882
+ where POINTING subtables have been modified after the data are recorded.
883
+
884
+
885
+ Examples of parameter usage :
886
+
887
+ [100.0,100.0] : Pointing offsets of 100 arcsec or less are considered
888
+ small enough to be ignored. Using large values for both
889
+ indicates a homogeneous array.
890
+
891
+
892
+ [10.0, 100.0] : Based on entries in the POINTING subtable, antennas
893
+ are grouped into clusters based on a 10arcsec bin size.
894
+ All antennas in a bin are given a pointing offset calculated
895
+ as the average of the offsets of all antennas in the bin.
896
+ On the time axis, offset changes upto 100 arcsec will be ignored.
897
+
898
+ [10.0,10.0] : Calculate separate pointing offsets for each antenna group
899
+ (with a 10 arcsec bin size). As a function of time, recalculate
900
+ the antenna binning if the POINTING table entries change by
901
+ more than 10 arcsec w.r.to the previously computed binning.
902
+
903
+ [1.0, 1.0] : Tight tolerances will imply a fully heterogenous situation where
904
+ each antenna gets its own pointing offset. Also, time-dependent
905
+ offset changes greater than 1 arcsec will trigger recomputes of
906
+ the phase gradients. This is the most general situation and is also
907
+ the most expensive option as it constructs and uses separate
908
+ phase gradients for all baselines and timesteps.
909
+
910
+ For VLASS 1.1 data with two kinds of pointing offsets, the recommended
911
+ setting is [ 30.0, 30.0 ].
912
+
913
+ For VLASS 1.2 data with only the time-dependent pointing offsets, the
914
+ recommended setting is [ 300.0, 30.0 ] to turn off the antenna grouping
915
+ but to retain the time dependent corrections required from one timestep
916
+ to the next.
917
+ pblimit PB gain level at which to cut off normalizations.
918
+
919
+ Divisions by .pb during normalizations have a cut off at a .pb gain
920
+ level given by pblimit. Outside this limit, image values are set to zero.
921
+ Additionally, by default, an internal T/F mask is applied to the .pb, .image and
922
+ .residual images to mask out (T) all invalid pixels outside the pblimit area.
923
+
924
+ Note : This internal T/F mask cannot be used as a deconvolution mask.
925
+ To do so, please follow the steps listed above in the Notes for the
926
+ 'gridder' parameter.
927
+
928
+ Note : To prevent the internal T/F mask from appearing in anything other
929
+ than the .pb and .image.pbcor images, 'pblimit' can be set to a
930
+ negative number.
931
+ The absolute value will still be used as a valid 'pblimit' for normalization
932
+ purposes. So, for example, pick pblimit=-0.1 (and not pblimit=-1).
933
+ A tclean restart using existing output images on disk that already
934
+ have this T/F mask in the .residual and .image but only pblimit set
935
+ to a negative value, will remove this mask after the next major cycle.
936
+
937
+ Note : An existing internal T/F mask may be removed from an image as
938
+ follows (without needing to re-run tclean itself).
939
+ ia.open('test.image');
940
+ ia.maskhandler(op='set', name='');
941
+ ia.done()
942
+ normtype Normalization type (flatnoise, flatsky, pbsquare).
943
+
944
+ Gridded (and FT'd) images represent the PB-weighted sky image.
945
+ Qualitatively it can be approximated as two instances of the PB
946
+ applied to the sky image (one naturally present in the data
947
+ and one introduced during gridding via the convolution functions).
948
+
949
+ xxx.weight : Weight image approximately equal to sum ( square ( pb ) )
950
+ xxx.pb : Primary beam calculated as sqrt ( xxx.weight )
951
+
952
+ normtype='flatnoise' : Divide the raw image by sqrt(.weight) so that
953
+ the input to the minor cycle represents the
954
+ product of the sky and PB. The noise is 'flat'
955
+ across the region covered by each PB.
956
+
957
+ normtype='flatsky' : Divide the raw image by .weight so that the input
958
+ to the minor cycle represents only the sky.
959
+ The noise is higher in the outer regions of the
960
+ primary beam where the sensitivity is low.
961
+
962
+ normtype='pbsquare' : No normalization after gridding and FFT.
963
+ The minor cycle sees the sky times pb square
964
+ deconvolver Name of minor cycle algorithm (hogbom,clark,multiscale,mtmfs,mem,clarkstokes,asp)
965
+
966
+ Each of the following algorithms operate on residual images and PSFs
967
+ from the gridder and produce output model and restored images.
968
+ Minor cycles stop and a major cycle is triggered when cyclethreshold
969
+ or cycleniter are reached. For all methods, components are picked from
970
+ the entire extent of the image or (if specified) within a mask.
971
+
972
+ hogbom : An adapted version of Hogbom Clean [Hogbom, 1974].
973
+ - Find the location of the peak residual.
974
+ - Add this delta function component to the model image.
975
+ - Subtract a scaled and shifted PSF of the same size as the image
976
+ from regions of the residual image where the two overlap.
977
+ - Repeat.
978
+
979
+ clark : An adapted version of Clark Clean [Clark, 1980].
980
+ - Find the location of max(I^2+Q^2+U^2+V^2).
981
+ - Add delta functions to each stokes plane of the model image.
982
+ - Subtract a scaled and shifted PSF within a small patch size
983
+ from regions of the residual image where the two overlap.
984
+ - After several iterations trigger a Clark major cycle to subtract
985
+ components from the visibility domain, but without de-gridding.
986
+ - Repeat.
987
+
988
+ ( Note : 'clark' maps to imagermode='' in the old clean task.
989
+ 'clark_exp' is another implementation that maps to
990
+ imagermode='mosaic' or 'csclean' in the old clean task
991
+ but the behavior is not identical. For now, please
992
+ use deconvolver='hogbom' if you encounter problems. )
993
+
994
+ clarkstokes : Clark Clean operating separately per Stokes plane.
995
+
996
+ (Note : 'clarkstokes_exp' is an alternate version. See above.)
997
+
998
+ multiscale : MultiScale Clean [Cornwell, 2008].
999
+ - Smooth the residual image to multiple scale sizes.
1000
+ - Find the location and scale at which the peak occurs.
1001
+ - Add this multiscale component to the model image.
1002
+ - Subtract a scaled,smoothed,shifted PSF (within a small
1003
+ patch size per scale) from all residual images.
1004
+ - Repeat from step 2.
1005
+
1006
+ mtmfs : Multi-term (Multi Scale) Multi-Frequency Synthesis [Rau and Cornwell, 2011].
1007
+ - Smooth each Taylor residual image to multiple scale sizes.
1008
+ - Solve a NTxNT system of equations per scale size to compute
1009
+ Taylor coefficients for components at all locations.
1010
+ - Compute gradient chi-square and pick the Taylor coefficients
1011
+ and scale size at the location with maximum reduction in
1012
+ chi-square.
1013
+ - Add multi-scale components to each Taylor-coefficient
1014
+ model image.
1015
+ - Subtract scaled,smoothed,shifted PSF (within a small patch size
1016
+ per scale) from all smoothed Taylor residual images.
1017
+ - Repeat from step 2.
1018
+
1019
+
1020
+ mem : Maximum Entropy Method [Cornwell and Evans, 1985].
1021
+ - Iteratively solve for values at all individual pixels via the
1022
+ MEM method. It minimizes an objective function of
1023
+ chi-square plus entropy (here, a measure of difference
1024
+ between the current model and a flat prior model).
1025
+
1026
+ (Note : This MEM implementation is not very robust.
1027
+ Improvements will be made in the future.)
1028
+
1029
+ asp : Adaptive Scale Pixel algorithm [Bhatnagar and Cornwell, 2004].
1030
+ - Define a set of initial scales defined as 0, W, 2W 4W and 8W.
1031
+ where W is a 2D Gaussian fitting width to the PSF.
1032
+ - Smooth the residual image by a Gaussian beam at initial scales.
1033
+ - Search for the global peak (F) among these smoothed residual images.
1034
+ - form an active Aspen set: amplitude(F), amplitude location(x,y).
1035
+ - Optimize the Aspen set by minimizing the objective function RI-Aspen*PSF,
1036
+ where RI is the residual image and * is the convulition operation.
1037
+ - Compute the model image and update the residual image
1038
+ - Repeat from step 2
1039
+ scales List of scale sizes (in pixels) for multi-scale and mtmfs algorithms.
1040
+ --> scales=[0,6,20]
1041
+ This set of scale sizes should represent the sizes
1042
+ (diameters in units of number of pixels)
1043
+ of dominant features in the image being reconstructed.
1044
+
1045
+ The smallest scale size is recommended to be 0 (point source),
1046
+ the second being the size of the synthesized beam and the third being 3-5
1047
+ times the synthesized beam, etc. For example, if the synthesized
1048
+ beam is 10" FWHM and cell=2",try scales = [0,5,15].
1049
+
1050
+ For numerical stability, the largest scale must be
1051
+ smaller than the image (or mask) size and smaller than or
1052
+ comparable to the scale corresponding to the lowest measured
1053
+ spatial frequency (as a scale size much larger than what the
1054
+ instrument is sensitive to is unconstrained by the data making
1055
+ it harder to recover from errors during the minor cycle).
1056
+ nterms Number of Taylor coefficients in the spectral model.
1057
+
1058
+ - nterms=1 : Assume flat spectrum source.
1059
+ - nterms=2 : Spectrum is a straight line with a slope.
1060
+ - nterms=N : A polynomial of order N-1.
1061
+
1062
+ From a Taylor expansion of the expression of a power law, the
1063
+ spectral index is derived as alpha = taylorcoeff_1 / taylorcoeff_0.
1064
+
1065
+ Spectral curvature is similarly derived when possible.
1066
+
1067
+ The optimal number of Taylor terms depends on the available
1068
+ signal to noise ratio, bandwidth ratio, and spectral shape of the
1069
+ source as seen by the telescope (sky spectrum x PB spectrum).
1070
+
1071
+ nterms=2 is a good starting point for wideband EVLA imaging
1072
+ and the lower frequency bands of ALMA (when fractional bandwidth
1073
+ is greater than 10%) and if there is at least one bright source for
1074
+ which a dynamic range of greater than few 100 is desired.
1075
+
1076
+ Spectral artifacts for the VLA often look like spokes radiating out from
1077
+ a bright source (i.e. in the image made with standard mfs imaging).
1078
+ If increasing the number of terms does not eliminate these artifacts,
1079
+ check the data for inadequate bandpass calibration. If the source is away
1080
+ from the pointing center, consider including wide-field corrections too.
1081
+
1082
+ (Note : In addition to output Taylor coefficient images .tt0,.tt1,etc
1083
+ images of spectral index (.alpha), an estimate of error on
1084
+ spectral index (.alpha.error) and spectral curvature (.beta,
1085
+ if nterms is greater than 2) are produced.
1086
+ - These alpha, alpha.error and beta images contain
1087
+ internal T/F masks based on a threshold computed
1088
+ as peakresidual/10. Additional masking based on
1089
+ .alpha/.alpha.error may be desirable.
1090
+ - .alpha.error is a purely empirical estimate derived
1091
+ from the propagation of error during the division of
1092
+ two noisy numbers (alpha = xx.tt1/xx.tt0) where the
1093
+ 'error' on tt1 and tt0 are simply the values picked from
1094
+ the corresponding residual images. The absolute value
1095
+ of the error is not always accurate and it is best to interpret
1096
+ the errors across the image only in a relative sense.
1097
+ smallscalebias A numerical control to bias the scales when using multi-scale or mtmfs algorithms.
1098
+ The peak from each scale's smoothed residual is
1099
+ multiplied by ( 1 - smallscalebias \* scale/maxscale )
1100
+ to increase or decrease the amplitude relative to other scales,
1101
+ before the scale with the largest peak is chosen.
1102
+ Smallscalebias can be varied between -1.0 and 1.0.
1103
+ A score of 0.0 gives all scales equal weight (default).
1104
+ A score larger than 0.0 will bias the solution towards smaller scales.
1105
+ A score smaller than 0.0 will bias the solution towards larger scales.
1106
+ The effect of smallscalebias is more pronounced when using multi-scale relative to mtmfs.
1107
+ fusedthreshold ring Hogbom Clean (number in units of Jy).
1108
+
1109
+ fusedthreshold = 0.0001 : 0.1 mJy.
1110
+
1111
+ This is a subparameter of the Asp Clean deconvolver. When peak residual
1112
+ is lower than the threshold, Asp Clean is "switched to Hogbom Clean" (i.e. only use the 0 scale for cleaning) for
1113
+ the following number of iterations until it switches back to Asp Clean.
1114
+
1115
+ NumberIterationsInHogbom = 50 + 2 * (exp(0.05 * NthHogbom) - 1)
1116
+
1117
+ , where NthHogbom is the number of times Hogbom Clean has been triggered.
1118
+
1119
+ When the Asp Clean detects it is approaching convergence, it uses only the 0 scale for the following number of iterations for better computational efficiency.
1120
+
1121
+ NumberIterationsInHogbom = 500 + 2 * (exp(0.05 * NthHogbom) - 1)
1122
+
1123
+ Set 'fusedthreshold = -1' to make the Asp Clean deconvolver never "switch" to Hogbom Clean.
1124
+ largestscale xels) allowed for the initial guess for the Asp Clean deconvolver.
1125
+
1126
+ largestscale = 100
1127
+
1128
+ The default initial scale sizes used by Asp Clean is [0, w, 2w, 4w, 8w],
1129
+ where `w` is the PSF width. The default `largestscale` is -1 which indicates
1130
+ users accept these initial scales. If `largestscale` is set, the initial scales
1131
+ would be [0, w, ... up to the `largestscale`]. This is only an initial guess,
1132
+ and actual fitted scale sizes may evolve from these initial values.
1133
+
1134
+ It is recommended not to set `largestscale` unless Asp Clean picks a large
1135
+ scale that has no constraints from the data (the UV hole issue).
1136
+ restoration e.
1137
+
1138
+ Construct a restored image : imagename.image by convolving the model
1139
+ image with a clean beam and adding the residual image to the result.
1140
+ If a restoringbeam is specified, the residual image is also
1141
+ smoothed to that target resolution before adding it in.
1142
+
1143
+ If a .model does not exist, it will make an empty one and create
1144
+ the restored image from the residuals ( with additional smoothing if needed ).
1145
+ With algorithm='mtmfs', this will construct Taylor coefficient maps from
1146
+ the residuals and compute .alpha and .alpha.error.
1147
+ restoringbeam ize to use.
1148
+
1149
+ - restoringbeam='' or [''].
1150
+ A Gaussian fitted to the PSF main lobe (separately per image plane).
1151
+
1152
+ - restoringbeam='10.0arcsec'.
1153
+ Use a circular Gaussian of this width for all planes.
1154
+
1155
+ - restoringbeam=['8.0arcsec','10.0arcsec','45deg'].
1156
+ Use this elliptical Gaussian for all planes.
1157
+
1158
+ - restoringbeam='common'.
1159
+ Automatically estimate a common beam shape/size appropriate for
1160
+ all planes. This option can be used when the beam shape is different as a function of frequency, and will smooth all planes to a single beam, defined by the largest beam in the cube.
1161
+
1162
+ Note : For any restoring beam different from the native resolution
1163
+ the model image is convolved with the beam and added to
1164
+ residuals that have been convolved to the same target resolution.
1165
+ pbcor the output restored image.
1166
+
1167
+ A new image with extension .image.pbcor will be created from
1168
+ the evaluation of .image / .pb for all pixels above the specified pblimit.
1169
+
1170
+ Note : Stand-alone PB-correction can be triggered by re-running
1171
+ tclean with the appropriate imagename and with
1172
+ niter=0, calcpsf=False, calcres=False, pbcor=True, vptable='vp.tab'
1173
+ ( where vp.tab is the name of the vpmanager file;
1174
+ see the inline help for the 'vptable' parameter ). Alternatively, task impbcor can be used for primary beam correction using the .image and .pb files.
1175
+
1176
+ Note : For deconvolver='mtmfs', pbcor will divide each Taylor term image by the .tt0 average PB.
1177
+ For all gridders, this calculation is accurate for small fractional bandwidths.
1178
+
1179
+ For large fractional bandwidths, please use one of the following options.
1180
+
1181
+ (a) For single pointings, run the tclean task with specmode='mfs', deconvolver='mtmfs',
1182
+ and gridder='standard' with pbcor=True or False.
1183
+ If a PB-corrected spectral index is required,
1184
+ please use the widebandpbcor task to apply multi-tern PB-correction.
1185
+
1186
+ (b) For mosaics, run tclean task with specmode='mfs', deconvolver='mtmfs',
1187
+ and gridder='awproject' , wbawp=True, conjbeams=True, with pbcor=True.
1188
+ This option applies wideband PB correction as part of the gridding step and
1189
+ pbcor=True will be accurate because the spectral index map will already
1190
+ be PB-corrected.
1191
+
1192
+ (c) For mosaics, run tclean with specmode='mvc', deconvolver='mtmfs',
1193
+ and gridder='mosaic' or 'awp2' with pbcor=True.
1194
+ This option applies wideband PB-correction to channelized residual images
1195
+ prior to the minor cycle and pbcor=True will be accurate because the spectral
1196
+ index map will already be PB-corrected.
1197
+
1198
+ Note : Frequency-dependent PB corrections are typically required for full-band imaging with the VLA.
1199
+ Wideband PB corrections are required when the amplitude of the
1200
+ brightest source is known accurately enough to be sensitive
1201
+ to the difference in the PB gain between the upper and lower
1202
+ end of the band at its location. As a guideline, the artificial spectral
1203
+ index due to the PB is -1.4 at the 0.5 gain level and less than -0.2
1204
+ at the 0.9 gain level at the middle frequency )
1205
+ outlierfile Name of outlier-field image definitions.
1206
+
1207
+ A text file containing sets of parameter=value pairs,
1208
+ one set per outlier field.
1209
+
1210
+ Example : outlierfile='outs.txt'
1211
+
1212
+ Contents of outs.txt :
1213
+
1214
+ imagename=tst1
1215
+ nchan=1
1216
+ imsize=[80,80]
1217
+ cell=[8.0arcsec,8.0arcsec]
1218
+ phasecenter=J2000 19:58:40.895 +40.55.58.543
1219
+ mask=circle[[40pix,40pix],10pix]
1220
+
1221
+ imagename=tst2
1222
+ nchan=1
1223
+ imsize=[100,100]
1224
+ cell=[8.0arcsec,8.0arcsec]
1225
+ phasecenter=J2000 19:58:40.895 +40.56.00.000
1226
+ mask=circle[[60pix,60pix],20pix]
1227
+
1228
+ The following parameters are currently allowed to be different between
1229
+ the main field and the outlier fields (i.e. they will be recognized if found
1230
+ in the outlier text file). If a parameter is not listed, the value is picked from
1231
+ what is defined in the main task input.
1232
+
1233
+ imagename, imsize, cell, phasecenter, startmodel, mask
1234
+ specmode, nchan, start, width, nterms, reffreq,
1235
+ gridder, deconvolver, wprojplanes.
1236
+
1237
+ Note : 'specmode' is an option, so combinations of mfs and cube
1238
+ for different image fields, for example, are supported.
1239
+ 'deconvolver' and 'gridder' are also options that allow different
1240
+ imaging or deconvolution algorithm per image field.
1241
+
1242
+ For example, multiscale with wprojection and 16 w-term planes
1243
+ on the main field and mtmfs with nterms=3 and wprojection
1244
+ with 64 planes on a bright outlier source for which the frequency
1245
+ dependence of the primary beam produces a strong effect that
1246
+ must be modeled. The traditional alternative to this approach is
1247
+ to first image the outlier, subtract it out of the data (uvsub) and
1248
+ then image the main field.
1249
+ weighting Weighting scheme (natural,uniform,briggs,superuniform,radial, briggsabs, briggsbwtaper).
1250
+
1251
+ During gridding of the dirty or residual image, each visibility value is
1252
+ multiplied by a weight before it is accumulated on the uv-grid.
1253
+ The PSF's uv-grid is generated by gridding only the weights (weightgrid).
1254
+
1255
+ weighting='natural' : Gridding weights are identical to the data weights
1256
+ from the MS. For visibilities with similar data weights,
1257
+ the weightgrid will follow the sample density
1258
+ pattern on the uv-plane. This weighting scheme
1259
+ provides the maximum imaging sensitivity at the
1260
+ expense of a PSF with possibly wider main lobes and high sidelobes.
1261
+ It is most appropriate for detection experiments
1262
+ where sensitivity is most important.
1263
+
1264
+ weighting='uniform' : Gridding weights per visibility data point are the
1265
+ original data weights divided by the total weight of
1266
+ all data points that map to the same uv grid cell :
1267
+ ' data_weight / total_wt_per_cell '.
1268
+
1269
+ The weightgrid is as close to flat as possible resulting
1270
+ in a PSF with a narrow main lobe and suppressed
1271
+ sidelobes. However, since heavily sampled areas of
1272
+ the uv-plane get down-weighted, the imaging
1273
+ sensitivity is not as high as with natural weighting.
1274
+ It is most appropriate for imaging experiments where
1275
+ a well behaved PSF can help the reconstruction.
1276
+
1277
+ weighting='briggs' : Gridding weights per visibility data point are given by
1278
+ 'data_weight / ( A \* total_wt_per_cell + B ) ' where
1279
+ A and B vary according to the 'robust' parameter.
1280
+
1281
+ robust = -2.0 maps to A=1,B=0 or uniform weighting.
1282
+ robust = +2.0 maps to natural weighting.
1283
+ (robust=0.5 is equivalent to robust=0.0 in AIPS IMAGR.)
1284
+
1285
+ Robust/Briggs weighting generates a PSF that can
1286
+ vary smoothly between 'natural' and 'uniform' and
1287
+ allow customized trade-offs between PSF shape and
1288
+ imaging sensitivity.
1289
+ weighting='briggsabs' : Experimental option.
1290
+ Same as Briggs except the formula is different A=
1291
+ robust\*robust and B is dependent on the
1292
+ noise per visibility estimated. Giving noise='0Jy'
1293
+ is a not a reasonable option.
1294
+ In this mode (or formula) robust values
1295
+ from -2.0 to 0.0 only make sense (2.0 and
1296
+ -2.0 will get the same weighting)
1297
+
1298
+ weighting='superuniform' : This is similar to uniform weighting except that
1299
+ the total_wt_per_cell is replaced by the
1300
+ total_wt_within_NxN_cells around the uv cell of
1301
+ interest. N=7 is the default (when the
1302
+ parameter 'npixels' is set to 0 with 'superuniform')
1303
+
1304
+ This method tends to give a PSF with inner
1305
+ sidelobes that are suppressed as in uniform
1306
+ weighting but with far-out sidelobes closer to
1307
+ natural weighting. The peak sensitivity is also
1308
+ closer to natural weighting.
1309
+
1310
+ weighting='radial' : Gridding weights are given by ' data_weight \* uvdistance '
1311
+ This method approximately minimizes rms sidelobes
1312
+ for an east-west synthesis array.
1313
+
1314
+ weighting='briggsbwtaper' : A modified version of Briggs weighting for cubes where an inverse uv taper,
1315
+ which is proportional to the fractional bandwidth of the entire cube,
1316
+ is applied per channel. The objective is to modify cube (perchanweightdensity = True)
1317
+ imaging weights to have a similar density to that of the continuum imaging weights.
1318
+ This is currently an experimental weighting scheme being developed for ALMA.
1319
+
1320
+ For more details on weighting please see Chapter3
1321
+ of Dan Briggs' thesis (http://www.aoc.nrao.edu/dissertations/dbriggs)
1322
+ robust Robustness parameter for Briggs weighting.
1323
+
1324
+ robust = -2.0 maps to uniform weighting.
1325
+ robust = +2.0 maps to natural weighting.
1326
+ (robust=0.5 is equivalent to robust=0.0 in AIPS IMAGR.)
1327
+ noise noise parameter for briggs abs mode weighting
1328
+ npixels Number of pixels to determine uv-cell size for super-uniform weighting
1329
+ (0 defaults to -/+ 3 pixels).
1330
+
1331
+ npixels -- uv-box used for weight calculation
1332
+ a box going from -npixel/2 to +npixel/2 on each side
1333
+ around a point is used to calculate weight density.
1334
+
1335
+ npixels=2 goes from -1 to +1 and covers 3 pixels on a side.
1336
+
1337
+ npixels=0 implies a single pixel, which does not make sense for
1338
+ superuniform weighting. Therefore, for 'superuniform'
1339
+ weighting, if npixels=0 it will be forced to 6 (or a box
1340
+ of -3pixels to +3pixels) to cover 7 pixels on a side.
1341
+ uvtaper uv-taper on outer baselines in uv-plane.
1342
+
1343
+ Apply a Gaussian taper in addition to the weighting scheme specified
1344
+ via the 'weighting' parameter. Higher spatial frequencies are weighted
1345
+ down relative to lower spatial frequencies to suppress artifacts
1346
+ arising from poorly sampled areas of the uv-plane. It is equivalent to
1347
+ smoothing the PSF obtained by other weighting schemes and can be
1348
+ specified either as the HWHM of a Gaussian in uv-space (eg. units of lambda)
1349
+ or as the FWHM of a Gaussian in the image domain (eg. angular units like arcsec).
1350
+
1351
+ uvtaper = [bmaj, bmin, bpa].
1352
+
1353
+ Note : FWHM_uv_lambda = (4 log2) / ( pi * FWHM_lm_radians ).
1354
+
1355
+ A FWHM_lm of 100.000 arcsec maps to a HWHM_uv of 910.18 lambda.
1356
+ A FWHM_lm of 1 arcsec maps to a HWHM_uv of 91 klambda.
1357
+
1358
+ default: uvtaper=[]; no Gaussian taper applied.
1359
+ example: uvtaper=['5klambda'] circular taper of HWHM=5 kilo-lambda.
1360
+ uvtaper=['5klambda','3klambda','45.0deg'] uv-domain HWHM.
1361
+ uvtaper=['50arcsec','30arcsec','30.0deg'] : image domain FWHM.
1362
+ uvtaper=['10arcsec'] : image domain FWHM.
1363
+ uvtaper=['300.0'] default units are lambda in aperture plane.
1364
+ niter Maximum number of iterations.
1365
+
1366
+ A stopping criterion based on total iteration count.
1367
+ Currently the parameter type is defined as an integer therefore the integer value
1368
+ larger than 2147483647 will not be set properly as it causes an overflow.
1369
+
1370
+ Iterations are typically defined as the selecting one flux component
1371
+ and partially subtracting it out from the residual image.
1372
+
1373
+ niter=0 : Do only the initial major cycle (make dirty image, psf, pb, etc).
1374
+
1375
+ niter larger than zero : Run major and minor cycles.
1376
+
1377
+ Note : Global stopping criteria vs major-cycle triggers.
1378
+
1379
+ In addition to global stopping criteria, the following rules are
1380
+ used to determine when to terminate a set of minor cycle iterations
1381
+ and trigger major cycles [derived from Cotton-Schwab Clean, 1984].
1382
+
1383
+ 'cycleniter' : controls the maximum number of iterations per image
1384
+ plane before triggering a major cycle.
1385
+ 'cyclethreshold' : Automatically computed threshold related to the
1386
+ max sidelobe level of the PSF and peak residual.
1387
+ Divergence, detected as an increase of 10% in peak residual from the
1388
+ minimum so far (during minor cycle iterations).
1389
+
1390
+ The first criterion to be satisfied takes precedence.
1391
+
1392
+ Note : Iteration counts for cubes or multi-field images :
1393
+ For images with multiple planes (or image fields) on which the
1394
+ deconvolver operates in sequence, iterations are counted across
1395
+ all planes (or image fields). The iteration count is compared with
1396
+ 'niter' only after all channels/planes/fields have completed their
1397
+ minor cycles and exited either due to 'cycleniter' or 'cyclethreshold'.
1398
+ Therefore, the actual number of iterations reported in the logger
1399
+ can sometimes be larger than the user specified value in 'niter'.
1400
+ For example, with niter=100, cycleniter=20,nchan=10,threshold=0,
1401
+ a total of 200 iterations will be done in the first set of minor cycles
1402
+ before the total is compared with niter=100 and it exits.
1403
+
1404
+ Note : Additional global stopping criteria include:
1405
+ - no change in peak residual across two major cycles.
1406
+ - a 50% or more increase in peak residual across one major cycle.
1407
+ gain Loop gain.
1408
+
1409
+ Fraction of the source flux to subtract out of the residual image
1410
+ for the CLEAN algorithm and its variants.
1411
+
1412
+ A low value (0.2 or less) is recommended when the sky brightness
1413
+ distribution is not well represented by the basis functions used by
1414
+ the chosen deconvolution algorithm. A higher value can be tried when
1415
+ there is a good match between the true sky brightness structure and
1416
+ the basis function shapes. For example, for extended emission,
1417
+ multiscale clean with an appropriate set of scale sizes will tolerate
1418
+ a higher loop gain than Clark clean.
1419
+ threshold Stopping threshold (number in units of Jy, or string).
1420
+
1421
+ A global stopping threshold that the peak residual (within clean mask)
1422
+ across all image planes is compared to.
1423
+
1424
+ threshold = 0.005 : 5mJy
1425
+ threshold = '5.0mJy'
1426
+
1427
+ Note : A 'cyclethreshold' is internally computed and used as a major cycle
1428
+ trigger. It is related to what fraction of the PSF can be reliably
1429
+ used during minor cycle updates of the residual image. By default
1430
+ the minor cycle iterations terminate once the peak residual reaches
1431
+ the first sidelobe level of the brightest source.
1432
+
1433
+ 'cyclethreshold' is computed as follows using the settings in
1434
+ parameters 'cyclefactor','minpsffraction','maxpsffraction','threshold' :
1435
+
1436
+ psf_fraction = max_psf_sidelobe_level \* 'cyclefactor'
1437
+ psf_fraction = max(psf_fraction, 'minpsffraction');
1438
+ psf_fraction = min(psf_fraction, 'maxpsffraction');
1439
+ cyclethreshold = peak_residual \* psf_fraction
1440
+ cyclethreshold = max( cyclethreshold, 'threshold' )
1441
+
1442
+ If nsigma is set (>0.0), the N-sigma threshold is calculated (see
1443
+ the description under nsigma), then cyclethreshold is further modified as,
1444
+
1445
+ cyclethreshold = max( cyclethreshold, nsgima_threshold ).
1446
+
1447
+
1448
+ 'cyclethreshold' is made visible and editable only in the
1449
+ interactive GUI when tclean is run with interactive=True.
1450
+ nsigma Multiplicative factor for rms-based threshold stopping.
1451
+
1452
+ N-sigma threshold is calculated as nsigma \* rms value per image plane determined
1453
+ from a robust statistics. For nsigma > 0.0, in a minor cycle, a maximum of the two values,
1454
+ the N-sigma threshold and cyclethreshold, is used to trigger a major cycle
1455
+ (see also the descreption under 'threshold').
1456
+ Set nsigma=0.0 to preserve the previous tclean behavior without this feature.
1457
+ The top level parameter, fastnoise is relevant for the rms noise calculation which is used
1458
+ to determine the threshold.
1459
+
1460
+ The parameter 'nsigma' may be an int, float, or a double.
1461
+ cycleniter Maximum number of minor-cycle iterations (per plane) before triggering
1462
+ a major cycle.
1463
+
1464
+ For example, for a single plane image, if niter=100 and cycleniter=20,
1465
+ there will be 5 major cycles after the initial one (assuming there is no
1466
+ threshold based stopping criterion). At each major cycle boundary, if
1467
+ the number of iterations left over (to reach niter) is less than cycleniter,
1468
+ it is set to the difference.
1469
+
1470
+ Note : cycleniter applies per image plane, even if cycleniter x nplanes
1471
+ gives a total number of iterations greater than 'niter'. This is to
1472
+ preserve consistency across image planes within one set of minor
1473
+ cycle iterations.
1474
+ cyclefactor Scaling on PSF sidelobe level to compute the minor-cycle stopping threshold.
1475
+
1476
+ Please refer to the Note under the documentation for 'threshold' that
1477
+ discussed the calculation of 'cyclethreshold'.
1478
+
1479
+ cyclefactor=1.0 results in a cyclethreshold at the first sidelobe level of
1480
+ the brightest source in the residual image before the minor cycle starts.
1481
+
1482
+ cyclefactor=0.5 allows the minor cycle to go deeper.
1483
+ cyclefactor=2.0 triggers a major cycle sooner.
1484
+ minpsffraction PSF fraction that marks the max depth of cleaning in the minor cycle.
1485
+
1486
+ Please refer to the Note under the documentation for 'threshold' that
1487
+ discussed the calculation of 'cyclethreshold'.
1488
+
1489
+ For example, minpsffraction=0.5 will stop cleaning at half the height of
1490
+ the peak residual and trigger a major cycle earlier.
1491
+ maxpsffraction PSF fraction that marks the minimum depth of cleaning in the minor cycle.
1492
+
1493
+ Please refer to the Note under the documentation for 'threshold' that
1494
+ discussed the calculation of 'cyclethreshold'.
1495
+
1496
+ For example, maxpsffraction=0.8 will ensure that at least the top 20
1497
+ percent of the source will be subtracted out in the minor cycle even if
1498
+ the first PSF sidelobe is at the 0.9 level (an extreme example), or if the
1499
+ cyclefactor is set too high for anything to get cleaned.
1500
+ nmajor The nmajor parameter limits the number of minor and major cycle sets
1501
+ that tclean executes. It is defined as the number of major cycles after the
1502
+ initial set of minor cycle iterations. In other words, the count of nmajor does
1503
+ not include the initial residual calculation that occurs when calcres=True.
1504
+
1505
+ A setting of nmajor=-1 implies no limit (default -1).
1506
+ A setting of nmajor=0 implies nothing other than the initial residual calculation
1507
+ A setting of nmajor>0 imples that nmajor sets of minor and major cycles will
1508
+ be done in addition to the initial residual calculation.
1509
+
1510
+ If the major cycle limit is reached, stopcode 9 will be returned. Other stopping
1511
+ criteria (such as threshold) could cause tclean to stop in fewer than this
1512
+ number of major cycles. If tclean reaches another stopping criteria, first
1513
+ or at the same time as nmajor, then that stopcode will be returned instead.
1514
+
1515
+ Note however that major cycle ids in the log messages as well as in the return
1516
+ dictionary do begin with 1 for the initial residual calculation, when it exists.
1517
+
1518
+ Example 1 : A tclean run with 'nmajor=5' and 'calcres=True' will iterate for
1519
+ 5 major cycles (not counting the initial residual calculation). But, the return
1520
+ dictionary will show 'nmajordone:6'. If 'calcres=False', then the return
1521
+ dictionary will show 'nmajordone:5'.
1522
+
1523
+ Example 2 : For both the following cases, there will be a printout in the logs
1524
+ "Running Major Cycle 1" and the return value will include "nmajordone: 1",
1525
+ however there is a difference in the purpose of the major cycle and the
1526
+ number of minor cycles executed:
1527
+ Case 1; nmajor=0, calcres=True: The major cycle done is for the creation
1528
+ of the residual, and no minor cycles are executed.
1529
+ Case 2; nmajor=1, calcres=False: The major cycle is done as part of the
1530
+ major/minor cycle loop, and 1 minor cycle will be executed.
1531
+ usemask Type of mask(s) to be used for deconvolution.
1532
+
1533
+ user: (default) mask image(s) or user specified region file(s) or string CRTF expression(s).
1534
+ subparameters: mask, pbmask.
1535
+ pb: primary beam mask.
1536
+ subparameter: pbmask.
1537
+
1538
+ Example: usemask="pb", pbmask=0.2.
1539
+ Construct a mask at the 0.2 pb gain level.
1540
+ (Currently, this option will work only with
1541
+
1542
+ gridders that produce .pb (i.e. mosaic, awp2 and awproject)
1543
+ or if an externally produced .pb image exists on disk)
1544
+
1545
+
1546
+ auto-multithresh : auto-masking by multiple thresholds for deconvolution.
1547
+ subparameters : sidelobethreshold, noisethreshold, lownoisethreshold, negativethrehsold, smoothfactor,
1548
+ minbeamfrac, cutthreshold, pbmask, growiterations, dogrowprune, minpercentchange, verbose.
1549
+ Additional top level parameter relevant to auto-multithresh: fastnoise.
1550
+
1551
+ if pbmask is >0.0, the region outside the specified pb gain level is excluded from
1552
+ image statistics in determination of the threshold.
1553
+
1554
+
1555
+
1556
+
1557
+ Note: By default the intermediate mask generated by automask at each deconvolution cycle
1558
+ is over-written in the next cycle but one can save them by setting
1559
+ the environment variable, SAVE_ALL_AUTOMASKS="true".
1560
+ (e.g. in the CASA prompt, os.environ['SAVE_ALL_AUTOMASKS']="true" )
1561
+ The saved CASA mask image name will be imagename.mask.autothresh#, where
1562
+ # is the iteration cycle number.
1563
+ mask Mask (a list of image name(s) or region file(s) or region string(s).
1564
+
1565
+
1566
+ The name of a CASA image or region file or region string that specifies
1567
+ a 1/0 mask to be used for deconvolution. Only locations with value 1 will
1568
+ be considered for the centers of flux components in the minor cycle.
1569
+ If regions specified fall completely outside of the image, tclean will throw an error.
1570
+
1571
+ Manual mask options/examples :
1572
+
1573
+ mask='xxx.mask' : Use this CASA image named xxx.mask and containing
1574
+ ones and zeros as the mask.
1575
+ If the mask is only different in spatial coordinates from what is being made
1576
+ it will be resampled to the target coordinate system before being used.
1577
+ The mask has to have the same shape in velocity and Stokes planes
1578
+ as the output image. Exceptions are single velocity and/or single
1579
+ Stokes plane masks. They will be expanded to cover all velocity and/or
1580
+ Stokes planes of the output cube.
1581
+
1582
+ [ Note : If an error occurs during image resampling or
1583
+ if the expected mask does not appear, please try
1584
+ using tasks 'imregrid' or 'makemask' to resample
1585
+ the mask image onto a CASA image with the target
1586
+ shape and coordinates and supply it via the 'mask'
1587
+ parameter. ]
1588
+
1589
+
1590
+ mask='xxx.crtf' : A text file with region strings and the following on the first line
1591
+ ( #CRTFv0 CASA Region Text Format version 0 )
1592
+ This is the format of a file created via the viewer's region
1593
+ tool when saved in CASA region file format.
1594
+
1595
+ mask='circle[[40pix,40pix],10pix]' : A CASA region string.
1596
+
1597
+ mask=['xxx.mask','xxx.crtf', 'circle[[40pix,40pix],10pix]'] : a list of masks.
1598
+
1599
+
1600
+
1601
+
1602
+
1603
+ Note : Mask images for deconvolution must contain 1 or 0 in each pixel.
1604
+ Such a mask is different from an internal T/F mask that can be
1605
+ held within each CASA image. These two types of masks are not
1606
+ automatically interchangeable, so please use the makemask task
1607
+ to copy between them if you need to construct a 1/0 based mask
1608
+ from a T/F one.
1609
+
1610
+ Note : Work is in progress to generate more flexible masking options and
1611
+ enable more controls.
1612
+ pbmask Sub-parameter for usemask: primary beam mask.
1613
+
1614
+ Examples : pbmask=0.0 (default, no pb mask).
1615
+ pbmask=0.2 (construct a mask at the 0.2 pb gain level).
1616
+ sidelobethreshold Sub-parameter for "auto-multithresh": mask threshold based on sidelobe levels: sidelobethreshold \* max_sidelobe_level \* peak residual.
1617
+ noisethreshold Sub-parameter for "auto-multithresh": mask threshold based on the noise level: noisethreshold \* rms + location (=median).
1618
+
1619
+ The rms is calculated from the median absolute deviation (MAD), with rms = 1.4826\*MAD.
1620
+ lownoisethreshold Sub-parameter for "auto-multithresh": mask threshold to grow previously masked regions via binary dilation: lownoisethreshold \* rms in residual image + location (=median).
1621
+
1622
+ The rms is calculated from the median absolute deviation (MAD), with rms = 1.4826\*MAD.
1623
+ negativethreshold Sub-parameter for "auto-multithresh": mask threshold for negative features: -1.0* negativethreshold \* rms + location(=median).
1624
+
1625
+ The rms is calculated from the median absolute deviation (MAD), with rms = 1.4826\*MAD.
1626
+ smoothfactor Sub-parameter for "auto-multithresh": smoothing factor in a unit of the beam.
1627
+ minbeamfrac Sub-parameter for "auto-multithresh": minimum beam fraction in size to prune masks smaller than mimbeamfrac \* beam
1628
+ <=0.0 : No pruning
1629
+ cutthreshold Sub-parameter for "auto-multithresh": threshold to cut the smoothed mask to create a final mask: cutthreshold \* peak of the smoothed mask.
1630
+ growiterations Sub-parameter for "auto-multithresh": Maximum number of iterations to perform using binary dilation for growing the mask.
1631
+ dogrowprune Experimental sub-parameter for "auto-multithresh": Do pruning on the grow mask.
1632
+ minpercentchange If the change in the mask size in a particular channel is less than minpercentchange, stop masking that channel in subsequent cycles. This check is only applied when noise based threshold is used and when the previous clean major cycle had a cyclethreshold value equal to the clean threshold. Values equal to -1.0 (or any value less than 0.0) will turn off this check (the default). Automask will still stop masking if the current channel mask is an empty mask and the noise threshold was used to determine the mask.
1633
+ verbose he summary of automasking at the end of each automasking process
1634
+ is printed in the logger. Following information per channel will be listed in the summary.
1635
+
1636
+ chan: channel number.
1637
+ masking?: F - stop updating automask for the subsequent iteration cycles.
1638
+ RMS: robust rms noise.
1639
+ peak: peak in residual image.
1640
+ thresh_type: type of threshold used (noise or sidelobe).
1641
+ thresh_value: the value of threshold used.
1642
+ N_reg: number of the automask regions.
1643
+ N_pruned: number of the automask regions removed by pruning.
1644
+ N_grow: number of the grow mask regions.
1645
+ N_grow_pruned: number of the grow mask regions removed by pruning.
1646
+ N_neg_pix: number of pixels for negative mask regions.
1647
+
1648
+ Note that for a large cube, extra logging may slow down the process.
1649
+ fastnoise Only relevant when automask (user='multi-autothresh') and/or n-sigma stopping threshold (nsigma>0.0) are/is used. If it is set to True, a simpler but faster noise calucation is used.
1650
+ In this case, the threshold values are determined based on classic statistics (using all
1651
+ unmasked pixels for the calculations).
1652
+
1653
+ If it is set to False, the new noise calculation
1654
+ method is used based on pre-existing mask.
1655
+
1656
+ Case 1: no exiting mask.
1657
+ Calculate image statistics using Chauvenet algorithm.
1658
+
1659
+ Case 2: there is an existing mask.
1660
+ Calculate image statistics by classical method on the region
1661
+ outside the mask and inside the primary beam mask.
1662
+
1663
+ In all cases above RMS noise is calculated from the median absolute deviation (MAD).
1664
+ restart images (and start from an existing model image)
1665
+ or automatically increment the image name and make a new image set.
1666
+
1667
+ True : Re-use existing images. If imagename.model exists the subsequent
1668
+ run will start from this model (i.e. predicting it using current gridder
1669
+ settings and starting from the residual image). Care must be taken
1670
+ when combining this option with startmodel. Currently, only one or
1671
+ the other can be used.
1672
+
1673
+ startmodel='', imagename.model exists :
1674
+ - Start from imagename.model.
1675
+ startmodel='xxx', imagename.model does not exist :
1676
+ - Start from startmodel.
1677
+ startmodel='xxx', imagename.model exists :
1678
+ - Exit with an error message requesting the user to pick
1679
+ only one model. This situation can arise when doing one
1680
+ run with startmodel='xxx' to produce an output
1681
+ imagename.model that includes the content of startmodel,
1682
+ and wanting to restart a second run to continue deconvolution.
1683
+ Startmodel should be set to '' before continuing.
1684
+
1685
+ If any change in the shape or coordinate system of the image is
1686
+ desired during the restart, please change the image name and
1687
+ use the startmodel (and mask) parameter(s) so that the old model
1688
+ (and mask) can be regridded to the new coordinate system before starting.
1689
+
1690
+ False : A convenience feature to increment imagename with '_1', '_2',
1691
+ etc as suffixes so that all runs of tclean are fresh starts (without
1692
+ having to change the imagename parameter or delete images).
1693
+
1694
+ This mode will search the current directory for all existing
1695
+ imagename extensions, pick the maximum, and adds 1.
1696
+ For imagename='try' it will make try.psf, try_2.psf, try_3.psf, etc.
1697
+
1698
+ This also works if you specify a directory name in the path :
1699
+ imagename='outdir/try'. If './outdir' does not exist, it will create it.
1700
+ Then it will search for existing filenames inside that directory.
1701
+
1702
+ If outlier fields are specified, the incrementing happens for each
1703
+ of them (since each has its own 'imagename'). The counters are
1704
+ synchronized across imagefields, to make it easier to match up sets
1705
+ of output images. It adds 1 to the 'max id' from all outlier names
1706
+ on disk. So, if you do two runs with only the main field
1707
+ (imagename='try'), and in the third run you add an outlier with
1708
+ imagename='outtry', you will get the following image names
1709
+ for the third run : 'try_3' and 'outtry_3' even though
1710
+ 'outry' and 'outtry_2' have not been used.
1711
+ savemodel Options to save model visibilities (none, virtual, modelcolumn).
1712
+
1713
+ Often, model visibilities must be created and saved in the MS
1714
+ to be later used for self-calibration (or to just plot and view them).
1715
+
1716
+ none : Do not save any model visibilities in the MS. The MS is opened
1717
+ in readonly mode.
1718
+
1719
+ Model visibilities can be predicted in a separate step by
1720
+ restarting tclean with niter=0,savemodel=virtual or modelcolumn
1721
+ and not changing any image names so that it finds the .model on
1722
+ disk (or by changing imagename and setting startmodel to the
1723
+ original imagename).
1724
+
1725
+ virtual : In the last major cycle, save the image model and state of the
1726
+ gridder used during imaging within the SOURCE subtable of the
1727
+ MS. Images required for de-gridding will also be stored internally.
1728
+ All future references to model visibilities will activate the
1729
+ (de)gridder to compute them on-the-fly. This mode is useful
1730
+ when the dataset is large enough that an additional model data
1731
+ column on disk may be too much extra disk I/O, when the
1732
+ gridder is simple enough that on-the-fly recomputing of the
1733
+ model visibilities is quicker than disk I/O.
1734
+ For e.g. that gridder='awproject' and 'awp2' does not support virtual model.
1735
+
1736
+ modelcolumn : In the last major cycle, save predicted model visibilities
1737
+ in the MODEL_DATA column of the MS. This mode is useful when
1738
+ the de-gridding cost to produce the model visibilities is higher
1739
+ than the I/O required to read the model visibilities from disk.
1740
+ This mode is currently required for gridder='awproject' and 'awp2'.
1741
+ This mode is also required for the ability to later pull out
1742
+ model visibilities from the MS into a python array for custom
1743
+ processing.
1744
+
1745
+ Note 1 : The imagename.model image on disk will always be constructed
1746
+ if the minor cycle runs. This savemodel parameter applies only to
1747
+ model visibilities created by de-gridding the model image.
1748
+
1749
+ Note 2 : It is possible for an MS to have both a virtual model
1750
+ as well as a model_data column, but under normal operation,
1751
+ the last used mode will get triggered. Use the delmod task to
1752
+ clear out existing models from an MS if confusion arises.
1753
+ Note 3: when parallel=True, use savemodel='none'; Other options are not yet ready
1754
+ for use in parallel. If model visibilities need to be saved (virtual or modelcolumn):
1755
+ please run tclean in serial mode with niter=0; after the parallel run
1756
+ calcres Calculate initial residual image.
1757
+
1758
+ This parameter controls what the first major cycle does.
1759
+
1760
+ calcres=False with niter greater than 0 will assume that
1761
+ a .residual image already exists and that the minor cycle can
1762
+ begin without recomputing it.
1763
+
1764
+ calcres=False with niter=0 implies that only the PSF will be made
1765
+ and no data will be gridded.
1766
+
1767
+ calcres=True requires that calcpsf=True or that the .psf and .sumwt
1768
+ images already exist on disk (for normalization purposes).
1769
+
1770
+ Usage example : For large runs (or a pipeline scripts) it may be
1771
+ useful to first run tclean with niter=0 to create
1772
+ an initial .residual to look at and perhaps make
1773
+ a custom mask for. Imaging can be resumed
1774
+ without recomputing it.
1775
+ calcpsf Calculate PSF
1776
+
1777
+ This parameter controls what the first major cycle does.
1778
+
1779
+ calcpsf=False will assume that a .psf image already exists
1780
+ and that the minor cycle can begin without recomputing it.
1781
+ psfcutoff When the .psf image is created a 2 dimensional Gaussian is fit to the main lobe of the PSF.
1782
+ Which pixels in the PSF are fitted is determined by psfcutoff.
1783
+ The default value of psfcutoff is 0.35 and can varied from 0.01 to 0.99.
1784
+ Fitting algorithm:
1785
+ - A region of 41 x 41 pixels around the peak of the PSF is compared against the psfcutoff.
1786
+ Sidelobes are ignored by radially searching from the PSF peak.
1787
+ - Calculate the bottom left corner (blc) and top right corner (trc) from the points. Expand blc and trc with a number of pixels (5).
1788
+ - Create a new sub-matrix from blc and trc.
1789
+ - Interpolate matrix to a target number of points (3001) using CUBIC spline.
1790
+ - All the non-sidelobe points, in the interpolated matrix, that are above the psfcutoff are used to fit a Gaussian.
1791
+ A Levenberg-Marquardt algorithm is used.
1792
+ - If the fitting fails the algorithm is repeated with the psfcutoff decreased (psfcutoff=psfcutoff/1.5).
1793
+ A message in the log will apear if the fitting fails along with the new value of psfcutoff.
1794
+ This will be done up to 50 times if fitting fails.
1795
+ This Gaussian beam is defined by a major axis, minor axis, and position angle.
1796
+ During the restoration process, this Gaussian beam is used as the Clean beam.
1797
+ Varying psfcutoff might be useful for producing a better fit for highly non-Gaussian PSFs, however, the resulting fits should be carefully checked.
1798
+ This parameter should rarely be changed.
1799
+
1800
+ (This is not the support size for clark clean.)
1801
+ parallel Run major cycles in parallel.
1802
+
1803
+ Parallel tclean will run only if casa has already been started using mpirun.
1804
+ Please refer to external resources on high performance computing for details on how to start this on your system.
1805
+
1806
+ Example : mpirun -n 3 -xterm 0 `which casa`
1807
+
1808
+ Continuum Imaging :
1809
+ - Data are partitioned (in time) into NProc pieces.
1810
+ - Gridding/iFT is done separately per partition.
1811
+ - Images (and weights) are gathered and then normalized.
1812
+ - One non-parallel minor cycle is run.
1813
+ - Model image is scattered to all processes.
1814
+ - Major cycle is done in parallel per partition.
1815
+
1816
+ Cube Imaging :
1817
+ - Data and Image coordinates are partitioned (in freq) into NProc pieces.
1818
+ - Each partition is processed independently (major and minor cycles).
1819
+ - All processes are synchronized at major cycle boundaries for convergence checks.
1820
+ - At the end, cubes from all partitions are concatenated along the spectral axis.
1821
+
1822
+ Note 1 : Iteration control for cube imaging is independent per partition.
1823
+ - There is currently no communication between them to synchronize
1824
+ information such as peak residual and cyclethreshold. Therefore,
1825
+ different chunks may trigger major cycles at different levels.
1826
+ (Proper synchronization of iteration control is work in progress.)
1827
+ RETURNS void
1828
+
1829
+ --------- examples -----------------------------------------------------------
1830
+
1831
+
1832
+
1833
+ For more information, see the task pages of tclean in CASA Docs:
1834
+
1835
+ https://casadocs.readthedocs.io
1836
+
1837
+
1838
+
1839
+
1840
+
1841
+ '''
1842
+ def __stop( self, _=None ):
1843
+ self.__result_future.set_result(self.__retrieve_result( ))
1844
+
1845
+ def _abort_handler( self, err ):
1846
+ self._error_result = err
1847
+ self.__stop( )
1848
+
1849
+ def __reset( self ):
1850
+ if self.__pipes_initialized:
1851
+ self._pipe = { 'control': None }
1852
+ self._clean = { 'converge': { 'state': { } }, 'last-success': None }
1853
+ reset_bokeh_output( )
1854
+ reset_resource_manager( )
1855
+
1856
+ ###
1857
+ ### reset asyncio result future
1858
+ ###
1859
+ self.__result_future = None
1860
+
1861
+ ###
1862
+ ### used by data pipe (websocket) initialization function
1863
+ ###
1864
+ self.__pipes_initialized = False
1865
+
1866
+ ###
1867
+ ### error or exception result
1868
+ ###
1869
+ self._error_result = None
1870
+
1871
+ '''
1872
+ _gen_port_fwd_cmd()
1873
+
1874
+ Create an SSH port-forwarding command to create the tunnels necessary for remote connection.
1875
+ NOTE: This assumes that the same remote ports are also available locally - which may
1876
+ NOT always be true.
1877
+ '''
1878
+ def _gen_port_fwd_cmd(self):
1879
+ hostname = os.uname()[1]
1880
+
1881
+ ###
1882
+ ### need to add extra cube ports here for multifield imaging
1883
+ ###
1884
+ ports = [ self._pipe['control'].address[1], self._clean['converge']['pipe'].address[1] ]
1885
+
1886
+ for imid, imdetails in self._clean_targets.items( ):
1887
+ ports.append( imdetails['gui']['cube']._pipe['image'].address[1] )
1888
+ ports.append( imdetails['gui']['cube']._pipe['control'].address[1] )
1889
+
1890
+ # Also forward http port if serving webpage
1891
+ if not self._is_notebook:
1892
+ ports.append(self._http_port)
1893
+
1894
+ cmd = 'ssh'
1895
+ for port in ports:
1896
+ cmd += (' -L ' + str(port) + ':localhost:' + str(port))
1897
+
1898
+ cmd += ' ' + str(hostname)
1899
+ return cmd
1900
+
1901
+ def _residual_path( self, gclean, imid ):
1902
+ if self._clean['gclean_paths'] is None:
1903
+ raise RuntimeError( f'''gclean paths are not available for {imid}''' )
1904
+ for p in self._clean['gclean_paths']:
1905
+ if p['name'] == imid:
1906
+ return f"{p['imagepath']}/{p['residualname']}"
1907
+ raise RuntimeError( f'''gclean residual path not found for {imid}''' )
1908
+
1909
+ def _mask_path( self, gclean, imid ):
1910
+ if self._clean['gclean_paths'] is None:
1911
+ raise RuntimeError( f'''gclean paths are not available for {imid}''' )
1912
+ for p in self._clean['gclean_paths']:
1913
+ if p['name'] == imid:
1914
+ return f"{p['imagepath']}/{p['maskname']}"
1915
+ raise RuntimeError( f'''gclean mask path not found for {imid}''' )
1916
+
1917
+ def __init__( self, vis, imagename, selectdata=True, field='', spw='', timerange='', uvrange='', antenna='', scan='', observation='', intent='', datacolumn='corrected', imsize=[ int(100) ], cell=[ ], phasecenter='', stokes='I', projection='SIN', startmodel='', specmode='mfs', reffreq='', nchan=int(-1), start='', width='', outframe='LSRK', veltype='radio', restfreq=[ ], interpolation='linear', perchanweightdensity=True, gridder='standard', facets=int(1), psfphasecenter='', wprojplanes=int(1), vptable='', mosweight=True, aterm=True, psterm=False, wbawp=True, conjbeams=False, cfcache='', usepointing=False, computepastep=float(360.0), rotatepastep=float(360.0), pointingoffsetsigdev=[ ], pblimit=float(0.2), normtype='flatnoise', deconvolver='hogbom', scales=[ ], nterms=int(2), smallscalebias=float(0.0), fusedthreshold=float(0.0), largestscale=int(-1), restoration=True, restoringbeam=[ ], pbcor=False, outlierfile='', weighting='natural', robust=float(0.5), noise='1.0Jy', npixels=int(0), uvtaper=[ '' ], niter=int(0), gain=float(0.1), threshold=float(0.0), nsigma=float(0.0), cycleniter=int(-1), cyclefactor=float(1.0), minpsffraction=float(0.05), maxpsffraction=float(0.8), nmajor=int(-1), usemask='user', mask='', pbmask=float(0.0), sidelobethreshold=float(3.0), noisethreshold=float(5.0), lownoisethreshold=float(1.5), negativethreshold=float(0.0), smoothfactor=float(1.0), minbeamfrac=float(0.3), cutthreshold=float(0.01), growiterations=int(75), dogrowprune=True, minpercentchange=float(-1.0), verbose=False, fastnoise=True, restart=True, savemodel='none', calcres=True, calcpsf=True, psfcutoff=float(0.35), parallel=False, iclean_backend="PROD" ):
1918
+
1919
+ ###
1920
+ ### iclean_backend can be used to select alternate backends for interactive clean. This could be used
1921
+ ### to enable a backend with extended features or it could be used to select a stub backend designed
1922
+ ### for testing
1923
+ ###
1924
+ mod_specs = None
1925
+ self._gclean_module = None
1926
+ if iclean_backend == 'PROD':
1927
+ mod_specs = find_pkg( "casatasks.private.imagerhelpers._gclean" )
1928
+ else:
1929
+ mod_specs = find_pkg( f"_gclean_{iclean_backend}" )
1930
+
1931
+ if mod_specs:
1932
+ self._gclean_module = load_pkg(mod_specs[0])
1933
+ else:
1934
+ raise ImportError(f"Could not locate {iclean_backend} kind of iclean backend")
1935
+
1936
+ ###
1937
+ ### With Bokeh 3.2.2, the spectrum and convergence plots extend beyond the edge of the
1938
+ ### browser window (requiring scrolling) if a width is not specified. It could be that
1939
+ ### this should be computed from the width of the tabbed control area at the right of
1940
+ ### the image display.
1941
+ ###
1942
+ self._conv_spect_plot_width = 450
1943
+ ###
1944
+ ### Create application context (which includes a temporary directory).
1945
+ ### This sets the title of the plot.
1946
+ ###
1947
+ self._app_state = AppContext( 'Interactive Clean' )
1948
+
1949
+ ###
1950
+ ### Whether or not the Interactive Clean session is running remotely
1951
+ ###
1952
+ #self._is_remote = remote
1953
+ self._is_remote = False
1954
+
1955
+ ###
1956
+ ### whether or not the session is being run from a jupyter notebook or script
1957
+ ###
1958
+ self._is_notebook = is_notebook()
1959
+
1960
+ ##
1961
+ ## the http port for serving GUI in webpage if not running in script
1962
+ ##
1963
+ self._http_port = None
1964
+
1965
+ ###
1966
+ ### the asyncio future that is used to transmit the result from interactive clean
1967
+ ###
1968
+ self.__result_future = None
1969
+
1970
+ ###
1971
+ ### This is used to tell whether the websockets have been initialized, but also to
1972
+ ### indicate if __call__ is being called multiple times to allow for resetting Bokeh
1973
+ ###
1974
+ self.__pipes_initialized = False
1975
+
1976
+ ###
1977
+ ### State required to manage iteration control
1978
+ ###
1979
+ self._control = { 'iteration': { } }
1980
+
1981
+ ###
1982
+ ### color specs
1983
+ ###
1984
+ self._converge_color = { 'residual': 'black',
1985
+ 'flux': 'forestgreen' }
1986
+
1987
+ ###
1988
+ ### widgets shared across image tabs (multifield imaging)
1989
+ ###
1990
+ self._cube_palette = None
1991
+ self._image_bitmask_controls = None
1992
+
1993
+ ###
1994
+ ### String which indicates the changes applied to the mask to indicte when
1995
+ ### the mask has changed... however, THIS IS NO LONGER USED
1996
+ ### It could be removed, but it adds minor overhead and would be
1997
+ ### DIFFICULT to add back in the future
1998
+ ###
1999
+ self._last_mask_breadcrumbs = ''
2000
+
2001
+ ###
2002
+ ### Set up dictionary of javascript code snippets
2003
+ ###
2004
+ self._initialize_javascript( )
2005
+
2006
+ # Create folder for the generated html webpage - needs its own folder to not name conflict (must be 'index.html')
2007
+ webpage_dirname = imagename + '_webpage'
2008
+ ### Directory is created when an HTTP server is running
2009
+ ### (MAX)
2010
+ # if not os.path.isdir(webpage_dirname):
2011
+ # os.makedirs(webpage_dirname)
2012
+ self._webpage_path = os.path.abspath(webpage_dirname)
2013
+
2014
+ self._pipe = { 'control': None }
2015
+ self._clean = { 'converge': { 'state': { } }, 'last-success': None }
2016
+
2017
+ self._clean_targets = { imagename: { 'args': {'vis': vis, 'selectdata': selectdata, 'field': field, 'spw': spw, 'timerange': timerange, 'uvrange': uvrange, 'antenna': antenna, 'scan': scan, 'observation': observation, 'intent': intent, 'datacolumn': datacolumn, 'imagename': imagename, 'imsize': imsize, 'cell': cell, 'phasecenter': phasecenter, 'stokes': stokes, 'projection': projection, 'startmodel': startmodel, 'specmode': specmode, 'reffreq': reffreq, 'nchan': nchan, 'start': start, 'width': width, 'outframe': outframe, 'veltype': veltype, 'restfreq': restfreq, 'interpolation': interpolation, 'perchanweightdensity': perchanweightdensity, 'gridder': gridder, 'facets': facets, 'psfphasecenter': psfphasecenter, 'wprojplanes': wprojplanes, 'vptable': vptable, 'mosweight': mosweight, 'aterm': aterm, 'psterm': psterm, 'wbawp': wbawp, 'conjbeams': conjbeams, 'cfcache': cfcache, 'usepointing': usepointing, 'computepastep': computepastep, 'rotatepastep': rotatepastep, 'pointingoffsetsigdev': pointingoffsetsigdev, 'pblimit': pblimit, 'normtype': normtype, 'deconvolver': deconvolver, 'scales': scales, 'nterms': nterms, 'smallscalebias': smallscalebias, 'fusedthreshold': fusedthreshold, 'largestscale': largestscale, 'restoration': restoration, 'restoringbeam': restoringbeam, 'pbcor': pbcor, 'outlierfile': outlierfile, 'weighting': weighting, 'robust': robust, 'noise': noise, 'npixels': npixels, 'uvtaper': uvtaper, 'niter': niter, 'gain': gain, 'threshold': threshold, 'nsigma': nsigma, 'cycleniter': cycleniter, 'cyclefactor': cyclefactor, 'minpsffraction': minpsffraction, 'maxpsffraction': maxpsffraction, 'nmajor': nmajor, 'usemask': usemask, 'mask': mask, 'pbmask': pbmask, 'sidelobethreshold': sidelobethreshold, 'noisethreshold': noisethreshold, 'lownoisethreshold': lownoisethreshold, 'negativethreshold': negativethreshold, 'smoothfactor': smoothfactor, 'minbeamfrac': minbeamfrac, 'cutthreshold': cutthreshold, 'growiterations': growiterations, 'dogrowprune': dogrowprune, 'minpercentchange': minpercentchange, 'verbose': verbose, 'fastnoise': fastnoise, 'restart': restart, 'savemodel': savemodel, 'calcres': calcres, 'calcpsf': calcpsf, 'psfcutoff': psfcutoff, 'parallel': parallel} } }
2018
+ self._initial_clean_params = { }
2019
+
2020
+ self._parameters = ImagerParameters( **{ k:v for k,v in self._clean_targets[imagename]['args'].items( )
2021
+ if k in ImagerParameters.__init__.__code__.co_varnames[1:] } )
2022
+
2023
+ ###
2024
+ ### For 6.6.5, outliers are not yet completely implemented so the
2025
+ ### 'outlierfile' parameter may not be present.
2026
+ ###
2027
+ if 'outlierfile' in locals( ) and outlierfile and exists(outlierfile):
2028
+ outliers, err = self._parameters.parseOutlierFile(outlierfile)
2029
+ if err: raise RuntimeError( f'''outlierfile error: {err}''' )
2030
+ for image in outliers:
2031
+ if 'impars' in image and 'imagename' in image['impars']:
2032
+ name = image['impars']['imagename']
2033
+ self._clean_targets[name] = { }
2034
+ args = {'vis': vis, 'selectdata': selectdata, 'field': field, 'spw': spw, 'timerange': timerange, 'uvrange': uvrange, 'antenna': antenna, 'scan': scan, 'observation': observation, 'intent': intent, 'datacolumn': datacolumn, 'imagename': imagename, 'imsize': imsize, 'cell': cell, 'phasecenter': phasecenter, 'stokes': stokes, 'projection': projection, 'startmodel': startmodel, 'specmode': specmode, 'reffreq': reffreq, 'nchan': nchan, 'start': start, 'width': width, 'outframe': outframe, 'veltype': veltype, 'restfreq': restfreq, 'interpolation': interpolation, 'perchanweightdensity': perchanweightdensity, 'gridder': gridder, 'facets': facets, 'psfphasecenter': psfphasecenter, 'wprojplanes': wprojplanes, 'vptable': vptable, 'mosweight': mosweight, 'aterm': aterm, 'psterm': psterm, 'wbawp': wbawp, 'conjbeams': conjbeams, 'cfcache': cfcache, 'usepointing': usepointing, 'computepastep': computepastep, 'rotatepastep': rotatepastep, 'pointingoffsetsigdev': pointingoffsetsigdev, 'pblimit': pblimit, 'normtype': normtype, 'deconvolver': deconvolver, 'scales': scales, 'nterms': nterms, 'smallscalebias': smallscalebias, 'fusedthreshold': fusedthreshold, 'largestscale': largestscale, 'restoration': restoration, 'restoringbeam': restoringbeam, 'pbcor': pbcor, 'outlierfile': outlierfile, 'weighting': weighting, 'robust': robust, 'noise': noise, 'npixels': npixels, 'uvtaper': uvtaper, 'niter': niter, 'gain': gain, 'threshold': threshold, 'nsigma': nsigma, 'cycleniter': cycleniter, 'cyclefactor': cyclefactor, 'minpsffraction': minpsffraction, 'maxpsffraction': maxpsffraction, 'nmajor': nmajor, 'usemask': usemask, 'mask': mask, 'pbmask': pbmask, 'sidelobethreshold': sidelobethreshold, 'noisethreshold': noisethreshold, 'lownoisethreshold': lownoisethreshold, 'negativethreshold': negativethreshold, 'smoothfactor': smoothfactor, 'minbeamfrac': minbeamfrac, 'cutthreshold': cutthreshold, 'growiterations': growiterations, 'dogrowprune': dogrowprune, 'minpercentchange': minpercentchange, 'verbose': verbose, 'fastnoise': fastnoise, 'restart': restart, 'savemodel': savemodel, 'calcres': calcres, 'calcpsf': calcpsf, 'psfcutoff': psfcutoff, 'parallel': parallel}
2035
+ args['outlierfile'] = '' ### >>HERE>> outlierfile TEMPORARILY handled in _interactiveclean.py
2036
+ for _,arg_mods in image.items( ):
2037
+ for k,v in arg_mods.items( ):
2038
+ if k in args:
2039
+ args[k] = v
2040
+ self._clean_targets[name]['args'] = args
2041
+
2042
+ ###
2043
+ ### create clean interface -- final version will have only one gclean object
2044
+ ###
2045
+ self._init_values = { "deconvolver": deconvolver, ### used by _residual_path( )
2046
+ "cycleniter": cycleniter, ### used by _setup( )
2047
+ "threshold": threshold, ### used by _setup( )
2048
+ "cyclefactor": cyclefactor, ### used by _setup( )
2049
+ "gain": gain, ### used by _setup( )
2050
+ "nsigma": nsigma, ### used by _setup( )
2051
+ "convergence_state": { 'convergence': {}, ### shares state between
2052
+ 'cyclethreshold': {} } } ### __init__( ) and _setup( )
2053
+
2054
+ self._clean['gclean'] = None
2055
+ self._clean['gclean_paths'] = None
2056
+ self._clean['imid'] = [ ]
2057
+ self._clean['gclean_rest'] = [ ]
2058
+ for imid, imdetails in self._clean_targets.items( ):
2059
+ self._clean['imid'].append(imid)
2060
+
2061
+ ###
2062
+ ### Residual path...
2063
+ ###
2064
+ if 'path' not in imdetails: imdetails['path'] = { }
2065
+ if self._clean['gclean'] is None:
2066
+
2067
+ self._clean['gclean'] = self._gclean_module.gclean( **imdetails['args'] )
2068
+ self._clean['gclean_paths'] = self._clean['gclean'].image_products( )
2069
+
2070
+ imdetails['path']['residual'] = self._residual_path(self._clean['gclean'],imid)
2071
+ imdetails['path']['mask'] = self._mask_path(self._clean['gclean'],imid)
2072
+
2073
+ else:
2074
+
2075
+ imdetails['path']['residual'] = self._residual_path(self._clean['gclean'],imid)
2076
+ imdetails['path']['mask'] = self._mask_path(self._clean['gclean'],imid)
2077
+
2078
+ for idx, (imid, imdetails) in enumerate(self._clean_targets.items( )):
2079
+ imdetails['gui'] = { }
2080
+
2081
+ imdetails['gui'] = { 'params': { 'iteration': { }, 'automask': { } },
2082
+ 'image': { },
2083
+ 'image-adjust': { } }
2084
+
2085
+ ###
2086
+ ### Only the first image should initialize the initial convergence state
2087
+ ###
2088
+ imdetails['gui']['cube'] = CubeMask( imdetails['path']['residual'], mask=imdetails['path']['mask'], abort=self._abort_handler,
2089
+ init_script=CustomJS( args=dict( initial_convergence_state=self._init_values["convergence_state"],
2090
+ name=imid ),
2091
+ code='''document._casa_convergence_data = initial_convergence_state''' )
2092
+ if idx == 0 else None )
2093
+
2094
+ ###
2095
+ ### Auto Masking Parameters
2096
+ ###
2097
+ imdetails['params'] = { }
2098
+ imdetails['params']['am'] = { }
2099
+ imdetails['params']['am']['usemask'] = usemask
2100
+ imdetails['params']['am']['noisethreshold'] = noisethreshold
2101
+ imdetails['params']['am']['sidelobethreshold'] = sidelobethreshold
2102
+ imdetails['params']['am']['lownoisethreshold'] = lownoisethreshold
2103
+ imdetails['params']['am']['minbeamfrac'] = minbeamfrac
2104
+ imdetails['params']['am']['negativethreshold'] = negativethreshold
2105
+ imdetails['params']['am']['dogrowprune'] = dogrowprune
2106
+ imdetails['params']['am']['fastnoise'] = fastnoise
2107
+
2108
+ def _init_pipes( self ):
2109
+ if not self.__pipes_initialized:
2110
+ self.__pipes_initialized = True
2111
+ self._pipe['control'] = DataPipe( address=find_ws_address( ), abort=self._abort_handler )
2112
+ ###
2113
+ ### One pipe for updating the convergence plots.
2114
+ ###
2115
+ self._clean['converge'] = { 'state': None }
2116
+ self._clean['converge']['pipe'] = DataPipe( address=find_ws_address( ), abort=self._abort_handler )
2117
+ self._clean['converge']['id'] = str(uuid4( ))
2118
+
2119
+
2120
+
2121
+ # Get port for serving HTTP server if running in script
2122
+ self._http_port = find_ws_address("")[1]
2123
+ for imid, imdetails in self._clean_targets.items( ):
2124
+ imdetails['gui']['cube']._init_pipes( )
2125
+
2126
+ def _create_convergence_gui( self, imdetails, orient='horizontal', sizing_mode='stretch_width', **kw ):
2127
+ TOOLTIPS='''<div>
2128
+ <div>
2129
+ <span style="font-weight: bold;">@type</span>
2130
+ <span>@values</span>
2131
+ </div>
2132
+ <div>
2133
+ <span style="font-weight: bold; font-size: 10px">cycle threshold</span>
2134
+ <span>@cyclethreshold</span>
2135
+ </div>
2136
+ <div>
2137
+ <span style="font-weight: bold; font-size: 10px">stop</span>
2138
+ <span>@stopDesc</span>
2139
+ </div>
2140
+ </div>'''
2141
+
2142
+ hover = HoverTool( tooltips=TOOLTIPS )
2143
+ imdetails['gui']['convergence'] = figure( sizing_mode=sizing_mode, y_axis_location="right",
2144
+ tools=[ hover ], toolbar_location=None, **kw )
2145
+
2146
+ if orient == 'vertical':
2147
+ imdetails['gui']['convergence'].yaxis.axis_label='Iteration (cycle threshold dotted red)'
2148
+ imdetails['gui']['convergence'].xaxis.axis_label='Peak Residual'
2149
+ imdetails['gui']['convergence'].extra_x_ranges = { 'residual_range': DataRange1d( follow='end' ),
2150
+ 'flux_range': DataRange1d( follow='end' ) }
2151
+
2152
+ imdetails['gui']['convergence'].step( 'values', 'iterations', source=imdetails['converge-data']['cyclethreshold'],
2153
+ line_color='red', x_range_name='residual_range', line_dash='dotted', line_width=2 )
2154
+ imdetails['gui']['convergence'].line( 'values', 'iterations', source=imdetails['converge-data']['residual'],
2155
+ line_color=self._converge_color['residual'], x_range_name='residual_range' )
2156
+ imdetails['gui']['convergence'].scatter( 'values', 'iterations', source=imdetails['converge-data']['residual'],
2157
+ color=self._converge_color['residual'], x_range_name='residual_range',size=10 )
2158
+ imdetails['gui']['convergence'].line( 'values', 'iterations', source=imdetails['converge-data']['flux'],
2159
+ line_color=self._converge_color['flux'], x_range_name='flux_range' )
2160
+ imdetails['gui']['convergence'].scatter( 'values', 'iterations', source=imdetails['converge-data']['flux'],
2161
+ color=self._converge_color['flux'], x_range_name='flux_range', size=10 )
2162
+
2163
+ imdetails['gui']['convergence'].add_layout( LinearAxis( x_range_name='flux_range', axis_label='Total Flux',
2164
+ axis_line_color=self._converge_color['flux'],
2165
+ major_label_text_color=self._converge_color['flux'],
2166
+ axis_label_text_color=self._converge_color['flux'],
2167
+ major_tick_line_color=self._converge_color['flux'],
2168
+ minor_tick_line_color=self._converge_color['flux'] ), 'above')
2169
+
2170
+ else:
2171
+ imdetails['gui']['convergence'].xaxis.axis_label='Iteration (cycle threshold dotted red)'
2172
+ imdetails['gui']['convergence'].yaxis.axis_label='Peak Residual'
2173
+ imdetails['gui']['convergence'].extra_y_ranges = { 'residual_range': DataRange1d( follow='end' ),
2174
+ 'flux_range': DataRange1d( follow='end' ) }
2175
+
2176
+ imdetails['gui']['convergence'].step( 'iterations', 'values', source=imdetails['converge-data']['cyclethreshold'],
2177
+ line_color='red', y_range_name='residual_range', line_dash='dotted', line_width=2 )
2178
+ imdetails['gui']['convergence'].line( 'iterations', 'values', source=imdetails['converge-data']['residual'],
2179
+ line_color=self._converge_color['residual'], y_range_name='residual_range' )
2180
+ imdetails['gui']['convergence'].scatter( 'iterations', 'values', source=imdetails['converge-data']['residual'],
2181
+ color=self._converge_color['residual'], y_range_name='residual_range',size=10 )
2182
+ imdetails['gui']['convergence'].line( 'iterations', 'values', source=imdetails['converge-data']['flux'],
2183
+ line_color=self._converge_color['flux'], y_range_name='flux_range' )
2184
+ imdetails['gui']['convergence'].scatter( 'iterations', 'values', source=imdetails['converge-data']['flux'],
2185
+ color=self._converge_color['flux'], y_range_name='flux_range', size=10 )
2186
+
2187
+ imdetails['gui']['convergence'].add_layout( LinearAxis( y_range_name='flux_range', axis_label='Total Flux',
2188
+ axis_line_color=self._converge_color['flux'],
2189
+ major_label_text_color=self._converge_color['flux'],
2190
+ axis_label_text_color=self._converge_color['flux'],
2191
+ major_tick_line_color=self._converge_color['flux'],
2192
+ minor_tick_line_color=self._converge_color['flux'] ), 'right')
2193
+
2194
+
2195
+ def _launch_gui( self ):
2196
+ '''create and show GUI
2197
+ '''
2198
+ ###
2199
+ ### Will contain the top level GUI
2200
+ ###
2201
+ self._fig = { }
2202
+
2203
+ ###
2204
+ ### Python-side handler for events from the interactive clean control buttons
2205
+ ###
2206
+ async def clean_handler( msg, self=self ):
2207
+ if msg['action'] == 'next' or msg['action'] == 'finish':
2208
+
2209
+ if 'mask' in msg['value']:
2210
+ ###
2211
+ ### >>HERE>> breadcrumbs must be specific to the field they are related to...
2212
+ ###
2213
+ if 'breadcrumbs' in msg['value'] and msg['value']['breadcrumbs'] is not None and msg['value']['breadcrumbs'] != self._last_mask_breadcrumbs:
2214
+ self._last_mask_breadcrumbs = msg['value']['breadcrumbs']
2215
+ mask_dir = "%s.mask" % self._imagename
2216
+ shutil.rmtree(mask_dir)
2217
+ new_mask = imdetails['gui']['cube'].jsmask_to_raw(msg['value']['mask'])
2218
+ self._mask_history.append(new_mask)
2219
+
2220
+ msg['value']['mask'] = convert_masks(masks=new_mask, coord='pixel', cdesc=imdetails['gui']['cube'].coorddesc())
2221
+
2222
+ else:
2223
+ ##### seemingly the mask path used to be spliced in?
2224
+ #msg['value']['mask'] = self._mask_path
2225
+ pass
2226
+ else:
2227
+ ##### seemingly the mask path used to be spliced in?
2228
+ #msg['value']['mask'] = self._mask_path
2229
+ pass
2230
+
2231
+ ###
2232
+ ### In the final implementation, there will only be one gclean object...
2233
+ ###
2234
+ convergence_state={ 'convergence': {}, 'cyclethreshold': {} }
2235
+ err,errmsg = self._clean['gclean'].update( dict( **msg['value']['iteration'],
2236
+ **msg['value']['automask'] ) )
2237
+
2238
+ iteration_limit = int(msg['value']['iteration']['niter'])
2239
+ stopdesc, stopcode, majordone, majorleft, iterleft, self._convergence_data = await self._clean['gclean'].__anext__( )
2240
+
2241
+ clean_cmds = self._clean['gclean'].cmds( )
2242
+
2243
+ for key, value in self._convergence_data.items( ):
2244
+
2245
+ if len(value['chan']) == 0 or stopcode[0] == -1:
2246
+ ### stopcode[0] == -1 indicates an error condition within gclean
2247
+ return dict( result='error', stopcode=stopcode, cmd=clean_cmds,
2248
+ convergence=None, majordone=majordone,
2249
+ majorleft=majorleft, iterleft=iterleft, stopdesc=stopdesc )
2250
+
2251
+ convergence_state['convergence'][key] = value['chan']
2252
+ convergence_state['cyclethreshold'][key] = value['major']['cyclethreshold']
2253
+
2254
+ ### stopcode[0] != 0 indicates that some stopping criteria has been reached
2255
+ ### this will also catch errors as well as convergence
2256
+ ### (so 'converged' isn't quite right...)
2257
+ self._clean['last-success'] = dict( result='converged' if stopcode[0] else 'update', stopcode=stopcode, cmd=clean_cmds,
2258
+ convergence=convergence_state['convergence'],
2259
+ iterdone=iteration_limit - iterleft, iterleft=iterleft,
2260
+ majordone=majordone, majorleft=majorleft, cyclethreshold=convergence_state['cyclethreshold'], stopdesc=stopdesc )
2261
+ return self._clean['last-success']
2262
+
2263
+ elif msg['action'] == 'stop':
2264
+ self.__stop( )
2265
+ return dict( result='stopped', update=dict( ) )
2266
+ elif msg['action'] == 'status':
2267
+ return dict( result="ok", update=dict( ) )
2268
+ else:
2269
+ print( "got something else: '%s'" % msg['action'] )
2270
+
2271
+ ###
2272
+ ### set up websockets which will be used for control and convergence updates
2273
+ ###
2274
+ self._init_pipes( )
2275
+
2276
+ ###
2277
+ ### Setup id that will be used for messages from each button
2278
+ ###
2279
+ self._clean_ids = { }
2280
+ for btn in "continue", 'finish', 'stop':
2281
+ self._clean_ids[btn] = str(uuid4( ))
2282
+ #print("%s: %s" % ( btn, self._clean_ids[btn] ) )
2283
+ self._pipe['control'].register( self._clean_ids[btn], clean_handler )
2284
+
2285
+
2286
+ ###
2287
+ ### There is one set of tclean controls for all images/outlier/etc. because
2288
+ ### in the final version gclean will handle the iterations for all fields...
2289
+ ###
2290
+ cwidth = 64
2291
+ cheight = 40
2292
+ self._control['iteration'] = { }
2293
+ self._control['iteration']['continue'] = TipButton( max_width=cwidth, max_height=cheight, name='continue',
2294
+ icon=svg_icon(icon_name="iclean-continue", size=18),
2295
+ tooltip=Tooltip( content=HTML( '''Stop after <b>one major cycle</b> or when any stopping criteria is met.''' ), position='left') )
2296
+ self._control['iteration']['finish'] = TipButton( max_width=cwidth, max_height=cheight, name='finish',
2297
+ icon=svg_icon(icon_name="iclean-finish", size=18),
2298
+ tooltip=Tooltip( content=HTML( '''<b>Continue</b> until some stopping criteria is met.''' ), position='left') )
2299
+ self._control['iteration']['stop'] = TipButton( button_type="danger", max_width=cwidth, max_height=cheight, name='stop',
2300
+ icon=svg_icon(icon_name="iclean-stop", size=18),
2301
+ 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' ) )
2302
+
2303
+ ###
2304
+ ### The single SHARED help button will be supplied by the first CubeMask...
2305
+ ###
2306
+ help_button = None
2307
+ ###
2308
+ ### First status line will be reused...
2309
+ ###
2310
+ status_line = None
2311
+
2312
+ ###
2313
+ ### Manage the widgets which are shared between tabs...
2314
+ ###
2315
+ icw = SharedWidgets( )
2316
+ toolbars = [ ]
2317
+ for imid, imdetails in self._clean_targets.items( ):
2318
+ imdetails['gui']['stats'] = imdetails['gui']['cube'].statistics( )
2319
+ imdetails['image-channels'] = imdetails['gui']['cube'].shape( )[3]
2320
+
2321
+ 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 )
2322
+
2323
+ ###
2324
+ ### Retrieve convergence information
2325
+ ###
2326
+ def convergence_handler( msg, self=self, imid=imid ):
2327
+ if msg['action'] == 'retrieve':
2328
+ return { 'result': self._clean['last-success'] }
2329
+ else:
2330
+ return { 'result': None, 'error': 'unrecognized action' }
2331
+
2332
+ self._clean['converge']['pipe'].register( self._clean['converge']['id'], convergence_handler )
2333
+
2334
+ ###
2335
+ ### Data source that will be used for updating the convergence plot
2336
+ ###
2337
+ stokes = 0
2338
+ convergence = imdetails['converge']['chan'][0][stokes]
2339
+ imdetails['converge-data'] = { }
2340
+ imdetails['converge-data']['flux'] = ColumnDataSource( data=dict( values=convergence['modelFlux'], iterations=convergence['iterations'],
2341
+ cyclethreshold=convergence['cycleThresh'],
2342
+ stopDesc=list( map( ImagingDict.get_summaryminor_stopdesc, convergence['stopCode'] ) ),
2343
+ type=['flux'] * len(convergence['iterations']) ) )
2344
+ imdetails['converge-data']['residual'] = ColumnDataSource( data=dict( values=convergence['peakRes'], iterations=convergence['iterations'],
2345
+ cyclethreshold=convergence['cycleThresh'],
2346
+ stopDesc=list( map( ImagingDict.get_summaryminor_stopdesc, convergence['stopCode'] ) ),
2347
+ type=['residual'] * len(convergence['iterations'])) )
2348
+ imdetails['converge-data']['cyclethreshold'] = ColumnDataSource( data=dict( values=convergence['cycleThresh'], iterations=convergence['iterations'] ) )
2349
+
2350
+
2351
+ ###
2352
+ ### help page for cube interactions
2353
+ ###
2354
+ if help_button is None:
2355
+ 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>',
2356
+ '<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' )
2357
+
2358
+ self._create_convergence_gui( imdetails, orient='horizontal', sizing_mode='stretch_height', width=self._conv_spect_plot_width )
2359
+
2360
+ imdetails['gui']['params']['iteration']['nmajor'] = icw.nmajor( title='nmajor', value="%s" % self._initial_clean_params['nmajor'], width=90 )
2361
+ imdetails['gui']['params']['iteration']['niter'] = icw.niter( title='niter', value="%s" % self._initial_clean_params['niter'], width=90 )
2362
+ imdetails['gui']['params']['iteration']['cycleniter'] = icw.cycleniter( title="cycleniter", value="%s" % self._initial_clean_params['cycleniter'], width=90 )
2363
+ imdetails['gui']['params']['iteration']['threshold'] = icw.threshold( title="threshold", value="%s" % self._initial_clean_params['threshold'], width=90 )
2364
+ imdetails['gui']['params']['iteration']['cyclefactor'] = icw.cyclefactor( value="%s" % self._initial_clean_params['cyclefactor'], title="cyclefactor", width=90 )
2365
+ imdetails['gui']['params']['iteration']['gain'] = icw.gain( title='gain', value="%s" % self._initial_clean_params['gain'], width=90 )
2366
+ imdetails['gui']['params']['iteration']['nsigma'] = icw.nsigma( title='nsigma', value="%s" % self._initial_clean_params['nsigma'], width=90 )
2367
+
2368
+ if imdetails['params']['am']['usemask'] == 'auto-multithresh':
2369
+ ###
2370
+ ### Currently automasking tab is only available when the user selects 'auto-multithresh'
2371
+ ###
2372
+ imdetails['gui']['params']['automask']['active'] = True
2373
+ imdetails['gui']['params']['automask']['noisethreshold'] = icw.noisethreshold( title='noisethreshold', value="%s" % imdetails['params']['am']['noisethreshold'], margin=( 5, 25, 5, 5 ), width=90 )
2374
+ imdetails['gui']['params']['automask']['sidelobethreshold'] = icw.sidelobethreshold( title='sidelobethreshold', value="%s" % imdetails['params']['am']['sidelobethreshold'], margin=( 5, 25, 5, 5 ), width=90 )
2375
+ imdetails['gui']['params']['automask']['lownoisethreshold'] = icw.lownoisethreshold( title='lownoisethreshold', value="%s" % imdetails['params']['am']['lownoisethreshold'], margin=( 5, 25, 5, 5 ), width=90 )
2376
+ imdetails['gui']['params']['automask']['minbeamfrac'] = icw.minbeamfrac( title='minbeamfrac', value="%s" % imdetails['params']['am']['minbeamfrac'], width=90 )
2377
+ imdetails['gui']['params']['automask']['negativethreshold'] = icw.negativethreshold( title='negativethreshold', value="%s" % imdetails['params']['am']['negativethreshold'], margin=( 5, 25, 5, 5 ), width=90 )
2378
+ imdetails['gui']['params']['automask']['dogrowprune'] = icw.dogrowprune( label='dogrowprune', active=imdetails['params']['am']['dogrowprune'], margin=( 15, 25, 5, 5 ) )
2379
+ imdetails['gui']['params']['automask']['fastnoise'] = icw.fastnoise( label='fastnoise', active=imdetails['params']['am']['fastnoise'], margin=( 15, 25, 5, 5 ) )
2380
+
2381
+
2382
+ imdetails['gui']['image']['src'] = imdetails['gui']['cube'].js_obj( )
2383
+ imdetails['gui']['image']['fig'] = imdetails['gui']['cube'].image( grid=False, height_policy='max', width_policy='max',
2384
+ channelcb=CustomJS( args=dict( img_state={ 'src': imdetails['gui']['image']['src'],
2385
+ 'flux': imdetails['converge-data']['flux'],
2386
+ 'residual': imdetails['converge-data']['residual'],
2387
+ 'cyclethreshold': imdetails['converge-data']['cyclethreshold'] },
2388
+ imid=imid,
2389
+ ctrl={ 'converge': self._clean['converge'] },
2390
+ stopdescmap=ImagingDict.get_summaryminor_stopdesc( ) ),
2391
+ code=self._js['update-converge'] +
2392
+ '''update_convergence_single( img_state, document._casa_convergence_data.convergence[imid] )''' ) )
2393
+
2394
+ ###
2395
+ ### collect toolbars for syncing selection
2396
+ ###
2397
+ toolbars.append(imdetails['gui']['image']['fig'].toolbar)
2398
+
2399
+ ###
2400
+ ### spectrum plot must be disabled during iteration due to "tap to change channel" functionality
2401
+ ###
2402
+ if imdetails['image-channels'] > 1:
2403
+ imdetails['gui']['spectrum'] = imdetails['gui']['cube'].spectrum( orient='vertical', sizing_mode='stretch_height', width=self._conv_spect_plot_width )
2404
+ imdetails['gui']['slider'] = imdetails['gui']['cube'].slider( show_value=False, title='', margin=(14,5,5,5), sizing_mode="scale_width" )
2405
+ imdetails['gui']['goto'] = imdetails['gui']['cube'].goto( )
2406
+ else:
2407
+ imdetails['gui']['spectrum'] = None
2408
+ imdetails['gui']['slider'] = None
2409
+ imdetails['gui']['goto'] = None
2410
+
2411
+ imdetails['gui']['channel-ctrl'] = imdetails['gui']['cube'].channel_ctrl( )
2412
+
2413
+ imdetails['gui']['cursor-pixel-text'] = imdetails['gui']['cube'].pixel_tracking_text( margin=(-3, 5, 3, 30) )
2414
+
2415
+ self._image_bitmask_controls = imdetails['gui']['cube'].bitmask_ctrl( reuse=self._image_bitmask_controls, button_type='light' )
2416
+
2417
+ if imdetails['params']['am']['usemask'] == 'auto-multithresh':
2418
+ imdetails['gui']['auto-masking-panel'] = [ TabPanel( child=column( row( Tip( imdetails['gui']['params']['automask']['noisethreshold'],
2419
+ tooltip=Tooltip( content=HTML( 'sets the signal-to-noise threshold above which significant emission is masked during the initial round of mask creation' ),
2420
+ position='bottom' ) ),
2421
+ Tip( imdetails['gui']['params']['automask']['sidelobethreshold'],
2422
+ 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' ),
2423
+ position='bottom' ) ),
2424
+ Tip( imdetails['gui']['params']['automask']['minbeamfrac'],
2425
+ tooltip=Tooltip( content=HTML( 'sets the minimum size a region must be to be retained in the mask' ),
2426
+ position='bottom' ) ) ),
2427
+ row( Tip( imdetails['gui']['params']['automask']['lownoisethreshold'],
2428
+ 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' ),
2429
+ position='bottom' ) ),
2430
+ Tip( imdetails['gui']['params']['automask']['negativethreshold'],
2431
+ tooltip=Tooltip( content=HTML( 'sets the signal-to-noise threshold for absorption features to be masked' ),
2432
+ position='bottom' ) ) ),
2433
+ row( Tip( imdetails['gui']['params']['automask']['dogrowprune'],
2434
+ 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' ),
2435
+ position='bottom' ) ),
2436
+ Tip( imdetails['gui']['params']['automask']['fastnoise'],
2437
+ tooltip=Tooltip( content=HTML( 'When set to True, a simpler but faster noise calucation is used' ),
2438
+ position='bottom' ) ) ) ),
2439
+ title='Automask' ) ]
2440
+ else:
2441
+ imdetails['gui']['auto-masking-panel'] = [ ]
2442
+
2443
+
2444
+ ###
2445
+ ### synchronize toolbar selections among figures
2446
+ ###
2447
+ if toolbars:
2448
+ for tb in toolbars:
2449
+ tb.js_on_change( 'active_changed',
2450
+ ###
2451
+ ### toolbars must filter out 'tb' to avoid circular references
2452
+ ###
2453
+ CustomJS( args=dict(toolbars=[t for t in toolbars if t.id != tb.id]),
2454
+ code='''casalib.map( (gest,tool) => {
2455
+ if ( tool.active ) {
2456
+ // a tool which belongs to the toolbar that signaled a change
2457
+ // is active for this gesture...
2458
+ toolbars.forEach( (other_tb) => {
2459
+ let new_active = other_tb.gestures[gest].tools.find(
2460
+ (t) => t.name == tool.active.name )
2461
+ if ( ! other_tb.gestures[gest].active ) {
2462
+ if ( new_active ) {
2463
+ other_tb.gestures[gest].active = new_active
2464
+ new_active.active = true
2465
+ }
2466
+ } else if ( other_tb.gestures[gest].active.name != tool.active.name ) {
2467
+ if ( new_active ) {
2468
+ other_tb.gestures[gest].active.active = false
2469
+ new_active.active = true
2470
+ other_tb.gestures[gest].active = new_active
2471
+ }
2472
+ }
2473
+ } )
2474
+ } else {
2475
+ // a tool which belongs to the toolbar that signaled a change
2476
+ // is NOT active for this gesture...
2477
+ toolbars.forEach( (other_tb) => {
2478
+ if ( other_tb.gestures[gest] && other_tb.gestures[gest].active ) {
2479
+ other_tb.gestures[gest].active.active = false
2480
+ other_tb.gestures[gest].active = null
2481
+ }
2482
+ } )
2483
+ }
2484
+ }, cb_obj.gestures )''' ) )
2485
+
2486
+ ###
2487
+ ### button to display the tclean log -- in the final implmentation, outliers and other multifield imaging should be handled by gclean
2488
+ ###
2489
+ self._log_button = TipButton( max_width=help_button.width, max_height=help_button.height, name='log',
2490
+ icon=svg_icon(icon_name="bp-application-sm", size=25),
2491
+ tooltip=Tooltip( content=HTML('''click here to see the <pre>tclean</pre> execution log'''), position="right" ),
2492
+ margin=(-1, 0, -10, 0), button_type='light',
2493
+ stylesheets=[ InlineStyleSheet( css='''.bk-btn { border: 0px solid #ccc; padding: 0 var(--padding-vertical) var(--padding-horizontal); margin-top: 3px; }''' ) ] )
2494
+
2495
+ self._control['iteration']['cb'] = CustomJS( args=dict( images_state={ k: { 'status': v['gui']['stopcode'],
2496
+ 'automask': v['gui']['params']['automask'],
2497
+ 'iteration': v['gui']['params']['iteration'],
2498
+ 'img': v['gui']['image']['fig'],
2499
+ 'src': v['gui']['cube'].js_obj( ),
2500
+ 'spectrum': v['gui']['spectrum'],
2501
+ 'src': v['gui']['image']['src'],
2502
+ 'flux': v['converge-data']['flux'],
2503
+ 'cyclethreshold': v['converge-data']['cyclethreshold'],
2504
+ 'residual': v['converge-data']['residual'],
2505
+ 'navi': { 'slider': v['gui']['slider'],
2506
+ 'goto': v['gui']['goto'],
2507
+ ## it doesn't seem like pixel tracking must be disabled
2508
+ ##'tracking': v['gui']['cursor-pixel-text'],
2509
+ 'stokes': v['gui']['channel-ctrl'][1] } }
2510
+ for k,v in self._clean_targets.items( ) },
2511
+ ctrl={ 'converge': self._clean['converge'] },
2512
+ clean_ctrl=self._control['iteration'],
2513
+ state=dict( mode='interactive', stopped=False, awaiting_stop=False, mask="" ),
2514
+ ctrl_pipe=self._pipe['control'],
2515
+ ids=self._clean_ids,
2516
+ logbutton=self._log_button,
2517
+ stopdescmap=ImagingDict.get_summaryminor_stopdesc( )
2518
+ ),
2519
+ code=self._js['update-converge'] + self._js['clean-refresh'] + self._js['clean-disable'] +
2520
+ self._js['clean-enable'] + self._js['clean-status-update'] +
2521
+ self._js['iter-gui-update'] + self._js['clean-wait'] +
2522
+ '''function invalid_niter( s ) {
2523
+ let v = parseInt( s )
2524
+ if ( v > 0 ) return ''
2525
+ if ( v == 0 ) return 'niter is zero'
2526
+ if ( v < 0 ) return 'niter cannot be negative'
2527
+ if ( isNaN(v) ) return 'niter must be an integer'
2528
+ }
2529
+ const itobj = Object.entries(images_state)[0][1].iteration
2530
+ if ( ! state.stopped && cb_obj.origin.name == 'finish' ) {
2531
+ let invalid = invalid_niter(itobj.niter.value)
2532
+ if ( invalid ) update_status( invalid )
2533
+ else {
2534
+ state.mode = 'continuous'
2535
+ update_status( 'Running multiple iterations' )
2536
+ disable( false )
2537
+ clean_ctrl.stop.button_type = "warning"
2538
+ const thevalue = get_update_dictionary( )
2539
+ ctrl_pipe.send( ids[cb_obj.origin.name],
2540
+ { action: 'finish',
2541
+ value: thevalue },
2542
+ update_gui )
2543
+ }
2544
+ }
2545
+ if ( ! state.stopped && state.mode === 'interactive' &&
2546
+ cb_obj.origin.name === 'continue' ) {
2547
+ let invalid = invalid_niter(itobj.niter.value)
2548
+ if ( invalid ) update_status( invalid )
2549
+ else {
2550
+ update_status( 'Running one set of deconvolution iterations' )
2551
+ disable( true )
2552
+ // only send message for button that was pressed
2553
+ // it's unclear whether 'this.origin.' or 'cb_obj.origin.' should be used
2554
+ // (or even if 'XXX.origin.' is public)...
2555
+ ctrl_pipe.send( ids[cb_obj.origin.name],
2556
+ { action: 'next',
2557
+ value: get_update_dictionary( ) },
2558
+ update_gui )
2559
+ }
2560
+ }
2561
+ if ( state.mode === 'interactive' && cb_obj.origin.name === 'stop' ) {
2562
+ if ( confirm( "Are you sure you want to end this interactive clean session and close the GUI?" ) ) {
2563
+ disable( true )
2564
+ //ctrl_pipe.send( ids[cb_obj.origin.name],
2565
+ // { action: 'stop',
2566
+ // value: { } },
2567
+ // update_gui )
2568
+ document._casa_window_closed = true
2569
+ /*** this will close the tab >>>>---------+ ***/
2570
+ /*** | ***/
2571
+ /*** vvvvv----------------------------+ ***/
2572
+ document._cube_done( Object.entries(images_state).reduce((acc,[k,v]) => ({ ...acc, [k]: v.src.masks( ) }),{ } ) )
2573
+ }
2574
+ } else if ( state.mode === 'continuous' &&
2575
+ cb_obj.origin.name === 'stop' &&
2576
+ ! state.awaiting_stop ) {
2577
+ disable( true )
2578
+ state.awaiting_stop = true
2579
+ ctrl_pipe.send( ids[cb_obj.origin.name],
2580
+ { action: 'status',
2581
+ value: { } },
2582
+ wait_for_tclean_stop )
2583
+ }''' )
2584
+
2585
+
2586
+ self._control['iteration']['continue'].js_on_click( self._control['iteration']['cb'] )
2587
+ self._control['iteration']['finish'].js_on_click( self._control['iteration']['cb'] )
2588
+ self._control['iteration']['stop'].js_on_click( self._control['iteration']['cb'] )
2589
+
2590
+ self._log_button.js_on_click( CustomJS( args=dict( logbutton=self._log_button ),
2591
+ code='''function format_log( elem ) {
2592
+ return `<html>
2593
+ <head>
2594
+ <style type="text/css">
2595
+ body {
2596
+ counter-reset: section;
2597
+ }
2598
+ p:before {
2599
+ font-weight: bold;
2600
+ counter-increment: section;
2601
+ content: "" counter(section) ": ";
2602
+ }
2603
+ </style>
2604
+ </head>
2605
+ <body>
2606
+ <h1>Interactive Clean History</h1>
2607
+ ` + elem.map((x) => `<p>${x}</p>`).join('\\n') + '</body>\\n</html>'
2608
+ }
2609
+ let b = cb_obj.origin
2610
+ if ( ! b._window || b._window.closed ) {
2611
+ b._window = window.open("about:blank","Interactive Clean Log")
2612
+ b._window.document.write(format_log(b._log))
2613
+ b._window.document.close( )
2614
+ }''' ) )
2615
+
2616
+ ###
2617
+ ### Setup script that will be called when the user closes the
2618
+ ### browser tab that is running interactive clean
2619
+ ###
2620
+ initial_log = self._clean['gclean'].cmds( )
2621
+
2622
+ self._pipe['control'].init_script=CustomJS( args=dict( ctrl_pipe=self._pipe['control'],
2623
+ ids=self._clean_ids,
2624
+ logbutton=self._log_button,
2625
+ log=initial_log,
2626
+ initial_image=list(self._clean_targets.items( ))[0][0]
2627
+ ),
2628
+ code=self._js['initialize'] +
2629
+ '''if ( ! logbutton._log ) {
2630
+ /*** store log list with log button for access in other callbacks ***/
2631
+ logbutton._log = log
2632
+ }''' )
2633
+
2634
+ tab_panels = list( map( self._create_image_panel, self._clean_targets.items( ) ) )
2635
+
2636
+ for imid, imdetails in self._clean_targets.items( ):
2637
+ imdetails['gui']['cube'].connect( )
2638
+
2639
+ image_tabs = Tabs( tabs=tab_panels, tabs_location='below', height_policy='max', width_policy='max' )
2640
+
2641
+ self._fig['layout'] = column(
2642
+ row( help_button,
2643
+ self._log_button,
2644
+ Spacer( height=self._control['iteration']['stop'].height, sizing_mode="scale_width" ),
2645
+ Div( text="<div><b>status:</b></div>" ),
2646
+ status_line,
2647
+ self._control['iteration']['stop'], self._control['iteration']['continue'], self._control['iteration']['finish'], sizing_mode="scale_width" ),
2648
+ row( image_tabs, height_policy='max', width_policy='max' ),
2649
+ height_policy='max', width_policy='max' )
2650
+
2651
+ ###
2652
+ ### Keep track of which image is currently active in document._casa_image_name (which is
2653
+ ### initialized in self._js['initialize']). Also, update the current control sub-tab
2654
+ ### when the field main-tab is changed. An attempt to manage this all within the
2655
+ ### control sub-tabs using a reference to self._image_control_tab_groups from
2656
+ ### each control sub-tab failed with:
2657
+ ###
2658
+ ### bokeh.core.serialization.SerializationError: circular reference
2659
+ ###
2660
+ image_tabs.js_on_change( 'active', CustomJS( args=dict( names=[ t[0] for t in self._clean_targets.items( ) ],
2661
+ itergroups=self._image_control_tab_groups ),
2662
+ code='''if ( ! hasprop(document,'_casa_last_control_tab') ) {
2663
+ document._casa_last_control_tab = 0
2664
+ }
2665
+ document._casa_image_name = names[cb_obj.active]
2666
+ itergroups[document._casa_image_name].active = document._casa_last_control_tab''' ) )
2667
+
2668
+ # Change display type depending on runtime environment
2669
+ if self._is_notebook:
2670
+ output_notebook()
2671
+ else:
2672
+ ### Directory is created when an HTTP server is running
2673
+ ### (MAX)
2674
+ ### output_file(self._imagename+'_webpage/index.html')
2675
+ pass
2676
+
2677
+ show(self._fig['layout'])
2678
+
2679
+ def _create_colormap_adjust( self, imdetails ):
2680
+ palette = imdetails['gui']['cube'].palette( reuse=self._cube_palette )
2681
+ return column( row( Div(text="<div><b>Colormap:</b></div>",margin=(5,2,5,25)), palette ),
2682
+ imdetails['gui']['cube'].colormap_adjust( ), sizing_mode='stretch_both' )
2683
+
2684
+
2685
+ def _create_control_image_tab( self, imid, imdetails ):
2686
+ result = Tabs( tabs=[ TabPanel(child=column( row( Tip( imdetails['gui']['params']['iteration']['nmajor'],
2687
+ tooltip=Tooltip( content=HTML( 'maximum number of major cycles to run before stopping'),
2688
+ position='bottom' ) ),
2689
+ Tip( imdetails['gui']['params']['iteration']['niter'],
2690
+ tooltip=Tooltip( content=HTML( 'number of clean iterations to run' ),
2691
+ position='bottom' ) ),
2692
+ Tip( imdetails['gui']['params']['iteration']['threshold'],
2693
+ tooltip=Tooltip( content=HTML( 'stopping threshold' ),
2694
+ position='bottom' ) ) ),
2695
+ row( Tip( imdetails['gui']['params']['iteration']['nsigma'],
2696
+ tooltip=Tooltip( content=HTML( 'multiplicative factor for rms-based threshold stopping'),
2697
+ position='bottom' ) ),
2698
+ Tip( imdetails['gui']['params']['iteration']['gain'],
2699
+ tooltip=Tooltip( content=HTML( 'fraction of the source flux to subtract out of the residual image'),
2700
+ position='bottom' ) ) ),
2701
+ row( Tip( imdetails['gui']['params']['iteration']['cycleniter'],
2702
+ tooltip=Tooltip( content=HTML( 'maximum number of <b>minor-cycle</b> iterations' ),
2703
+ position='bottom' ) ),
2704
+ Tip( imdetails['gui']['params']['iteration']['cyclefactor'],
2705
+ tooltip=Tooltip( content=HTML( 'scaling on PSF sidelobe level to compute the minor-cycle stopping threshold' ),
2706
+ position='bottom_left' ) ), background="lightgray" ),
2707
+ imdetails['gui']['convergence'], sizing_mode='stretch_height' ),
2708
+ title='Iteration' ) ] +
2709
+ ( [ TabPanel( child=imdetails['gui']['spectrum'],
2710
+ title='Spectrum' ) ] if imdetails['image-channels'] > 1 else [ ] ) +
2711
+ [ TabPanel( child=self._create_colormap_adjust(imdetails),
2712
+ title='Colormap' ),
2713
+ TabPanel( child=column( *imdetails['gui']['stats'] ),
2714
+ title='Statistics' ) ] + imdetails['gui']['auto-masking-panel'],
2715
+ width=500, sizing_mode='stretch_height', tabs_location='below' )
2716
+
2717
+ if not hasattr(self,'_image_control_tab_groups'):
2718
+ self._image_control_tab_groups = { }
2719
+
2720
+ self._image_control_tab_groups[imid] = result
2721
+ result.js_on_change( 'active', CustomJS( args=dict( ),
2722
+ code='''document._casa_last_control_tab = cb_obj.active''' ) )
2723
+ return result
2724
+
2725
+ def _create_image_panel( self, imagetuple ):
2726
+ imid, imdetails = imagetuple
2727
+
2728
+
2729
+
2730
+ return TabPanel( child=column( row( *imdetails['gui']['channel-ctrl'], imdetails['gui']['cube'].coord_ctrl( ),
2731
+ *self._image_bitmask_controls,
2732
+ #Spacer( height=5, height_policy="fixed", sizing_mode="scale_width" ),
2733
+ imdetails['gui']['cursor-pixel-text'],
2734
+ row( Spacer( sizing_mode='stretch_width' ),
2735
+ imdetails['gui']['cube'].tapedeck( size='20px' ) if imdetails['image-channels'] > 1 else Div( ),
2736
+ Spacer( height=5, width=350 ), width_policy='max' ),
2737
+ width_policy='max' ),
2738
+ row( imdetails['gui']['image']['fig'],
2739
+ column( row( imdetails['gui']['goto'],
2740
+ imdetails['gui']['slider'],
2741
+ width_policy='max' ) if imdetails['image-channels'] > 1 else Div( ),
2742
+ self._create_control_image_tab(imid, imdetails), height_policy='max' ),
2743
+ height_policy='max', width_policy='max' ),
2744
+ height_policy='max', width_policy='max' ), title=imid )
2745
+
2746
+ def __call__( self ):
2747
+ '''Display GUI and process events until the user stops the application.
2748
+
2749
+ Example:
2750
+ Create ``iclean`` object and display::
2751
+
2752
+ print( "Result: %s" %
2753
+ iclean( vis='refim_point_withline.ms', imagename='test', imsize=512,
2754
+ cell='12.0arcsec', specmode='cube',
2755
+ interpolation='nearest', ... )( ) )
2756
+ '''
2757
+
2758
+ self._setup()
2759
+
2760
+ # If Interactive Clean is being run remotely, print helper info for port tunneling
2761
+ if self._is_remote:
2762
+ # Tunnel ports for Jupyter kernel connection
2763
+ print("\nImportant: Copy the following line and run in your local terminal to establish port forwarding.\
2764
+ You may need to change the last argument to align with your ssh config.\n")
2765
+ print(self._gen_port_fwd_cmd())
2766
+
2767
+ # TODO: Include?
2768
+ # VSCode will auto-forward ports that appear in well-formatted addresses.
2769
+ # Printing this line will cause VSCode to autoforward the ports
2770
+ # print("Cmd: " + str(repr(self.auto_fwd_ports_vscode())))
2771
+ input("\nPress enter when port forwarding is setup...")
2772
+
2773
+ async def _run_( ):
2774
+ async with self.serve( ) as s:
2775
+ await s
2776
+
2777
+ if self._is_notebook:
2778
+ ic_task = asyncio.create_task(_run_())
2779
+ else:
2780
+ asyncio.run(_run_( ))
2781
+ return self.result( )
2782
+
2783
+ def _setup( self ):
2784
+ self.__reset( )
2785
+
2786
+ def initialize_tclean( gclean ):
2787
+
2788
+ stopdesc, stopcode, majordone, majorleft, iterleft, all_converge = next(gclean)
2789
+
2790
+ for imid, converge in all_converge.items( ):
2791
+ #######################################################################################################
2792
+ ### gclean seems to return its internal state making it succeptable to modification... so we'll at ###
2793
+ ### least start out with unique dictionaries. ###
2794
+ #######################################################################################################
2795
+ converge = copy.deepcopy(converge)
2796
+
2797
+ imdetails = self._clean_targets[imid]
2798
+ imdetails['converge'] = converge
2799
+
2800
+ if imdetails['converge'] is None or len(imdetails['converge'].keys()) == 0 or \
2801
+ imdetails['converge']['major'] is None or imdetails['converge']['chan'] is None:
2802
+ ###
2803
+ ### gclean should provide argument checking (https://github.com/casangi/casagui/issues/33)
2804
+ ### but currently gclean can be initialized with bad arguments and it is not known until
2805
+ ### the initial calls to tclean/deconvolve
2806
+ ###
2807
+ raise RuntimeError(f'''gclean failure "%s" not returned: {imdetails["converge"]}''' % ('major' if imdetails['converge']['major'] is None else 'chan'))
2808
+
2809
+ self._clean['cmds'].extend(self._clean['gclean'].cmds( ))
2810
+
2811
+ self._initial_clean_params['nmajor'] = majorleft
2812
+ self._initial_clean_params['niter'] = iterleft
2813
+ self._initial_clean_params['cycleniter'] = self._init_values["cycleniter"]
2814
+ self._initial_clean_params['threshold'] = self._init_values["threshold"]
2815
+ self._initial_clean_params['cyclefactor'] = self._init_values["cyclefactor"]
2816
+ self._initial_clean_params['gain'] = self._init_values["gain"]
2817
+ self._initial_clean_params['nsigma'] = self._init_values["nsigma"]
2818
+
2819
+ self._init_values["convergence_state"]['convergence'][imid] = imdetails['converge']['chan']
2820
+ self._init_values["convergence_state"]['cyclethreshold'][imid] = imdetails['converge']['major']['cyclethreshold']
2821
+
2822
+ return (stopdesc, stopcode, majordone, majorleft, iterleft)
2823
+
2824
+
2825
+ self._clean['cmds'] = []
2826
+
2827
+ stopdesc, stopcode, majordone, majorleft, iterleft = initialize_tclean(self._clean['gclean'])
2828
+
2829
+
2830
+ self._clean['last-success'] = dict( result='converged' if stopcode[0] else 'update', stopcode=stopcode, cmd=self._clean['cmds'],
2831
+ convergence=self._init_values["convergence_state"]['convergence'],
2832
+ iterdone=0, iterleft=iterleft,
2833
+ majordone=majordone, majorleft=majorleft,
2834
+ cyclethreshold=self._init_values["convergence_state"]['cyclethreshold'],
2835
+ stopdesc=stopdesc )
2836
+
2837
+ ### Must occur AFTER initial "next" call to gclean(s)
2838
+ self._init_pipes()
2839
+
2840
+ @asynccontextmanager
2841
+ async def serve( self ):
2842
+ '''This function is intended for developers who would like to embed interactive
2843
+ clean as a part of a larger GUI. This embedded use of interactive clean is not
2844
+ currently supported and would require the addition of parameters to this function
2845
+ as well as changes to the interactive clean implementation. However, this function
2846
+ does expose the ``asyncio.Future`` that is used to signal completion of the
2847
+ interactive cleaning operation, and it provides the coroutines which must be
2848
+ managed by asyncio to make the interactive clean GUI responsive.
2849
+
2850
+ Example:
2851
+ Create ``iclean`` object, process events and retrieve result::
2852
+
2853
+ ic = iclean( vis='refim_point_withline.ms', imagename='test', imsize=512,
2854
+ cell='12.0arcsec', specmode='cube', interpolation='nearest', ... )
2855
+ async def process_events( ):
2856
+ async with ic.serve( ) as state:
2857
+ await state[0]
2858
+
2859
+ asyncio.run(process_events( ))
2860
+ print( "Result:", ic.result( ) )
2861
+
2862
+
2863
+ Returns
2864
+ -------
2865
+ (asyncio.Future, dictionary of coroutines)
2866
+ '''
2867
+ def start_http_server():
2868
+ import http.server
2869
+ import socketserver
2870
+ PORT = self._http_port
2871
+ DIRECTORY=self._webpage_path
2872
+
2873
+ class Handler(http.server.SimpleHTTPRequestHandler):
2874
+ def __init__(self, *args, **kwargs):
2875
+ super().__init__(*args, directory=DIRECTORY, **kwargs)
2876
+
2877
+ with socketserver.TCPServer(("", PORT), Handler) as httpd:
2878
+ print("\nServing Interactive Clean webpage from local directory: ", DIRECTORY)
2879
+ print("Use Control-C to stop Interactive clean.\n")
2880
+ print("Copy and paste one of the below URLs into your browser (Chrome or Firefox) to view:")
2881
+ print("http://localhost:"+str(PORT))
2882
+ print("http://127.0.0.1:"+str(PORT))
2883
+
2884
+ httpd.serve_forever()
2885
+
2886
+ self._launch_gui( )
2887
+
2888
+ async with CMC( *( [ ctx for img in self._clean_targets.keys( ) for ctx in
2889
+ [
2890
+ self._clean_targets[img]['gui']['cube'].serve(self.__stop),
2891
+ ]
2892
+ ] + [ websockets.serve( self._pipe['control'].process_messages,
2893
+ self._pipe['control'].address[0],
2894
+ self._pipe['control'].address[1] ),
2895
+ websockets.serve( self._clean['converge']['pipe'].process_messages,
2896
+ self._clean['converge']['pipe'].address[0],
2897
+ self._clean['converge']['pipe'].address[1] ) ]
2898
+ ) ):
2899
+ self.__result_future = asyncio.Future( )
2900
+ yield self.__result_future
2901
+
2902
+ def __retrieve_result( self ):
2903
+ '''If InteractiveClean had a return value, it would be filled in as part of the
2904
+ GUI dialog between Python and JavaScript and this function would return it'''
2905
+ if isinstance(self._error_result,Exception):
2906
+ raise self._error_result
2907
+ elif self._error_result is not None:
2908
+ return self._error_result
2909
+ return { k: v['converge'] for k,v in self._clean_targets.items( ) }
2910
+
2911
+ def result( self ):
2912
+ '''If InteractiveClean had a return value, it would be filled in as part of the
2913
+ GUI dialog between Python and JavaScript and this function would return it'''
2914
+ if self.__result_future is None:
2915
+ raise RuntimeError( 'no interactive clean result is available' )
2916
+
2917
+ self._clean['gclean'].restore( )
2918
+
2919
+ return self.__result_future.result( )
2920
+
2921
+ def masks( self ):
2922
+ '''Retrieves the masks which were used with interactive clean.
2923
+
2924
+ Returns
2925
+ -------
2926
+ The standard ``cubevis`` cube region dictionary which contains two elements
2927
+ ``masks`` and ``polys``.
2928
+
2929
+ The value of the ``masks`` element is a dictionary that is indexed by
2930
+ tuples of ``(stokes,chan)`` and the value of each element is a list
2931
+ whose elements describe the polygons drawn on the channel represented
2932
+ by ``(stokes,chan)``. Each polygon description in this list has a
2933
+ polygon index (``p``) and a x/y translation (``d``).
2934
+
2935
+ The value of the ``polys`` element is a dictionary that is indexed by
2936
+ polygon indexes. The value of each polygon index is a dictionary containing
2937
+ ``type`` (whose value is either ``'rect'`` or ``'poly``) and ``geometry``
2938
+ (whose value is a dictionary containing ``'xs'`` and ``'ys'`` (which are
2939
+ the x and y coordinates that define the polygon).
2940
+
2941
+ This can be converted to other formats with ``cubevis.utils.convert_masks``.
2942
+ '''
2943
+ return copy.deepcopy(self._mask_history) ## don't allow users to change history
2944
+
2945
+ def history( self ):
2946
+ '''Retrieves the commands used during the interactive clean session.
2947
+
2948
+ Returns
2949
+ -------
2950
+ list[str] tclean calls made during the interactive clean session.
2951
+ '''
2952
+ return self._clean.cmds( True )
2953
+
2954
+ def _initialize_javascript( self ):
2955
+ self._js = { ### initialize state
2956
+ ### --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
2957
+ ### -- document is used storing state --
2958
+ ### --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
2959
+ 'initialize': '''if ( ! document._casa_initialized ) {
2960
+ document._casa_image_name = initial_image
2961
+ document._casa_initialized = true
2962
+ document._casa_window_closed = false
2963
+ window.addEventListener( 'beforeunload',
2964
+ function (e) {
2965
+ // if the window is already closed this message is never
2966
+ // delivered (unless interactive clean is called again then
2967
+ // the event shows up in the newly created control pipe
2968
+ if ( document._casa_window_closed == false ) {
2969
+ ctrl_pipe.send( ids['stop'],
2970
+ { action: 'stop', value: { } },
2971
+ undefined ) } } )
2972
+ }''',
2973
+
2974
+ ### --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
2975
+ ### -- flux_src._convergence_data is used to store the complete --
2976
+ ### -- --
2977
+ ### -- The "Insert here ..." code seems to be called when when the stokes plane is changed --
2978
+ ### -- but there have been no tclean iterations yet... --
2979
+ ### --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
2980
+ 'update-converge': '''function update_convergence_single( target, data ) {
2981
+ const pos = target.src.cur_chan
2982
+ const imdata = data.get(pos[1]).get(pos[0])
2983
+ // chan----------------^^^^^^ ^^^^^^----stokes
2984
+ const iterations = imdata.iterations
2985
+ const peakRes = imdata.peakRes
2986
+ const cyclethreshold = imdata.cycleThresh
2987
+ const modelFlux = imdata.modelFlux
2988
+ const stopCode = imdata.stopCode
2989
+ const stopDesc = imdata.stopCode.map( code => stopdescmap.has(code) ? stopdescmap.get(code): "" )
2990
+ target.residual.data = { iterations, cyclethreshold, stopDesc, values: peakRes, type: Array(iterations.length).fill('residual') }
2991
+ target.flux.data = { iterations, cyclethreshold, stopDesc, values: modelFlux, type: Array(iterations.length).fill('flux') }
2992
+ target.cyclethreshold.data = { iterations, values: cyclethreshold }
2993
+ }
2994
+
2995
+ function update_convergence( recurse=false ) {
2996
+ let convdata
2997
+ if ( hasprop(document,'_casa_convergence_data') ) {
2998
+ convdata = document._casa_convergence_data
2999
+ } else {
3000
+ if ( ! recurse ) {
3001
+ ctrl.converge.pipe.send( ctrl.converge.id, { action: 'retrieve' },
3002
+ (msg) => { if ( hasprop( msg.result, 'convergence' ) ) {
3003
+ document._casa_convergence_data = { convergence: msg.result.convergence,
3004
+ cyclethreshold: msg.result.cyclethreshold }
3005
+ update_convergence(true)
3006
+ } } )
3007
+ } else { console.log( 'INTERNAL ERROR: fetching convergence data failed' ) }
3008
+ return
3009
+ }
3010
+
3011
+ Object.entries(images_state).map(
3012
+ ([k,v],i) => { update_convergence_single(v,convdata.convergence[k]) } )
3013
+ }''',
3014
+
3015
+ 'clean-refresh': '''function refresh( clean_msg ) {
3016
+ const itobj = Object.entries(images_state)[0][1].iteration
3017
+ let stokes = 0 // later we will receive the polarity
3018
+ // from some widget mechanism...
3019
+ if ( clean_msg !== undefined ) {
3020
+ if ( 'iterleft' in clean_msg ) {
3021
+ itobj.niter.value = '' + clean_msg['iterleft']
3022
+ } else if ( clean_msg !== undefined && 'iterdone' in clean_msg ) {
3023
+ const remaining = parseInt(itobj.niter.value) - parseInt(clean_msg['iterdone'])
3024
+ itobj.niter.value = '' + (remaining < 0 ? 0 : remaining)
3025
+ }
3026
+
3027
+ if ( 'majorleft' in clean_msg ) {
3028
+ itobj.nmajor.value = '' + clean_msg['majorleft']
3029
+ } else if ( 'majordone' in clean_msg ) {
3030
+ const nm = parseInt(itobj.nmajor.value)
3031
+ if ( nm != -1 ) {
3032
+ const remaining = nm - parseInt(clean_msg['majordone'])
3033
+ itobj.nmajor.value = '' + (remaining < 0 ? 0 : remaining)
3034
+ } else itobj.nmajor.value = '' + nm // nmajor == -1 implies do not consider nmajor in stop decision
3035
+ }
3036
+
3037
+ if ( hasprop(clean_msg,'convergence') && clean_msg.convergence != null ) {
3038
+ document._casa_convergence_data = { convergence: clean_msg.convergence,
3039
+ cyclethreshold: clean_msg.cyclethreshold }
3040
+ }
3041
+ }
3042
+
3043
+ // All images must be updated... without this no images are updated
3044
+ casalib.map( (im,state) => state.src.refresh( msg => {
3045
+ if ( 'stats' in msg ) state.src.update_statistics( msg.stats )
3046
+ } ), images_state )
3047
+ // Update convergence plot...
3048
+ update_convergence( )
3049
+ }''',
3050
+
3051
+ ###
3052
+ ### enabling/disabling tools in imdetails['gui']['image']['fig'].toolbar.tools does not seem to not work
3053
+ ### imdetails['gui']['image']['fig'].toolbar.tools.tool_name (e.g. "Box Select", "Lasso Select")
3054
+ ###
3055
+ ### By design, images_state[*].automask.*/images_state[*].iteration.* are singletons which only need
3056
+ ### to be disabled once...
3057
+ ###
3058
+ 'clean-disable': '''function disable( with_stop ) {
3059
+ const amobj = Object.entries(images_state)[0][1].automask
3060
+ Object.entries(amobj).map(
3061
+ ([k,v],i) => { if ( hasprop(v,'disabled') ) v.disabled = true } )
3062
+ const itobj = Object.entries(images_state)[0][1].iteration
3063
+ Object.entries(itobj).map(
3064
+ ([k,v],i) => { if ( hasprop(v,'disabled') ) v.disabled = true } )
3065
+ Object.entries(images_state).map(
3066
+ ([k,v],i) => {
3067
+ v.img.disabled = true
3068
+ if ( v.spectrum ) v.spectrum.disabled = true
3069
+ v.src.disable_masking( )
3070
+ v.src.disable_pixel_update( )
3071
+ Object.entries(v.navi).map(
3072
+ ([k1,v1],i1) => { if ( hasprop(v1,'disabled') ) v1.disabled = true }
3073
+ )
3074
+ }
3075
+ )
3076
+ clean_ctrl.continue.disabled = true
3077
+ clean_ctrl.finish.disabled = true
3078
+ clean_ctrl.stop.disabled = with_stop
3079
+ }''',
3080
+
3081
+ 'clean-enable': '''function enable( only_stop ) {
3082
+ const amobj = Object.entries(images_state)[0][1].automask
3083
+ Object.entries(amobj).map(
3084
+ ([k,v],i) => { if ( hasprop(v,'disabled') ) v.disabled = false } )
3085
+ const itobj = Object.entries(images_state)[0][1].iteration
3086
+ Object.entries(itobj).map(
3087
+ ([k,v],i) => { if ( hasprop(v,'disabled') ) v.disabled = false } )
3088
+ Object.entries(images_state).map(
3089
+ ([k,v],i) => {
3090
+ v.img.disabled = false
3091
+ if ( v.spectrum ) v.spectrum.disabled = false
3092
+ v.src.enable_masking( )
3093
+ v.src.enable_pixel_update( )
3094
+ Object.entries(v.navi).map(
3095
+ ([k1,v1],i) => { if ( hasprop(v1,'disabled') ) v1.disabled = false } )
3096
+ } )
3097
+
3098
+ clean_ctrl.stop.disabled = false
3099
+ if ( ! only_stop ) {
3100
+ clean_ctrl.continue.disabled = false
3101
+ clean_ctrl.finish.disabled = false
3102
+ }
3103
+ }''',
3104
+
3105
+
3106
+ 'clean-status-update': '''function update_status( status ) {
3107
+ const stopstr = [ 'Zero stop code',
3108
+ 'Iteration limit hit',
3109
+ 'Force stop',
3110
+ 'No change in peak residual across two major cycles',
3111
+ 'Peak residual increased by 3x from last major cycle',
3112
+ 'Peak residual increased by 3x from the minimum',
3113
+ 'Zero mask found',
3114
+ 'No mask found',
3115
+ 'N-sigma or other valid exit criterion',
3116
+ 'Stopping criteria encountered',
3117
+ 'Unrecognized stop code' ]
3118
+ if ( typeof status === 'number' ) {
3119
+ images_state[document._casa_image_name]['status'].text =
3120
+ '<p>' +
3121
+ stopstr[ status < 0 || status >= stopstr.length ?
3122
+ stopstr.length - 1 : status ] +
3123
+ '</p>'
3124
+ } else {
3125
+ images_state[document._casa_image_name]['status'].text = `<p>${status}</p>`
3126
+ }
3127
+ }''',
3128
+
3129
+ 'iter-gui-update': '''function get_update_dictionary( ) {
3130
+ //const amste = images_state[document._casa_image_name]['automask']
3131
+ //const clste = images_state[document._casa_image_name]['iteration']
3132
+ // Assumption is that there is ONE set of iteration and automask updates
3133
+ // for ALL imaging fields...
3134
+ const amobj = Object.entries(images_state)[0][1].automask
3135
+ const automask = amobj.active ?
3136
+ Object.entries(amobj).reduce(
3137
+ (acc,[k1,v1]) => { if ( hasprop(v1,'value') ) acc[k1] = v1.value; return acc },
3138
+ { dogrowprune: amobj.dogrowprune.active,
3139
+ fastnoise: amobj.fastnoise.active,
3140
+ active: true }
3141
+ ) : { }
3142
+ const itobj = Object.entries(images_state)[0][1].iteration
3143
+ const iteration = Object.entries(itobj).reduce(
3144
+ (acc,[k1,v1]) => { if ( hasprop(v1,'value') ) acc[k1] = v1.value; return acc },
3145
+ { }
3146
+ )
3147
+
3148
+ const masks = Object.entries(images_state).reduce( (acc,[k,v]) => { acc[k] = v.src.masks( ); return acc }, { } )
3149
+ const breadcrumbs = Object.entries(images_state).reduce( (acc,[k,v]) => { acc[k] = v.src.breadcrumbs( ); return acc }, { } )
3150
+ return { iteration, automask, masks, breadcrumbs, current_image: document._casa_image_name }
3151
+ }
3152
+ function update_log( log_lines ) {
3153
+ let b = logbutton
3154
+ b._log = b._log.concat( log_lines )
3155
+ if ( b._window && ! b._window.closed ) {
3156
+ for ( const line of log_lines ) {
3157
+ const p = b._window.document.createElement('p')
3158
+ p.appendChild( b._window.document.createTextNode(line) )
3159
+ b._window.document.body.appendChild(p)
3160
+ }
3161
+ }
3162
+ }
3163
+ function update_gui( msg ) {
3164
+ const itobj = Object.entries(images_state)[0][1].iteration
3165
+ if ( msg.result === 'error' ) {
3166
+ // ************************************************************************************
3167
+ // ******** error occurs and is signaled by _gclean, e.g. exception in gclean ********
3168
+ // ************************************************************************************
3169
+ state.mode = 'interactive'
3170
+ clean_ctrl.stop.button_type = "danger"
3171
+ enable(false)
3172
+ state.stopped = false
3173
+ update_status( msg.stopdesc ? msg.stopdesc : 'An internal error has occurred' )
3174
+ if ( 'cmd' in msg ) {
3175
+ update_log( msg.cmd )
3176
+ }
3177
+ } else if ( msg.result === 'no-action' ) {
3178
+ update_status( msg.stopdesc ? msg.stopdesc : 'nothing done' )
3179
+ enable( false )
3180
+ if ( 'cmd' in msg ) {
3181
+ update_log( msg.cmd )
3182
+ }
3183
+ } else if ( msg.result == 'converged' ) {
3184
+ state.mode = 'interactive'
3185
+ clean_ctrl.stop.button_type = "danger"
3186
+ enable(false)
3187
+ state.stopped = false
3188
+ update_status( msg.stopdesc ? msg.stopdesc : 'stopping criteria reached' )
3189
+ if ( 'cmd' in msg ) {
3190
+ update_log( msg.cmd )
3191
+ }
3192
+ refresh( msg )
3193
+ } else if ( msg.result === 'update' ) {
3194
+ if ( 'cmd' in msg ) {
3195
+ update_log( msg.cmd )
3196
+ }
3197
+ refresh( msg )
3198
+ // stopcode[0] == 1: iteration limit hit
3199
+ // stopcode[0] == 9: major cycle limit hit
3200
+ // *******************************************************************************************
3201
+ // ******** perhaps the user should not be locked into exiting after the limit is hit ********
3202
+ // *******************************************************************************************
3203
+ //state.stopped = state.stopped || (msg.stopcode[0] > 1 && msg.stopcode[0] < 9) || msg.stopcode[0] == 0
3204
+ state.stopped = false
3205
+ if ( state.mode === 'interactive' && ! state.awaiting_stop ) {
3206
+ clean_ctrl.stop.button_type = "danger"
3207
+ update_status( msg.stopdesc ? msg.stopdesc : 'stopcode' in msg ? msg.stopcode[0] : -1 )
3208
+ if ( ! state.stopped ) {
3209
+ enable( false )
3210
+ } else {
3211
+ disable( false )
3212
+ }
3213
+ } else if ( state.mode === 'continuous' && ! state.awaiting_stop ) {
3214
+ if ( ! state.stopped && itobj.niter.value > 0 && (itobj.nmajor.value > 0 || itobj.nmajor.value == -1) ) {
3215
+ // *******************************************************************************************
3216
+ // ******** 'niter.value > 0 so continue with one more iteration ********
3217
+ // ******** 'nmajor.value' == -1 implies do not consider nmajor in stop consideration ********
3218
+ // *******************************************************************************************
3219
+ ctrl_pipe.send( ids[cb_obj.origin.name],
3220
+ { action: 'finish',
3221
+ value: get_update_dictionary( ) },
3222
+ update_gui )
3223
+ } else if ( ! state.stopped ) {
3224
+ // *******************************************************************************************
3225
+ // ******** 'niter.value <= 0 so iteration should stop ********
3226
+ // *******************************************************************************************
3227
+ state.mode = 'interactive'
3228
+ clean_ctrl.stop.button_type = "danger"
3229
+ enable(false)
3230
+ state.stopped = false
3231
+ update_status( msg.stopdesc ? msg.stopdesc : 'stopping criteria reached' )
3232
+ } else {
3233
+ state.mode = 'interactive'
3234
+ clean_ctrl.stop.button_type = "danger"
3235
+ enable(false)
3236
+ state.stopped = false
3237
+ update_status( msg.stopdesc ? msg.stopdesc : 'stopcode' in msg ? msg.stopcode[0] : -1 )
3238
+ }
3239
+ }
3240
+ } else if ( msg.result === 'error' ) {
3241
+ img_src.drop_breadcrumb('E')
3242
+ if ( 'cmd' in msg ) {
3243
+ update_log( msg.cmd )
3244
+ }
3245
+ state.mode = 'interactive'
3246
+ clean_ctrl.stop.button_type = "danger"
3247
+ state.stopped = false
3248
+ update_status( 'stopcode' in msg ? msg.stopcode[0] : -1 )
3249
+ enable( false )
3250
+ }
3251
+ }''',
3252
+
3253
+ 'clean-wait': '''function wait_for_tclean_stop( msg ) {
3254
+ state.mode = 'interactive'
3255
+ clean_ctrl.stop.button_type = "danger"
3256
+ enable( false )
3257
+ state.awaiting_stop = false
3258
+ update_status( 'user requested stop' )
3259
+ }''',
3260
+ }