Ejemplo n.º 1
0
def simulate_data(affine2d=None, psf_offset_det=None, pistons_w=None):

    print(" simulate_data: ", affine2d.name)

    #************ADD PISTONS TO PERFECT DATA******************
    pistons_w = pistons_w - pistons_w.mean()
    pistons_m = pistons_w * lamc
    pistons_r = pistons_w * 2.0 * np.pi

    utils.show_pistons_w(pistons_w, str="simulate_data: input pistons")

    np.set_printoptions(precision=4,
                        formatter={'float': lambda x: '{:+.1e}'.format(x)},
                        linewidth=80)
    print(" simulate_data: pistons_um", pistons_m / 1e-6)
    print(" simulate_data: pistons_r", pistons_r)
    print(" simulate_data: pistons_w stdev/w", round(pistons_w.std(), 4))
    print(" simulate_data: pistons_w stdev/r",
          round(pistons_w.std() * 2 * np.pi, 4))
    print(" simulate_data: pistons_w mean/r",
          round(pistons_w.mean() * 2 * np.pi, 4))
    default_printoptions()

    #***********ADD EFFECTS TO SIMULATE*******************
    jw = NRM_Model(mask='jwst', holeshape="hex", affine2d=affine2d)
    jw.set_pixelscale(pixelscale_as * arcsec2rad)
    jw.set_pistons(pistons_m)
    print(" simulate: ", psf_offset_det, type(psf_offset_det))
    jw.simulate(fov=fov,
                bandpass=bandpass,
                over=oversample,
                psf_offset=psf_offset_det)
    fits.PrimaryHDU(data=jw.psf).writeto(fitsimdir + "all_effects_data.fits",
                                         overwrite=True)

    #**********Convert simulated data to mirage format.*******
    utils.amisim2mirage(fitsimdir, ("all_effects_data", ), mirexample, filt)
Ejemplo n.º 2
0
def verify_pistons(arg):
    """
    Create simulated data with pistons,
    1. analyze the data by calling fit_image
    Do not use fringefitter since the data is perfecrly centered (the if loop).
    Check if input and output pistons match.
    
    2. analyze the data by calling fit_image via fringefitter
    Fringefitter finds the bestcenter and makes model with bestcenter.
    Since the data is perfecrly centered fringefitter should not affect output pistons.
    Check if input and output pistons match.
    """

    jw = NRM_Model(mask='jwst', holeshape="hex")
    pixelscale_as = 0.0656
    arcsec2rad = u.arcsec.to(u.rad)

    jw.set_pixelscale(pixelscale_as * arcsec2rad)

    np.random.seed(100)

    #lambda/14 ~ 80% strehl ratio
    phi = np.random.normal(0, 1.0, 7) / 14.0  # waves
    print("phi", phi, "varphi", phi.var(), "waves")
    phi = phi - phi.mean()

    print("phi_nb stdev/w", phi.std())
    print("phi_nb stdev/r", phi.std() * 2 * np.pi)
    print("phi_nb mean/r", phi.mean() * 2 * np.pi)
    pistons = phi * 4.3e-6  #OR

    print("/=====input pistons/m=======/\n", pistons)
    print("/=====input pistons/r=======/\n", pistons * (2 * np.pi) / 4.3e-6)

    jw.set_pistons(pistons)
    jw.simulate(fov=81, bandpass=4.3e-6, over=oversample)
    fits.PrimaryHDU(data=jw.psf).writeto(
        "implaneia_tests/perfect_wpistons.fits", overwrite=True)

    if arg == ("no_fringefitter"):

        jw.make_model(fov=81, bandpass=4.3e-6, over=oversample)
        jw.fit_image(jw.psf, modelin=jw.model)

        pos = np.get_printoptions()
        np.set_printoptions(precision=4,
                            formatter={'float': lambda x: '{:+.4e}'.format(x)},
                            linewidth=80)
        print("Residual/psfpeak array center:", jw.psf.shape)
        print((jw.residual / jw.psf.max())[36:-36, 36:-36])
        np.set_printoptions(pos)

        fits.PrimaryHDU(data=jw.residual).writeto(
            "residual_pistons_no_ff.fits", overwrite=True)
        #return jw
        #print("output pistons/r",jw.fringepistons)
        #print("output pistons/w",jw.fringepistons/(2*np.pi))
        #print("output pistons/m",jw.fringepistons*4.3e-6/(2*np.pi))
        #print("input pistons/m ",jw.phi)

    elif arg == ("use_fringefitter"):

        fits.PrimaryHDU(data=jw.psf).writeto(datadir +
                                             "/perfect_wpistons.fits",
                                             overwrite=True)

        amisim2mirage(datadir, ("perfect_wpistons", ), mirexample, filt)

        niriss = InstrumentData.NIRISS(filt)
        ff_t = nrm_core.FringeFitter(niriss,
                                     datadir=datadir,
                                     savedir=datadir,
                                     oversample=oversample,
                                     interactive=False)
        print(test_tar)
        ff_t.fit_fringes(test_tar)

        print("Residual:")
        #print(ff_t.nrm.residual)
        print("Residual/psfpeak array center:", ff_t.nrm.reference.shape)
        pos = np.get_printoptions()
        np.set_printoptions(precision=3,
                            formatter={'float': lambda x: '{:+.3e}'.format(x)},
                            linewidth=80)
        print((ff_t.nrm.residual / jw.psf.max())[36:-36, 36:-36])
        np.set_printoptions(pos)

        fits.PrimaryHDU(data=ff_t.nrm.residual).writeto(datadir+\
                        "/residual_pistons_with_ff.fits",overwrite=True)

        utils.compare_pistons(jw.phi * 2 * np.pi / 4.3e-6,
                              ff_t.nrm.fringepistons,
                              str="ff_t")