Source
idplot = plt.bar(idx, idNvisDistributionPerSubMs[id], width, bottom=bottomLevel, color=plt.cm.Paired(1.*colorVector[coloridx]/nid))
import os
import sys
import shutil
import pprint as pp
import traceback
import time
import commands
import numpy as np
import matplotlib.pyplot as plt
from __main__ import *
from taskinit import *
class convertToMMS():
def __init__(self,\
inpdir=None, \
mmsdir=None, \
axis='auto', \
numsubms=4,
# createmslink=False, \
cleanup=False):
'''Run the partition task to create MMSs from a directory with MSs'''
casalog.origin('convertToMMS')
self.inpdir = inpdir
self.outdir = mmsdir
self.axis = axis
self.numsubms = numsubms
# self.createmslink = createmslink
self.mmsdir = '/tmp/mmsdir'
self.cleanup = cleanup
# Input directory is mandatory
if self.inpdir is None:
casalog.post('You must give an input directory to this script')
self.usage()
return
if not os.path.exists(self.inpdir):
casalog.post('Input directory inpdir does not exist -> '+self.inpdir,'ERROR')
self.usage()
return
if not os.path.isdir(self.inpdir):
casalog.post('Value of inpdir is not a directory -> '+self.inpdir,'ERROR')
self.usage()
return
# Only work with absolute paths
self.inpdir = os.path.abspath(self.inpdir)
casalog.post('Will read input MS from '+self.inpdir)
# Verify output directory
if self.outdir is None:
self.mmsdir = os.path.join(os.getcwd(),'mmsdir')
elif self.outdir == '/':
casalog.post('inpdir is set to root!', 'WARN')
self.mmsdir = os.path.join(os.getcwd(),'mmsdir')
else:
self.outdir = os.path.abspath(self.outdir)
self.mmsdir = self.outdir
if self.mmsdir == self.inpdir:
casalog.post('Output directory cannot be same of input directory','ERROR')
return
# Cleanup output directory
if self.cleanup:
casalog.post('Cleaning up output directory '+self.mmsdir)
if os.path.isdir(self.mmsdir):
shutil.rmtree(self.mmsdir)
if not os.path.exists(self.mmsdir):
os.makedirs(self.mmsdir)
casalog.post('Will save output MMS to '+self.mmsdir)
# Walk through input directory
files = os.walk(self.inpdir,followlinks=True).next()
# Get MS list
mslist = []
mslist = self.getMSlist(files)
casalog.post('List of MSs in input directory')
pp.pprint(mslist)
# Get non-MS directories and other files