예제 #1
0
def combine_fitsheader(headers, cdelt=None, pa=None):
    """
    Returns a FITS header which encompasses all input headers.
    """

    if not isinstance(headers, (list, tuple)):
        header = (headers, )

    if len(headers) == 1 and cdelt is None and pa is None:
        return headers[0]

    crval = barycenter_lonlat([h['CRVAL1'] for h in headers],
                              [h['CRVAL2'] for h in headers])

    if cdelt is None or pa is None:
        cdeltpa = [get_cdelt_pa(h) for h in headers]

    if cdelt is None:
        cdelt = min([np.min(abs(cdelt)) for cdelt, pa in cdeltpa])

    if pa is None:
        pa = tmf.mean_degrees(np.array([pa for cdelt, pa in cdeltpa]))

    header0 = create_fitsheader((1, 1),
                                cdelt=cdelt,
                                pa=pa,
                                crpix=(1, 1),
                                crval=crval)

    proj0 = wcs.Projection(header0)
    xy0 = []
    for h in headers:
        proj = wcs.Projection(h)
        nx = h['NAXIS1']
        ny = h['NAXIS2']
        x = h['CRPIX1']
        y = h['CRPIX2']
        edges = proj.toworld(
            ([0.5, x, nx + 0.5, 0.5, x, nx + 0.5, 0.5, x, nx + 0.5],
             [0.5, 0.5, 0.5, y, y, y, ny + 0.5, ny + 0.5, ny + 0.5]))
        xy0.append(proj0.topixel(edges))

    xmin0 = np.round(min([min(c[0]) for c in xy0]))
    xmax0 = np.round(max([max(c[0]) for c in xy0]))
    ymin0 = np.round(min([min(c[1]) for c in xy0]))
    ymax0 = np.round(max([max(c[1]) for c in xy0]))

    header0['NAXIS1'] = int(xmax0 - xmin0 + 1)
    header0['NAXIS2'] = int(ymax0 - ymin0 + 1)
    header0['CRPIX1'] = 2 - xmin0
    header0['CRPIX2'] = 2 - ymin0

    return header0
예제 #2
0
def combine_fitsheader(headers, cdelt=None, pa=None):
    """
    Returns a FITS header which encompasses all input headers.
    """

    if not isinstance(headers, (list, tuple)):
        header = (headers,)

    if len(headers) == 1 and cdelt is None and pa is None:
        return headers[0]

    crval = barycenter_lonlat([h['CRVAL1'] for h in headers],
                              [h['CRVAL2'] for h in headers])

    if cdelt is None or pa is None:
        cdeltpa = [get_cdelt_pa(h) for h in headers]

    if cdelt is None:
        cdelt = min([np.min(abs(cdelt)) for cdelt, pa in cdeltpa])

    if pa is None:
        pa = tmf.mean_degrees(np.array([pa for cdelt, pa in cdeltpa]))

    header0 = create_fitsheader((1,1), cdelt=cdelt, pa=pa, crpix=(1,1),
                                crval=crval)

    proj0 = wcs.Projection(header0)
    xy0 = []
    for h in headers:
        proj = wcs.Projection(h)
        nx = h['NAXIS1']
        ny = h['NAXIS2']
        x  = h['CRPIX1']
        y  = h['CRPIX2']
        edges = proj.toworld(([0.5,x,nx+0.5,0.5,x,nx+0.5,0.5,x,nx+0.5],
                              [0.5,0.5,0.5,y,y,y,ny+0.5,ny+0.5,ny+0.5]))
        xy0.append(proj0.topixel(edges))

    xmin0 = np.round(min([min(c[0]) for c in xy0]))
    xmax0 = np.round(max([max(c[0]) for c in xy0]))
    ymin0 = np.round(min([min(c[1]) for c in xy0]))
    ymax0 = np.round(max([max(c[1]) for c in xy0]))

    header0['NAXIS1'] = int(xmax0 - xmin0 + 1)
    header0['NAXIS2'] = int(ymax0 - ymin0 + 1)
    header0['CRPIX1'] = 2 - xmin0
    header0['CRPIX2'] = 2 - ymin0

    return header0
예제 #3
0
def mean_degrees(array):
    """
    Returns the mean value of an array of values in degrees, by taking into 
    account the discrepancy at 0 degree
    """
    return tmf.mean_degrees(np.asarray(array, dtype=var.FLOAT_DTYPE).ravel())
예제 #4
0
def mean_degrees(array):
    """
    Returns the mean value of an array of values in degrees, by taking into 
    account the discrepancy at 0 degree
    """
    return tmf.mean_degrees(np.asarray(array, dtype=var.FLOAT_DTYPE).ravel())