Exemplo n.º 1
0
def get_theoretical_noise(self, dataset, gausslimit, startchan=None, endchan=None):
    """
    Subroutine to create a Stokes V image from a dataset and measure the noise, which should be similar to the theoretical one
    image (string): The path to the dataset file.
    startchan(int): First channel to use for imaging, zero-based
    endchan(int): Last channel to use for imaging, zero-based
    returns (numpy array): The rms of the image
    """
    invert = lib.miriad('invert')
    invert.vis = dataset
    invert.map = 'vrms'
    invert.beam = 'vbeam'
    invert.imsize = 1024
    invert.cell = 5
    invert.stokes = 'v'
    invert.slop = 1
    invert.robust = -2
    invert.options='mfs'
    if (startchan and endchan) != None:
        invert.line = 'channel,1,' + str(startchan + 1) + ',' + str(endchan - startchan + 1) + ',' + str(endchan - startchan + 1)
    else:
        pass
    invert.go()
    vmax, vmin, vstd = imstats.getimagestats(self, 'vrms')
    gaussianity = qa.checkimagegaussianity(self, 'vrms', gausslimit)
    if os.path.isdir('vrms') and os.path.isdir('vbeam'):
        managefiles.director(self, 'rm', 'vrms')
        managefiles.director(self, 'rm', 'vbeam')
    else:
        raise ApercalException('Stokes V image was not created successfully. Cannot calculate theoretical noise! No iterative selfcal possible!')
    return gaussianity, vstd
Exemplo n.º 2
0
Arquivo: qa.py Projeto: rs1701/apercal
def checkmodelpolimage(self, image):
    """
    Subroutine to check if a model image is valid
    image (string): The path/name of the image to check
    returns (boolean): True if image is ok, False otherwise
    """
    modelstats = imstats.getimagestats(self, image)
    if modelstats[2] != np.nan and modelstats[1] <= 1000 and modelstats[0] >= -10.0:
        return True
    else:
        return False
Exemplo n.º 3
0
Arquivo: qa.py Projeto: rs1701/apercal
def checkmaskimage(self, image):
    """
    Checks if a mask is completely blanked.
    image: The input mask to check
    return: True if mask is not blank
    """
    maskstats = imstats.getimagestats(self, image)
    if np.isnan(maskstats[0]) or np.isnan(maskstats[1]) or np.isnan(maskstats[2]):
        return False
    else:
        return True
Exemplo n.º 4
0
Arquivo: qa.py Projeto: rs1701/apercal
def checkdirtyimage(self, image):
    """
    Subroutine to check if a dirty image is valid
    image (string): The path/name of the image to check
    returns (boolean): True if image is ok, False otherwise
    """
    dirtystats = imstats.getimagestats(self, image)
    if (dirtystats[1] >= dirtystats[0]) and (dirtystats[2] != np.nan):
        return True
    else:
        return False
Exemplo n.º 5
0
    def mosaic_continuum_mf(self):
        """Looks for all available stacked continuum images and mosaics them into one large image."""
        subs_setinit.setinitdirs(self)
        subs_setinit.setdatasetnamestomiriad(self)

        ##########################################################################################################
        # Check if the parameter is already in the parameter file and load it otherwise create the needed arrays #
        ##########################################################################################################

        mosaiccontinuummfstatus = get_param_def(
            self, 'mosaic_continuum_mf_status',
            False)  # Status of the continuum mf mosaic
        mosaiccontinuummfcontinuumstatus = get_param_def(
            self, 'mosaic_continuum_mf_continuumstatus',
            np.full(self.NBEAMS, False))  # Status of the continuum imaging
        mosaiccontinuummfcopystatus = get_param_def(
            self, 'mosaic_continuum_mf_copystatus',
            np.full(self.NBEAMS, False))  # Status of the copy of the images
        mosaiccontinuummfconvolstatus = get_param_def(
            self, 'mosaic_continuum_mf_convolstatus',
            np.full(self.NBEAMS, False))  # Status of the convolved images
        mosaiccontinuummfcontinuumbeamparams = get_param_def(
            self, 'mosaic_continuum_mf_continuumbeamparams',
            np.full((self.NBEAMS, 3),
                    np.nan))  # Beam sizes of the input images
        mosaiccontinuummfcontinuumimagestats = get_param_def(
            self, 'mosaic_continuum_mf_continuumimagestats',
            np.full((self.NBEAMS, 3),
                    np.nan))  # Image statistics of the input images

        # Start the mosaicking of the stacked continuum images
        if self.mosaic_continuum_mf:
            subs_setinit.setinitdirs(self)
            subs_setinit.setdatasetnamestomiriad(self)
            subs_managefiles.director(self, 'ch', self.mosdir + '/continuum')
            if not mosaiccontinuummfstatus:
                logger.info('Mosaicking multi-frequency continuum images')
                # Acquire the results and statistics from continuum mf imaging
                for b in range(self.NBEAMS):
                    mosaiccontinuummfcontinuumstatus[b] = get_param_def(
                        self, 'continuum_B' + str(b).zfill(2) +
                        '_targetbeams_mf_status', False)
                    if mosaiccontinuummfcontinuumstatus[b]:
                        finalminor = get_param_def(
                            self, 'continuum_B' + str(b).zfill(2) +
                            '_targetbeams_mf_final_minorcycle', np.nan)
                        subs_managefiles.director(
                            self,
                            'cp',
                            str(b).zfill(2) + '.fits',
                            file_=self.basedir + str(b).zfill(2) + '/' +
                            self.contsubdir + '/' + 'image_mf_' +
                            str(finalminor).zfill(2) + '.fits')
                        if os.path.isfile(str(b).zfill(2) + '.fits'):
                            mosaiccontinuummfcopystatus[b] = True
                            subs_convim.fitstomir(
                                str(b).zfill(2) + '.fits',
                                str(b).zfill(2))
                            subs_managefiles.director(
                                self, 'rm',
                                str(b).zfill(2) + '.fits')
                        else:
                            mosaiccontinuummfcopystatus[b] = False
                            logger.warning('Beam ' + str(b).zfill(2) +
                                           ' was not copied successfully!')
                # Copy the images over to the mosaic directory
                for b in range(self.NBEAMS):
                    if mosaiccontinuummfcontinuumstatus[
                            b] and mosaiccontinuummfcopystatus[b]:
                        # Get the image beam parameters and the image statistics
                        mosaiccontinuummfcontinuumimagestats[
                            b, :] = subs_imstats.getimagestats(
                                self,
                                str(b).zfill(2))
                        mosaiccontinuummfcontinuumbeamparams[
                            b, :] = subs_readmirhead.getbeamimage(
                                str(b).zfill(2))
                    else:
                        logger.warning(
                            'Skipping Beam ' + str(b).zfill(2) +
                            '! Continuum mf-imaging was not successful or continuum image not available!'
                        )
                # Calculate the synthesised beam and reject outliers (algorithm needs to be updated)
                rejbeams, beamparams = subs_combim.calc_synbeam(
                    mosaiccontinuummfcontinuumbeamparams)
                # Convolve all the images to the calculated beam
                for b in range(self.NBEAMS):
                    if mosaiccontinuummfcontinuumstatus[
                            b] and mosaiccontinuummfcopystatus[b]:
                        try:
                            convol = lib.miriad('convol')
                            convol.map = str(b).zfill(2)
                            convol.fwhm = str(beamparams[0]) + ',' + str(
                                beamparams[1])
                            convol.pa = str(beamparams[2])
                            convol.options = 'final'
                            convol.out = str(b).zfill(2) + '_cv'
                            convol.go()
                            if os.path.isdir(str(b).zfill(2) + '_cv'):
                                mosaiccontinuummfconvolstatus[b] = True
                            else:
                                mosaiccontinuummfconvolstatus[b] = False
                                logger.warning(
                                    'Beam ' + str(b).zfill(2) +
                                    ' could not be convolved to the calculated beam size! File not there!'
                                )
                        except:
                            mosaiccontinuummfconvolstatus[b] = False
                            logger.warning(
                                'Beam ' + str(b).zfill(2) +
                                ' could not be convolved to the calculated beam size!'
                            )
                # Combine all the images using linmos (needs to be updated with proper primary beam model)
                linmosimages = ''
                linmosrms = ''
                for b in range(self.NBEAMS):
                    if mosaiccontinuummfcontinuumstatus[
                            b] and mosaiccontinuummfcopystatus[
                                b] and mosaiccontinuummfconvolstatus[b]:
                        linmosimages = linmosimages + str(b).zfill(2) + '_cv,'
                        linmosrms = linmosrms + str(
                            subs_imstats.getimagestats(
                                self,
                                str(b).zfill(2) + '_cv')[2]) + ','
                linmos = lib.miriad('linmos')
                linmos.in_ = linmosimages.rstrip(',')
                linmos.rms = linmosrms.rstrip(',')
                linmos.out = self.target.rstrip('.MS') + '_mf'
                linmos.go()
                if os.path.isdir(self.target.rstrip('.MS') + '_mf'):
                    mosaiccontinuummfstatus = True
                    subs_convim.mirtofits(
                        self.target.rstrip('.MS') + '_mf',
                        self.target.rstrip('.MS') + '_mf.fits')
                    logger.info(
                        'Mosaicking of multi-frequency image successful!')
                else:
                    mosaiccontinuummfstatus = False
                    logger.error(
                        'Multi-freqeuncy mosaic was not created successfully!')
            else:
                mosaiccontinuummfstatus = True
                logger.info(
                    'Multi-frequency continuum mosaic was already successfully created!'
                )

        # Save the derived parameters to the parameter file

        subs_param.add_param(self, 'mosaic_continuum_mf_status',
                             mosaiccontinuummfstatus)
        subs_param.add_param(self, 'mosaic_continuum_mf_continuumstatus',
                             mosaiccontinuummfcontinuumstatus)
        subs_param.add_param(self, 'mosaic_continuum_mf_copystatus',
                             mosaiccontinuummfcopystatus)
        subs_param.add_param(self, 'mosaic_continuum_mf_convolstatus',
                             mosaiccontinuummfconvolstatus)
        subs_param.add_param(self, 'mosaic_continuum_mf_continuumbeamparams',
                             mosaiccontinuummfcontinuumbeamparams)
        subs_param.add_param(self, 'mosaic_continuum_mf_continuumimagestats',
                             mosaiccontinuummfcontinuumimagestats)