Just one thing: numpy.interp says it doesn't check that the x coordinates are increasing, so make sure it's the case.<br><br>Assuming this is ok, I could still see how you may get some non-smooth behavior: this may be because your spike can either be split between two bins (which "dilutes" it somehow), or be included in a single bin (which would make it stand out more). And as you increase your bin size, you will switch between these two situations.<br>
<br>-=- Olivier<br><br><div class="gmail_quote">2011/11/13 Johannes Bauer <span dir="ltr"><<a href="mailto:dfnsonfsduifb@gmx.de">dfnsonfsduifb@gmx.de</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi group,<br>
<br>
I have a rather simple problem, or so it would seem. However I cannot<br>
seem to find the right solution. Here's the problem:<br>
<br>
A Geiger counter measures counts in distinct time intervals. The time<br>
intervals are not of constant length. Imaging for example that the<br>
counter would always create a table entry when the counts reach 10. Then<br>
we would have the following bins (made-up data for illustration):<br>
<br>
Seconds         Counts  Len     CPS<br>
0 - 44          10      44      0.23<br>
44 - 120        10      76      0.13<br>
120 - 140       10      20      0.5<br>
140 - 200       10      60      0.16<br>
<br>
So we have n bins (in this example 4), but they're not equidistant. I<br>
want to rebin samples to make them equidistant. For example, I would<br>
like to rebin into 5 bins of 40 seconds time each. Then the rebinned<br>
example (I calculate by hand so this might contain errors):<br>
<br>
0-40            9.09<br>
40-80           5.65<br>
80-120          5.26<br>
120-160         13.33<br>
160-200         6.66<br>
<br>
That means, if a destination bin completely overlaps a source bin, its<br>
complete value is taken. If it overlaps partially, linear interpolation<br>
of bin sizes should be used.<br>
<br>
It is very important that the overall count amount stays the same (in<br>
this case 40, so my numbers seem to be correct, I checked that). In this<br>
example I increased the bin size, but usually I will want to decrease<br>
bin size (even dramatically).<br>
<br>
Now my pathetic attempts look something like this:<br>
<br>
interpolation_points = 4000<br>
xpts = [ time.mktime(x.timetuple()) for x in self.getx() ]<br>
<br>
interpolatedx = numpy.linspace(xpts[0], xpts[-1], interpolation_points)<br>
interpolatedy = numpy.interp(interpolatedx, xpts, self.gety())<br>
<br>
self._xreformatted = [ datetime.datetime.fromtimestamp(x) for x in<br>
interpolatedx ]<br>
self._yreformatted = interpolatedy<br>
<br>
This works somewhat, however I see artifacts depending on the<br>
destination sample size: for example when I have a spike in the sample<br>
input and reduce the number of interpolation points (i.e. increase<br>
destination bin size) slowly, the spike will get smaller and smaller<br>
(expected behaviour). After some amount of increasing, the spike however<br>
will "magically" reappear. I believe this to be an interpolation artifact.<br>
<br>
Is there some standard way to get from a non-uniformally distributed bin<br>
distribution to a unifomally distributed bin distribution of arbitrary<br>
bin width?<br>
<br>
Best regards,<br>
Joe<br>
_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
</blockquote></div><br>