You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It looks like it is taking only the upper left element of the original pixel grid and using it as the value for the output pixel. I would expect this to do an average or some other combination on the pixel values to get the value for the output pixel. i.e. I would expect the output of the above example to be:
CCDData([[ 6.5, 8.5],
[26.5, 28.5]])
Am I misunderstanding the role of this function or is this the expected behavior?
I think rebin is probably the wrong name for the function. From the code it seems like it's more a replicate-function because it doesn't apply any function to subsections but only takes the calculated elements. For example it works well if the output-shape is bigger than the initial shape:
Just for comparison I think the functionality you want is avaiable for "numpy-arrays"-only in astropy/skikit-image and astroscrappy:
from skimage.measure import block_reduce as skimage_rebin # this is also used by astropy.nddata.utils.block_reduce
from astroscrappy import rebin as astroscrappy_rebin # assumes 2x2 block-size
astroscrappy_rebin(a) # can only handle float32 and assumes 2x2 blocks
array([[ 6.5, 8.5],
[ 26.5, 28.5]], dtype=float32)
skimage_rebin(a, (2,2), np.mean) # (2,2) is block size not final shape! instead of mean also sum could be used.
array([[ 6.5, 8.5],
[ 26.5, 28.5]], dtype=float32)
Yes the rebinning in ccdproc uses slicing. There is a private _blkavg function that would do more of what you want but I think we didn't include it as a public function at the time as we weren't sure exactly how to handle the uncertainty and masking (and hence the rebinning uses slicing . It is probably something that would be good to revisit now, but at the very least, the doc string to rebin should be updated to indicate that it is slicing and not an average.
Thanks for the info. FYI, it looks like the astroscrappy_rebin is faster than the skimage_rebin:
In [90]: %timeit skimage_rebin(arr1, (2,2), np.mean)
10000 loops, best of 3: 123 µs per loop
In [91]: %timeit astroscrappy_rebin(arr1.data.astype(np.float32))
The slowest run took 9.63 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 2.99 µs per loop
Interestingly, skimage_rebin took a CCDData object as input.
I'll play with uncertainty and masking and if I get something that works for me, I'll probably do a PR because I think this would be a common task that people want to do.
@joshwalawender -- any progress on this? We are currently thinking that we will deprecate the current rebin, replacing with block_reduce and block_replicate from astropy.nddata.utils.
Those completely ignore masking and uncertainty, though...and we are having trouble figuring a generic way to do that and are thinking instead about documenting how you would apply reduce/replicate to uncertainty and/or mask.
Activity
MSeifert04 commentedon Aug 12, 2016
I think
rebinis probably the wrong name for the function. From the code it seems like it's more a replicate-function because it doesn't apply any function to subsections but only takes the calculated elements. For example it works well if the output-shape is bigger than the initial shape:Just for comparison I think the functionality you want is avaiable for "numpy-arrays"-only in astropy/skikit-image and astroscrappy:
crawfordsm commentedon Aug 13, 2016
Yes the rebinning in ccdproc uses slicing. There is a private _blkavg function that would do more of what you want but I think we didn't include it as a public function at the time as we weren't sure exactly how to handle the uncertainty and masking (and hence the rebinning uses slicing . It is probably something that would be good to revisit now, but at the very least, the doc string to
rebinshould be updated to indicate that it is slicing and not an average.joshwalawender commentedon Aug 14, 2016
Thanks for the info. FYI, it looks like the
astroscrappy_rebinis faster than theskimage_rebin:Interestingly,
skimage_rebintook aCCDDataobject as input.I'll play with uncertainty and masking and if I get something that works for me, I'll probably do a PR because I think this would be a common task that people want to do.
mwcraig commentedon Sep 6, 2016
@joshwalawender -- any progress on this? We are currently thinking that we will deprecate the current
rebin, replacing withblock_reduceandblock_replicatefrom astropy.nddata.utils.Those completely ignore masking and uncertainty, though...and we are having trouble figuring a generic way to do that and are thinking instead about documenting how you would apply reduce/replicate to uncertainty and/or mask.
joshwalawender commentedon Sep 7, 2016
@mwcraig -- No progress. I put in a work around in my code for now, but haven't made any progress on a general tool.