Exemplo n.º 1
0
Arquivo: pyse.py Projeto: hughbg/tkp
def get_detection_labels(filename, det, anl, beam, configuration, plane=0):
    print "Detecting islands in %s" % (filename,)
    print "Thresholding with det = %f sigma, analysis = %f sigma" % (det, anl)
    ff = open_accessor(filename, beam=beam, plane=plane)
    imagedata = sourcefinder_image_from_accessor(ff, **configuration)
    labels, labelled_data = imagedata.label_islands(det * imagedata.rmsmap, anl * imagedata.rmsmap)
    return labels, labelled_data
Exemplo n.º 2
0
def get_detection_labels(filename, det, anl, beam, configuration, plane=0):
    print "Detecting islands in %s" % (filename, )
    print "Thresholding with det = %f sigma, analysis = %f sigma" % (det, anl)
    ff = open_accessor(filename, beam=beam, plane=plane)
    imagedata = sourcefinder_image_from_accessor(ff, **configuration)
    labels, labelled_data = imagedata.label_islands(det * imagedata.rmsmap,
                                                    anl * imagedata.rmsmap)
    return labels, labelled_data
Exemplo n.º 3
0
def run_sourcefinder(files, options):
    """
    Iterate over the list of files, running a sourcefinding step on each in
    turn. If specified, a DS9-compatible region file and/or a FITS file
    showing the residuals after Gaussian fitting are dumped for each file.
    A string containing a human readable list of sources is returned.
    """
    output = StringIO()

    beam = get_beam(options.bmaj, options.bmin, options.bpa)
    configuration = get_sourcefinder_configuration(options)

    if options.mode == "detimage":
        labels, labelled_data = get_detection_labels(options.detection_image,
                                                     options.detection,
                                                     options.analysis, beam,
                                                     configuration)
    else:
        labels, labelled_data = [], None

    for counter, filename in enumerate(files):
        print "Processing %s (file %d of %d)." % (filename, counter + 1,
                                                  len(files))
        imagename = os.path.splitext(os.path.basename(filename))[0]
        ff = open_accessor(filename, beam=beam, plane=0)
        imagedata = sourcefinder_image_from_accessor(ff, **configuration)

        if options.mode == "fixed":
            sr = imagedata.fit_fixed_positions(
                options.fixed_coords, options.ffbox * max(imagedata.beam[0:2]))

        else:
            if options.mode == "fdr":
                print "Using False Detection Rate algorithm with alpha = %f" % (
                    options.alpha, )
                sr = imagedata.fd_extract(
                    alpha=options.alpha,
                    deblend_nthresh=options.deblend_thresholds,
                    force_beam=options.force_beam)
            else:
                if labelled_data is None:
                    print "Thresholding with det = %f sigma, analysis = %f sigma" % (
                        options.detection, options.analysis)

                sr = imagedata.extract(
                    det=options.detection,
                    anl=options.analysis,
                    labelled_data=labelled_data,
                    labels=labels,
                    deblend_nthresh=options.deblend_thresholds,
                    force_beam=options.force_beam)

        if options.regions:
            regionfile = imagename + ".reg"
            regionfile = open(regionfile, 'w')
            regionfile.write(regions(sr))
            regionfile.close()
        if options.residuals or options.islands:
            gaussian_map, residual_map = generate_result_maps(
                imagedata.data, sr)
        if options.residuals:
            residualfile = imagename + ".residuals.fits"
            writefits(residualfile, residual_map, pyfits.getheader(filename))
        if options.islands:
            islandfile = imagename + ".islands.fits"
            writefits(islandfile, gaussian_map, pyfits.getheader(filename))
        if options.rmsmap:
            rmsfile = imagename + ".rms.fits"
            writefits(rmsfile, numpy.array(imagedata.rmsmap),
                      pyfits.getheader(filename))
        if options.sigmap:
            sigfile = imagename + ".sig.fits"
            writefits(sigfile,
                      numpy.array(imagedata.data_bgsubbed / imagedata.rmsmap),
                      pyfits.getheader(filename))
        if options.skymodel:
            with open(imagename + ".skymodel", 'w') as skymodelfile:
                if ff.freq_eff:
                    skymodelfile.write(skymodel(sr, ff.freq_eff))
                else:
                    print "WARNING: Using default reference frequency for %s" % (
                        skymodelfile.name, )
                    skymodelfile.write(skymodel(sr))
        if options.csv:
            with open(imagename + ".csv", 'w') as csvfile:
                csvfile.write(csv(sr))
        print >> output, summary(filename, sr),
    return output.getvalue()
Exemplo n.º 4
0
Arquivo: pyse.py Projeto: hughbg/tkp
def run_sourcefinder(files, options):
    """
    Iterate over the list of files, running a sourcefinding step on each in
    turn. If specified, a DS9-compatible region file and/or a FITS file
    showing the residuals after Gaussian fitting are dumped for each file.
    A string containing a human readable list of sources is returned.
    """
    output = StringIO()

    beam = get_beam(options.bmaj, options.bmin, options.bpa)
    configuration = get_sourcefinder_configuration(options)

    if options.mode == "detimage":
        labels, labelled_data = get_detection_labels(
            options.detection_image, options.detection, options.analysis, beam, configuration
        )
    else:
        labels, labelled_data = [], None

    for counter, filename in enumerate(files):
        print "Processing %s (file %d of %d)." % (filename, counter + 1, len(files))
        imagename = os.path.splitext(os.path.basename(filename))[0]
        ff = open_accessor(filename, beam=beam, plane=0)
        imagedata = sourcefinder_image_from_accessor(ff, **configuration)

        if options.mode == "fixed":
            sr = imagedata.fit_fixed_positions(options.fixed_coords, options.ffbox * max(imagedata.beam[0:2]))

        else:
            if options.mode == "fdr":
                print "Using False Detection Rate algorithm with alpha = %f" % (options.alpha,)
                sr = imagedata.fd_extract(
                    alpha=options.alpha, deblend_nthresh=options.deblend_thresholds, force_beam=options.force_beam
                )
            else:
                if labelled_data is None:
                    print "Thresholding with det = %f sigma, analysis = %f sigma" % (
                        options.detection,
                        options.analysis,
                    )

                sr = imagedata.extract(
                    det=options.detection,
                    anl=options.analysis,
                    labelled_data=labelled_data,
                    labels=labels,
                    deblend_nthresh=options.deblend_thresholds,
                    force_beam=options.force_beam,
                )

        if options.regions:
            regionfile = imagename + ".reg"
            regionfile = open(regionfile, "w")
            regionfile.write(regions(sr))
            regionfile.close()
        if options.residuals or options.islands:
            gaussian_map, residual_map = generate_result_maps(imagedata.data, sr)
        if options.residuals:
            residualfile = imagename + ".residuals.fits"
            writefits(residualfile, residual_map, pyfits.getheader(filename))
        if options.islands:
            islandfile = imagename + ".islands.fits"
            writefits(islandfile, gaussian_map, pyfits.getheader(filename))
        if options.rmsmap:
            rmsfile = imagename + ".rms.fits"
            writefits(rmsfile, numpy.array(imagedata.rmsmap), pyfits.getheader(filename))
        if options.sigmap:
            sigfile = imagename + ".sig.fits"
            writefits(sigfile, numpy.array(imagedata.data_bgsubbed / imagedata.rmsmap), pyfits.getheader(filename))
        if options.skymodel:
            with open(imagename + ".skymodel", "w") as skymodelfile:
                if ff.freq_eff:
                    skymodelfile.write(skymodel(sr, ff.freq_eff))
                else:
                    print "WARNING: Using default reference frequency for %s" % (skymodelfile.name,)
                    skymodelfile.write(skymodel(sr))
        if options.csv:
            with open(imagename + ".csv", "w") as csvfile:
                csvfile.write(csv(sr))
        print >> output, summary(filename, sr),
    return output.getvalue()