# Path: killMS/Other/rad2hmsdms.py
# def rad2hmsdms(rad,Type="dec",deg=False):
#     
#     if deg==False:
#         deg=rad*180/np.pi
#     else:
#         deg=rad
# 
#     strsgn="+"
#     if Type=="ra":
#         deg/=15.
#         strsgn=""
# 
#     if np.sign(deg)==-1.: strsgn="-"
#     deg=np.abs(deg)
#     degd=np.int(deg)
#     degms=(deg-degd)*60.
#     degm=np.int(degms)
#     degs=((degms-degm)*60)
#     return "%s%2.2i %2.2i %06.3f"%(strsgn,degd,degm,degs)
# 
# Path: killMS/Other/ModColor.py
# HEADER = '\033[95m'
# OKBLUE = '\033[94m'
# OKGREEN = '\033[92m'
# WARNING = '\033[93m'
# FAIL = '\033[91m'
# ENDC = '\033[0m'
#     HEADER = ''
#     OKBLUE = ''
#     OKGREEN = ''
#     WARNING = ''
#     FAIL = ''
#     ENDC = ''
# def Str(strin0,col="red",Bold=True):
# def Sep(strin=None,D=1):
# def Title(strin,Big=False):
# def disable():
# 
# Path: killMS/Other/reformat.py
# def reformat(ssin,slash=True,LastSlash=True):
#     ss=ssin.split("/")
#     ss=filter (lambda a: a != "", ss)
#     ss="/".join(ss)+"/"
#     if ssin[0]=="/": ss="/"+ss
#     if not(slash):
#         ss=ss[1:-1]
#     if not(LastSlash):
#         if ss[-1]=="/": ss=ss[0:-1]
#     return ss
# 
# Path: killMS/Other/ClassTimeIt.py
# class ClassTimeIt():
#     def __init__(self,name="",f=1.):
#         self.t0=timemod.time()
#         self.IsEnable=True
#         if name=="":
#             self.name=name
#         else:
#             self.name=name+": "
#         self.IsEnableIncr=False
#         self.Counter=""
#         self.f=f
# 
#     def reinit(self):
#         self.t0=timemod.time()
# 
#     def timeit(self,stri=" Time",hms=False):
#         if self.IsEnable==False: return
#         t1=timemod.time()
#         dt=self.f*(t1-self.t0)
#         if not(hms):
#             Sout= "  * %s%s %s : %7.5fs"%(self.name,stri,str(self.Counter),dt)
#             if self.IsEnableIncr: self.Counter+=1
#         else:
#             ss=(dt)/60.
#             m=int(ss)
#             s=(ss-m)*60.
#             Sout= "  * %s computation time: %i min. %4.1f sec."%(stri,m,s)
#         self.t0=t1
#         if DoLog:
#             log.print( Sout)
#         else:
#             print(Sout)
# 
#         return dt
# 
#     def timeitHMS(self,stri=" Time"):
#         t1=timemod.time()
#         self.t0=t1
# 
#     def disable(self):
#         self.IsEnable=False
# 
#     def enableIncr(self,incr=1):
#         self.IsEnableIncr=True
#         self.Counter=0
# 
#     def AddDt(self,Var):
#         t1=timemod.time()
#         dt=t1-self.t0
#         Var=Var+dt
#         self.t0=t1
#         return Var


import numpy as np
import os
import pyrap.quanta as qa
import pyrap.measures as pm
import ephem
import DDFacet.ToolsDir.ModRotate
        import copy
        import sidereal
        import datetime
            import pylab
        import pylab
        import ModRotate
        import pyrap.tables
from pyrap.tables import table
from killMS.Other.rad2hmsdms import rad2hmsdms
from killMS.Other import ModColor
from killMS.Other import reformat
from DDFacet.Other import logger
from killMS.Other import ClassTimeIt
from DDFacet.Other.progressbar import ProgressBar
        from lofar.stationresponse import stationresponse
            from DDFacet.Data.ClassFITSBeam import ClassFITSBeam as ClassDDFBeam
            from DDFacet.Data.ClassATCABeam import ClassATCABeam as ClassDDFBeam
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
log=logger.getLogger("ClassMS")
#from DDFacet.Other.PrintList import ListToStr

class ClassMS():
    def __init__(self,MSname,Col="DATA",zero_flag=True,ReOrder=False,EqualizeFlag=False,DoPrint=True,DoReadData=True,
                 TimeChunkSize=None,GetBeam=False,RejectAutoCorr=False,SelectSPW=None,DelStationList=None,Field=0,DDID=0,
                 ReadUVWDT=False,ChanSlice=None,GD=None,
                 ToRADEC=None):


        if MSname=="": exit()
        self.GD=GD
        self.ToRADEC = ToRADEC
            
        self.ReadUVWDT=ReadUVWDT

# Path: killMS/Other/rad2hmsdms.py
# def rad2hmsdms(rad,Type="dec",deg=False):
#     
#     if deg==False:
#         deg=rad*180/np.pi
#     else:
#         deg=rad
# 
#     strsgn="+"
#     if Type=="ra":
#         deg/=15.
#         strsgn=""
# 
#     if np.sign(deg)==-1.: strsgn="-"
#     deg=np.abs(deg)
#     degd=np.int(deg)
#     degms=(deg-degd)*60.
#     degm=np.int(degms)
#     degs=((degms-degm)*60)
#     return "%s%2.2i %2.2i %06.3f"%(strsgn,degd,degm,degs)
# 
# Path: killMS/Other/ModColor.py
# HEADER = '\033[95m'
# OKBLUE = '\033[94m'
# OKGREEN = '\033[92m'
# WARNING = '\033[93m'
# FAIL = '\033[91m'
# ENDC = '\033[0m'
#     HEADER = ''
#     OKBLUE = ''
#     OKGREEN = ''
#     WARNING = ''
#     FAIL = ''
#     ENDC = ''
# def Str(strin0,col="red",Bold=True):
# def Sep(strin=None,D=1):
# def Title(strin,Big=False):
# def disable():
# 
# Path: killMS/Other/reformat.py
# def reformat(ssin,slash=True,LastSlash=True):
#     ss=ssin.split("/")
#     ss=filter (lambda a: a != "", ss)
#     ss="/".join(ss)+"/"
#     if ssin[0]=="/": ss="/"+ss
#     if not(slash):
#         ss=ss[1:-1]
#     if not(LastSlash):
#         if ss[-1]=="/": ss=ss[0:-1]
#     return ss
# 
# Path: killMS/Other/ClassTimeIt.py
# class ClassTimeIt():
#     def __init__(self,name="",f=1.):
#         self.t0=timemod.time()
#         self.IsEnable=True
#         if name=="":
#             self.name=name
#         else:
#             self.name=name+": "
#         self.IsEnableIncr=False
#         self.Counter=""
#         self.f=f
# 
#     def reinit(self):
#         self.t0=timemod.time()
# 
#     def timeit(self,stri=" Time",hms=False):
#         if self.IsEnable==False: return
#         t1=timemod.time()
#         dt=self.f*(t1-self.t0)
#         if not(hms):
#             Sout= "  * %s%s %s : %7.5fs"%(self.name,stri,str(self.Counter),dt)
#             if self.IsEnableIncr: self.Counter+=1
#         else:
#             ss=(dt)/60.
#             m=int(ss)
#             s=(ss-m)*60.
#             Sout= "  * %s computation time: %i min. %4.1f sec."%(stri,m,s)
#         self.t0=t1
#         if DoLog:
#             log.print( Sout)
#         else:
#             print(Sout)
# 
#         return dt
# 
#     def timeitHMS(self,stri=" Time"):
#         t1=timemod.time()
#         self.t0=t1
# 
#     def disable(self):
#         self.IsEnable=False
# 
#     def enableIncr(self,incr=1):
#         self.IsEnableIncr=True
#         self.Counter=0
# 
#     def AddDt(self,Var):
#         t1=timemod.time()
#         dt=t1-self.t0
#         Var=Var+dt
#         self.t0=t1
#         return Var


# Path: killMS/Data/ClassMS.py
import numpy as np
import os
import pyrap.quanta as qa
import pyrap.measures as pm
import ephem
import DDFacet.ToolsDir.ModRotate
        import copy
        import sidereal
        import datetime
            import pylab
        import pylab
        import ModRotate
        import pyrap.tables
from pyrap.tables import table
from killMS.Other.rad2hmsdms import rad2hmsdms
from killMS.Other import ModColor
from killMS.Other import reformat
from DDFacet.Other import logger
from killMS.Other import ClassTimeIt
from DDFacet.Other.progressbar import ProgressBar
        from lofar.stationresponse import stationresponse
            from DDFacet.Data.ClassFITSBeam import ClassFITSBeam as ClassDDFBeam
            from DDFacet.Data.ClassATCABeam import ClassATCABeam as ClassDDFBeam

as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
log=logger.getLogger("ClassMS")
#from DDFacet.Other.PrintList import ListToStr

class ClassMS():
    def __init__(self,MSname,Col="DATA",zero_flag=True,ReOrder=False,EqualizeFlag=False,DoPrint=True,DoReadData=True,
                 TimeChunkSize=None,GetBeam=False,RejectAutoCorr=False,SelectSPW=None,DelStationList=None,Field=0,DDID=0,
                 ReadUVWDT=False,ChanSlice=None,GD=None,
                 ToRADEC=None):


        if MSname=="": exit()
        self.GD=GD
        self.ToRADEC = ToRADEC
            
        self.ReadUVWDT=ReadUVWDT

        MSname=reformat.reformat(os.path.abspath(MSname),LastSlash=False)