From a5fe84a4630a0385284045025f9a2b707a0b4af4 Mon Sep 17 00:00:00 2001 From: Darrell Schiebel Date: Tue, 9 Jan 2024 17:09:25 -0500 Subject: [PATCH] to keep convergence update in sync with the displayed channel it must be updated after the channel has been loaded --- casagui/apps/_interactiveclean.py | 18 ++++++++---------- casagui/toolbox/_cube.py | 15 ++++++++++----- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/casagui/apps/_interactiveclean.py b/casagui/apps/_interactiveclean.py index bcd45d2..a1474ff 100644 --- a/casagui/apps/_interactiveclean.py +++ b/casagui/apps/_interactiveclean.py @@ -908,18 +908,16 @@ def convergence_handler( msg, self=self ): if image_channels > 1: self._control['goto'] = TextInput( title="goto channel", value="", width=90 ) - self._fig['slider'] = self._cube.slider( ) self._fig['spectra'] = self._cube.spectra( 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, + convergence_fig=self._fig['convergence'], + conv_pipe=self._pipe['converge'], convergence_id=self._convergence_id, + img_src=self._fig['image-source'], + stopdescmap=ImagingDict.get_summaryminor_stopdesc( ) ), + code=self._js['update-converge'] + self._js['slider-update'] ) ) - self._fig['slider'].js_on_change( 'value', - CustomJS( args=dict( flux_src=self._flux_data, - residual_src=self._residual_data, - threshold_src=self._cyclethreshold_data, - convergence_fig=self._fig['convergence'], - conv_pipe=self._pipe['converge'], convergence_id=self._convergence_id, - img_src=self._fig['image-source'], - stopdescmap=ImagingDict.get_summaryminor_stopdesc( ) ), - code=self._js['update-converge'] + self._js['slider-update'] ) ) self._control['goto'].js_on_change( 'value', CustomJS( args=dict( img=self._cube.js_obj( ), slider=self._fig['slider'], diff --git a/casagui/toolbox/_cube.py b/casagui/toolbox/_cube.py index 87aea0d..6a231a2 100644 --- a/casagui/toolbox/_cube.py +++ b/casagui/toolbox/_cube.py @@ -106,6 +106,7 @@ def __init__( self, image, mask=None, abort=None ): self._bitmask_transparency_button = None # select whether the 1s or 0s is transparent self._mask0 = None # INTERNAL systhesis imaging mask self._slider = None # slider to move from plane to plane + self._slider_callback = None # called after the channel update for slider movement is complete self._spectra = None # figure displaying spectra along the frequency axis self._statistics = None # statistics data table self._statistics_mask = None # button to switch from channel statistics to mask statistics @@ -492,10 +493,12 @@ def __init__( self, image, mask=None, abort=None ): ### 'slider_w_stats': '''if ( casalib.hotkeys.getScope( ) !== 'channel' ) { source.channel( slider.value, source.cur_chan[0], - msg => { if ( 'stats' in msg ) { source.update_statistics( msg.stats ) } } ) + msg => { if ( 'stats' in msg ) { source.update_statistics( msg.stats ) } + if ( cb ) cb.execute( this ) } ) }''', 'slider_wo_stats': '''if ( casalib.hotkeys.getScope( ) !== 'channel' ) { - source.channel( slider.value, source.cur_chan[0] ) + source.channel( slider.value, source.cur_chan[0], + msg => { if ( cb ) cb.execute( this ) } ) }''', ### initialize mask state ### @@ -1111,7 +1114,7 @@ async def mod_mask( msg, self=self ): return self._image - def slider( self, **kw ): + def slider( self, callback=None, **kw ): '''Return slider that is used to change the image plane that is displayed on the 2D raster display. @@ -1126,6 +1129,7 @@ def slider( self, **kw ): slider_end = shape[-1]-1 self._slider = set_attributes( Slider( start=0, end=1 if slider_end == 0 else slider_end , value=0, step=1, title="Channel" ), **kw ) + self._slider_callback = callback if slider_end == 0: # for a cube with one channel, a slider is of no use self._slider.disabled = True @@ -1743,8 +1747,9 @@ def connect( self ): ### ... ALSO statistics would be based upon the SELECTION SET... ### self._cb['slider'] = CustomJS( args=dict( source=self._image_source, slider=self._slider, - stats_source=self._statistics_source ), - code=self._js['slider_w_stats'] if self._statistics_source else self._js['slider_wo_stats'] ) + stats_source=self._statistics_source, + cb=self._slider_callback ), + code=(self._js['slider_w_stats'] if self._statistics_source else self._js['slider_wo_stats']) ) self._slider.js_on_change( 'value', self._cb['slider'] ) if self._statistics_mask: