|
Re: rebin (corrected): msg#00074python.numeric.general
At 9:06 AM -0700 2004-08-30, Russell E Owen wrote: At 9:14 AM -0400 2004-08-30, Perry Greenfield wrote: I made several mistakes, one of them very serious: the convolve boxcar cannot do the job unless the array size is an exact multiple of the bin factor. The problem is that boxcar starts in the "wrong" place. Here's an example: Problem: solve rebin [0, 1, 2, 3, 4] by 2 to yield: [0.5, 2.5, 4.0] where the last point (value 4) is averaged with next-off-the-end, which we approximate by extending the data (note: my propsed "polished" version messed that up; Perry had it right). Using boxcar almost works: array([0, 1, 2, 3, 4])import numarray as num array([ 0. , 0.5, 1.5, 2.5, 3.5])boxcar(a, (2,)) array([ 0. , 0.5, 1.5, 2.5, 3.5])b = boxcar(a, (2,)) array([ 0.5, 2.5])b[1::2] but oops: the last point is missing!!! What is needed is some way to make the boxcar average start later, so it finishes by averaging 4 plus the next value off the edge of the array, e.g. a hypothetical version of boxcar with a start argument: [0.5, 1.5, 2.5, 3.5, 4.0]b2 = nonexistent_boxcar(a, (2,), start=1) b[0::2] [0.5, 2.5, 4.0] nd_image.boxcar_filter has an origin argument that *might* be for this purpose. Unfortunately, it is not documented and my attempt to use it as desired failed. I have no idea if this is a bug in nd_image or a misunderstanding on my part: array([ 0. , 0.5, 1.5, 2.5, 3.5], type=Float32)from numarray.nd_image import boxcar_filter Traceback (most recent call last):# now try the origin argument and get a traceback; origin=1 gives the same error: File "<stdin>", line 1, in ? File "/usr/local/lib/python2.3/site-packages/numarray/nd_image/filters.py", line 339, in boxcar_filter output_type = output_type) File "/usr/local/lib/python2.3/site-packages/numarray/nd_image/filters.py", line 280, in boxcar_filter1d cval, origin, output_type) RuntimeError: shift not within filter extent So, yes, a rebin function that actually worked would be a real godsend! Meanwhile, any other suggestions? Fortunately in our application we *can* call out to IDL, but it seems a shame to have to do that. -- Russell ------------------------------------------------------- This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools! Get your free copy of BEA WebLogic Workshop 8.1 today. http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: rebin: 00074, Russell E Owen |
|---|---|
| Next by Date: | Re: rebin (corrected): 00074, Rick White |
| Previous by Thread: | Re: rebini: 00074, Russell E Owen |
| Next by Thread: | Re: rebin (corrected): 00074, Rick White |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |