Commits
28 28 | import os |
29 29 | import asyncio |
30 30 | from functools import reduce |
31 31 | import copy |
32 32 | import numpy as np |
33 33 | import shutil |
34 34 | import time |
35 35 | import subprocess |
36 36 | |
37 37 | from casatasks.private.imagerhelpers.imager_return_dict import ImagingDict |
38 - | from casatasks import deconvolve, tclean |
38 + | from casatasks import deconvolve, tclean, imstat |
39 39 | |
40 40 | ### |
41 41 | ### import check versions |
42 42 | ### |
43 43 | _GCV001 = True |
44 44 | _GCV002 = True |
45 45 | _GCV003 = True |
46 46 | _GCV004 = True |
47 47 | |
48 48 | |
359 359 | if key == 'iterDone': |
360 360 | # Maintain cumulative sum of iterations per entry |
361 361 | outrec[nn][ss]['iterations'] = np.cumsum(self.global_imdict.get_key(key, stokes=ss, chan=nn)) |
362 362 | # Replace iterDone with iterations |
363 363 | #outrec[nn][ss]['iterations'] = self.global_imdict.get_key(key, stokes=ss, chan=nn) |
364 364 | else: |
365 365 | outrec[nn][ss][key] = self.global_imdict.get_key(key, stokes=ss, chan=nn) |
366 366 | |
367 367 | return outrec |
368 368 | |
369 + | def _update_peakres(self): |
370 + | if self._deconvolver == 'mtmfs': |
371 + | residname = self._imagename + '.residual.tt0' |
372 + | else: |
373 + | residname = self._imagename + '.residual' |
374 + | |
375 + | maskname = self._imagename + '.mask' |
376 + | |
377 + | peakres = imstat(imagename=residname, mask=maskname)['max'][0] |
378 + | return peakres |
369 379 | |
370 380 | def __next__( self ): |
371 381 | """ Runs tclean and returns the (stopcode, convergence result) when executed with the python builtin next() function. |
372 382 | |
373 383 | The returned convergence result is a nested dictionary: |
374 384 | { |
375 385 | channel id: { |
376 386 | stokes id: { |
377 387 | summary key: [values, one per minor cycle] |
378 388 | }, |
426 436 | ## Initial call where niterleft and nmajorleft are same as original input values. |
427 437 | self.hasit, self.stopdescription = self.global_imdict.has_converged(self._niter, self._threshold, self._nmajor) |
428 438 | |
429 439 | self.current_imdict.returndict['stopcode'] = self.hasit |
430 440 | self.current_imdict.returndict['stopDescription'] = self.stopdescription |
431 441 | self._major_done = 0 |
432 442 | else: |
433 443 | # Reset convergence every time, since we return control to the GUI after a single major cycle |
434 444 | self.current_imdict.returndict['iterdone'] = 0. |
435 445 | |
436 - | self.hasit, self.stopdescription = self.global_imdict.has_converged(self._niter, self._threshold, self._nmajor) |
446 + | # Mask can be updated here... |
447 + | # Check for mask update - peakres + masksum |
448 + | _peakres = self._update_peakres() |
449 + | |
450 + | self.hasit, self.stopdescription = self.global_imdict.has_converged(self._niter, self._threshold, self._nmajor, peakres=_peakres) |
437 451 | |
438 452 | #print("HASIT : ",self.hasit) |
439 453 | #print("DESC : ",self.stopdescription) |
440 454 | |
441 455 | #self.global_imdict.returndict['stopcode'] = self.hasit |
442 456 | #self.global_imdict.returndict['stopDescription'] = self.stopdescription |
443 457 | |
444 458 | #self.current_imdict.returndict['stopcode'] = self.hasit |
445 459 | #self.current_imdict.returndict['stopDescription'] = self.stopdescription |
446 460 | |