medians for degree measurements

Bas wegwerp at gmail.com
Mon Jan 25 12:06:34 EST 2010


> 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.

Chears,
Bas





More information about the Python-list mailing list