Skip to content

Commit

Permalink
Merge pull request #169 from carlgogo/master
Browse files Browse the repository at this point in the history
Improved HCICube class. New ``check_array`` function
  • Loading branch information
carlos-gg authored Apr 16, 2018
2 parents 9a6c001 + 1071622 commit fdac955
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 104 deletions.
34 changes: 33 additions & 1 deletion vip_hci/conf/utils_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,43 @@
__all__ = []

import sys

import numpy as np

sep = '-' * 80


def check_array(input, dim=1, name=None):
""" Checks the dimensionality of input. Returns it as a np.ndarray.
"""
if name is None:
name = 'Input'

if dim == 1:
msg = name + ' must be either a list or a 1d np.ndarray'
if isinstance(input, (list, tuple)):
input = np.array(input)
if not isinstance(input, np.ndarray):
raise TypeError(msg)
if not input.ndim == 1:
raise TypeError(msg)
elif dim == 2:
msg = name + ' must be an image or 2d np.ndarray'
if not isinstance(input, np.ndarray):
if not input.ndim == 2:
raise TypeError(msg)
elif dim == 3:
msg = name + ' must be a cube or 3d np.ndarray'
if not isinstance(input, np.ndarray):
if not input.ndim == 3:
raise TypeError(msg)
elif dim == 4:
msg = name + ' must be a cube or 4d np.ndarray'
if not isinstance(input, np.ndarray):
if not input.ndim == 4:
raise TypeError(msg)
return np.array(input)


def eval_func_tuple(f_args):
""" Takes a tuple of a function and args, evaluates and returns result"""
return f_args[0](*f_args[1:])
Expand Down
Loading

0 comments on commit fdac955

Please sign in to comment.