Commits

Kazuhiko Shimada authored d25edc89669 Merge
Merge remote-tracking branch 'origin' into CAS-12844

casa5/gcwrap/python/scripts/imagerhelpers/input_parameters.py

Modified
5 5 import string
6 6 import time
7 7 import re
8 8 import copy
9 9 import pprint
10 10
11 11 from casatasks.private.casa_transition import is_CASA6
12 12 if is_CASA6:
13 13 from casatools import synthesisutils
14 14 from casatasks import casalog
15 + from casatools import calibrater
16 + from casatools import table
17 + from casatasks.private.mslisthelper import check_mslist
18 + from casatasks.private.mslisthelper import sort_mslist
15 19 else:
16 20 from taskinit import *
21 + from taskinit import cbtool as calibrater
22 + from taskinit import tbtool as table
23 + from recipes.mslisthelper import check_mslist
24 + from recipes.mslisthelper import sort_mslist
17 25
18 26 synthesisutils = casac.synthesisutils
19 27
20 28 '''
21 29 A set of helper functions for the tasks tclean
22 30
23 31 Summary...
24 32
25 33 '''
26 34
392 400 # If it's already a dict with ms0,ms1,etc...leave it be.
393 401 ok=True
394 402 for kk in self.allselpars.keys():
395 403 if kk.find('ms')!=0:
396 404 ok=False
397 405
398 406 if ok==True:
399 407 #casalog.post("Already in correct format")
400 408 return errs
401 409
410 + #print("allselpars=",self.allselpars)
402 411 # msname, field, spw, etc must all be equal-length lists of strings, or all except msname must be of length 1.
403 - if not 'msname'in self.allselpars:
412 + if not 'msname' in self.allselpars:
404 413 errs = errs + 'MS name(s) not specified'
405 414 else:
415 + if type(self.allselpars['msname']) == list:
416 + #(timesortedvislist, times) = sort_mslist(self.allselpars['msname'])
417 + (timesortedvislist, times, newindex) = self.mslist_timesorting(self.allselpars['msname'])
418 + if timesortedvislist != self.allselpars['msname']:
419 + self.allselpars['msname'] = timesortedvislist
420 + casalog.post("Sorting the vis list by time. The new vis list:"+ str(self.allselpars['msname']))
421 + for selp in ['spw','field','timestr','uvdist','antenna','scan','obs','state']:
422 + if len(self.allselpars[selp]) == len(newindex):
423 + self.allselpars[selp] = [self.allselpars[selp][i] for i in newindex]
424 +
425 + #msdiff = check_mslist(self.allselpars['msname'], ignore_tables=['SORTED_TABLE', 'ASDM*'])
426 + msdiff = check_mslist(self.allselpars['msname'], ignore_tables=['SORTED_TABLE', 'ASDM*'], testcontent=False)
427 +
428 + # Only call this if vis == list and there is mismatch in wtspec columns
429 + # Maybe expanded for other checks later...
430 + if msdiff != {}:
431 + #print("MS diff===",msdiff)
432 + noWtspecmslist=[]
433 + for msfile, diff_info in msdiff.items():
434 + # check Main
435 + if 'Main' in diff_info:
436 + for diffkey in diff_info['Main']:
437 + if diffkey == "missingcol_a" or diffkey == "missingcol_b":
438 + if ('WEIGHT_SPECTRUM' in diff_info['Main']['missingcol_a'] and
439 + self.allselpars['msname'][0] not in noWtspecmslist):
440 + noWtspecmslist.append(self.allselpars['msname'][0])
441 + if ('WEIGHT_SPECTRUM' in diff_info['Main']['missingcol_b'] and
442 + msfile not in noWtspecmslist):
443 + noWtspecmslist.append(msfile)
444 + # repalce this by addwtspec(list_of_ms_withoutWtSpec)
445 + #self.checkmsforwtspec`
446 + if noWtspecmslist!=[]:
447 + #print ("OK addwtspec to "+str(noWtspecmslist))
448 + self.addwtspec(noWtspecmslist)
406 449
407 450 selkeys = self.allselpars.keys()
408 451
409 452 # Convert all non-list parameters into lists.
410 453 for par in selkeys:
411 454 if type( self.allselpars[par] ) != list:
412 455 self.allselpars[par] = [ self.allselpars[par] ]
413 456
414 457 # Check that all are the same length as nvis
415 458 # If not, and if they're single, replicate them nvis times
811 854 if contoutlier:
812 855 errmsg="Mixed cube and continuum mode for multifields is currently not supported for parallel mode"
813 856 else: # all cube modes, but need to check if the nchans are the same
814 857 if not isnchanmatch:
815 858 errmsg="Cubes for multifields with different nchans are currently not supported for parallel mode "
816 859 else: # mfs
817 860 if cubeoutlier:
818 861 errmsg="Mixed continuum and cube mode for multifields is currently not supported for parallel mode"
819 862 errs = errmsg
820 863 return errs
864 +
865 + def checkmsforwtspec(self):
866 + ''' check if WEIGHT_SPECTRUM column exist when
867 + a list of vis is given. Add the column for an MS
868 + which does not have one if other MSs have the column.
869 + This is a workaround for the issue probably in Vi/VB2
870 + not handling the state change for the optional column
871 + when dealing with multiples MSs
872 + '''
873 + mycb = calibrater()
874 + mytb = table()
875 + haswtspec=False
876 + mswithnowtspec=[]
877 + nms = 1
878 + if type(self.allselpars['msname'])==list:
879 + nms = len(self.allselpars['msname'])
880 +
881 + if nms > 1:
882 + for inms in self.allselpars['msname']:
883 + mytb.open(inms)
884 + cols = mytb.colnames()
885 + mytb.close()
886 + if 'WEIGHT_SPECTRUM' in cols:
887 + haswtspec=True
888 + else:
889 + mswithnowtspec.append(inms)
890 + if haswtspec and len(mswithnowtspec) > 0:
891 + casalog.post("Some of the MSes donot have WEIGHT_SPECTRUM while some other do."+
892 + " Automatically adding the column and initialize for those don't to avoid a process failure.","WARN")
893 + for inms in mswithnowtspec:
894 + mycb.open(inms, addcorr=False, addmodel=False)
895 + mycb.initweights(wtmode='weight', dowtsp=True)
896 + mycb.close()
897 + # noOp for nms==1
898 +
899 + def mslist_timesorting(self, mslist):
900 + '''
901 + wrapper for mslisthelper.sort_mslist to get a sorting order w.r.t the original
902 + '''
903 + (thenewmslist, times) = sort_mslist(mslist)
904 + theindex = []
905 + for vnew in thenewmslist:
906 + for vold in mslist:
907 + if vnew == vold:
908 + theindex.append(mslist.index(vnew))
909 + return (thenewmslist, times, theindex)
910 +
911 + def addwtspec(self, mslist):
912 + '''
913 + Add the column for an MS which does not have one if other MSs have the column.
914 + This is a workaround for the issue probably in Vi/VB2
915 + not handling the state change for the optional column
916 + when dealing with multiples MSs
917 + '''
918 + mycb = calibrater()
919 +
920 + if len(mslist) > 0:
921 + casalog.post("Some of the MSes donot have WEIGHT_SPECTRUM while some other do."+
922 + " Automatically adding the column and initialize using the existing WEIGHT column for those don't to avoid a process failure.","WARN")
923 + casalog.post("Adding WEIGHT_SPECTRUM in the following MS(s): "+str(mslist),"WARN")
924 + for inms in mslist:
925 + mycb.open(inms, addcorr=False, addmodel=False)
926 + mycb.initweights(wtmode='weight', dowtsp=True)
927 + mycb.close()
928 + mycb.done()
929 + # noOp for len(mlist) ==0
930 +
821 931 ############################

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut