Exemple #1
0
    def __init__(self,
                 imagename,
                 catalogname,
                 width=1,
                 beam=None,
                 delimiter=",",
                 verbosity=0,
                 beam2pix=False):

        self.log = utils.logger(verbosity)

        self.log.info("Laoding Image data and catalog info")

        self.imagename = imagename
        self.catalogname = catalogname
        self.delimiter = delimiter

        # Load data
        self.catalog = numpy.loadtxt(self.catalogname,
                                     delimiter=self.delimiter)
        self.nprofs = len(self.catalog)

        self.data, self.hdr, self.wcs = utils.loadFits(imagename)

        self.ndim = self.hdr["naxis"]
        self.centre = self.wcs.getCentreWCSCoords()

        self.log.info(
            "Image Centre RA,DEC {:+.3g}, {:+.3g} Deg".format(*self.centre))

        cubeslice = [slice(None)] * self.ndim
        if self.ndim > 3:
            stokes_ind = self.ndim - utils.fitsInd(self.hdr, "STOKES")
            cubeslice[stokes_ind] = 0

        self.cube = self.data[cubeslice]

        self.profiles = Manager().list([])
        self.weights = Manager().Value("d", 0)

        ind = utils.fitsInd(self.hdr, "FREQ")
        self.crpix = self.hdr["crpix%d" % ind]
        self.crval = self.hdr["crval%d" % ind]
        self.dfreq = self.hdr["cdelt%d" % ind]
        self.freq0 = self.crval + (self.crpix - 1) * self.dfreq
        self.nchan = self.hdr["naxis%d" % ind]
        self.width = int(width * 1e6 / self.dfreq)

        # Find restoring beam in FITS header if not specified
        if isinstance(beam, (float, int)):
            if beam == 0:
                beam = None
            else:
                self.bmaj = self.bmin = beam
                self.bpa = 0
        elif isinstance(beam, (list, tuple)):
            self.bmaj, self.bmin, self.bpa = beam

        elif beam is None:
            try:
                self.bmaj = self.hdr["bmaj"]
                self.bmin = self.hdr["bmin"]
                self.bpa = self.hdr["bpa"]
            except KeyError:
                self.log.critical(
                    "Beam not specified, and no beam information in FITS header"
                )
        else:
            raise TypeError("Beam must be a list, tuple, int or float")

        self.bmajPix = int(self.bmaj / abs(self.wcs.getXPixelSizeDeg()))
        self.bminPix = int(self.bmin / abs(self.wcs.getXPixelSizeDeg()))

        self.beamPix = self.bmajPix
        self.beam2pix = beam2pix

        self.excluded = Manager().Value("d", 0)
        self.track = Manager().Value("d", 0)
        self.lock = Lock()
Exemple #2
0
    def __init__(self,
                 imagename,
                 catalogname=None,
                 beam=0,
                 width=None,
                 stokes_ind=0,
                 delimiter=",",
                 beam2pix=False,
                 verbosity=0,
                 progress=True):
        """ Continuum stacking tool
            imagename: FITS image
            catalogname: List of RA, DEC values. Weights can be added as a 3rd column
            beam: PSF FWHM in degrees
            stokes_id: Index of stokes plane to stack (0,1,2,3) -> (I,Q,U,V)
        """

        self.imagename = imagename
        self.progress = progress

        if catalogname:
            self.catalogname = catalogname
            self.catalog = numpy.loadtxt(catalogname, delimiter=delimiter)
            self.npos = len(self.catalog)

            if self.catalog.shape[-1] == 2:
                self.catalog = numpy.append(self.catalog,
                                            numpy.ones([self.npos, 1]), 1)

        self.weights = manager.Value("f", 0)

        self.stokes_ind = stokes_ind

        self.log = utils.logger(verbosity)

        self.log.info("Started continuum stacker.")
        self.log.info("Loading Image data")
        self.data, self.hdr, self.wcs = utils.loadFits(imagename)

        self.centre = self.wcs.getCentreWCSCoords()
        self.log.info(
            "Image Centre RA,DEC {:+.3g}, {:+.3g} Deg".format(*self.centre))

        # Find restoring beam in FITS header if not specified
        if isinstance(beam, (float, int)):
            if beam == 0:
                beam = None
            else:
                self.bmaj = self.bmin = beam
                self.bpa = 0
        elif isinstance(beam, (list, tuple)):
            self.bmaj, self.bmin, self.bpa = beam

        elif beam is None:
            try:
                self.bmaj = self.hdr["bmaj"]
                self.bmin = self.hdr["bmin"]
                self.bpa = self.hdr["bpa"]
            except KeyError:
                self.log.critical(
                    "Beam not specified, and no beam information in FITS header"
                )
        else:
            raise TypeError("Beam must be a list, tuple, int or float")

        self.bmajPix = int(self.bmaj / abs(self.wcs.getXPixelSizeDeg()))
        self.bminPix = int(self.bmin / abs(self.wcs.getXPixelSizeDeg()))

        self.beamPix = self.bmajPix

        self.ndim = self.hdr["naxis"]

        stokes = self.ndim - utils.fitsInd(self.hdr, "STOKES")
        freq = self.ndim - utils.fitsInd(self.hdr, "FREQ")

        imslice = [slice(None)] * self.ndim
        imslice[stokes] = stokes_ind
        self.data = self.data[imslice].sum(0)
        #raise SystemError((self.data.shape, imslice, freq))

        self.cell = self.wcs.getXPixelSizeDeg()

        self.width = self.beamPix * width if beam else self.beamPix * 10
        self.stamps = manager.list([])
        self.beam2pix = beam2pix
        self.track = manager.Value("d", 0)
        self.lock = Lock()
Exemple #3
0
    def  __init__(self, imagename, catalogname=None, beam=0, width=None,
                  stokes_ind=0, delimiter=",", beam2pix=False, verbosity=0,
                 progress=True, cores=2):
        """ Continuum stacking tool
            imagename: FITS image
            catalogname: List of RA, DEC values. Weights can be added as a 3rd column
            beam: PSF FWHM in degrees
            stokes_id: Index of stokes plane to stack (0,1,2,3) -> (I,Q,U,V)
        """

        self.imagename = imagename
        self.progress = progress
        self.active = manager.Value("d",0)
        self.cores = cores

        if catalogname:
            self.catalogname = catalogname
            self.catalog = numpy.loadtxt(catalogname, delimiter=delimiter)
            self.npos = len(self.catalog)

            if self.catalog.shape[-1]==2:
                self.catalog = numpy.append(self.catalog,
                                numpy.ones([self.npos, 1]), 1)

        self.weights = manager.Value("f",0)

        self.stokes_ind = stokes_ind

        self.log = utils.logger(verbosity)

        self.log.info("Started continuum stacker.")
        self.log.info("Loading Image data")
        self.data, self.hdr, self.wcs = utils.loadFits(imagename)

        self.centre = self.wcs.getCentreWCSCoords()
        self.log.info("Image Centre RA,DEC {:+.3g}, {:+.3g} Deg".format(*self.centre))

        # Find restoring beam in FITS header if not specified
        if isinstance(beam, (float, int)):
            if beam==0:
                beam = None
            else:
                self.bmaj = self.bmin = beam/3600.0 # convert to arcsec
                self.bpa = 0
        elif isinstance(beam, (list, tuple)):
            self.bmaj, self.bmin, self.bpa = beam

        elif beam is None:
            try:
                self.bmaj = self.hdr["bmaj"]
                self.bmin = self.hdr["bmin"]
                self.bpa = self.hdr["bpa"]
            except KeyError: 
                self.log.critical("Beam not specified, and no beam information in FITS header")
        else:
            raise TypeError("Beam must be a list, tuple, int or float")

        self.bmajPix = int(self.bmaj/abs( self.wcs.getXPixelSizeDeg() ) )
        self.bminPix = int(self.bmin/abs( self.wcs.getXPixelSizeDeg() ) )

        self.beamPix = self.bmajPix

        self.ndim = self.hdr["naxis"]

        stokes = self.ndim - utils.fitsInd(self.hdr, "STOKES")
        freq = self.ndim - utils.fitsInd(self.hdr, "FREQ")

        imslice = [slice(None)]*self.ndim
        imslice[stokes] = stokes_ind
        self.data = self.data[imslice].sum(0)
        #raise SystemError((self.data.shape, imslice, freq))

        self.cell = self.wcs.getXPixelSizeDeg()

        self.width = self.beamPix*width if beam else self.beamPix*10
        self.stamps = manager.list([])
        self.beam2pix = beam2pix
        self.track = manager.Value("d",0)
        self.lock = Lock()
Exemple #4
0
    def __init__(self, imagename, catalogname, 
                 width=1, beam=None, delimiter=",", 
                 verbosity=0, beam2pix=False, cores=2):

        self.log = utils.logger(verbosity)
        self.active = Manager().Value("d", 0)
        self.cores = cores

        self.log.info("Laoding Image data and catalog info")

        self.imagename = imagename
        self.catalogname = catalogname
        self.delimiter = delimiter

        # Load data
        self.catalog = numpy.loadtxt(self.catalogname, delimiter=self.delimiter)
        self.nprofs = len(self.catalog)
        
        self.data, self.hdr, self.wcs = utils.loadFits(imagename)

        self.ndim = self.hdr["naxis"]
        self.centre = self.wcs.getCentreWCSCoords()

        self.log.info("Image Centre RA,DEC {:+.3g}, {:+.3g} Deg".format(*self.centre))
        
        cubeslice = [slice(None)]*self.ndim
        if self.ndim >3:
            stokes_ind = self.ndim - utils.fitsInd(self.hdr, "STOKES")
            cubeslice[stokes_ind] = 0

        self.cube = self.data[cubeslice]

        self.profiles = Manager().list([])
        self.weights = Manager().Value("d", 0)

        ind = utils.fitsInd(self.hdr, "FREQ")
        self.crpix = self.hdr["crpix%d"%ind]
        self.crval = self.hdr["crval%d"%ind]
        self.dfreq = self.hdr["cdelt%d"%ind]
        self.freq0 = self.crval + (self.crpix-1)*self.dfreq
        self.nchan = self.hdr["naxis%d"%ind]
        self.width = int(width*1e6/self.dfreq)

        # Find restoring beam in FITS header if not specified
        if isinstance(beam, (float, int)):
            if beam==0:
                beam = None
            else:
                self.bmaj = self.bmin = beam/3600.
                self.bpa = 0
        elif isinstance(beam, (list, tuple)):
            self.bmaj, self.bmin, self.bpa = beam
            self.bmaj /= 3600.
            self.bmin /= 3600.

        elif beam is None:
            try:
                self.bmaj = self.hdr["bmaj"]
                self.bmin = self.hdr["bmin"]
                self.bpa = self.hdr["bpa"]
            except KeyError: 
                self.log.critical("Beam not specified, and no beam information in FITS header")
        else:
            raise TypeError("Beam must be a list, tuple, int or float")

        self.bmajPix = int(self.bmaj/abs( self.wcs.getXPixelSizeDeg() ) )
        self.bminPix = int(self.bmin/abs( self.wcs.getXPixelSizeDeg() ) )

        self.beamPix = self.bmajPix
        self.beam2pix = beam2pix
    
        self.excluded = Manager().Value("d",0)
        self.track = Manager().Value("d",0)
        self.lock = Lock()