def source_selection(self): sources = self.pmodel.sources noise, mean = utils.negative_noise(self.data, self.prefix) for srs in sources: pos = map(lambda rad: numpy.rad2deg(rad), (srs.pos.ra, srs.pos.dec)) positions = self.wcs.wcs2pix(*pos) # local noise, determining SNR using the local noise # threshold is determined using the global noise local_noise = self.local_noise(positions) signal_to_noise = srs.flux.I / local_noise thresh = self.snr_factor * noise if signal_to_noise > thresh and srs.rel > 0.99: if self.psfname: corr = srs.correlation_factor if corr > self.corrthresh: self.number_negatives(srs) if not self.psfname: self.number_negatives(srs) return self.pmodel, self.nmodel
def source_selection(self): sources = self.pmodel.sources noise, mean = utils.negative_noise(self.data, self.prefix) for srs in sources: pos = map(lambda rad: numpy.rad2deg(rad),(srs.pos.ra,srs.pos.dec)) positions = self.wcs.wcs2pix(*pos) # local noise, determining SNR using the local noise # threshold is determined using the global noise local_noise = self.local_noise(positions) signal_to_noise = srs.flux.I/local_noise thresh = self.snr_factor * noise if signal_to_noise > thresh and srs.rel > 0.99: if self.psfname: corr = srs.correlation_factor if corr > self.corrthresh: self.number_negatives(srs) if not self.psfname: self.number_negatives(srs) return self.pmodel, self.nmodel
def __init__(self, imagename, psfname=None, sourcefinder_name='pybdsm', saveformat="gaul", makeplots=True, do_psf_corr=True, do_local_var=True, psf_corr_region=5, local_var_region=10, rel_excl_src=None, pos_smooth=2, neg_smooth=2, loglevel=0, thresh_pix=5, thresh_isl=3, neg_thresh_isl=3, neg_thresh_pix=5, reset_rel=None, prefix=None, do_nearsources=False, savefits=False, increase_beam_cluster=False, savemask_pos=False, savemask_neg=False, no_smooth=True, **kw): """ Takes in image and extracts sources and makes reliability estimations.. imagename: Fits image psfname: PSF fits image, optional. sourcefinder_name: str, optional. Default 'pybdsm'. Uses source finder specified. makeplots: bool, optional. Default is True. Make reliability plots. do_psf_corr : bool, optional. Default True. If True, PSF correlation will be added as an extra parameter for density estimations. NB: the PSF fits image must be provided. do_local_var : bool, optional. Default is True. If True, adds local variance as an extra parameter, for density estimations. do_nearsources: boolean. Default is False. If true it adds number of nearest neighnours as an extra parameter. It looks for sources around 5 beam sizes. psf_corr_region : int, optional. Default value is 5. Data size to correlate around a source, in beam sizes. local_var_region: int, optional. Default 10. Data size to compute the local variance in beam sizes. rel_excl_src : floats, optional. Default is None. Excludes sources in a specified region e.g ra, dec, radius in degrees. For 2 regions: ra1, dec1, radius1: ra2, dec2, radius2, etc. pos_smooth : float, optional. Default 2. Masking threshold for the positive image. For default value 2, data peaks < 2 * image noise are masked. neg_smooth : float, optional. Default 2. Similar to pos_smooth but applied to the negative image. thresh_isl : float, optional. Default is 3. Threshold for forming islands in the positive image thresh_pix : float, optional. Default is 5. Threshold for model fitting, in positive image. neg_thresh_isl : float, optional. Default is 3. Simialr to thresh_isl but for negative image. neg_thresh_pix : float, optional. Default is 5. Similar to thresh_pix but for negative image. savefits: boolean. Default is False. If True a negative image is saved. reset_rel: boolean. Default is False. If true then sources with correlation < 0.002 and rel >0.60 have their reliabilities set to 0. increase_beam_cluster: boolean, optional. If True, sources groupings will be increase by 20% the beam size. If False, the actual beam size will be used. Default is False. savemask_pos: boolean, optional. If true the mask applied on the positive side of an image after smoothing is saved. savemask_neg: Similar to savemask_pos but for the negative side of an image. loglevel : int, optional. Default is 0. Provides Pythonlogging options, 0, 1, 2 and 3 are for info, debug, error and critial respectively. kw : kward for source extractions. Should be a mapping e.g kw['thresh_isl'] = 2.0 or kw['do_polarization'] = True """ # self.smoothing = not no_smooth self.prefix = prefix # log level self.loglevel = loglevel self.log = utils.logger(self.loglevel, prefix=self.prefix) # image, psf image self.imagename = imagename self.psfname = psfname with pyfits.open(imagename) as hdu: self.header = hdu[0].header self.wcs = WCS(self.header, mode="pyfits") self.pixelsize = abs(self.header["cdelt1"]) self.bmaj = numpy.deg2rad(self.header["BMAJ"]) # boolean optionals self.makeplots = makeplots self.do_local_var = do_local_var self.nearsources = do_nearsources self.do_psf_corr = do_psf_corr self.savemaskpos = savemask_pos self.savemaskneg = savemask_neg self.savefits = savefits self.derel = reset_rel self.log.info("Catalogues will be saved as %s, where srl is source " " and gaul is Gaussians. "%saveformat) self.catalogue_format = "." + saveformat if not self.psfname: self.log.info(" No psf provided, do_psf_corr is set to False.") self.do_psf_corr = False # computing negative noise self.noise, self.mean = utils.negative_noise(self.imagename, self.prefix) self.log.info(" The negative noise is %e Jy/beam"%self.noise) if self.noise == 0: self.log.debug(" The negative noise is 0, check image") # source finder initialization self.sourcefinder_name = sourcefinder_name self.log.info(" Using %s source finder to extract the sources."% self.sourcefinder_name) self.negimage = self.prefix + "_negative.fits" utils.invert_image(self.imagename, self.negimage) # smoothing factors self.pos_smooth = pos_smooth self.neg_smooth = neg_smooth # region to evaluate self.corrstep = psf_corr_region self.localstep = local_var_region self.radiusrm = rel_excl_src self.do_beam = increase_beam_cluster beam_pix = int(round(numpy.rad2deg(self.bmaj)/self.pixelsize)) self.locstep = self.localstep * beam_pix self.cfstep = self.corrstep * beam_pix self.bmin, self.bpa = self.header["BMIN"], self.header["BPA"] self.opts_pos = {} if self.do_beam: bmaj = self.header["BMAJ"] self.opts_pos["beam"] = (1.2*bmaj, 1.2*self.bmin, self.bpa) # Pybdsm or source finder fitting thresholds self.thresh_isl = thresh_isl self.thresh_pix = thresh_pix self.opts_pos = dict(thresh_pix=self.thresh_pix, thresh_isl=self.thresh_isl) self.opts_pos.update(kw) self.opts_neg = {} self.opts_neg.update(kw) self.neg_thresh_isl = neg_thresh_isl self.neg_thresh_pix = neg_thresh_pix self.opts_neg["thresh_isl"] = self.neg_thresh_isl self.opts_neg["thresh_pix"] = self.neg_thresh_pix
def __init__(self, imagename, psfname=None, sourcefinder_name='pybdsm', makeplots=True, do_psf_corr=True, do_local_var=True, psf_corr_region=2, local_var_region=10, rel_excl_src=None, pos_smooth=1.6, neg_smooth=1.6, loglevel=0, thresh_pix=5, thresh_isl=3, neg_thresh_isl=3, neg_thresh_pix=5, prefix=None, do_nearsources=False, **kw): """ Takes in image and extracts sources and makes reliability estimations.. imagename: Fits image psfname: PSF fits image, optional. sourcefinder_name: str, optional. Default 'pybdsm'. Uses source finder specified by the users. makeplots: bool, optional. Default is True. Make reliability plots. do_psf_corr : bool, optional. Default True. If True, correlation of sources with PSF will be added as an extra source parameter in reliability estimation. But the PSF fits image must be provided. do_local_var : bool, optional. Default is True. Adds local variance as an extra source parameter, similar to do_psf_corr but independent of the PSF image. psf_corr_region : int, optional. Default value is 2. Data size to correlate around a source in beam sizes. local_var_region: int, optional. Default 10. Data size to compute the local variance in beam sizes. rel_excl_src : float numbers, optional. Default is None. Excludes sources in this region from the reliability estimations, e.g ra, dec, radius in degrees. For many regions: ra1, dec1, radius1: ra2, dec2, radius2. pos_smooth : float, optional. Default 1.6 Data smoothing threshold in the positive side of an image. For default value 1.6, data peaks < 1.6 * image noise will be averaged out. neg_smooth : float, optional. Default 1.6. Similar to pos_smooth but applied to the negative side of an image. loglevel : int, optional. Default is 0. Provides Pythonlogging options, 0, 1, 2 and 3 for info, debug, error and critial respectively. thresh_isl : float, optional. Default is 3. Threshold for the island boundary in number of sigma above the mean. Determines extent of island used for fitting [pybdsm]. For positive pixels. thresh_pix : float, optional. Default is 5. Source detection threshold: threshold for the island peak in number of sigma above the mean. For positive pixels. neg_thresh_isl : float, optional. Default is 3. Simialr to thresh_isl but applied to negative side of the image. neg_thresh_pix : float, optional. Default is 5. Similar to thresh_pix but applied to the negative side of an image. do_nearsources: boolean. Default is False. If true it adds number of nearest neighnours as an extra parameter. It looks for sources around 5 beam sizes. kw : kward for source extractions. Should be a mapping e.g kw['thresh_isl'] = 2.0 or kw['do_polarization'] = True """ # image, psf image self.imagename = imagename self.psfname = psfname # setting output file names self.prefix = prefix self.poslsm = self.prefix + "_positive.lsm.html" self.neglsm = self.prefix + "_negative.lsm.html" # log level self.loglevel = loglevel self.log = utils.logger(self.loglevel, prefix=self.prefix) self.log.info("Loading Image data") # reading imagename data self.imagedata, self.wcs, self.header, self.pixelsize =\ utils.reshape_data(self.imagename, prefix=self.prefix) self.bmaj = numpy.deg2rad(self.header["BMAJ"]) self.do_psf_corr = do_psf_corr if not self.psfname: self.log.info("No psf provided, do_psf_corr = False.") self.do_psf_corr = False # computing negative noise self.noise = utils.negative_noise(self.imagedata) self.log.info("The negative noise is %e"%self.noise) if self.noise == 0: self.log.debug("The negative noise is 0, check image") # source finder initialization self.sourcefinder_name = sourcefinder_name self.log.info("Using %s source finder to extract sources."% self.sourcefinder_name) # making negative image self.negativeimage = utils.invert_image( self.imagename, self.imagedata, self.header, self.prefix) # boolean optionals self.makeplots = makeplots self.do_local_var = do_local_var self.nearsources = do_nearsources # smoothing factors self.pos_smooth = pos_smooth self.neg_smooth = neg_smooth # region to evaluate self.psf_corr_region = psf_corr_region self.local_var_region = local_var_region self.rel_excl_src = rel_excl_src # Pybdsm or source finder fitting thresholds self.thresh_isl = thresh_isl self.thresh_pix = thresh_pix self.opts_pos = dict(thresh_pix=self.thresh_pix, thresh_isl=self.thresh_isl) self.opts_pos.update(kw) self.opts_neg = {} self.neg_thresh_isl = neg_thresh_isl self.neg_thresh_pix = neg_thresh_pix self.opts_neg["thresh_isl"] = self.neg_thresh_isl self.opts_neg["thresh_pix"] = self.neg_thresh_pix
def __init__(self, imagename, psfname=None, sourcefinder_name='pybdsm', saveformat="gaul", makeplots=True, do_psf_corr=True, do_local_var=True, psf_corr_region=5, local_var_region=10, rel_excl_src=None, pos_smooth=2, neg_smooth=2, loglevel=0, thresh_pix=5, thresh_isl=3, neg_thresh_isl=3, neg_thresh_pix=5, reset_rel=None, prefix=None, do_nearsources=False, savefits=False, increase_beam_cluster=False, savemask_pos=False, savemask_neg=False, no_smooth=True, **kw): """ Takes in image and extracts sources and makes reliability estimations.. imagename: Fits image psfname: PSF fits image, optional. sourcefinder_name: str, optional. Default 'pybdsm'. Uses source finder specified. makeplots: bool, optional. Default is True. Make reliability plots. do_psf_corr : bool, optional. Default True. If True, PSF correlation will be added as an extra parameter for density estimations. NB: the PSF fits image must be provided. do_local_var : bool, optional. Default is True. If True, adds local variance as an extra parameter, for density estimations. do_nearsources: boolean. Default is False. If true it adds number of nearest neighnours as an extra parameter. It looks for sources around 5 beam sizes. psf_corr_region : int, optional. Default value is 5. Data size to correlate around a source, in beam sizes. local_var_region: int, optional. Default 10. Data size to compute the local variance in beam sizes. rel_excl_src : floats, optional. Default is None. Excludes sources in a specified region e.g ra, dec, radius in degrees. For 2 regions: ra1, dec1, radius1: ra2, dec2, radius2, etc. pos_smooth : float, optional. Default 2. Masking threshold for the positive image. For default value 2, data peaks < 2 * image noise are masked. neg_smooth : float, optional. Default 2. Similar to pos_smooth but applied to the negative image. thresh_isl : float, optional. Default is 3. Threshold for forming islands in the positive image thresh_pix : float, optional. Default is 5. Threshold for model fitting, in positive image. neg_thresh_isl : float, optional. Default is 3. Simialr to thresh_isl but for negative image. neg_thresh_pix : float, optional. Default is 5. Similar to thresh_pix but for negative image. savefits: boolean. Default is False. If True a negative image is saved. reset_rel: boolean. Default is False. If true then sources with correlation < 0.002 and rel >0.60 have their reliabilities set to 0. increase_beam_cluster: boolean, optional. If True, sources groupings will be increase by 20% the beam size. If False, the actual beam size will be used. Default is False. savemask_pos: boolean, optional. If true the mask applied on the positive side of an image after smoothing is saved. savemask_neg: Similar to savemask_pos but for the negative side of an image. loglevel : int, optional. Default is 0. Provides Pythonlogging options, 0, 1, 2 and 3 are for info, debug, error and critial respectively. kw : kward for source extractions. Should be a mapping e.g kw['thresh_isl'] = 2.0 or kw['do_polarization'] = True """ # self.smoothing = not no_smooth self.prefix = prefix # log level self.loglevel = loglevel self.log = utils.logger(self.loglevel, prefix=self.prefix) # image, psf image self.imagename = imagename self.psfname = psfname with pyfits.open(imagename) as hdu: self.header = hdu[0].header self.wcs = WCS(self.header, mode="pyfits") self.pixelsize = abs(self.header["cdelt1"]) self.bmaj = numpy.deg2rad(self.header["BMAJ"]) # boolean optionals self.makeplots = makeplots self.do_local_var = do_local_var self.nearsources = do_nearsources self.do_psf_corr = do_psf_corr self.savemaskpos = savemask_pos self.savemaskneg = savemask_neg self.savefits = savefits self.derel = reset_rel self.log.info("Catalogues will be saved as %s, where srl is source " " and gaul is Gaussians. " % saveformat) self.catalogue_format = "." + saveformat if not self.psfname: self.log.info(" No psf provided, do_psf_corr is set to False.") self.do_psf_corr = False # computing negative noise self.noise, self.mean = utils.negative_noise(self.imagename, self.prefix) self.log.info(" The negative noise is %e Jy/beam" % self.noise) if self.noise == 0: self.log.debug(" The negative noise is 0, check image") # source finder initialization self.sourcefinder_name = sourcefinder_name self.log.info(" Using %s source finder to extract the sources." % self.sourcefinder_name) self.negimage = self.prefix + "_negative.fits" utils.invert_image(self.imagename, self.negimage) # smoothing factors self.pos_smooth = pos_smooth self.neg_smooth = neg_smooth # region to evaluate self.corrstep = psf_corr_region self.localstep = local_var_region self.radiusrm = rel_excl_src self.do_beam = increase_beam_cluster beam_pix = int(round(numpy.rad2deg(self.bmaj) / self.pixelsize)) self.locstep = self.localstep * beam_pix self.cfstep = self.corrstep * beam_pix self.bmin, self.bpa = self.header["BMIN"], self.header["BPA"] self.opts_pos = {} if self.do_beam: bmaj = self.header["BMAJ"] self.opts_pos["beam"] = (1.2 * bmaj, 1.2 * self.bmin, self.bpa) # Pybdsm or source finder fitting thresholds self.thresh_isl = thresh_isl self.thresh_pix = thresh_pix self.opts_pos = dict(thresh_pix=self.thresh_pix, thresh_isl=self.thresh_isl) self.opts_pos.update(kw) self.opts_neg = {} self.opts_neg.update(kw) self.neg_thresh_isl = neg_thresh_isl self.neg_thresh_pix = neg_thresh_pix self.opts_neg["thresh_isl"] = self.neg_thresh_isl self.opts_neg["thresh_pix"] = self.neg_thresh_pix
def __init__(self, imagename, psfname, poscatalog, negcatalog, snr_thresh=100, local_thresh=0.6, local_region=10, psfcorr_region=2, high_corr_thresh=0.5, negdetec_region=10, negatives_thresh=10, phasecenter_excl_radius=None, prefix=None, loglevel=0): """ Determines sources that require direction-dependent (DD) calibration solutions. imagename: Fits data psfname : PSF fits data poscatalog : Catalog of positive detections. negcatalog : Catalog of negative detections. Sources extracted from the negative side of an image. snr_thresh : float, optional. Default is 100. Any source with 100 times the minimum SNR is considered a high SN source. local_thresh : float, optional. Default is 0.6. Sources with local variance greater than 0.6 * negative noise are considered as sources of high local variance. local_region : integer, optional. Default is 10. A region to compute the local variance in beam sizes. psfcorr : integer, optional. Default is 2. Data size to correlate. In beam sizes. high_corr_thresh : float, optional. Default is 0.5. Correlation threshold. Sources of high correlation with the PSF have correlation > the specified. negdetec_region : float, optional. Default is 10. Region to lookup for negative detections around a given source. In beam size. negative_thresh : float, optional. Default is 6. Number of negative detections, N, threshold. Sources with number > N negatives around them are require direction dependent (DD) calibration solutions. phasecenter_excl_region : float (in degrees), optional. A radius from the phase center (in beam sizes) to exclude in making final DD source selection. prefix : str, optional. Sets a prefix to the output directory. loglevel : int, optional. Default 0. Python logging. 0, 1, 2, 3 for info, debug, error and critical respectively. """ # image, psf image, positive and negative catalogues self.imagename = imagename self.psfname = psfname self.poscatalog = poscatalog self.negcatalog = negcatalog self.loglevel = loglevel self.prefix = prefix self.log = utils.logger(self.loglevel, prefix=self.prefix) # reading the imagename data self.imagedata, self.wcs, self.header, self.pixsize =\ utils.reshape_data(self.imagename, prefix=self.prefix) self.log.info("Loading image data") # computing the noise self.noise = utils.negative_noise(self.imagedata) self.log.info("The negative noise of an image is %e"% self.noise) # tags self.snr_tag = "snr" self.high_local_tag = "high_var" self.high_corr_tag = "high_corr" self.dd_tag = "dE" # thresholds self.snr_thresh = snr_thresh self.local_thresh = local_thresh self.high_corr_thresh = high_corr_thresh self.negatives_thresh = negatives_thresh #regions self.psfcorr_region = psfcorr_region self.local_region = local_region self.phasecenter_excl_radius = phasecenter_excl_radius self.negdetec_region = negdetec_region # central ra, dec, beam major axes self. ra0 = numpy.deg2rad(self.header["CRVAL1"]) self.dec0 = numpy.deg2rad(self.header["CRVAL2"]) self.bmaj_deg = self.header['BMAJ'] # in degrees