Esempio n. 1
0
def _validate_read_mi_file(path):
    """
    Validate the `read_mi_file` function.

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

    """

    _validate(path, path, {'type': str})
Esempio n. 2
0
def _validate_remove_annotations(h5file):
    """
    Validate the `remove_annotations` function.

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

    """

    _validate(h5file, 'h5file', {'class': tables.file.File})
Esempio n. 3
0
def _validate_split_path(path):
    """
    Validate the `split_path` function.

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

    """

    _validate(path, "path", {"type": str})
Esempio n. 4
0
    def _validate_get(self, key):
        """
        Validate the `get` function.

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

        """

        _validate(key, 'key', {'val_in': list(self._param.keys())}, True)
Esempio n. 5
0
def _validate_annotate_database(h5file):
    """
    Validate the `annotate_database` function.

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

    """

    _validate(h5file, 'h5file', {'class': tables.file.File})
Esempio n. 6
0
def _validate_setup_matplotlib(settings):
    """
    Validate the `setup_matplotlib` function.

    See Also
    --------
    setup_matplotlib : The validated function.
    magni.util.validation.validate : Validation.

    """

    _validate(settings, 'settings', [{'type': dict}, {'type': dict}])
Esempio n. 7
0
    def _validate_getitem(self, name):
        """
        Validate the `__getitem__` function.

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

        """

        _validate(name, 'name', {'val_in': list(self._brews.keys())})
Esempio n. 8
0
    def _validate_get_attr(self, key):
        """
        Validate the `get_attr` function.

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

        """

        _validate(key, 'key', {'val_in': list(self._headers.keys())}, True)
Esempio n. 9
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})
Esempio n. 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)})
Esempio n. 11
0
    def _validate_get_buffer(self, key):
        """
        Validate the `get_buffer` function.

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

        """

        keys = [buffer.get_attr('bufferLabel') for buffer in self._buffers]
        _validate(key, 'key', {'val_in': keys}, True)
Esempio n. 12
0
def _validate_get_DFT(shape):
    """
    Validate the `get_DFT` function.

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

    """

    _validate(shape, 'shape',
              [{'type_in': (list, tuple), 'len': 2}, {'type': int, 'min': 1}])
Esempio n. 13
0
def _validate_load_phase_transition(path, label):
    """
    Validate the `load_phase_transition` function.

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

    """

    _validate(path, 'path', {'type': str})
    _validate(label, 'label', {'type': str})
Esempio n. 14
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})
Esempio n. 15
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)})
Esempio n. 16
0
    def _validate_get_data(self, intensity_func, intensity_args):
        """
        Validate the `get_data` function.

        See Also
        --------
        Buffer.get_data : The validated function.
        fat.utils.validation.validate : Validation.

        """

        _validate(intensity_func, 'intensity_func',
                  {'type': types.FunctionType}, ignore_none=True)
        _validate(intensity_args, 'intensity_args', {'type_in': (list, tuple)})
Esempio n. 17
0
def _validate_determine(algorithm, path, label, overwrite):
    """
    Validate the `determine` function.

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

    """

    _validate(algorithm, 'algorithm', {'type': types.FunctionType})
    _validate(path, 'path', {'type': str})
    _validate(label, 'label', {'type': str})

    # regular expression matching invalid characters
    regexp = re.compile(r'[^a-zA-Z0-9 ,.\-_/]')

    if regexp.search(label):
        raise RuntimeError("label may not contain {!r}."
                           .format(regexp.search(label).group()))

    # regular expression matching labels without empty path components
    regexp = re.compile(r'^([^/]+/)*[^/]+$')

    if not regexp.search(label):
        raise RuntimeError('label may not contain empty path components.')

    _validate(overwrite, 'overwrite', {'type': bool})
Esempio n. 18
0
    def _validate_init(self, brews):
        """
        Validate the `__init__` function.

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

        """

        _validate(brews, 'brews', [{'type': dict},
                                   {'type_in': (list, tuple)},
                                   {'type_in': (list, tuple), 'len': 3},
                                   {'type': int, 'min': 0, 'max': 255}])
Esempio n. 19
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})
Esempio n. 20
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)})
Esempio n. 21
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)
Esempio n. 22
0
def _validate_square_spiral_sample_surface(l, w, speed, sample_rate, time):
    """
    Validate the `square_spiral_sample_surface` function.

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

    """

    _validate(l, 'l', {'type': float, 'min': _min_l})
    _validate(w, 'w', {'type': float, 'min': _min_w})
    _validate(speed, 'speed', {'type': float, 'min': _min_speed})
    _validate(sample_rate, 'sample_rate', {'type': float,
                                           'min': _min_sample_rate})
    _validate(time, 'time', {'type': float, 'min': _min_time})
Esempio n. 23
0
    def _validate_init(self, param, requirements):
        """
        Validate the `__init__` function.

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

        """

        _validate(param, 'param', {'type': dict})
        _validate(requirements, 'requirements',
                  [{'type': dict}, {'type_in': [list, tuple, dict]}])

        if not sorted(param.keys()) == sorted(requirements.keys()):
            raise KeyError('param and requirements must have the same keys.')
Esempio n. 24
0
    def _validate_init(self, matrices):
        """
        Validate the `__init__` function.

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

        """

        _validate(matrices, 'matrices',
                  [{'type_in': (list, tuple)}, {'class': Matrix}])

        for i in range(len(matrices) - 1):
            if matrices[0].shape[1] != matrices[1].shape[0]:
                raise ValueError('The matrices must have compatible shapes.')
Esempio n. 25
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.')
Esempio n. 26
0
def _validate_spiral_sample_surface(l, w, speed, sample_rate, time):
    """
    Validate the `spiral_sample_surface` function.

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

    """

    _validate(l, 'l', {'type': float, 'min': _min_l})
    _validate(w, 'w', {'type': float, 'min': _min_w})

    if l != w:
        raise ValueError('l must equal w for an archimedian sprial to make' +
                         'sense.')

    _validate(speed, 'speed', {'type': float, 'min': _min_speed})
    _validate(sample_rate, 'sample_rate', {'type': float,
                                           'min': _min_sample_rate})
    _validate(time, 'time', {'type': float, 'min': _min_time})
Esempio n. 27
0
    def _validate_init(self, func, trans, args, shape):
        """
        Validate the `__init__` function.

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

        """

        _validate(func, 'func', {'type': types.FunctionType})
        _validate(trans, 'trans', {'type': types.FunctionType})
        _validate(args, 'args', {'type_in': (list, tuple)})
        _validate(shape, 'shape', [{'type_in': (list, tuple)}, {'type': int}])
Esempio n. 28
0
def _validate_square_spiral_sample_image(h, w, scan_length, num_points):
    """
    Validate the `square_spiral_sample_image` function.

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

    """

    _validate(h, 'h', {'type': int, 'min': 2})
    _validate(w, 'w', {'type': int, 'min': 2})
    _validate(scan_length, 'scan_length', {'type': float,
                                           'min': _min_scan_length})
    _validate(num_points, 'num_points', {'type': int, 'min': _min_num_points})
Esempio n. 29
0
def _validate_process(func, namespace, args_list, kwargs_list, maxtasks):
    """
    Validation of the `process` function.

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

    """

    _validate(func, "func", [{"type": types.FunctionType}])
    _validate(namespace, "namespace", [{"type": dict}])
    requirement = {"type_in": [list, tuple]}
    _validate(args_list, "args_list", [requirement, requirement], True)
    _validate(kwargs_list, "kwargs_list", [requirement, {"type": dict}], True)

    if args_list is None and kwargs_list is None:
        raise ValueError("args_list and kwargs_list cannot both be None.")
    elif args_list is not None and kwargs_list is not None:
        if len(args_list) != len(kwargs_list):
            raise ValueError("len(args_list) must equal len(kwargs_list).")

    _validate(maxtasks, "maxtasks", {"type": int}, True)
Esempio n. 30
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')})