# Path: photutils/utils/_round.py
# def _py2intround(a):
#     """
#     Round the input to the nearest integer.
# 
#     If two integers are equally close, rounding is done away from 0.
#     """
#     data = np.asanyarray(a)
#     value = np.where(data >= 0, np.floor(data + 0.5),
#                      np.ceil(data - 0.5)).astype(int)
# 
#     if not hasattr(a, '__iter__'):
#         value = value.item()
# 
#     return value


import inspect
import warnings
import numpy as np
from astropy.nddata.utils import overlap_slices
from astropy.utils.exceptions import AstropyUserWarning
from ..utils._round import _py2intround
    if xpeak is not None and ((xpeak < 0) or (xpeak > data.shape[1] - 1)):
        raise ValueError('xpeak is outside of the input data')
    if ypeak is not None and ((ypeak < 0) or (ypeak > data.shape[0] - 1)):
        raise ValueError('ypeak is outside of the input data')

    data = np.asanyarray(data, dtype=float)
    ny, nx = data.shape

    badmask = ~np.isfinite(data)
    if np.any(badmask):
        warnings.warn('Input data contains non-finite values (e.g., NaN or '
                      'inf) that were automatically masked.',
                      AstropyUserWarning)
        data[badmask] = np.nan

    if mask is not None:
        if data.shape != mask.shape:
            raise ValueError('data and mask must have the same shape.')
        data[mask] = np.nan

    fit_boxsize = _process_boxsize(fit_boxsize, data.shape)

    if np.product(fit_boxsize) < 6:
        raise ValueError('fit_boxsize is too small.  6 values are required '
                         'to fit a 2D quadratic polynomial.')

    if xpeak is None or ypeak is None:
        yidx, xidx = np.unravel_index(np.nanargmax(data), data.shape)
    else:
        xidx = _py2intround(xpeak)

# Path: photutils/utils/_round.py
# def _py2intround(a):
#     """
#     Round the input to the nearest integer.
# 
#     If two integers are equally close, rounding is done away from 0.
#     """
#     data = np.asanyarray(a)
#     value = np.where(data >= 0, np.floor(data + 0.5),
#                      np.ceil(data - 0.5)).astype(int)
# 
#     if not hasattr(a, '__iter__'):
#         value = value.item()
# 
#     return value


# Path: photutils/centroids/core.py
import inspect
import warnings
import numpy as np
from astropy.nddata.utils import overlap_slices
from astropy.utils.exceptions import AstropyUserWarning
from ..utils._round import _py2intround

    if xpeak is not None and ((xpeak < 0) or (xpeak > data.shape[1] - 1)):
        raise ValueError('xpeak is outside of the input data')
    if ypeak is not None and ((ypeak < 0) or (ypeak > data.shape[0] - 1)):
        raise ValueError('ypeak is outside of the input data')

    data = np.asanyarray(data, dtype=float)
    ny, nx = data.shape

    badmask = ~np.isfinite(data)
    if np.any(badmask):
        warnings.warn('Input data contains non-finite values (e.g., NaN or '
                      'inf) that were automatically masked.',
                      AstropyUserWarning)
        data[badmask] = np.nan

    if mask is not None:
        if data.shape != mask.shape:
            raise ValueError('data and mask must have the same shape.')
        data[mask] = np.nan

    fit_boxsize = _process_boxsize(fit_boxsize, data.shape)

    if np.product(fit_boxsize) < 6:
        raise ValueError('fit_boxsize is too small.  6 values are required '
                         'to fit a 2D quadratic polynomial.')

    if xpeak is None or ypeak is None:
        yidx, xidx = np.unravel_index(np.nanargmax(data), data.shape)
    else:
        xidx = _py2intround(xpeak)

        yidx = _py2intround(ypeak)