Ejemplo n.º 1
0
def match_kdtree_catalog(wcs, catfn):
    from astrometry.libkd.spherematch import (
        tree_open,
        tree_close,
        tree_build_radec,
        tree_free,
        trees_match,
        tree_permute,
    )
    from astrometry.libkd import spherematch_c
    from astrometry.util.starutil_numpy import deg2dist, xyztoradec
    import numpy as np
    import sys

    rc, dc = wcs.get_center()
    rr = wcs.get_radius()
    kd = tree_open(catfn)
    kd2 = tree_build_radec(np.array([rc]), np.array([dc]))
    r = deg2dist(rr)
    I, J, nil = trees_match(kd, kd2, r, permuted=False)
    # HACK
    # I2,J,d = trees_match(kd, kd2, r)
    xyz = spherematch_c.kdtree_get_positions(kd, I.astype(np.uint32))
    # print 'I', I
    I2 = tree_permute(kd, I)
    # print 'I2', I2
    tree_free(kd2)
    tree_close(kd)
    tra, tdec = xyztoradec(xyz)
    return tra, tdec, I2
Ejemplo n.º 2
0
 def drop_cache(self):
     '''
     Clears all cached data contained in this object.  Useful for
     pickling / multiprocessing.
     '''
     self.ccds = None
     self.bricks = None
     if self.bricktree is not None:
         from astrometry.libkd.spherematch import tree_free
         tree_free(self.bricktree)
     self.bricktree = None
Ejemplo n.º 3
0
 def drop_cache(self):
     '''
     Clears all cached data contained in this object.  Useful for
     pickling / multiprocessing.
     '''
     self.ccds = None
     self.bricks = None
     if self.bricktree is not None:
         from astrometry.libkd.spherematch import tree_free
         tree_free(self.bricktree)
     self.bricktree = None
Ejemplo n.º 4
0
def match_kdtree_catalog(wcs, catfn):
    from astrometry.libkd.spherematch import tree_open, tree_close, tree_build_radec, tree_free, trees_match, tree_permute
    from astrometry.libkd import spherematch_c
    from astrometry.util.starutil_numpy import deg2dist, xyztoradec
    import numpy as np
    import sys

    rc, dc = wcs.get_center()
    rr = wcs.get_radius()
    kd = tree_open(catfn)
    kd2 = tree_build_radec(np.array([rc]), np.array([dc]))
    r = deg2dist(rr)
    I, J, nil = trees_match(kd, kd2, r, permuted=False)
    # HACK
    #I2,J,d = trees_match(kd, kd2, r)
    xyz = spherematch_c.kdtree_get_positions(kd, I.astype(np.uint32))
    #print 'I', I
    I2 = tree_permute(kd, I)
    #print 'I2', I2
    tree_free(kd2)
    tree_close(kd)
    tra, tdec = xyztoradec(xyz)
    return tra, tdec, I2
Ejemplo n.º 5
0
def plot_wcs_outline(wcsfn,
                     plotfn,
                     W=256,
                     H=256,
                     width=36,
                     zoom=True,
                     zoomwidth=3.6,
                     grid=10,
                     hd=False,
                     hd_labels=False,
                     tycho2=False):
    anutil.log_init(3)
    #anutil.log_set_level(3)

    wcs = anutil.Tan(wcsfn, 0)
    ra, dec = wcs.radec_center()

    plot = ps.Plotstuff(outformat='png', size=(W, H), rdw=(ra, dec, width))
    plot.linestep = 1.
    plot.color = 'verydarkblue'
    plot.plot('fill')

    plot.fontsize = 12
    #plot.color = 'gray'
    # dark gray
    plot.rgb = (0.3, 0.3, 0.3)
    if grid is not None:
        plot.plot_grid(*([grid] * 4))

    plot.rgb = (0.4, 0.6, 0.4)
    ann = plot.annotations
    ann.NGC = ann.bright = ann.HD = 0
    ann.constellations = 1
    ann.constellation_labels = 1
    ann.constellation_labels_long = 1
    plot.plot('annotations')
    plot.stroke()
    ann.constellation_labels = 0
    ann.constellation_labels_long = 0
    ann.constellation_lines = 0

    ann.constellation_markers = 1
    plot.markersize = 3
    plot.rgb = (0.4, 0.6, 0.4)
    plot.plot('annotations')
    plot.fill()
    ann.constellation_markers = 0

    ann.bright_labels = False
    ann.bright = True
    plot.markersize = 2
    if zoom >= 2:
        ann.bright_labels = True
    plot.plot('annotations')
    ann.bright = False
    ann.bright_labels = False
    plot.fill()

    if hd:
        ann.HD = True
        ann.HD_labels = hd_labels
        ps.plot_annotations_set_hd_catalog(ann, settings.HENRY_DRAPER_CAT)
        plot.plot('annotations')
        plot.stroke()
        ann.HD = False
        ann.HD_labels = False

    if tycho2 and settings.TYCHO2_KD:
        from astrometry.libkd.spherematch import tree_open, tree_close, tree_build_radec, tree_free, trees_match
        from astrometry.libkd import spherematch_c
        from astrometry.util.starutil_numpy import deg2dist, xyztoradec
        import numpy as np
        import sys
        kd = tree_open(settings.TYCHO2_KD)
        # this is a bit silly: build a tree with a single point, then do match()
        kd2 = tree_build_radec(np.array([ra]), np.array([dec]))
        r = deg2dist(width * np.sqrt(2.) / 2.)
        #r = deg2dist(wcs.radius())
        I, nil, nil = trees_match(kd, kd2, r, permuted=False)
        del nil
        #print 'Matched', len(I)
        xyz = spherematch_c.kdtree_get_positions(kd, I)
        del I
        tree_free(kd2)
        tree_close(kd)
        #print >>sys.stderr, 'Got', xyz.shape, xyz
        tra, tdec = xyztoradec(xyz)
        #print >>sys.stderr, 'RA,Dec', ra,dec
        plot.apply_settings()
        for r, d in zip(tra, tdec):
            plot.marker_radec(r, d)
        plot.fill()

    ann.NGC = 1
    plot.plot('annotations')
    ann.NGC = 0

    plot.color = 'white'
    plot.lw = 3
    out = plot.outline
    out.wcs_file = wcsfn
    plot.plot('outline')

    if zoom:
        # MAGIC width, height are arbitrary
        zoomwcs = anutil.anwcs_create_box(ra, dec, zoomwidth, 1000, 1000)
        out.wcs = zoomwcs
        plot.lw = 1
        plot.dashed(3)
        plot.plot('outline')

    plot.write(plotfn)
Ejemplo n.º 6
0
		from astrometry.libkd.spherematch import tree_open, tree_close, tree_build_radec, tree_free, trees_match
		from astrometry.libkd import spherematch_c
		from astrometry.util.starutil_numpy import deg2dist, xyztoradec
		import numpy as np
		import sys
		wcs = plot.wcs
		rc,dc = wcs.get_center()
		rr = wcs.get_radius()
		kd = tree_open(opt.t2cat)
		kd2 = tree_build_radec(np.array([rc]), np.array([dc]))
		r = deg2dist(rr)
		I,J,d = trees_match(kd, kd2, r, permuted=False)
		# HACK
		I2,J,d = trees_match(kd, kd2, r)
		xyz = spherematch_c.kdtree_get_positions(kd, I)
		tree_free(kd2)
		tree_close(kd)
		tra,tdec = xyztoradec(xyz)
		T = fits_table(opt.t2cat, hdu=6)
		for r,d,t1,t2,t3 in zip(tra,tdec, T.tyc1[I2], T.tyc2[I2], T.tyc3[I2]):
			if not plot.wcs.is_inside(r, d):
				continue
			ann.add_target(r, d, 'Tycho-2 %i-%i-%i' % (t1,t2,t3))

			
	plot.color = opt.textcolor
	plot.fontsize = opt.textsize
	plot.lw = opt.lw
	plot.valign = opt.valign
	plot.halign = opt.halign
	plot.label_offset_x = opt.tox;
Ejemplo n.º 7
0
def plot_wcs_outline(wcsfn, plotfn, W=256, H=256, width=36, zoom=True,
                     zoomwidth=3.6, grid=10, hd=False, hd_labels=False,
                     tycho2=False):
    anutil.log_init(3)
    #anutil.log_set_level(3)

    wcs = anutil.Tan(wcsfn, 0)
    ra,dec = wcs.radec_center()

    plot = ps.Plotstuff(outformat='png', size=(W, H), rdw=(ra,dec,width))
    plot.linestep = 1.
    plot.color = 'verydarkblue'
    plot.plot('fill')

    plot.fontsize = 12
    #plot.color = 'gray'
    # dark gray
    plot.rgb = (0.3,0.3,0.3)
    if grid is not None:
        plot.plot_grid(*([grid]*4))

    plot.rgb = (0.4, 0.6, 0.4)
    ann = plot.annotations
    ann.NGC = ann.bright = ann.HD = 0
    ann.constellations = 1
    ann.constellation_labels = 1
    ann.constellation_labels_long = 1
    plot.plot('annotations')
    plot.stroke()
    ann.constellation_labels = 0
    ann.constellation_labels_long = 0
    ann.constellation_lines = 0

    ann.constellation_markers = 1
    plot.markersize = 3
    plot.rgb = (0.4, 0.6, 0.4)
    plot.plot('annotations')
    plot.fill()
    ann.constellation_markers = 0

    ann.bright_labels = False
    ann.bright = True
    plot.markersize = 2
    if zoom >= 2:
        ann.bright_labels = True
    plot.plot('annotations')
    ann.bright = False
    ann.bright_labels = False
    plot.fill()

    if hd:
        ann.HD = True
        ann.HD_labels = hd_labels
        ps.plot_annotations_set_hd_catalog(ann, settings.HENRY_DRAPER_CAT)
        plot.plot('annotations')
        plot.stroke()
        ann.HD = False
        ann.HD_labels = False

    if tycho2:
        from astrometry.libkd.spherematch import tree_open, tree_close, tree_build_radec, tree_free, trees_match
        from astrometry.libkd import spherematch_c
        from astrometry.util.starutil_numpy import deg2dist, xyztoradec
        import numpy as np
        import sys
        kd = tree_open(settings.TYCHO2_KD)
        # this is a bit silly: build a tree with a single point, then do match()
        kd2 = tree_build_radec(np.array([ra]), np.array([dec]))
        r = deg2dist(width * np.sqrt(2.) / 2.)
        #r = deg2dist(wcs.radius())
        I,J,d = trees_match(kd, kd2, r, permuted=False)
        del J
        del d
        #print 'Matched', len(I)
        xyz = spherematch_c.kdtree_get_positions(kd, I)
        del I
        tree_free(kd2)
        tree_close(kd)
        #print >>sys.stderr, 'Got', xyz.shape, xyz
        tra,tdec = xyztoradec(xyz)
        #print >>sys.stderr, 'RA,Dec', ra,dec
        plot.apply_settings()
        for r,d in zip(tra,tdec):
            plot.marker_radec(r,d)
        plot.fill()

    ann.NGC = 1
    plot.plot('annotations')
    ann.NGC = 0

    plot.color = 'white'
    plot.lw = 3
    out = plot.outline
    out.wcs_file = wcsfn
    plot.plot('outline')

    if zoom:
        # MAGIC width, height are arbitrary
        zoomwcs = anutil.anwcs_create_box(ra, dec, zoomwidth, 1000,1000)
        out.wcs = zoomwcs
        plot.lw = 1
        plot.dashed(3)
        plot.plot('outline')

    plot.write(plotfn)