# Path: killMS/Array/NpShared.py
# def zeros(*args,**kwargs):
# def ToShared(Name,A):
# def DelArray(Name):
# def ListNames():
# def DelAll(key=None):
# def GiveArray(Name):
# def DicoToShared(Prefix,Dico,DelInput=False):
# def SharedToDico(Prefix):
#     def __init__(self,prefixName,Dico):
# def SharedObjectToDico(SObject):
# def PackListArray(Name,LArray):
# def UnPackListArray(Name):
#     T=ClassTimeIt.ClassTimeIt("   SharedToDico")
#     T=ClassTimeIt.ClassTimeIt("   SharedToDico")
#     T=ClassTimeIt.ClassTimeIt("   SharedToDico")
#     S=SharedArray.create(Name,(1+NArray+NDimTot+TotSize,),dtype=dS)
#     S[0]=NArray
#         A=LArray[i]
#         A=LArray[i]
#     S=GiveArray(Name)
#         A=S[idx:idx+size].reshape(shape)
# class SharedDicoDescriptor():
# 
# 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/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():


import numpy as np
import DDFacet.Other.MyPickle
import os
import pprint
import multiprocessing
from DDFacet.Imager.ClassDeconvMachine import ClassImagerDeconv
from pyrap.images import image
from killMS.Array import NpShared
from killMS.Other import reformat
from killMS.Other import ModColor
from DDFacet.Other import logger
from DDFacet.Other.progressbar import ProgressBar
from DDFacet.ToolsDir.GiveEdges import GiveEdges
from DDFacet.Imager.ClassImToGrid import ClassImToGrid
from DDFacet.Data import ClassVisServer
from DDFacet.Imager.ModModelMachine import ClassModModelMachine
from pyrap.tables import table
        from DDFacet.Other.AsyncProcessPool import APP
        from killMS.Data import ClassBeam
        self.result_queue = result_queue
        self.kill_received = False
        self.exit = multiprocessing.Event()
        self.GD=GD
        self.IdSharedMem=IdSharedMem
        self.DicoImager=DicoImager
        self.FacetMode=FacetMode
        self.SharedMemNameSphe="%sSpheroidal"%(self.IdSharedMem)
        self.ifzfCF=NpShared.GiveArray(self.SharedMemNameSphe)
        self.ClassImToGrid=ClassImToGrid(*argsImToGrid,ifzfCF=self.ifzfCF)
        self.Image=NpShared.GiveArray("%sModelImage"%(self.IdSharedMem))

    def shutdown(self):
        self.exit.set()
    def run(self):
        while not self.kill_received:
            try:
                Job = self.work_queue.get()
            except:
                break


            # ModelFacet=NpShared.GiveArray("%sModelFacet.%3.3i"%(self.IdSharedMem,iFacet))
            # Grid=self.ClassImToGrid.setModelIm(ModelFacet)
            # _=NpShared.ToShared("%sModelGrid.%3.3i"%(self.IdSharedMem,iFacet),Grid)
            # self.result_queue.put({"Success":True})

            iFacet=Job["iFacet"]
            FacetDataCache=Job["FacetDataCache"]


# Path: killMS/Array/NpShared.py
# def zeros(*args,**kwargs):
# def ToShared(Name,A):
# def DelArray(Name):
# def ListNames():
# def DelAll(key=None):
# def GiveArray(Name):
# def DicoToShared(Prefix,Dico,DelInput=False):
# def SharedToDico(Prefix):
#     def __init__(self,prefixName,Dico):
# def SharedObjectToDico(SObject):
# def PackListArray(Name,LArray):
# def UnPackListArray(Name):
#     T=ClassTimeIt.ClassTimeIt("   SharedToDico")
#     T=ClassTimeIt.ClassTimeIt("   SharedToDico")
#     T=ClassTimeIt.ClassTimeIt("   SharedToDico")
#     S=SharedArray.create(Name,(1+NArray+NDimTot+TotSize,),dtype=dS)
#     S[0]=NArray
#         A=LArray[i]
#         A=LArray[i]
#     S=GiveArray(Name)
#         A=S[idx:idx+size].reshape(shape)
# class SharedDicoDescriptor():
# 
# 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/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/Predict/ClassImageSM2.py
import numpy as np
import DDFacet.Other.MyPickle
import os
import pprint
import multiprocessing
from DDFacet.Imager.ClassDeconvMachine import ClassImagerDeconv
from pyrap.images import image
from killMS.Array import NpShared
from killMS.Other import reformat
from killMS.Other import ModColor
from DDFacet.Other import logger
from DDFacet.Other.progressbar import ProgressBar
from DDFacet.ToolsDir.GiveEdges import GiveEdges
from DDFacet.Imager.ClassImToGrid import ClassImToGrid
from DDFacet.Data import ClassVisServer
from DDFacet.Imager.ModModelMachine import ClassModModelMachine
from pyrap.tables import table
        from DDFacet.Other.AsyncProcessPool import APP
        from killMS.Data import ClassBeam

        self.result_queue = result_queue
        self.kill_received = False
        self.exit = multiprocessing.Event()
        self.GD=GD
        self.IdSharedMem=IdSharedMem
        self.DicoImager=DicoImager
        self.FacetMode=FacetMode
        self.SharedMemNameSphe="%sSpheroidal"%(self.IdSharedMem)
        self.ifzfCF=NpShared.GiveArray(self.SharedMemNameSphe)
        self.ClassImToGrid=ClassImToGrid(*argsImToGrid,ifzfCF=self.ifzfCF)
        self.Image=NpShared.GiveArray("%sModelImage"%(self.IdSharedMem))

    def shutdown(self):
        self.exit.set()
    def run(self):
        while not self.kill_received:
            try:
                Job = self.work_queue.get()
            except:
                break


            # ModelFacet=NpShared.GiveArray("%sModelFacet.%3.3i"%(self.IdSharedMem,iFacet))
            # Grid=self.ClassImToGrid.setModelIm(ModelFacet)
            # _=NpShared.ToShared("%sModelGrid.%3.3i"%(self.IdSharedMem,iFacet),Grid)
            # self.result_queue.put({"Success":True})

            iFacet=Job["iFacet"]
            FacetDataCache=Job["FacetDataCache"]


            Image=NpShared.GiveArray("%sModelImage"%(self.IdSharedMem))