Exemplo n.º 1
0
def adjacency_matrix(tilera, tiledec, fiberposfile=None):
    """Overlap area matrix between slit blocks and radial bins, given 
    tile ras and decs."""
    # compute x & y on each tile to ra & dec
    # match ras and decs together at some fiducial size
    # (this ignores ellipticity, etc., but the slite blocks are pretty big)
    #
    if fiberposfile is None:
        fiberposfile = os.path.join(os.environ['DESIMODEL'], 'data',
                                    'focalplane', 'fiberpos.fits')
    from astropy.io import fits
    fpos = fits.getdata(fiberposfile)
    # really slow, not vectorized.
    pos = [[
        focalplane.xy2radec(tra, tdec, fx, fy)
        for fx, fy in zip(fpos['x'], fpos['y'])
    ] for tra, tdec in zip(tilera, tiledec)]
    pos = numpy.array(pos)
    ras = pos[:, :, 0].ravel()
    decs = pos[:, :, 1].ravel()
    slitno = numpy.tile(fpos['slitblock'] + fpos['petal'] * 20, len(tilera))
    radbin = numpy.floor(numpy.sqrt(fpos['x']**2 + fpos['y']**2) /
                         20).astype('i4')
    radbin = numpy.tile(radbin, len(tilera))
    expnum = numpy.repeat(numpy.arange(len(tilera)), len(fpos))
    rad = 1.4 / 60
    m1, m2, d12 = match_radec(ras, decs, ras, decs, rad, notself=True)
    m = expnum[m1] != expnum[m2]
    m1 = m1[m]
    m2 = m2[m]
    d12 = d12[m]
    # area of intersection of two equal-size circles?
    # area: 2r^2 arccos(d/2r)-0.5 d sqrt((2r-d)(2r+d))
    area = (2 * rad**2 * numpy.arccos(d12 / 2. / rad) - 0.5 * d12 * numpy.sqrt(
        (2 * rad - d12) * (2 * rad + d12)))
    nslitno = numpy.max(slitno) + 1
    nradbin = numpy.max(radbin) + 1
    adj = numpy.zeros(nslitno**2, dtype='f4')
    adjr = numpy.zeros(nradbin**2, dtype='f4')
    ind = slitno[m1] * nslitno + slitno[m2]
    indr = radbin[m1] * nradbin + radbin[m2]
    adj += numpy.bincount(ind, weights=area[m1], minlength=len(adj))
    adj = adj.reshape(nslitno, nslitno)
    adjr += numpy.bincount(indr, weights=area[m1], minlength=len(adjr))
    adjr = adjr.reshape(nradbin, nradbin)
    return adj, adjr
Exemplo n.º 2
0
def adjacency_matrix(tilera, tiledec, fiberposfile=None):
    """Overlap area matrix between slit blocks and radial bins, given 
    tile ras and decs."""
    # compute x & y on each tile to ra & dec
    # match ras and decs together at some fiducial size
    # (this ignores ellipticity, etc., but the slite blocks are pretty big)
    # 
    if fiberposfile is None:
        fiberposfile = os.path.join(os.environ['DESIMODEL'], 'data', 
                                    'focalplane', 'fiberpos.fits')
    from astropy.io import fits
    fpos = fits.getdata(fiberposfile)
    # really slow, not vectorized.
    pos = [[focalplane.xy2radec(tra, tdec, fx, fy) 
            for fx, fy in zip(fpos['x'], fpos['y'])]
           for tra, tdec in zip(tilera, tiledec)]
    pos = numpy.array(pos)
    ras = pos[:, :, 0].ravel()
    decs = pos[:, :, 1].ravel()
    slitno = numpy.tile(fpos['slitblock']+fpos['petal']*20, len(tilera))
    radbin = numpy.floor(numpy.sqrt(fpos['x']**2+fpos['y']**2)/20).astype('i4')
    radbin = numpy.tile(radbin, len(tilera))
    expnum = numpy.repeat(numpy.arange(len(tilera)), len(fpos))
    rad = 1.4/60
    m1, m2, d12 = match_radec(ras, decs, ras, decs, rad, 
                                       notself=True)
    m = expnum[m1] != expnum[m2]
    m1 = m1[m]
    m2 = m2[m]
    d12 = d12[m]
    # area of intersection of two equal-size circles?
    # area: 2r^2 arccos(d/2r)-0.5 d sqrt((2r-d)(2r+d))
    area = (2*rad**2*numpy.arccos(d12/2./rad) -
            0.5*d12*numpy.sqrt((2*rad-d12)*(2*rad+d12)))
    nslitno = numpy.max(slitno)+1
    nradbin = numpy.max(radbin)+1
    adj = numpy.zeros(nslitno**2, dtype='f4')
    adjr = numpy.zeros(nradbin**2, dtype='f4')
    ind = slitno[m1]*nslitno+slitno[m2]
    indr = radbin[m1]*nradbin+radbin[m2]
    adj += numpy.bincount(ind, weights=area[m1], minlength=len(adj))
    adj = adj.reshape(nslitno, nslitno)
    adjr += numpy.bincount(indr, weights=area[m1], minlength=len(adjr))
    adjr = adjr.reshape(nradbin, nradbin)
    return adj, adjr
Exemplo n.º 3
0
def plot_circles_radec(ax, circles, sample_per_circle):
    """ Transforms points on a list of circles into radec and plots them
    Parameters
    ----------
    ax : matplotlib Axes object
    circles : list
        A list of Circle objects that needs plotting
    sample_per_circle:
        Number of points to plot around a circle
    """
    ra_col = np.array([])
    dec_col = np.array([])
    for c in circles:
        x, y = c.get_points(sample_per_circle)
        ra, dec = xy2radec(telra, teldec, Column(x), Column(y))
        ra_col = append(ra_col, ra)
        dec_col = append(dec_col, dec)
    plot(ra_col, dec_col, '.')
Exemplo n.º 4
0
def transform2radec(telra, teldec, v):
    """Transforms a single point to radec
    Temporary utility function. Can be replaced by xy2radec
    """
    ra, dec = xy2radec(telra, teldec, Column([v[0]]), Column(v[1]))
    return np.array([ra[0], dec[0]])
Exemplo n.º 5
0
def transform_circle_radec(circle, sample):
    x, y = circle.get_points(sample)
    ra, dec = xy2radec(telra, teldec, Column(x), Column(y))
    return ra, dec
Exemplo n.º 6
0
fp = desimodel.io.load_fiberpos()  #- load the fiberpos.fits file
telra, teldec = 10.0, 20.0  #- telescope central pointing at this RA,dec

# Create circles at each fiberpos
circles = []
for i in range(len(fp['X'])):
    circles.append(Circle(fp['X'][i], fp['Y'][i], 6))

# circles = [Circle(-200, -300, 6)]

# Aggregate transformed points from each circle
ra_col = np.array([])
dec_col = np.array([])
for c in circles:
    x, y = c.get_points(50)
    ra, dec = xy2radec(telra, teldec, Column(x), Column(y))
    ra_col = append(ra_col, ra)
    dec_col = append(dec_col, dec)

ion()
figure(figsize=(8, 4))
# subplot(121)
# plot(fp['X'], fp['Y'], '.'); xlabel('X [mm]'); ylabel('Y [mm]')
ax = subplot(121)
plot(ra_col, dec_col, '.')
xlabel('RA [degrees]')
ylabel('dec [degrees]')

xlim([10.80, 10.90])
ylim([18.75, 18.85])