예제 #1
0
    def _validate_init(self, Phi, Psi):
        """
        Validate the `__init__` function.

        See Also
        --------
        MultiDomainImage.__init__ : The validated function.
        magni.utils.validation.validate_matrix : Validation.

        """

        try:
            _validate_ndarray(Phi, 'Phi')
        except TypeError:
            if not isinstance(Phi, _Matrix) and not isinstance(Phi, _MatrixC):
                raise TypeError('Phi must be a matrix.')

        try:
            _validate_ndarray(Psi, 'Psi')
        except TypeError:
            if not isinstance(Psi, _Matrix) and not isinstance(Psi, _MatrixC):
                raise TypeError('Psi must be a matrix.')

        if Phi.shape[1] != Psi.shape[0]:
            raise ValueError('Phi and Psi must have compatible shapes.')
예제 #2
0
def _validate_plot_pixel_mask(h, w, pixels, output_path):
    """
    Validate the `plot_pixel_mask` function.

    See Also
    --------
    plot_pixel_mask : The validated function.
    magni.utils.validation.validate : Validation.

    """

    _validate(h, 'h', {'type': int, 'min': 2})
    _validate(w, 'w', {'type': int, 'min': 2})
    _validate_ndarray(pixels, 'pixels', {'subdtype': np.integer, 'dim': 2})
    _validate(output_path, 'output_path', {'type': str}, ignore_none=True)

    if pixels.shape[1] != 2:
        raise TypeError('pixels.shape[1] must be 2.')

    if pixels.min() < 0:
        raise TypeError('All pixel coordinates must be non-negative.')

    if pixels[:, 0].max() > w - 1:
        raise TypeError('Pixel x-coordinates must not exceed pixel width.')

    if pixels[:, 1].max() > h - 1:
        raise TypeError('Pixel y-coordinates must not exceed pixel heigth.')
예제 #3
0
def _validate_mat2vec(x):
    """
    Validatate the `mat2vec` function.

    See also
    --------
    magni.utils.validation.validate : Validation.

    """

    _validate_ndarray(x, 'x', {'dim': 2})
예제 #4
0
    def _validate_measurements(self, value):
        """
        Validate the `measurements.setter` function.

        See Also
        --------
        MultiDomainImage.measurements.setter : The validated function.
        magni.utils.validation.validate_ndarray : Validation.

        """

        _validate_ndarray(value, 'value', {'shape': (self._Phi.shape[0], 1)})
예제 #5
0
    def _validate_dot(self, vec):
        """
        Validate the `dot` function.

        See Also
        --------
        MatrixCollection.dot : The validated function.
        magni.utils.validation.validate_matrix : Validation.

        """

        _validate_ndarray(vec, 'vec', {'shape': (self.shape[1], 1)})
예제 #6
0
def _validate_calculate_mse(x_org, x_recons):
    """
    Validate the `calculate_mse` function.

    See Also
    --------
    magni.utils.validation.validate : Validation.

    """

    _validate_ndarray(x_org, 'x_org', {})
    _validate_ndarray(x_recons, 'x_recons', {'shape': x_org.shape})
예제 #7
0
    def _validate_coefficients(self, value):
        """
        Validate the `coefficients.setter` function.

        See Also
        --------
        MultiDomainImage.coefficients.setter : The validated function.
        magni.utils.validation.validate_ndarray : Validation.

        """

        _validate_ndarray(value, 'value', {'shape': (self._Psi.shape[1], 1)})
예제 #8
0
def _validate_calculate_psnr(x_org, x_recons, peak):
    """
    Validate the `calculate_psnr` function.

    See Also
    --------
    magni.utils.validation.validate : Validation.

    """

    _validate_ndarray(x_org, 'x_org', {})
    _validate_ndarray(x_recons, 'x_recons', {'shape': x_org.shape})
    _validate(peak, 'peak', {'type_in': [float, int], 'min': 0})
예제 #9
0
def _validate_run(y, A):
    """
    Validate the `run` function.

    See Also
    --------
    run : The validated function.
    magni.utils.validation.validate : Validation.

    """

    _validate_ndarray(A, 'A', {'dim': 2})
    _validate_ndarray(y, 'y', {'shape': (A.shape[0], 1)})
예제 #10
0
def _validate_transform(x, m, n):
    """
    Validatate a 2D transform.

    See also
    --------
    magni.utils.validation.validate : Validation.

    """

    _validate(m, 'm', {'type': int, 'min': 1})
    _validate(n, 'n', {'type': int, 'min': 1})
    _validate_ndarray(x, 'x', {'shape': (m * n, 1)})
예제 #11
0
def _validate_stretch_image(img, max_val):
    """
    Validate the `stretch_image` function.

    See Also
    --------
    stretch_image : The validated function.
    magni.utils.validation.validate : Validation.

    """

    _validate_ndarray(img, 'img', {'subdtype': np.floating})
    _validate(max_val, 'max_val', {'type_in': [int, float], 'min': 0})
예제 #12
0
    def _validate_init(self, data, hdrs):
        """
        Validate the `__init__` function.

        See Also
        --------
        Image.__init__ : The validated function.
        magni.utils.validation.validate : Validation.
        magni.utils.validation.validate_ndarray : Validation.

        """

        _validate_ndarray(data, 'data')
        _validate(hdrs, 'hdrs', {'type_in': (list, tuple)})
예제 #13
0
def _validate_shift_mean(x_mod, x_org):
    """
    Validate the `shift_mean` function.

    See Also
    --------
    shift_mean : The validated function.
    magni.utils.validation.validate : Validation.

    """

    _validate_ndarray(x_org, 'x_mod', {})
    _validate_ndarray(x_mod, 'x_org', {'dtype': x_mod.dtype,
                                       'shape': x_mod.shape})
예제 #14
0
def _validate_construct_measurement_matrix(coords, h, w):
    """
    Validate the `construct_measurement_matrix` function.

    See Also
    --------
    construct_measurement_matrix : The validated function.
    magni.utils.validation.validate : Validation.
    magni.utils.validation.validate_ndarray : Validation.

    """

    _validate_ndarray(coords, 'coords', {'shape': (coords.shape[0], 2)})
    _validate(h, 'h', {'type': int, 'min': 1})
    _validate(w, 'w', {'type': int, 'min': 1})
예제 #15
0
def _validate_vec2mat(x, mn_tuple):
    """
    Validatate the `vec2mat` function.

    See also
    --------
    magni.utils.validation.validate : Validation.

    """

    m, n = mn_tuple

    _validate(m, 'm', {'type': int, 'min': 1})
    _validate(n, 'n', {'type': int, 'min': 1})
    _validate_ndarray(x, 'x', {'shape': (m * n, 1)})
예제 #16
0
    def _validate_init(self, data, hdrs, width, height):
        """
        Validate the `__init__` function.

        See Also
        --------
        Buffer.__init__ : The validated function.
        magni.utils.validation.validate : Validation.
        magni.utils.validation.validate_ndarray : Validation.

        """

        _validate_ndarray(data, 'data')
        _validate(hdrs, 'hdrs', {'type_in': (list, tuple)})
        _validate(width, 'width', {'type': int, 'min': 1})
        _validate(height, 'height', {'dtype': int, 'min': 1})
예제 #17
0
def _validate_detilt(img, mask, mode, degree, return_tilt):
    """
    Validate the `detilt` function.

    See Also
    --------
    magni.utils.validation.validate : Validation

    """

    _validate_ndarray(img, 'img', {'dim': 2, 'subdtype': np.floating})
    _validate_ndarray(mask, 'mask', {'shape': img.shape, 'dtype': np.bool_},
                      ignore_none=True)
    _validate(mode, 'mode', {'type': str, 'val_in': ['plane_flatten',
                                                     'line_flatten']})
    _validate(degree, 'degree', {'type': int, 'min': 1})
    _validate(return_tilt, 'return_tilt', {'type': bool})
예제 #18
0
def _validate_imshow(X, ax, intensity_func, intensity_args, show_axis):
    """
    Validate the `imshow` function.

    See Also
    --------
    imshow : The validated function.
    magni.utils.validation.validate : Validation.

    """

    _validate_ndarray(X, 'X')
    _validate(ax, 'ax', {'class': mpl.axes.Axes}, ignore_none=True)
    _validate(intensity_func, 'intensity_func', {'type': types.FunctionType},
              ignore_none=True)
    _validate(intensity_args, 'intensity_args', {'type_in': (list, tuple)})
    _validate(show_axis, 'show_axis', {'type': str,
                                       'val_in': ('none', 'top', 'inherit')})
예제 #19
0
def _validate_unique_pixels(coords):
    """
    Validate the `unique_pixels` function.

    See Also
    --------
    unique_pixels : The validated function.
    magni.utils.validation.validate : Validation.

    """

    _validate_ndarray(coords, 'coords', {'subdtype': np.floating, 'dim': 2})

    if coords.shape[1] != 2:
        raise TypeError('coords.shape[1] must be 2.')

    if coords.min() < 0:
        raise TypeError('All coordinates must be non-negative.')
예제 #20
0
def _validate_run(y, A):
    """
    Validate the `run` function.

    See Also
    --------
    run : The validated function.
    magni.utils.validation.validate : Validation.

    """

    try:
        _validate_ndarray(A, 'A')
    except TypeError:
        if not isinstance(A, _Matrix) and not isinstance(A, _MatrixC):
            raise TypeError('A must be a matrix.')

    _validate_ndarray(y, 'y', {'shape': (A.shape[0], 1)})
예제 #21
0
def _validate_analyse(x, Phi, Psi):
    """
    Validate the `analyse` function.

    See Also
    --------
    analyse : The validated function.
    magni.utils.validation.validate_ndarray : Validation.
    magni.utils.validation.validate_matrix : Validation.

    """

    try:
        _validate_ndarray(Phi, 'Phi')
    except TypeError:
        if not isinstance(Phi, _Matrix) and not isinstance(Phi, _MatrixC):
            raise TypeError('Phi must be a matrix.')

    try:
        _validate_ndarray(Psi, 'Psi')
    except TypeError:
        if not isinstance(Psi, _Matrix) and not isinstance(Psi, _MatrixC):
            raise TypeError('Psi must be a matrix.')

    if Phi.shape[1] != Psi.shape[0]:
        raise ValueError('Phi and Psi must have compatible shapes.')

    _validate_ndarray(x, 'x', {'shape': (Phi.shape[1], 1)})
예제 #22
0
def _validate_plot_pattern(l, w, coords, mode, output_path):
    """
    Validate the `plot_pattern` function.

    See Also
    --------
    plot_pattern : The validated function.
    magni.utils.validation.validate : Validation.

    """

    _validate(mode, 'mode', {'type': str, 'val_in': {'surface', 'image'}})
    _validate_ndarray(coords, 'coords', {'subdtype': np.floating, 'dim': 2})
    _validate(output_path, 'output_path', {'type': str}, ignore_none=True)

    if coords.shape[1] != 2:
        raise TypeError('coords.shape[1] must be 2.')

    if mode == 'surface':
        _validate(l, 'l', {'type': float, 'min': _min_l})
        _validate(w, 'w', {'type': float, 'min': _min_w})
    elif mode == 'image':
        _validate(l, 'l', {'type': int, 'min': 2})
        _validate(w, 'w', {'type': int, 'min': 2})
예제 #23
0
def _validate_plot_phase_transition_colormap(dist, delta, rho, plot_l1,
                                             output_path):
    """
    Validate the `plot_phase_transition_colormap` function.

    See Also
    --------
    magni.utils.validation.validate : Validation.

    """

    _validate_ndarray(delta, 'delta')
    _validate_ndarray(rho, 'rho', {'shape': (rho.shape[0],)})
    _validate_ndarray(dist, 'dist', {'dim': 3, 'shape': (
        delta.shape[0], rho.shape[0], dist.shape[2])})
    _validate(plot_l1, 'plot_l1', {'type': bool})
    _validate(output_path, 'output_path', {'type': str}, ignore_none=True)