from __future__ import absolute_import
from __future__ import print_function
import os
import math
import shutil
import string
import time
import re;
import copy
from casatasks.private.casa_transition import is_CASA6
if is_CASA6:
from casatools import synthesisutils
from casatasks import casalog
else:
from taskinit import *
synthesisutils = casac.synthesisutils
'''
A set of helper functions for the tasks tclean
Summary...
'''
try:
from mpi4casa.MPIInterface import MPIInterface as mpi_clustermanager
mpi_available = True
except:
mpi_available = False
class PyParallelImagerHelper():
def __init__(self):
self.CL=None
self.sc=None
self.nodeList=None;
self.NN = self.setupCluster()
def getNodeList(self):
return self.nodeList;
def chunkify(self,lst,n):
return [ lst[i::n] for i in range(n) ]
def partitionCFCacheList(self,gridPars):
cfcName = gridPars['cfcache'];
cflist=[];
if (not (cfcName == '')):
cflist=[f for f in os.listdir(cfcName) if re.match(r'CFS*', f)];
nCF = len(cflist);
nProcs=len(self.nodeList);
if (nProcs > nCF):
n=nCF;
else:
n=nProcs;
if (nCF > 0):
casalog.post("########################################################");
casalog.post("nCF = " + str(nCF) + " nProcs = " + str(n) + " NodeList=" + str(self.nodeList));
casalog.post("########################################################");
xx=self.chunkify(cflist,n);
allcfs={};
for i in range(n):
allcfs[i+1]=xx[i];
return allcfs;