[SciPy-user] Flux conservative rebinning
Yannick Copin
yannick.copin at laposte.net
Thu Jul 6 17:11:10 EDT 2006
Hi,
I'm looking for a "flux-conservative" rebinning scheme, i.e. resampling
an input vector while consering the total "flux" (i.e. sum).
As for now, I'm aware of basically two techniques, none of them suitable:
1. boxcar-filtering and sub-sampling (e.g.
http://article.gmane.org/gmane.comp.python.numeric.general/888)
2. interpolation (e.g. http://www.scipy.org/Cookbook/Rebinning)
For example (attachment), given
y = array([0,2,1,3], dtype='d')
with a total sum of 6.0, boxcar-filtering and sub-sampling (x2) would be:
yy = convolve(y, ones(2), mode='valid')[::2]
giving yy = [ 2. 4.] sum = 6.0. The problem is that I can reduce size
only by an integer factor (e.g. I cannot rebin y on 3 points), and
furthermore it looks like a waste of CPU to compute a convolution on
full input vector and *then* sub-sampling.
Using recipe #3 of http://www.scipy.org/Cookbook/Rebinning allows "any
dimension sizes" rebinning, but unfortunately does not conserve the flux:
yy = congrid(y, (3,), method='linear', centre=True)
gives yy = [ 0.33333337 1.5 2.66666698] sum = 4.5.
Finally, what I would have liked is yy = [ 0.66666667 2.
3.33333333] sum = 6.0, which is
yy = dot(mat, y)
with mat = array([[1.,1./3.,0.,0.],[0.,2./3.,2./3.,0.],[0.,0.,1./3.,1.]]).
Any way to efficiently construct the 'mat' array?
Cheers.
PS: BTW, method='neighbour' in congrid of example #3 of
http://www.scipy.org/Cookbook/Rebinning does not work out of the box and
raises:
NameError: name 'xi' is not defined
Is the code still incomplete?
--
.~. Yannick COPIN (o:>* Doctus cum libro
/V\ ---===<<<### NOT IN THE OFFICE ###>>>===---
// \\ Institut de physique nucleaire de Lyon (IN2P3 - France)
/( )\ http://snovae.in2p3.fr/ycopin/
^`~'^
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rebin.py
Type: text/x-python
Size: 5915 bytes
Desc: not available
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20060706/c5a4b696/attachment.py>
More information about the SciPy-User
mailing list