Exemple #1
0
def parseSFind (lines, pristine=False):
    for linenum, line in enumerate (lines):
        if line[0] == '#':
            continue

        a = line.strip ().split ()
        source = Holder ()
        source.ra = parsehours (a[0])
        source.dec = parsedeglat (a[1])

        if a[1][0] in '+-':
            ofs = 1
        else:
            ofs = 0

        for i, name in enumerate (_sfindMiscColumns):
            substr = line[_sfindMiscOffsets[i]+ofs:_sfindMiscOffsets[i+1]+ofs]

            if '*' in substr:
                val = None
            else:
                val = float (substr) * _sfindUnits[i]

            setattr (source, name, val)

        if (not pristine and source.totflux is not None and
            source.pkflux is not None and source.totflux < source.pkflux):
            # Sfind docs say you can occasionally get this for
            # unresolved sources if the fitted Gaussian parameters are
            # smaller than the beamsize.
            source.totflux = source.pkflux

        if source.pkflux_uc == 0.:
            # Sometimes the precision in the text output is
            # insufficient; be conservative.
            source.pkflux_uc = 0.0005 * 1e-3

        if source.pkflux_uc is None:
            source.totflux_uc = None
        else:
            source.totflux_uc = abs (source.totflux * source.pkflux_uc / source.pkflux)

        if source.ra_uc == 0.: # as with pkflux_uc
            source.ra_uc = 0.0005 * A2R

        if source.dec_uc == 0.:
            source.dec_uc = 0.005 * A2R

        yield source
Exemple #2
0
def parseNVSS (stream):
    linenum = 0
    datalinenum = 0
    source = None

    for line in stream:
        linenum += 1

        if line[0] == '#':
            continue

        if datalinenum % 2 == 0:
            assert source is None, 'NVSS internal logic error 1'
            source = Holder ()
            colspec = nvss_columns1
        else:
            colspec = nvss_columns2

        try:
            for key, (b0, b1) in colspec.iteritems ():
                parser = nvss_parsers.get (key, float)
                setattr (source, key, parser (line[b0:b1]))
        except Exception as e:
            raise Exception ('line %d, item %s: %s' % (linenum, key, e))

        if datalinenum % 2 == 1:
            # Fixups
            source.major_is_ul = source.major[0]
            source.major = source.major[1]
            source.minor_is_ul = source.minor[0]
            source.minor = source.minor[1]
            # Done
            yield source
            source = None

        datalinenum += 1

    assert source is None, 'NVSS internal logic error 2'