コード例 #1
0
 def from_tree_transform(cls, node, ctx):
     return functional_models.Gaussian2D(amplitude=node['amplitude'],
                                         x_mean=node['x_mean'],
                                         y_mean=node['y_mean'],
                                         x_stddev=node['x_stddev'],
                                         y_stddev=node['y_stddev'],
                                         theta=node['theta'])
コード例 #2
0
def give_gauss(image_in, x_peak, y_peak):
    gauss_init  = functional_models.Gaussian2D(amplitude=image_in.max(),\
                                          x_mean=x_peak, \
                                          y_mean=y_peak, \
                                          bounds={'amplitude':(np.max(image_in)/1.5,\
                                                               2*np.max(image_in) )} )
    #If the amplitude is not bounded, it sometimes finds "negative" amplitude fitting...
    return fitter(gauss_init, fit_x, fit_y, image_in)
コード例 #3
0
ファイル: stingray_plus.py プロジェクト: snpike/scripts
    def set_xy_weights(self, centroid=[520, 460]):
        # We can weight the events based on their distance from the source.
        # It's fine to just use region filtering instead, but in the case of really high count rates this might be useful.

        H, xcenters, ycenters = self.make_image(plot=False)
        g_init = functional_models.Gaussian2D(amplitude=np.max(H), x_mean=centroid[0], y_mean=centroid[1],\
                                                  x_stddev=10.0, y_stddev=10.0)
        fit_g = fitting.LevMarLSQFitter()
        g = fit_g(g_init, xcenters, ycenters, H)
        self.xy_weights = g(self.x, self.y) / g.amplitude
        return self.xy_weights
コード例 #4
0
    def test__identical_to_astropy_gaussian_model__include_different_ellipticity_from_x_and_y_stddev(
        self,
    ):
        pixel_scales = 0.1

        x_stddev = (
            3.0e-5
            * (units.deg).to(units.arcsec)
            / pixel_scales
            / (2.0 * np.sqrt(2.0 * np.log(2.0)))
        )
        y_stddev = (
            2.0e-5
            * (units.deg).to(units.arcsec)
            / pixel_scales
            / (2.0 * np.sqrt(2.0 * np.log(2.0)))
        )

        theta_deg = 0.0
        theta = Angle(theta_deg, "deg").radian

        gaussian_astropy = functional_models.Gaussian2D(
            amplitude=1.0,
            x_mean=2.0,
            y_mean=2.0,
            x_stddev=x_stddev,
            y_stddev=y_stddev,
            theta=theta,
        )

        shape = (5, 5)
        y, x = np.mgrid[0 : shape[1], 0 : shape[0]]
        kernel_astropy = gaussian_astropy(x, y)
        kernel_astropy /= np.sum(kernel_astropy)

        kernel = aa.Kernel2D.from_as_gaussian_via_alma_fits_header_parameters(
            shape_native=shape,
            pixel_scales=pixel_scales,
            y_stddev=2.0e-5,
            x_stddev=3.0e-5,
            theta=theta_deg,
            normalize=True,
        )

        assert kernel_astropy == pytest.approx(kernel.native, 1e-4)
コード例 #5
0
    def test__identical_to_astropy_gaussian_model__circular_no_rotation_different_pixel_scale(
        self,
    ):
        pixel_scales = 0.02

        x_stddev = (
            2.0e-5
            * (units.deg).to(units.arcsec)
            / pixel_scales
            / (2.0 * np.sqrt(2.0 * np.log(2.0)))
        )
        y_stddev = (
            2.0e-5
            * (units.deg).to(units.arcsec)
            / pixel_scales
            / (2.0 * np.sqrt(2.0 * np.log(2.0)))
        )

        gaussian_astropy = functional_models.Gaussian2D(
            amplitude=1.0,
            x_mean=2.0,
            y_mean=2.0,
            x_stddev=x_stddev,
            y_stddev=y_stddev,
            theta=0.0,
        )

        shape = (5, 5)
        y, x = np.mgrid[0 : shape[1], 0 : shape[0]]
        kernel_astropy = gaussian_astropy(x, y)
        kernel_astropy /= np.sum(kernel_astropy)

        kernel = aa.Kernel2D.from_as_gaussian_via_alma_fits_header_parameters(
            shape_native=shape,
            pixel_scales=pixel_scales,
            y_stddev=2.0e-5,
            x_stddev=2.0e-5,
            theta=0.0,
            normalize=True,
        )

        assert kernel_astropy == pytest.approx(kernel.native, 1e-4)
コード例 #6
0
Max_x = 0
Max_y = 0
Val_sum = 0
for i in range(0, m - 1):
    for j in range(0, n - 1):
        Val_sum += z[i][j]  #Find Sum to calculate Mean
        if (z[i][j] > Max):
            Max = z[i][j]
            Max_x = i
            Max_y = j
Mean = Val_sum / (float)(m * n)

print Mean

# Fit the data using astropy.modeling
p_init = M.Gaussian2D(Max, Max_x, Max_y, 1, 10)

#p_init = M.Ring2D(210,Max_x,Max_y,0,30)

f = fitting.LinearLSQFitter()
p = f(p_init, x, y, z)

# Plot the data with the best-fit model
plt.figure(figsize=(8, 2.5))
plt.subplot(1, 4, 1)
plt.imshow(z, interpolation='nearest', vmin=0, vmax=Max)
plt.title("Data")
plt.subplot(1, 4, 2)
plt.imshow(p(x, y), interpolation='nearest', vmin=0, vmax=Max)
plt.title("Model")
plt.subplot(1, 4, 3)