# Path: vip_hci/var/coords.py
# def frame_center(array, verbose=False):
#     """
#     Return the coordinates y,x of the frame(s) center.
#     If odd: dim/2-0.5
#     If even: dim/2
# 
#     Parameters
#     ----------
#     array : 2d/3d/4d numpy ndarray
#         Frame or cube.
#     verbose : bool optional
#         If True the center coordinates are printed out.
# 
#     Returns
#     -------
#     cy, cx : int
#         Coordinates of the center.
# 
#     """
#     if array.ndim == 2:
#         shape = array.shape
#     elif array.ndim == 3:
#         shape = array[0].shape
#     elif array.ndim == 4:
#         shape = array[0, 0].shape
#     else:
#         raise ValueError('`array` is not a 2d, 3d or 4d array')
# 
#     cy = shape[0] / 2
#     cx = shape[1] / 2
# 
#     if shape[0]%2:
#         cy-=0.5
#     if shape[1]%2:
#         cx-=0.5        
# 
#     if verbose:
#         print('Center px coordinates at x,y = ({}, {})'.format(cx, cy))  
#     
#     return int(cy), int(cx)
# 
# Path: vip_hci/config/utils_conf.py
# def frame_or_shape(data):
#     """
#     Sanitize ``data``, always return a 2d frame.
# 
#     If ``data`` is a 2d frame, it is returned unchanged. If it is a shaped,
#     return an empty array of that shape.
# 
#     Parameters
#     ----------
#     data : 2d ndarray or shape tuple
# 
#     Returns
#     -------
#     array : 2d ndarray
# 
#     """
#     if isinstance(data, np.ndarray):
#         array = data
#         if array.ndim != 2:
#             raise TypeError('`data` is not a frame or 2d array')
#     elif isinstance(data, tuple):
#         array = np.zeros(data)
#     else:
#         raise TypeError('`data` must be a tuple (shape) or a 2d array')
# 
#     return array


import numpy as np
from skimage.draw import polygon
from skimage.draw import disk
from sklearn.preprocessing import scale
from .coords import frame_center
from ..config.utils_conf import frame_or_shape


def mask_circle(array, radius, fillwith=0, mode='in'):
    """
    Mask the pixels inside/outside of a centered circle with ``fillwith``.

    Returns a modified copy of ``array``.

    Parameters
    ----------
    array : 2d/3d/4d numpy ndarray
        Input frame or cube.
    radius : int
        Radius of the circular aperture.
    fillwith : int, float or np.nan, optional
        Value to put instead of the masked out pixels.
    mode : {'in', 'out'}, optional
        When set to 'in' then the pixels inside the radius are set to
        ``fillwith``. When set to 'out' the pixels outside the circular mask are
        set to ``fillwith``.

    Returns
    -------
    array_masked : numpy ndarray
        Masked frame or cube.

    """
    if not isinstance(fillwith, (int, float)):
        raise ValueError('`fillwith` must be integer, float or np.nan')


# Path: vip_hci/var/coords.py
# def frame_center(array, verbose=False):
#     """
#     Return the coordinates y,x of the frame(s) center.
#     If odd: dim/2-0.5
#     If even: dim/2
# 
#     Parameters
#     ----------
#     array : 2d/3d/4d numpy ndarray
#         Frame or cube.
#     verbose : bool optional
#         If True the center coordinates are printed out.
# 
#     Returns
#     -------
#     cy, cx : int
#         Coordinates of the center.
# 
#     """
#     if array.ndim == 2:
#         shape = array.shape
#     elif array.ndim == 3:
#         shape = array[0].shape
#     elif array.ndim == 4:
#         shape = array[0, 0].shape
#     else:
#         raise ValueError('`array` is not a 2d, 3d or 4d array')
# 
#     cy = shape[0] / 2
#     cx = shape[1] / 2
# 
#     if shape[0]%2:
#         cy-=0.5
#     if shape[1]%2:
#         cx-=0.5        
# 
#     if verbose:
#         print('Center px coordinates at x,y = ({}, {})'.format(cx, cy))  
#     
#     return int(cy), int(cx)
# 
# Path: vip_hci/config/utils_conf.py
# def frame_or_shape(data):
#     """
#     Sanitize ``data``, always return a 2d frame.
# 
#     If ``data`` is a 2d frame, it is returned unchanged. If it is a shaped,
#     return an empty array of that shape.
# 
#     Parameters
#     ----------
#     data : 2d ndarray or shape tuple
# 
#     Returns
#     -------
#     array : 2d ndarray
# 
#     """
#     if isinstance(data, np.ndarray):
#         array = data
#         if array.ndim != 2:
#             raise TypeError('`data` is not a frame or 2d array')
#     elif isinstance(data, tuple):
#         array = np.zeros(data)
#     else:
#         raise TypeError('`data` must be a tuple (shape) or a 2d array')
# 
#     return array


# Path: vip_hci/var/shapes.py
import numpy as np
from skimage.draw import polygon
from skimage.draw import disk
from sklearn.preprocessing import scale
from .coords import frame_center
from ..config.utils_conf import frame_or_shape



def mask_circle(array, radius, fillwith=0, mode='in'):
    """
    Mask the pixels inside/outside of a centered circle with ``fillwith``.

    Returns a modified copy of ``array``.

    Parameters
    ----------
    array : 2d/3d/4d numpy ndarray
        Input frame or cube.
    radius : int
        Radius of the circular aperture.
    fillwith : int, float or np.nan, optional
        Value to put instead of the masked out pixels.
    mode : {'in', 'out'}, optional
        When set to 'in' then the pixels inside the radius are set to
        ``fillwith``. When set to 'out' the pixels outside the circular mask are
        set to ``fillwith``.

    Returns
    -------
    array_masked : numpy ndarray
        Masked frame or cube.

    """
    if not isinstance(fillwith, (int, float)):
        raise ValueError('`fillwith` must be integer, float or np.nan')


    cy, cx = frame_center(array)