Skip to content

Commit

Permalink
Minor updates to py2intround
Browse files Browse the repository at this point in the history
  • Loading branch information
larrybradley committed Jul 3, 2023
1 parent 216fd15 commit b8751ca
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
6 changes: 3 additions & 3 deletions photutils/centroids/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from astropy.utils.exceptions import AstropyUserWarning

from photutils.utils._parameters import as_pair
from photutils.utils._round import _py2intround
from photutils.utils._round import py2intround

__all__ = ['centroid_com', 'centroid_quadratic', 'centroid_sources']

Expand Down Expand Up @@ -189,8 +189,8 @@ def centroid_quadratic(data, xpeak=None, ypeak=None, fit_boxsize=5,
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)
xidx = py2intround(xpeak)
yidx = py2intround(ypeak)

if search_boxsize is not None:
search_boxsize = as_pair('search_boxsize', search_boxsize,
Expand Down
6 changes: 3 additions & 3 deletions photutils/psf/epsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from photutils.psf.utils import _interpolate_missing_data
from photutils.utils._optional_deps import HAS_BOTTLENECK, HAS_TQDM
from photutils.utils._parameters import as_pair
from photutils.utils._round import _py2intround
from photutils.utils._round import py2intround

__all__ = ['EPSFFitter', 'EPSFBuilder']

Expand Down Expand Up @@ -453,8 +453,8 @@ def _resample_residual(self, star, epsf):

epsf_xcenter, epsf_ycenter = (int((epsf.data.shape[1] - 1) / 2),
int((epsf.data.shape[0] - 1) / 2))
xidx = _py2intround(x + epsf_xcenter)
yidx = _py2intround(y + epsf_ycenter)
xidx = py2intround(x + epsf_xcenter)
yidx = py2intround(y + epsf_ycenter)

resampled_img = np.full(epsf.shape, np.nan)

Expand Down
18 changes: 14 additions & 4 deletions photutils/utils/_round.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,27 @@
import numpy as np


def _py2intround(a):
def py2intround(a):
"""
Round the input to the nearest integer.
If two integers are equally close, rounding is done away from 0.
Parameters
----------
a : float or array-like
The input float or array.
Returns
-------
result : float or array-like
The integer-rounded values.
"""
data = np.asanyarray(a)
data = np.atleast_1d(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()
if np.isscalar(value):
value = value[0]

return value

0 comments on commit b8751ca

Please sign in to comment.