Ejemplo n.º 1
0
def test_deprecated_hat_kernel():

    # 'MexicanHat' was deprecated as a name for the models which are now
    # 'RickerWavelet'. This test ensures that the models are correctly
    # deprecated.

    with pytest.warns(AstropyDeprecationWarning):
        models.MexicanHat1D()

    with pytest.warns(AstropyDeprecationWarning):
        models.MexicanHat2D()
Ejemplo n.º 2
0
 def __init__(self, width, **kwargs):
     amplitude = 1.0 / (np.pi * width**4)
     self._model = models.MexicanHat2D(amplitude, 0, 0, width)
     self._default_size = _round_up_to_odd_integer(8 * width)
     super().__init__(**kwargs)
     self._truncation = np.abs(self._array.sum() / self._array.size)
Ejemplo n.º 3
0
def fit_2D_MexicanHat(box,
                      center=None,
                      fixed_center=False,
                      deviation_center=None,
                      radius=None,
                      x_shift=0.0,
                      y_shift=0.0,
                      zoom_factor=1.0,
                      mask=None):
    """
    This function ...
    :param box:
    :param center:
    :param fixed_center:
    :param deviation_center:
    :param radius:
    :param x_shift:
    :param y_shift:
    :param zoom_factor:
    :param mask:
    :return:
    """

    # Get the dimensions of the box
    box_ysize = box.shape[0]
    box_xsize = box.shape[1]

    # Set the initial guess for the center of the model (the one that is specified, otherwise the center of the box)
    init_x0 = center[0] if center is not None else 0.5 * (box_xsize - 1)
    init_y0 = center[1] if center is not None else 0.5 * (box_ysize - 1)

    # Set the initial guess for the radius of the model (the one that is specified, otherwise one tenth of the width of the box)
    init_sigma = radius if radius is not None else 0.1 * box_xsize

    # Initialize an empty dictionary to specify fixed parameters
    fixed_parameters = {}

    if fixed_center:

        fixed_parameters['x_0'] = True
        fixed_parameters['y_0'] = True

    # Initialize an empty dictionary to specify bounds
    bounds = {}

    if deviation_center is not None:

        bounds['x_mean'] = [
            init_x0 - deviation_center, init_x0 + deviation_center
        ]
        bounds['y_mean'] = [
            init_y0 - deviation_center, init_y0 + deviation_center
        ]

    # Fit the data using astropy.modeling
    mexicanhat_init = models.MexicanHat2D(amplitude=1.,
                                          x_0=init_x0,
                                          y_0=init_y0,
                                          sigma=init_sigma,
                                          fixed=fixed_parameters,
                                          bounds=bounds)
    fit_model = fitting.LevMarLSQFitter()

    x_values = []
    y_values = []
    z_values = []

    for x in range(box_xsize):
        for y in range(box_ysize):

            # If no mask is specified or the pixel is not masked, add the coordinates and value to the appropriate lists
            if mask is None or not mask[y, x]:

                x_values.append(x)
                y_values.append(y)
                z_values.append(box[y, x])

    # Ignore model linearity warning from the fitter
    with warnings.catch_warnings():

        warnings.simplefilter('ignore')
        mexicanhat = fit_model(
            mexicanhat_init, x_values, y_values,
            z_values)  # What comes out is the model with the parameters set

    # Adjust the position of the model to a different coordinate frame
    if zoom_factor > 1.0:

        mexicanhat.x_0.value = mexicanhat.x_0.value / zoom_factor + x_shift
        mexicanhat.y_0.value = mexicanhat.y_0.value / zoom_factor + y_shift
        mexicanhat.sigma.value /= zoom_factor

    else:

        mexicanhat.x_0.value += x_shift
        mexicanhat.y_0.value += y_shift

    # Return the fitted two-dimensional Mexican Hat model
    return mexicanhat