Real time updates on parameter optimization
Closed this issue · 2 comments
If BaSiC.fit()
could provide a way to peak at its parameters throughout optimization, we can do some cool stuff in the napari plugin. For example, there could be a preview layer that is updated with the flatfield estimate every n iterations. This would probably slow down the computation but would provide a cool way of watching the process unfold. We could also use the parameters to plot error, etc.
napari provides a thread_worker
decorator to simplify adding plugin functions as to not block using the gui. The worker
can yield values during its call, which can be passed onto other functions.
It is generally bad design to change output type of a function based on argument, but ignoring that, here is one way this could be implemented.
class BaSiC:
...
def fit(self, images, ..., updates=False):
...
while not CONVERGED:
...
if updates:
yield self.params
...
# napari plugin
def update_layer(image):
# update preview layer
...
@thread_worker(start_thread=False, connect={"yielded": update_layer})
def call_basic(images):
basic = BaSiC()
for update in basic.fit(images, updates=True):
yield update
...
This is a good idea and implementation.
Unfortunately, I believe this is not compatible with jit
-compiled functions. Closing this for now but please feel free to re-open.