def test_Ellipse2D_theta(): theta = Angle(90, 'deg') model1 = models.Ellipse2D(1, 25, 25, 15, 5, theta=theta) theta2 = np.pi / 2. model2 = models.Ellipse2D(1, 25, 25, 15, 5, theta=theta2) assert model1.theta.quantity.to('radian').value == model2.theta.value assert model1.bounding_box == model2.bounding_box assert model1(619.42, 31.314) == model2(619.42, 31.314)
def test_Ellipse2D_circular(): """Test that circular Ellipse2D agrees with Disk2D [3736].""" amplitude = 7.5 radius = 10 size = (radius * 2) + 1 y, x = np.mgrid[0:size, 0:size] ellipse = models.Ellipse2D(amplitude, radius, radius, radius, radius, theta=0)(x, y) disk = models.Disk2D(amplitude, radius, radius, radius)(x, y) assert np.all(ellipse == disk)
def test_Ellipse2D(): """Test Ellipse2D model.""" amplitude = 7.5 x0, y0 = 15, 15 theta = Angle(45, 'deg') em = models.Ellipse2D(amplitude, x0, y0, 7, 3, theta.radian) y, x = np.mgrid[0:30, 0:30] e = em(x, y) assert np.all(e[e > 0] == amplitude) assert e[y0, x0] == amplitude rotation = models.Rotation2D(angle=theta.degree) point1 = [2, 0] # Rotation2D center is (0, 0) point2 = rotation(*point1) point1 = np.array(point1) + [x0, y0] point2 = np.array(point2) + [x0, y0] e1 = models.Ellipse2D(amplitude, x0, y0, 7, 3, theta=0.) e2 = models.Ellipse2D(amplitude, x0, y0, 7, 3, theta=theta.radian) assert e1(*point1) == e2(*point2)
astmodels.RotateCelestial2Native(5.63, -72.5, 180), astmodels.EulerAngleRotation(23, 14, 2.3, axes_order='xzx'), astmodels.Mapping((0, 1), n_inputs=3), astmodels.Shift(2. * u.deg), astmodels.Scale(3.4 * u.deg), astmodels.RotateNative2Celestial(5.63 * u.deg, -72.5 * u.deg, 180 * u.deg), astmodels.RotateCelestial2Native(5.63 * u.deg, -72.5 * u.deg, 180 * u.deg), astmodels.RotationSequence3D([1.2, 2.3, 3.4, .3], 'xyzx'), astmodels.SphericalRotationSequence([1.2, 2.3, 3.4, .3], 'xyzy'), astmodels.AiryDisk2D(amplitude=10., x_0=0.5, y_0=1.5), astmodels.Box1D(amplitude=10., x_0=0.5, width=5.), astmodels.Box2D(amplitude=10., x_0=0.5, x_width=5., y_0=1.5, y_width=7.), astmodels.Const1D(amplitude=5.), astmodels.Const2D(amplitude=5.), astmodels.Disk2D(amplitude=10., x_0=0.5, y_0=1.5, R_0=5.), astmodels.Ellipse2D(amplitude=10., x_0=0.5, y_0=1.5, a=2., b=4., theta=0.1), astmodels.Exponential1D(amplitude=10., tau=3.5), astmodels.Gaussian1D(amplitude=10., mean=5., stddev=3.), astmodels.Gaussian2D(amplitude=10., x_mean=5., y_mean=5., x_stddev=3., y_stddev=3.), astmodels.KingProjectedAnalytic1D(amplitude=10., r_core=5., r_tide=2.), astmodels.Logarithmic1D(amplitude=10., tau=3.5), astmodels.Lorentz1D(amplitude=10., x_0=0.5, fwhm=2.5), astmodels.Moffat1D(amplitude=10., x_0=0.5, gamma=1.2, alpha=2.5), astmodels.Moffat2D(amplitude=10., x_0=0.5, y_0=1.5, gamma=1.2, alpha=2.5), astmodels.Planar2D(slope_x=0.5, slope_y=1.2, intercept=2.5), astmodels.RedshiftScaleFactor(z=2.5), astmodels.RickerWavelet1D(amplitude=10., x_0=0.5, sigma=1.2),
p = fit_p(p_init, x,y,imdat) ''' np.random.seed(0) y, x = np.mgrid[:imdat.shape[0], :imdat.shape[1]] #z = 2. * x ** 2 - 0.5 * x ** 2 + 1.5 * x * y - 1. #z += np.random.normal(0., 0.1, z.shape) * 50000. z = imdat # Fit the data using astropy.modeling x0 = imdat.shape[1]/2. y0 = imdat.shape[0]/2. a = imdat.shape[0]/5. b = .6*a theta=Angle(0,'deg') p_init = models.Ellipse2D(amplitude=np.max(imdat),x_0 = x0,y_0 = y0, a=a, b=b, theta=theta.radian) fit_p = fitting.LevMarLSQFitter() #imdat=50000*imdat with warnings.catch_warnings(): # Ignore model linearity warning from the fitter warnings.simplefilter('ignore') #p = fit_p(p_init, x, y, z) p = fit_p(p_init, x, y, imdat) # Plot the data with the best-fit model plt.figure(figsize=(8, 2.5)) plt.subplot(1, 3, 1) plt.imshow(imdat, origin='lower', interpolation='nearest', vmin=-1, vmax=12) plt.title("Data") plt.subplot(1, 3, 2)