medians for degree measurements
Robert Kern
robert.kern at gmail.com
Mon Jan 25 18:39:04 CET 2010
On 2010-01-25 11:06 AM, Bas wrote:
>> On 2010-01-25 10:16 AM, Bas wrote:
>>
>>> P.S.
>>> Slightly off-topic rant against both numpy and matlab implementation
>>> of unwrap: They always assume data is in radians. There is some option
>>> to specify the maximum jump size in radians, but to me it would be
>>> more useful to specify the interval of a complete cycle, so that you
>>> can do
>>
>>> unwrapped_radians = unwrap(radians)
>>> unwrapped_degrees = unwrap(degrees, 360)
>>> unwrapped_32bit_counter = unwrap(overflowing_counter, 2**32)
>
> On Jan 25, 5:34 pm, Robert Kern<robert.k... at gmail.com> wrote:>
>> Rants accompanied with patches are more effective. :-)
>
> As you wish (untested):
>
> def unwrap(p, cycle=2*pi, axis=-1):
> """docstring to be updated"""
> p = asarray(p)
> half_cycle = cycle / 2
> nd = len(p.shape)
> dd = diff(p, axis=axis)
> slice1 = [slice(None, None)]*nd # full slices
> slice1[axis] = slice(1, None)
> ddmod = mod(dd+half_cycle, cycle)-half_cycle
> _nx.putmask(ddmod, (ddmod==-half_cycle)& (dd> 0), half_cycle)
> ph_correct = ddmod - dd;
> _nx.putmask(ph_correct, abs(dd)<half_cycle, 0)
> up = array(p, copy=True, dtype='d')
> up[slice1] = p[slice1] + ph_correct.cumsum(axis)
> return up
>
> I never saw a use case for the discontinuity argument, so in my
> preferred version it would be removed. Of course this breaks old code
> (by who uses this option anyhow??) and breaks compatibility between
> matlab and numpy.
Sometimes legitimate features have phase discontinuities greater than pi. If you
want your feature to be accepted, please submit a patch that does not break
backwards compatibility and which updates the docstring and tests appropriately.
I look forward to seeing the complete patch! Thank you.
http://projects.scipy.org/numpy
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list
mailing list