Skip to content

Commit

Permalink
combine pixel & spectrum update so that both are done using a single …
Browse files Browse the repository at this point in the history
…fetched spectrum (as a result SpectraDataSource is no longer used)
  • Loading branch information
schiebel committed Feb 13, 2024
1 parent 480a6bb commit c1c3f72
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 94 deletions.
15 changes: 7 additions & 8 deletions casagui/apps/_interactiveclean.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def __init__( self, vis, imagename, usemask='user', mask='', initial_mask_pixel=
image_fig.disabled = true
stokes_dropdown.disabled = true
if ( cursor_tracking_text) { cursor_tracking_text.disabled = true }
if ( spectra_fig ) spectra_fig.disabled = true
if ( spectrum_fig ) spectrum_fig.disabled = true
if ( with_stop ) {
btns['stop'].disabled = true
} else {
Expand All @@ -469,7 +469,7 @@ def __init__( self, vis, imagename, usemask='user', mask='', initial_mask_pixel=
image_fig.disabled = false
stokes_dropdown.disabled = false
if ( cursor_tracking_text) { cursor_tracking_text.disabled = false }
if ( spectra_fig ) spectra_fig.disabled = false
if ( spectrum_fig ) spectrum_fig.disabled = false
if ( ! only_stop ) {
btns['continue'].disabled = false
btns['finish'].disabled = false
Expand Down Expand Up @@ -862,7 +862,7 @@ def convergence_handler( msg, self=self ):

if image_channels > 1:
self._control['goto'] = self._cube.goto( )
self._fig['spectra'] = self._cube.spectra( width=450 )
self._fig['spectrum'] = self._cube.spectrum( width=450 )
self._fig['slider'] = self._cube.slider( CustomJS( args=dict( flux_src=self._flux_data,
residual_src=self._residual_data,
threshold_src=self._cyclethreshold_data,
Expand All @@ -876,7 +876,7 @@ def convergence_handler( msg, self=self ):
else:
self._control['goto'] = None
self._fig['slider'] = None
self._fig['spectra'] = None
self._fig['spectrum'] = None

self._channel_ctrl = self._cube.channel_ctrl( )

Expand All @@ -894,7 +894,6 @@ def convergence_handler( msg, self=self ):
ctrl_pipe=self._pipe['control'], conv_pipe=self._pipe['converge'],
ids=self._ids['clean'],
img_src=self._fig['image-source'],
#spec_src=self._image_spectra,
niter=self._control['niter'], cycleniter=self._control['cycleniter'],
nmajor=self._control['nmajor'],
threshold=self._control['threshold'], cyclefactor=self._control['cycle_factor'],
Expand All @@ -906,7 +905,7 @@ def convergence_handler( msg, self=self ):
logbutton=self.__log_button,
slider=self._fig['slider'],
image_fig=self._fig['image'],
spectra_fig=self._fig['spectra'],
spectrum_fig=self._fig['spectrum'],
stokes_dropdown = self._channel_ctrl[1].child,
cursor_tracking_text = self._fig['cursor_pixel_text'],
stopstatus=self._status['stopcode'],
Expand Down Expand Up @@ -988,9 +987,9 @@ def convergence_handler( msg, self=self ):
### For cube imaging, tabify the spectrum and convergence plots
###
self._spec_conv_tabs = None
if self._fig['spectra']:
if self._fig['spectrum']:
self._spec_conv_tabs = Tabs( tabs=[ TabPanel(child=layout([self._fig['convergence']], sizing_mode='stretch_width'), title='Convergence'),
TabPanel(child=layout([self._fig['spectra']], sizing_mode='stretch_width'), title='Spectrum') ],
TabPanel(child=layout([self._fig['spectrum']], sizing_mode='stretch_width'), title='Spectrum') ],
sizing_mode='stretch_both' )

self._fig['layout'] = column(
Expand Down
24 changes: 16 additions & 8 deletions casagui/bokeh/sources/_image_pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ImagePipe(DataPipe):
the path to the image, and then it is used as the input to an
`ImageDataSource` or a `SpectraDataSource`. This allows a single CASA
or CNGI imge to be opened once and shared among multiple Bokeh plots,
for example ploting an image channel and a plot of a spectra from the
for example ploting an image channel and a plot of a spectrum from the
image cube.
Attributes
Expand Down Expand Up @@ -359,8 +359,8 @@ def put_mask( self, index, mask ):
else:
self.__msk.putchunk( blc=[0,0] + index, pixels=mask )

def spectra( self, index ):
"""Retrieve one spectra from the image cube. The `index` should be a
def spectrum( self, index, mask=False ):
"""Retrieve one spectrum from the image cube. The `index` should be a
three element list of integers. The first integer is the ''right
ascension'' axis, the second integer is the ''declination'' axis,
and the third integer is the ''stokes'' axis.
Expand All @@ -378,17 +378,25 @@ def spectra( self, index ):
index[1] = self.shape[1] - 1
if self.__img is None:
raise RuntimeError('no image is available')
result_mask = np.squeeze( self.__msk.getchunk( blc=index + [0],
trc=index + [self.shape[-1]] ) ) if self.__msk and mask else None
result = np.squeeze( self.__img.getchunk( blc=index + [0],
trc=index + [self.shape[-1]] ) )
### should return spectral freq etc.
### here for X rather than just the index
try:
return { 'x': list(range(len(result))), 'y': list(result) }
except Exception:
if mask:
return { 'x': list(range(len(result))), 'y': list(result) }, None if result_mask is None else list(result_mask.astype(bool))
else:
return { 'x': list(range(len(result))), 'y': list(result) }
except Exception as e:
## In this case, result is not iterable (e.g.) only one channel in the cube.
## A zero length numpy ndarray has no shape and looks like a float but it is
## an ndarray.
return { 'x': [0], 'y': [float(result)] }
if mask:
return { 'x': [0], 'y': [float(result)] }, None if result_mask is None else [ bool(result_mask) ]
else:
return { 'x': [0], 'y': [float(result)] }

def histogram_source( self, data ):
if not self._histogram_source:
Expand Down Expand Up @@ -418,8 +426,8 @@ async def _image_message_handler( self, cmd ):
'hist': histogram,
'id': cmd['id'] }

elif cmd['action'] == 'spectra':
return { 'spectrum': pack_arrays( self.spectra(cmd['index']) ), 'id': cmd['id'] }
elif cmd['action'] == 'spectrum':
return { 'spectrum': pack_arrays( self.spectrum(cmd['index']) ), 'id': cmd['id'] }
elif cmd['action'] == 'adjust-colormap':
if cmd['bounds'] == "reset":
self.__quant_adjustments = { 'bounds': [ [ ], [ ] ],
Expand Down
Loading

0 comments on commit c1c3f72

Please sign in to comment.