Exemplo n.º 1
0
def compute_Calias_element_YY(xx, yy, fc, d, nsub, tabx, taby, xoff=0, yoff=0):
    """
        Compute the element of the aliasing covariance matrix

    :parameters:
        Ca: (np.ndarray(ndim=2, dtype=np.float32)): aliasing covariance matrix to fill
        xx: (np.ndarray(ndim=2, dtype=np.float32)): X positions of the WFS subap
        yy: (np.ndarray(ndim=2, dtype=np.float32)): Y positions of the WFS subap
        fc: (float): cut-off frequency for structure function
        d: (float): subap diameter
        nsub: (int): number of subap
        tabx: (np.ndarray(ndim=1, dtype=np.float32)): X tabulation for dphi
        taby: (np.ndarray(ndim=1, dtype=np.float32)): Y tabulation for dphi
        xoff: (float) : (optionnal) offset to apply on the WFS xpos (units of d)
        yoff: (float) : (optionnal) offset to apply on the WFS ypos (units of d)
    """
    xx = xx - xx.T  #+ xoff * d
    yy = yy - yy.T  #+ yoff * d
    #xx = np.triu(xx) - np.triu(xx, -1).T
    #yy = np.triu(yy) - np.triu(yy, -1).T
    Ca = np.zeros((2 * nsub, 2 * nsub))

    # YY covariance
    CD = np.linalg.norm([xx + xoff, yy], axis=0)
    Cd = np.linalg.norm([xx + xoff, yy - d], axis=0)
    cD = np.linalg.norm([xx + xoff, yy + d], axis=0)
    cd = CD

    Ca[nsub:, nsub:] += starlord.dphi_highpass(
        Cd, fc, tabx, taby) + starlord.dphi_highpass(
            cD, fc, tabx,
            taby) - 2 * starlord.dphi_highpass(CD, fc, tabx, taby)

    return Ca
Exemplo n.º 2
0
def compute_Calias_element_XY(xx, yy, fc, d, nsub, tabx, taby, xoff=0, yoff=0):
    """
        Compute the element of the aliasing covariance matrix

    :parameters:
        Ca: (np.ndarray(ndim=2, dtype=np.float32)): aliasing covariance matrix to fill
        xx: (np.ndarray(ndim=2, dtype=np.float32)): X positions of the WFS subap
        yy: (np.ndarray(ndim=2, dtype=np.float32)): Y positions of the WFS subap
        fc: (float): cut-off frequency for struture function
        d: (float): subap diameter
        nsub: (int): number of subap
        tabx: (np.ndarray(ndim=1, dtype=np.float32)): X tabulation for dphi
        taby: (np.ndarray(ndim=1, dtype=np.float32)): Y tabulation for dphi
        xoff: (float) : (optionnal) offset to apply on the WFS xpos (units of d)
        yoff: (float) : (optionnal) offset to apply on the WFS ypos (units of d)
    """
    xx = xx - xx.T + xoff * d
    yy = yy - yy.T + yoff * d
    Ca = np.zeros((2 * nsub, 2 * nsub))

    # YY covariance
    aD = np.linalg.norm([xx + d / 2, yy + d / 2], axis=0)
    ad = np.linalg.norm([xx + d / 2, yy - d / 2], axis=0)
    Ad = np.linalg.norm([xx - d / 2, yy - d / 2], axis=0)
    AD = np.linalg.norm([xx - d / 2, yy + d / 2], axis=0)

    Ca[nsub:, :nsub] = 0.25 * (starlord.dphi_highpass(Ad, d, tabx, taby) +
                               starlord.dphi_highpass(aD, d, tabx, taby) -
                               starlord.dphi_highpass(AD, d, tabx, taby) -
                               starlord.dphi_highpass(ad, d, tabx, taby))
    Ca[:nsub, nsub:] = Ca[nsub:, :nsub].copy()
    return Ca
Exemplo n.º 3
0
def compute_Calias_element(xx, yy, fc, d, nsub, tabx, taby, xoff=0, yoff=0):
    """
        Compute the element of the aliasing covariance matrix

    :parameters:
        Ca: (np.ndarray(ndim=2, dtype=np.float32)): aliasing covariance matrix to fill
        xx: (np.ndarray(ndim=2, dtype=np.float32)): X positions of the WFS subap
        yy: (np.ndarray(ndim=2, dtype=np.float32)): Y positions of the WFS subap
        fc: (float): cut-off frequency for structure function
        d: (float): subap diameter
        nsub: (int): number of subap
        tabx: (np.ndarray(ndim=1, dtype=np.float32)): X tabulation for dphi
        taby: (np.ndarray(ndim=1, dtype=np.float32)): Y tabulation for dphi
        xoff: (float) : (optionnal) offset to apply on the WFS xpos (units of d)
        yoff: (float) : (optionnal) offset to apply on the WFS ypos (units of d)
    """
    xx = xx - xx.T + xoff * d
    yy = yy - yy.T + yoff * d
    Ca = np.zeros((2 * nsub, 2 * nsub))

    # XX covariance
    AB = np.linalg.norm([xx, yy], axis=0)
    Ab = np.linalg.norm([xx - d, yy], axis=0)
    aB = np.linalg.norm([xx + d, yy], axis=0)
    ab = AB

    Ca[:nsub, :nsub] += starlord.dphi_highpass(
        Ab, fc, tabx, taby) + starlord.dphi_highpass(
            aB, fc, tabx,
            taby) - 2 * starlord.dphi_highpass(AB, fc, tabx, taby)

    # YY covariance
    CD = AB
    Cd = np.linalg.norm([xx, yy - d], axis=0)
    cD = np.linalg.norm([xx, yy + d], axis=0)
    cd = CD

    Ca[nsub:, nsub:] += starlord.dphi_highpass(
        Cd, fc, tabx, taby) + starlord.dphi_highpass(
            cD, fc, tabx,
            taby) - 2 * starlord.dphi_highpass(CD, fc, tabx, taby)

    # XY covariance

    # aD = np.linalg.norm([xx + d/2, yy + d/2], axis=0)
    # ad = np.linalg.norm([xx + d/2, yy - d/2], axis=0)
    # Ad = np.linalg.norm([xx - d/2, yy - d/2], axis=0)
    # AD = np.linalg.norm([xx - d/2, yy + d/2], axis=0)
    #
    # Ca[nsub:,:nsub] = 0.25 * (starlord.dphi_highpass(Ad, d, tabx, taby)
    #                 + starlord.dphi_highpass(aD, d, tabx, taby)
    #                 - starlord.dphi_highpass(AD, d, tabx, taby)
    #                 - starlord.dphi_highpass(ad, d, tabx, taby)) * (1 / r0)**(5. / 3.)
    # Ca[:nsub,nsub:] = Ca[nsub:,:nsub].copy()
    return Ca
Exemplo n.º 4
0
def compute_OTF_fitting(filename, otftel):
    """
    Modelize the OTF due to the fitting using dphi_highpass

    :parameters:
        filename: (str) : ROKET hdf5 file path
        otftel: (np.ndarray) : Telescope OTF
    :return:
        otf_fit: (np.ndarray) : Fitting OTF
        psf_fit (np.ndarray) : Fitting PSF
    """
    f = h5py.File(filename, 'r')
    r0 = f.attrs["_Param_atmos__r0"] * (f.attrs["_Param_target__Lambda"][0] /
                                        0.5)**(6. / 5.)
    ratio_lambda = 2 * np.pi / f.attrs["_Param_target__Lambda"][0]
    # Telescope OTF
    spup = drax.get_pup(filename)
    mradix = 2
    fft_size = mradix**int((np.log(2 * spup.shape[0]) / np.log(mradix)) + 1)
    mask = np.ones((fft_size, fft_size))
    mask[np.where(otftel < 1e-5)] = 0

    x = np.arange(fft_size) - fft_size / 2
    pixsize = f.attrs["_Param_tel__diam"] / f.attrs["_Param_geom__pupdiam"]
    x = x * pixsize
    r = np.sqrt(x[:, None] * x[:, None] + x[None, :] * x[None, :])
    tabx, taby = starlord.tabulateIj0()
    dphi = np.fft.fftshift(
        starlord.dphi_highpass(
            r, f.attrs["_Param_tel__diam"] /
            (f.attrs["_Param_dm__nact"][0] - 1), tabx, taby) *
        (1 / r0)**(5 / 3.))  # * den * ratio_lambda**2 * mask
    otf_fit = np.exp(-0.5 * dphi) * mask
    otf_fit = otf_fit / otf_fit.max()

    psf_fit = np.fft.fftshift(np.real(np.fft.ifft2(otftel * otf_fit)))
    psf_fit *= (fft_size * fft_size / float(np.where(spup)[0].shape[0]))

    f.close()
    return otf_fit, psf_fit