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,332 @@
1
+ ########################################################################
2
+ #
3
+ # Copyright (C) 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
+ ##################### generated by xml-casa (v2) from createmask.xml
29
+ ##################### 26fdebc4cbd4e58e368f393b9b7ccde7 ##############################
30
+ from __future__ import absolute_import
31
+ from casashell.private.stack_manip import find_local as __sf__
32
+ from casashell.private.stack_manip import find_frame as _find_frame
33
+ from casatools.typecheck import validator as _pc
34
+ from casatools.coercetype import coerce as _coerce
35
+ from casatools.errors import create_error_string
36
+ from casatasks.private.task_logging import start_log as _start_log
37
+ from casatasks.private.task_logging import end_log as _end_log
38
+ from cubevis.apps import InteractiveClean
39
+ from collections import OrderedDict
40
+ import numpy
41
+ import sys
42
+ import os
43
+
44
+ import shutil
45
+
46
+ def static_var(varname, value):
47
+ def decorate(func):
48
+ setattr(func, varname, value)
49
+ return func
50
+ return decorate
51
+
52
+
53
+ def _createmask_t( *args, **kwargs ):
54
+ ic = InteractiveClean( *args, **kwargs )
55
+ return ic( )
56
+
57
+
58
+ class _createmask:
59
+ """
60
+ createmask ---- Create mask cubes interactively with a GUI
61
+
62
+ Create a mask cube for one or more images using a GUI.
63
+ This task is based upon the same tools that are used to build
64
+ the interactive clean application so the same command keys are
65
+ used for both applications.
66
+
67
+
68
+ --------- parameter descriptions ---------------------------------------------
69
+
70
+ image
71
+ mask
72
+ create
73
+
74
+ --------- examples -----------------------------------------------------------
75
+
76
+
77
+
78
+
79
+ """
80
+
81
+ _info_group_ = """imaging"""
82
+ _info_desc_ = """Create mask cubes interactively with a GUI"""
83
+
84
+ __schema = { 'image': {'anyof': [{'type': 'cReqPath', 'coerce': _coerce.expand_path}, {'type': 'cReqPathVec', 'coerce': [_coerce.to_list,_coerce.expand_pathvec]}]}, 'mask': {'anyof': [{'type': 'cPath', 'coerce': _coerce.expand_path}, {'type': 'cPathVec', 'coerce': [_coerce.to_list,_coerce.expand_pathvec]}]}, 'create': {'type': 'cBool'}, }
85
+
86
+ def __init__(self):
87
+ self.__stdout = None
88
+ self.__stderr = None
89
+ self.__root_frame_ = None
90
+
91
+ def __globals_(self):
92
+ if self.__root_frame_ is None:
93
+ self.__root_frame_ = _find_frame( )
94
+ assert self.__root_frame_ is not None, "could not find CASAshell global frame"
95
+ return self.__root_frame_
96
+
97
+ def __to_string_(self,value):
98
+ if type(value) is str:
99
+ return "'%s'" % value
100
+ else:
101
+ return str(value)
102
+
103
+ def __validate_(self,doc,schema):
104
+ return _pc.validate(doc,schema)
105
+
106
+ def __do_inp_output(self,param_prefix,description_str,formatting_chars):
107
+ out = self.__stdout or sys.stdout
108
+ description = description_str.split( )
109
+ prefix_width = 23 + 23 + 4
110
+ output = [ ]
111
+ addon = ''
112
+ first_addon = True
113
+ if len(description) == 0:
114
+ out.write(param_prefix + " #\n")
115
+ return
116
+ while len(description) > 0:
117
+ ## starting a new line.....................................................................
118
+ if len(output) == 0:
119
+ ## for first line add parameter information............................................
120
+ if len(param_prefix)-formatting_chars > prefix_width - 1:
121
+ output.append(param_prefix)
122
+ continue
123
+ addon = param_prefix + ' #'
124
+ first_addon = True
125
+ addon_formatting = formatting_chars
126
+ else:
127
+ ## for subsequent lines space over prefix width........................................
128
+ addon = (' ' * prefix_width) + '#'
129
+ first_addon = False
130
+ addon_formatting = 0
131
+ ## if first word of description puts us over the screen width, bail........................
132
+ if len(addon + description[0]) - addon_formatting + 1 > self.term_width:
133
+ ## if we're doing the first line make sure it's output.................................
134
+ if first_addon: output.append(addon)
135
+ break
136
+ while len(description) > 0:
137
+ ## if the next description word puts us over break for the next line...................
138
+ if len(addon + description[0]) - addon_formatting + 1 > self.term_width: break
139
+ addon = addon + ' ' + description[0]
140
+ description.pop(0)
141
+ output.append(addon)
142
+ out.write('\n'.join(output) + '\n')
143
+
144
+ #--------- go functions -----------------------------------------------------------
145
+ def __image_dflt( self, glb ):
146
+ return [ ]
147
+
148
+ def __image( self, glb ):
149
+ if 'image' in glb: return glb['image']
150
+ return [ ]
151
+
152
+ def __image_inp(self):
153
+ def xml_default( ):
154
+ ## play the crazy subparameter shell game
155
+ dflt = self.__image_dflt( self.__globals_( ) )
156
+ if dflt is not None: return dflt
157
+ return [ ]
158
+ description = 'Image(s) for which a mask cube will be created or updated'
159
+ value = self.__image( self.__globals_( ) )
160
+ (pre,post) = (('','') if value == xml_default( ) else ('\x1B[34m','\x1B[0m')) if self.__validate_({'image': value},{'image': self.__schema['image']}) else ('\x1B[91m','\x1B[0m')
161
+ self.__do_inp_output('%-6.6s = %s%-23s%s' % ('image',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
162
+
163
+ def __mask_dflt( self, glb ):
164
+ return [ ]
165
+
166
+ def __mask( self, glb ):
167
+ if 'mask' in glb: return glb['mask']
168
+ return [ ]
169
+
170
+ def __mask_inp(self):
171
+ def xml_default( ):
172
+ ## play the crazy subparameter shell game
173
+ dflt = self.__mask_dflt( self.__globals_( ) )
174
+ if dflt is not None: return dflt
175
+ return [ ]
176
+ description = 'Mask cubes(s) to be updated or created'
177
+ value = self.__mask( self.__globals_( ) )
178
+ (pre,post) = (('','') if value == xml_default( ) else ('\x1B[34m','\x1B[0m')) if self.__validate_({'mask': value},{'mask': self.__schema['mask']}) else ('\x1B[91m','\x1B[0m')
179
+ self.__do_inp_output('%-6.6s = %s%-23s%s' % ('mask',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
180
+
181
+ def __create_dflt( self, glb ):
182
+ return True
183
+
184
+ def __create( self, glb ):
185
+ if 'create' in glb: return glb['create']
186
+ return True
187
+
188
+ def __create_inp(self):
189
+ def xml_default( ):
190
+ ## play the crazy subparameter shell game
191
+ dflt = self.__create_dflt( self.__globals_( ) )
192
+ if dflt is not None: return dflt
193
+ return True
194
+ description = 'If equal to True, mask cubes are created if they do not exist'
195
+ value = self.__create( self.__globals_( ) )
196
+ (pre,post) = (('','') if value == xml_default( ) else ('\x1B[34m','\x1B[0m')) if self.__validate_({'create': value},{'create': self.__schema['create']}) else ('\x1B[91m','\x1B[0m')
197
+ self.__do_inp_output('%-6.6s = %s%-23s%s' % ('create',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
198
+
199
+
200
+ #--------- global default implementation-------------------------------------------
201
+ @static_var('state', __sf__('casa_inp_go_state'))
202
+ def set_global_defaults(self):
203
+ self.set_global_defaults.state['last'] = self
204
+ glb = self.__globals_( )
205
+ if 'image' in glb: del glb['image']
206
+ if 'mask' in glb: del glb['mask']
207
+ if 'create' in glb: del glb['create']
208
+
209
+ #--------- inp function -----------------------------------------------------------
210
+ def inp(self):
211
+ print("# createmask -- %s" % self._info_desc_)
212
+ self.term_width, self.term_height = shutil.get_terminal_size(fallback=(80, 24))
213
+ self.__image_inp( )
214
+ self.__mask_inp( )
215
+ self.__create_inp( )
216
+
217
+ #--------- tget function ----------------------------------------------------------
218
+ @static_var('state', __sf__('casa_inp_go_state'))
219
+ def tget(self,savefile=None):
220
+ from runpy import run_path
221
+ filename = savefile
222
+ if filename is None:
223
+ filename = "createmask.last" if os.path.isfile("createmask.last") else "createmask.saved"
224
+ if os.path.isfile(filename):
225
+ glob = _find_frame( )
226
+ newglob = run_path( filename, init_globals={ } )
227
+ for i in newglob:
228
+ glob[i] = newglob[i]
229
+ self.tget.state['last'] = self
230
+ else:
231
+ print("could not find last file: %s\nsetting defaults instead..." % filename)
232
+ self.set_global_defaults( )
233
+
234
+ #--------- tput function ----------------------------------------------------------
235
+ def tput(self,outfile=None):
236
+ def noobj(s):
237
+ if s.startswith('<') and s.endswith('>'):
238
+ return "None"
239
+ else:
240
+ return s
241
+
242
+ _postfile = outfile if outfile is not None else os.path.realpath('createmask.last')
243
+
244
+ _invocation_parameters = OrderedDict( )
245
+ _invocation_parameters['image'] = self.__image( self.__globals_( ) )
246
+ _invocation_parameters['mask'] = self.__mask( self.__globals_( ) )
247
+ _invocation_parameters['create'] = self.__create( self.__globals_( ) )
248
+
249
+ try:
250
+ with open(_postfile,'w') as _f:
251
+ for _i in _invocation_parameters:
252
+ _f.write("%-20s = %s\n" % (_i,noobj(repr(_invocation_parameters[_i]))))
253
+ _f.write("#createmask( ")
254
+ count = 0
255
+ for _i in _invocation_parameters:
256
+ _f.write("%s=%s" % (_i,noobj(repr(_invocation_parameters[_i]))))
257
+ count += 1
258
+ if count < len(_invocation_parameters): _f.write(",")
259
+ _f.write(" )\n")
260
+ except: return False
261
+ return True
262
+
263
+ def __call__( self, image=None, mask=None, create=None ):
264
+ def noobj(s):
265
+ if s.startswith('<') and s.endswith('>'):
266
+ return "None"
267
+ else:
268
+ return s
269
+ _prefile = os.path.realpath('createmask.pre')
270
+ _postfile = os.path.realpath('createmask.last')
271
+ task_result = None
272
+ _arguments = [image,mask,create,]
273
+ _invocation_parameters = OrderedDict( )
274
+ if any(map(lambda x: x is not None,_arguments)):
275
+ # invoke python style
276
+ # set the non sub-parameters that are not None
277
+ local_global = { }
278
+ if image is not None: local_global['image'] = image
279
+ if mask is not None: local_global['mask'] = mask
280
+ if create is not None: local_global['create'] = create
281
+
282
+ # the invocation parameters for the non-subparameters can now be set - this picks up those defaults
283
+ _invocation_parameters['image'] = self.__image( local_global )
284
+ _invocation_parameters['mask'] = self.__mask( local_global )
285
+ _invocation_parameters['create'] = self.__create( local_global )
286
+
287
+ # the sub-parameters can then be set. Use the supplied value if not None, else the function, which gets the appropriate default
288
+
289
+ else:
290
+ # invoke with inp/go semantics
291
+ _invocation_parameters['image'] = self.__image( self.__globals_( ) )
292
+ _invocation_parameters['mask'] = self.__mask( self.__globals_( ) )
293
+ _invocation_parameters['create'] = self.__create( self.__globals_( ) )
294
+ try:
295
+ with open(_prefile,'w') as _f:
296
+ for _i in _invocation_parameters:
297
+ _f.write("%-20s = %s\n" % (_i,noobj(repr(_invocation_parameters[_i]))))
298
+ _f.write("#createmask( ")
299
+ count = 0
300
+ for _i in _invocation_parameters:
301
+ _f.write("%s=%s" % (_i,noobj(repr(_invocation_parameters[_i]))))
302
+ count += 1
303
+ if count < len(_invocation_parameters): _f.write(",")
304
+ _f.write(" )\n")
305
+ except: pass
306
+ try:
307
+ _logging_state_ = None
308
+ assert _pc.validate(_invocation_parameters,self.__schema), create_error_string(_pc.errors)
309
+ _logging_state_ = _start_log( 'createmask', [ 'image=' + repr(_pc.document['image']), 'mask=' + repr(_pc.document['mask']), 'create=' + repr(_pc.document['create']), ] )
310
+ task_result = _createmask_t( image=_pc.document['image'],mask=_pc.document['mask'],create=_pc.document['create'], )
311
+ except Exception as e:
312
+ from traceback import format_exc
313
+ from casatasks import casalog
314
+ casalog.origin('createmask')
315
+ casalog.post("Exception Reported: Error in createmask: %s" % str(e),'SEVERE')
316
+ casalog.post(format_exc( ))
317
+ raise #exception is now raised
318
+ #task_result = False
319
+ finally:
320
+ try:
321
+ os.rename(_prefile,_postfile)
322
+ except: pass
323
+ if _logging_state_:
324
+ task_result = _end_log( _logging_state_, 'createmask', task_result )
325
+
326
+ #Added if _createmask_t returns False and does not raise an exception.
327
+ if task_result is False:
328
+ raise
329
+
330
+ return task_result #Still needed
331
+
332
+ createmask = _createmask( )