Example #1
0
def test_regrid_binaryop_2d():
    y0, x0 = np.mgrid[20:29, 10:20]
    y0 = y0.flatten()
    x0 = x0.flatten()

    gmdl = Gauss2D()
    gmdl.fwhm = 14
    gmdl.xpos = 15
    gmdl.ypos = 24
    gmdl.ampl = 10

    cmdl = Const2D()
    cmdl.c0 = 4

    xr1 = np.arange(10, 20, 1)
    yr1 = np.arange(20, 29, 1)

    rmdlg = gmdl.regrid(xr1, yr1)
    rmdlc = cmdl.regrid(xr1, yr1)

    shape = y0.shape
    truthg = gmdl(x0, y0).reshape(shape)
    truthc = cmdl(x0, y0).reshape(shape)
    truth = truthg + truthc

    ans1 = rmdlg(x0, y0).reshape(shape)
    ans2 = rmdlc(x0, y0).reshape(shape)
    assert (ans1 == truthg).all()
    assert (ans2 == truthc).all()

    rmdl = (gmdl + cmdl).regrid(xr1, yr1)
    ans3 = rmdl(x0, y0).reshape(shape)
    assert (ans3 == truth).all()
Example #2
0
def source_Gauss2D(name, fwhm_init, fwhm_frozen, ampl_init, ampl_frozen, xpos_init, xpos_frozen,
                          ypos_init, ypos_frozen,ellep_init=None, ellep_frozen=None, ampl_max=None,fwhm_min=None):
    mygaus = Gauss2D(name)
    set_par(mygaus.fwhm, val=fwhm_init, min=fwhm_min, max=None, frozen=fwhm_frozen)
    set_par(mygaus.ampl, val=ampl_init, min=0, max=ampl_max, frozen=ampl_frozen)
    set_par(mygaus.xpos, val=xpos_init, min=None, max=None, frozen=xpos_frozen)
    set_par(mygaus.ypos, val=ypos_init, min=None, max=None, frozen=ypos_frozen)
    return mygaus
Example #3
0
def test_data2d_int_eval_model_to_fit(array_sizes_fixture):
    from sherpa.fit import Fit
    from sherpa.optmethods import LevMar
    from sherpa.stats import Chi2
    from sherpa.models import Gauss2D

    x0, x1, dx, y = array_sizes_fixture
    data2 = Data2DInt('name', x0.flatten(), x0.flatten() + dx, x1.flatten(), x1.flatten() + dx, y.flatten(),
                      staterror=numpy.sqrt(y).flatten())

    model2 = Gauss2D()
    fitter = Fit(data2, model2, Chi2(), LevMar())
    fitter.fit()  # Failed in Sherpa 4.11.0
    # source_center_SgrA = SkyCoord.from_name("SgrA*")
    source_center_G0p9 = SkyCoord(0.868, 0.075, unit='deg', frame="galactic")
    psf_image_G0p9 = fill_acceptance_image(header, on.center(), psf_file_G0p9["theta"].to("deg"),
                                           psf_file_G0p9["psf_value"].data, psf_file_G0p9["theta"].to("deg")[-1])
    psf_image_SgrA.writeto("psf_image_SgrA_" + str(E1) + "_" + str(E2) + ".fits", clobber=True)
    psf_image_G0p9.writeto("psf_image_G0p9_" + str(E1) + "_" + str(E2) + ".fits", clobber=True)
    load_psf("psf_SgrA", "psf_image_SgrA_" + str(E1) + "_" + str(E2) + ".fits")
    load_psf("psf_G0p9", "psf_image_G0p9_" + str(E1) + "_" + str(E2) + ".fits")

    # modele gauss pour sgrA centre sur SgrA
    mygaus_SgrA = normgauss2dint("SgrA")
    mygaus_SgrA.xpos, mygaus_SgrA.ypos = skycoord_to_pixel(source_center_SgrA, on.wcs)
    mygaus_SgrA.xpos.val += 0.5
    mygaus_SgrA.ypos.val += 0.5
    # Modele marge gaussienne a multiplie avec CS centre sur SgrA
    large_gaus = Gauss2D("Gauss_to_CS")
    large_gaus.xpos, large_gaus.ypos = skycoord_to_pixel(source_center_SgrA, on.wcs)
    large_gaus.fwhm = 100
    central_gauss = Gauss2D("central_gauss")
    central_gauss.xpos, central_gauss.ypos = skycoord_to_pixel(source_center_SgrA, on.wcs)
    central_gauss.fwhm = 100
    # modele gauss pour G0p9 centre sur G0p9
    mygaus_G0p9 = normgauss2dint("G0p9")
    mygaus_G0p9.xpos, mygaus_G0p9.ypos = skycoord_to_pixel(source_center_G0p9, on.wcs)
    mygaus_G0p9.xpos.val += 0.5
    mygaus_G0p9.ypos.val += 0.5

    #Arc_source
    arc_source=SkyCoord(0.130, -0.139, unit='deg', frame="galactic")
    mygaus_arcsource = Gauss2D("Arc Source")
    mygaus_arcsource.xpos, mygaus_arcsource.ypos = skycoord_to_pixel(arc_source, on.wcs)