Exemple #1
0
#! /usr/bin/env python
# -*- python -*-

import sys, astimage, bgfit
from bgfit import fitknown

stpath = sys.argv[1]
image = astimage.open(sys.argv[2], "r")

if len(sys.argv) == 4:
    residpath = sys.argv[3]
else:
    residpath = None

fitknown(image, stpath, residpath, 1, 0, sys.stdout.write, fixpos=False, fixshape=False)
Exemple #2
0
    def genSources (self, ra0, dec0, freq0):
        self.sources = []

        a = pbalphas (freq0)

        if pxalignimg is None:
            pximg = None
        else:
            import astimage
            pximg = astimage.open (pxalignimg, 'r').simple ()

        for i in xrange (npsrc):
            s = basicsource (ra0, dec0, a, pximg)
            self.sources.append (s)
            s.major = s.minor = s.pa = None

        for i in xrange (ngsrc):
            s = basicsource (ra0, dec0, a, pximg)
            self.sources.append (s)
            s.major = 300 * A2R
            s.minor = 80 * A2R
            s.pa = orientcen (randangle ())

        # Assign sources to fitgroups so that bgfit can handle very nearby
        # sources. We get rid of *extremely* close sources, on the grounds that
        # in practice we'd never identify them as two separate sources. Otherwise
        # we make sure that any two sources nearer than *groupdist* are in the
        # same fitgroup. This could have various pathological failure modes but
        # will be fine most of the time (and the only penalty to overgrouping is
        # a larger instantaneous fitting problem, I think).

        groupnum = 0

        for i in xrange (len (self.sources)):
            s1 = self.sources[i]
            if s1.delete:
                continue

            for j in xrange (i + 1, len (self.sources)):
                s2 = self.sources[j]
                if s2.delete:
                    continue

                d = sphdist (s1.dec, s1.ra, s2.dec, s2.ra)

                if d > groupdist:
                    continue
                if d < tooclosedist:
                    s2.delete = True
                    continue

                if s1.fitgroup is not None and s2.fitgroup is not None:
                    # Need to merge two existing fitgroups
                    newgroup = s1.fitgroup
                    oldgroup = s2.fitgroup
                    for s3 in self.sources:
                        if s3.fitgroup == oldgroup:
                            s3.fitgroup = newgroup
                elif s1.fitgroup is not None:
                    s2.fitgroup = s1.fitgroup
                elif s2.fitgroup is not None:
                    # This can happen, if sources A B and C appear in
                    # that order in the list, and A is near enough to
                    # C, and B is near enough to C, but A is not near
                    # enough to B.
                    s1.fitgroup = s2.fitgroup
                else:
                    s1.fitgroup = str (groupnum)
                    groupnum += 1
                    s2.fitgroup = s1.fitgroup

        self.sources = [s for s in self.sources if not s.delete]

        # Now we can output.

        import srctable, flatdb
        cols = srctable.columns ('ra dec totflux major minor pa')
        cols.append (flatdb.Column (name='fitgroup', kind=flatdb.K_STR, width=10))
        cols.append (srctable.floatcol ('fadedflux', 12, '%.5f'))
        flatdb.writeStreamedTable (sys.stdout.write, [], cols, self.sources)