当前位置: 首页>>代码示例>>Python>>正文


Python fitting.LevMarLSQFitter方法代码示例

本文整理汇总了Python中astropy.modeling.fitting.LevMarLSQFitter方法的典型用法代码示例。如果您正苦于以下问题:Python fitting.LevMarLSQFitter方法的具体用法?Python fitting.LevMarLSQFitter怎么用?Python fitting.LevMarLSQFitter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在astropy.modeling.fitting的用法示例。


在下文中一共展示了fitting.LevMarLSQFitter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_fitting_with_initial_values

# 需要导入模块: from astropy.modeling import fitting [as 别名]
# 或者: from astropy.modeling.fitting import LevMarLSQFitter [as 别名]
def test_fitting_with_initial_values():

    x, y = _fake_gaussian_data()

    # Fit the data using a Gaussian with units
    g_init = models.Gaussian1D(amplitude=1. * u.mJy,
                               mean=3 * u.cm,
                               stddev=2 * u.mm)
    fit_g = fitting.LevMarLSQFitter()
    g = fit_g(g_init, x, y)

    # TODO: update actual numerical results once implemented, but these should
    # be close to the values below.
    assert_quantity_allclose(g.amplitude, 3 * u.Jy, rtol=0.05)
    assert_quantity_allclose(g.mean, 1.3 * u.m, rtol=0.05)
    assert_quantity_allclose(g.stddev, 0.8 * u.m, rtol=0.05) 
开发者ID:holzschu,项目名称:Carnets,代码行数:18,代码来源:test_quantities_fitting.py

示例2: fit_gauss

# 需要导入模块: from astropy.modeling import fitting [as 别名]
# 或者: from astropy.modeling.fitting import LevMarLSQFitter [as 别名]
def fit_gauss(sci):
    from astropy.modeling import models, fitting

    sh = sci.shape
    gau = models.Gaussian2D(amplitude=sci.max(), x_mean=sh[0]/2, y_mean=sh[0]/2., x_stddev=None, y_stddev=None, theta=None, cov_matrix=None)

    lm = fitting.LevMarLSQFitter()

    yp, xp = np.indices(sh)
    fit = lm(gau, xp, yp, sci)

    q = (fit.x_stddev/fit.y_stddev)**2
    theta = fit.theta.value
    if q > 1:
        q = 1./q
        theta += np.pi/2.

    return fit, q, theta 
开发者ID:gbrammer,项目名称:grizli,代码行数:20,代码来源:galfit.py

示例3: measure_fwhm

# 需要导入模块: from astropy.modeling import fitting [as 别名]
# 或者: from astropy.modeling.fitting import LevMarLSQFitter [as 别名]
def measure_fwhm(array):
    """Fit a Gaussian2D model to a PSF and return the FWHM

    Parameters
    ----------
    array : numpy.ndarray
        Array containing PSF

    Returns
    -------
    x_fwhm : float
        FWHM in x direction in units of pixels

    y_fwhm : float
        FWHM in y direction in units of pixels
    """
    yp, xp = array.shape
    y, x, = np.mgrid[:yp, :xp]
    p_init = models.Gaussian2D()
    fit_p = fitting.LevMarLSQFitter()
    fitted_psf = fit_p(p_init, x, y, array)
    return fitted_psf.x_fwhm, fitted_psf.y_fwhm 
开发者ID:spacetelescope,项目名称:mirage,代码行数:24,代码来源:tools.py

示例4: test_no_constraints

# 需要导入模块: from astropy.modeling import fitting [as 别名]
# 或者: from astropy.modeling.fitting import LevMarLSQFitter [as 别名]
def test_no_constraints(self):
        g1 = models.Gaussian1D(9.9, 14.5, stddev=.3)

        def func(p, x):
            return p[0] * np.exp(-0.5 / p[2] ** 2 * (x - p[1]) ** 2)

        def errf(p, x, y):
            return func(p, x) - y

        p0 = [9.9, 14.5, 0.3]
        y = g1(self.x)
        n = np.random.randn(100)
        ny = y + n
        fitpar, s = optimize.leastsq(errf, p0, args=(self.x, ny))
        fitter = fitting.LevMarLSQFitter()
        model = fitter(g1, self.x, ny)
        assert_allclose(model.parameters, fitpar, rtol=5 * 10 ** (-3)) 
开发者ID:holzschu,项目名称:Carnets,代码行数:19,代码来源:test_constraints.py

示例5: test_bounds_lsq

# 需要导入模块: from astropy.modeling import fitting [as 别名]
# 或者: from astropy.modeling.fitting import LevMarLSQFitter [as 别名]
def test_bounds_lsq(self):
        guess_slope = 1.1
        guess_intercept = 0.0
        bounds = {'slope': (-1.5, 5.0), 'intercept': (-1.0, 1.0)}
        line_model = models.Linear1D(guess_slope, guess_intercept,
                                     bounds=bounds)
        fitter = fitting.LevMarLSQFitter()
        with pytest.warns(AstropyUserWarning,
                          match=r'Model is linear in parameters'):
            model = fitter(line_model, self.x, self.y)
        slope = model.slope.value
        intercept = model.intercept.value
        assert slope + 10 ** -5 >= bounds['slope'][0]
        assert slope - 10 ** -5 <= bounds['slope'][1]
        assert intercept + 10 ** -5 >= bounds['intercept'][0]
        assert intercept - 10 ** -5 <= bounds['intercept'][1] 
开发者ID:holzschu,项目名称:Carnets,代码行数:18,代码来源:test_constraints.py

示例6: test_bounds_gauss2d_lsq

# 需要导入模块: from astropy.modeling import fitting [as 别名]
# 或者: from astropy.modeling.fitting import LevMarLSQFitter [as 别名]
def test_bounds_gauss2d_lsq(self):
        X, Y = np.meshgrid(np.arange(11), np.arange(11))
        bounds = {"x_mean": [0., 11.],
                  "y_mean": [0., 11.],
                  "x_stddev": [1., 4],
                  "y_stddev": [1., 4]}
        gauss = models.Gaussian2D(amplitude=10., x_mean=5., y_mean=5.,
                                  x_stddev=4., y_stddev=4., theta=0.5,
                                  bounds=bounds)
        gauss_fit = fitting.LevMarLSQFitter()
        with pytest.warns(AstropyUserWarning,
                          match='The fit may be unsuccessful'):
            model = gauss_fit(gauss, X, Y, self.data)
        x_mean = model.x_mean.value
        y_mean = model.y_mean.value
        x_stddev = model.x_stddev.value
        y_stddev = model.y_stddev.value
        assert x_mean + 10 ** -5 >= bounds['x_mean'][0]
        assert x_mean - 10 ** -5 <= bounds['x_mean'][1]
        assert y_mean + 10 ** -5 >= bounds['y_mean'][0]
        assert y_mean - 10 ** -5 <= bounds['y_mean'][1]
        assert x_stddev + 10 ** -5 >= bounds['x_stddev'][0]
        assert x_stddev - 10 ** -5 <= bounds['x_stddev'][1]
        assert y_stddev + 10 ** -5 >= bounds['y_stddev'][0]
        assert y_stddev - 10 ** -5 <= bounds['y_stddev'][1] 
开发者ID:holzschu,项目名称:Carnets,代码行数:27,代码来源:test_constraints.py

示例7: test_fitting_missing_model_units

# 需要导入模块: from astropy.modeling import fitting [as 别名]
# 或者: from astropy.modeling.fitting import LevMarLSQFitter [as 别名]
def test_fitting_missing_model_units():
    """
    Proceed if the data has units but the model doesn't
    """

    x, y = _fake_gaussian_data()

    g_init = models.Gaussian1D(amplitude=1., mean=3, stddev=2)
    fit_g = fitting.LevMarLSQFitter()
    g = fit_g(g_init, x, y)

    assert_quantity_allclose(g.amplitude, 3 * u.Jy, rtol=0.05)
    assert_quantity_allclose(g.mean, 1.3 * u.m, rtol=0.05)
    assert_quantity_allclose(g.stddev, 0.8 * u.m, rtol=0.05)

    g_init = models.Gaussian1D(amplitude=1., mean=3 * u.m, stddev=2 * u.m)
    fit_g = fitting.LevMarLSQFitter()
    g = fit_g(g_init, x, y)

    assert_quantity_allclose(g.amplitude, 3 * u.Jy, rtol=0.05)
    assert_quantity_allclose(g.mean, 1.3 * u.m, rtol=0.05)
    assert_quantity_allclose(g.stddev, 0.8 * u.m, rtol=0.05) 
开发者ID:holzschu,项目名称:Carnets,代码行数:24,代码来源:test_quantities_fitting.py

示例8: test_compound_without_units

# 需要导入模块: from astropy.modeling import fitting [as 别名]
# 或者: from astropy.modeling.fitting import LevMarLSQFitter [as 别名]
def test_compound_without_units(model):
    x = np.linspace(-5, 5, 10) * u.Angstrom
    with NumpyRNGContext(12345):
        y = np.random.sample(10)

    fitter = fitting.LevMarLSQFitter()
    res_fit = fitter(model, x, y * u.Hz)
    for param_name in res_fit.param_names:
        print(getattr(res_fit, param_name))
    assert all([res_fit[i]._has_units for i in range(3)])
    z = res_fit(x)
    assert isinstance(z, u.Quantity)

    res_fit = fitter(model, np.arange(10) * u.Unit('Angstrom'), y)
    assert all([res_fit[i]._has_units for i in range(3)])
    z = res_fit(x)
    assert isinstance(z, np.ndarray) 
开发者ID:holzschu,项目名称:Carnets,代码行数:19,代码来源:test_quantities_fitting.py

示例9: test_compound_fitting_with_units

# 需要导入模块: from astropy.modeling import fitting [as 别名]
# 或者: from astropy.modeling.fitting import LevMarLSQFitter [as 别名]
def test_compound_fitting_with_units():
    x = np.linspace(-5, 5, 15) * u.Angstrom
    y = np.linspace(-5, 5, 15) * u.Angstrom

    fitter = fitting.LevMarLSQFitter()
    m = models.Gaussian2D(10*u.Hz,
                          3*u.Angstrom, 4*u.Angstrom,
                          1*u.Angstrom, 2*u.Angstrom)
    p = models.Planar2D(3*u.Hz/u.Angstrom, 4*u.Hz/u.Angstrom, 1*u.Hz)
    model = m + p

    z = model(x, y)
    res = fitter(model, x, y, z)
    assert isinstance(res(x, y), np.ndarray)
    assert all([res[i]._has_units for i in range(2)])

    model = models.Gaussian2D() + models.Planar2D()
    res = fitter(model, x, y, z)
    assert isinstance(res(x, y), np.ndarray)
    assert all([res[i]._has_units for i in range(2)]) 
开发者ID:holzschu,项目名称:Carnets,代码行数:22,代码来源:test_quantities_fitting.py

示例10: test_fitting_convolve_models

# 需要导入模块: from astropy.modeling import fitting [as 别名]
# 或者: from astropy.modeling.fitting import LevMarLSQFitter [as 别名]
def test_fitting_convolve_models(self, mode):
        """
        test that a convolve model can be fitted
        """
        b1 = models.Box1D()
        g1 = models.Gaussian1D()

        x = np.linspace(-5, 5, 99)
        fake_model = models.Gaussian1D(amplitude=10)
        with NumpyRNGContext(123):
            fake_data = fake_model(x) + np.random.normal(size=len(x))

        init_model = convolve_models(b1, g1, mode=mode, normalize_kernel=False)
        fitter = fitting.LevMarLSQFitter()
        fitted_model = fitter(init_model, x, fake_data)

        me = np.mean(fitted_model(x) - fake_data)
        assert_almost_equal(me, 0.0, decimal=2) 
开发者ID:holzschu,项目名称:Carnets,代码行数:20,代码来源:test_convolve_models.py

示例11: test_FM90_fitting

# 需要导入模块: from astropy.modeling import fitting [as 别名]
# 或者: from astropy.modeling.fitting import LevMarLSQFitter [as 别名]
def test_FM90_fitting():

    # get an observed extinction curve to fit
    g03_model = G03_LMCAvg()

    x = g03_model.obsdata_x
    # convert to E(x-V)/E(B0V)
    y = (g03_model.obsdata_axav - 1.0) * g03_model.Rv
    # only fit the UV portion (FM90 only valid in UV)
    gindxs, = np.where(x > 3.125)

    fm90_init = FM90()
    fit = LevMarLSQFitter()
    g03_fit = fit(fm90_init, x[gindxs], y[gindxs])
    fit_vals = [
        g03_fit.C1.value,
        g03_fit.C2.value,
        g03_fit.C3.value,
        g03_fit.C4.value,
        g03_fit.xo.value,
        g03_fit.gamma.value,
    ]

    good_vals = np.array(
        [
            -0.958016797002,
            1.0109751831,
            2.96430606652,
            0.313137860902,
            4.59996300532,
            0.99000982258,
        ]
    )

    np.testing.assert_allclose(good_vals, fit_vals) 
开发者ID:karllark,项目名称:dust_extinction,代码行数:37,代码来源:test_fm90.py

示例12: test_Shift_model_levmar_fit

# 需要导入模块: from astropy.modeling import fitting [as 别名]
# 或者: from astropy.modeling.fitting import LevMarLSQFitter [as 别名]
def test_Shift_model_levmar_fit():
    """Test fitting Shift model with LevMarLSQFitter (issue #6103)."""

    init_model = models.Shift()

    x = np.arange(10)
    y = x+0.1

    fitter = fitting.LevMarLSQFitter()
    with pytest.warns(AstropyUserWarning,
                      match='Model is linear in parameters'):
        fitted_model = fitter(init_model, x, y)

    assert_allclose(fitted_model.parameters, [0.1], atol=1e-15) 
开发者ID:holzschu,项目名称:Carnets,代码行数:16,代码来源:test_functional_models.py

示例13: test_Voigt1D

# 需要导入模块: from astropy.modeling import fitting [as 别名]
# 或者: from astropy.modeling.fitting import LevMarLSQFitter [as 别名]
def test_Voigt1D():
    voi = models.Voigt1D(amplitude_L=-0.5, x_0=1.0, fwhm_L=5.0, fwhm_G=5.0)
    xarr = np.linspace(-5.0, 5.0, num=40)
    yarr = voi(xarr)
    voi_init = models.Voigt1D(amplitude_L=-1.0, x_0=1.0, fwhm_L=5.0, fwhm_G=5.0)
    fitter = fitting.LevMarLSQFitter()
    voi_fit = fitter(voi_init, xarr, yarr)
    assert_allclose(voi_fit.param_sets, voi.param_sets) 
开发者ID:holzschu,项目名称:Carnets,代码行数:10,代码来源:test_functional_models.py

示例14: test_KingProjectedAnalytic1D_fit

# 需要导入模块: from astropy.modeling import fitting [as 别名]
# 或者: from astropy.modeling.fitting import LevMarLSQFitter [as 别名]
def test_KingProjectedAnalytic1D_fit():
    km = models.KingProjectedAnalytic1D(amplitude=1, r_core=1, r_tide=2)
    xarr = np.linspace(0.1, 2, 10)
    yarr = km(xarr)
    km_init = models.KingProjectedAnalytic1D(amplitude=1, r_core=1, r_tide=1)
    fitter = fitting.LevMarLSQFitter()
    km_fit = fitter(km_init, xarr, yarr)
    assert_allclose(km_fit.param_sets, km.param_sets) 
开发者ID:holzschu,项目名称:Carnets,代码行数:10,代码来源:test_functional_models.py

示例15: test_fit

# 需要导入模块: from astropy.modeling import fitting [as 别名]
# 或者: from astropy.modeling.fitting import LevMarLSQFitter [as 别名]
def test_fit(self):

        fitter = LevMarLSQFitter()

        b = BlackBody1D(3000 * u.K)

        wav = np.array([0.5, 5, 10]) * u.micron
        fnu = np.array([1, 10, 5]) * u.Jy

        b_fit = fitter(b, wav, fnu)

        assert_quantity_allclose(b_fit.temperature, 2840.7438339457754 * u.K)
        assert_quantity_allclose(b_fit.bolometric_flux, 6.821837075583734e-08 * u.erg / u.cm**2 / u.s) 
开发者ID:holzschu,项目名称:Carnets,代码行数:15,代码来源:test_blackbody.py


注:本文中的astropy.modeling.fitting.LevMarLSQFitter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。