File: usnob_catalog.py

package info (click to toggle)
astrometry.net 0.76%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 18,120 kB
  • sloc: ansic: 161,636; python: 19,915; makefile: 1,439; awk: 159; cpp: 78; pascal: 67; sh: 61; perl: 9
file content (82 lines) | stat: -rwxr-xr-x 2,295 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#! /usr/bin/env python3
# This file is part of the Astrometry.net suite.
# Licensed under a 3-clause BSD style license - see LICENSE
from __future__ import print_function
import sys
from optparse import OptionParser

try:
    import pyfits
except ImportError:
    try:
        from astropy.io import fits as pyfits
    except ImportError:
        raise ImportError("Cannot import either pyfits or astropy.io.fits")
from numpy import *

from astrometry.util.fits import *
from astrometry.util.healpix import *
from astrometry.util.starutil_numpy import *
from astrometry.util.usnob_cuts import *

def get_usnob_sources(ra, dec, radius=1, basefn=None):
    usnob_nside = 9

    if basefn is None:
        usnob_pat = 'usnob10_hp%03i.fits'
    else:
        usnob_pat = basefn

    usnobhps = healpix_rangesearch(ra, dec, radius, usnob_nside)
    print('USNO-B healpixes in range:', usnobhps)
    allU = None
    for hp in usnobhps:
        usnobfn = usnob_pat % hp
        print('USNOB filename:', usnobfn)
        U = table_fields(usnobfn)
        I = (degrees_between(ra, dec, U.ra, U.dec) < radius)
        print('%i USNOB stars within range.' % sum(I))
        U = U[I]
        if allU is None:
            allU = U
        else:
            allU.append(U)
    return allU

if __name__ == '__main__':
    parser = OptionParser(usage='%prog [options] <ra> <dec> <output-filename>')

    parser.add_option('-r', dest='radius', type='float', help='Search radius, in deg (default 1 deg)')
    parser.add_option('-b', dest='basefn', help='Base filename of USNO-B FITS files (default: usnob10_hp%03i.fits)')
    parser.set_defaults(radius=1.0, basefn=None)

    (opt, args) = parser.parse_args()
    if len(args) != 3:
        parser.print_help()
        print()
        print('Got extra arguments:', args)
        sys.exit(-1)

    # parse RA,Dec.
    ra = float(args[0])
    dec = float(args[1])
    outfn = args[2]

    # ugh!
    opts = {}
    for k in ['radius', 'basefn']:
        opts[k] = getattr(opt, k)

    X = get_usnob_sources(ra, dec, **opts)
    print('Got %i USNO-B sources.' % len(X))

    print('Applying cuts...')
    I = usnob_apply_cuts(X)
    X = X[I]
    print(len(X), 'pass cuts')

    usnob_compute_average_mags(X)

    print('Writing to', outfn)
    X.write_to(outfn)