def split_tracks(lat,lon,*args):
        '''assumes eastward motion'''
        tracks = []
        lt,ln = [lat[0]],[lon[0]]
        zz = [[z[0]] for z in args]
        for i in range(1,len(lon)):
            lt.append(lat[i])
            for z,a in zip(zz,args):
                z.append(a[i])
            d1 = abs(lon[i] - lon[i-1])
            d2 = abs((lon[i-1] + 360) - lon[i])
            d3 = abs(lon[i-1] - (lon[i] + 360))
            if d2 < d1:
                ln.append(lon[i]-360)
                tracks.append([np.array(lt),np.array(ln)] \
                    + [np.array(z) for z in zz])
                lt = [lat[i-1],lat[i]]
                ln = [lon[i-1]+360,lon[i]]
                zz = [[z[i-1]] for z in args]
            elif d3 < d1:
                ln.append(lon[i]+360)
                tracks.append([np.array(lt),np.array(ln)] \
                    + [np.array(z) for z in zz])
                lt = [lat[i-1],lat[i]]
                ln = [lon[i-1]-360,lon[i]]
                zz = [[z[i-1],z[i]] for z in args]
            else:
                ln.append(lon[i])
        if len(lt):
            tracks.append([np.array(lt),np.array(ln)] \
                + [np.array(z) for z in zz])
        return tracks
def split_tracks ( lat , lon , * args ) : tracks = [ ] lt , ln = [ lat [ 0 ] ] , [ lon [ 0 ] ] zz = [ [ z [ 0 ] ] for z in args ] for i in range ( 1 , len ( lon ) ) : lt . append ( lat [ i ] ) for z , a in zip ( zz , args ) : z . append ( a [ i ] ) d1 = abs ( lon [ i ] - lon [ i - 1 ] ) d2 = abs ( ( lon [ i - 1 ] + 360 ) - lon [ i ] ) d3 = abs ( lon [ i - 1 ] - ( lon [ i ] + 360 ) ) if d2 < d1 : ln . append ( lon [ i ] - 360 ) tracks . append ( [ np . array ( lt ) , np . array ( ln ) ] + [ np . array ( z ) for z in zz ] ) lt = [ lat [ i - 1 ] , lat [ i ] ] ln = [ lon [ i - 1 ] + 360 , lon [ i ] ] zz = [ [ z [ i - 1 ] ] for z in args ] elif d3 < d1 : ln . append ( lon [ i ] + 360 ) tracks . append ( [ np . array ( lt ) , np . array ( ln ) ] + [ np . array ( z ) for z in zz ] ) lt = [ lat [ i - 1 ] , lat [ i ] ] ln = [ lon [ i - 1 ] - 360 , lon [ i ] ] zz = [ [ z [ i - 1 ] , z [ i ] ] for z in args ] else : ln . append ( lon [ i ] ) if len ( lt ) : tracks . append ( [ np . array ( lt ) , np . array ( ln ) ] + [ np . array ( z ) for z in zz ] ) return tracks
assumes eastward motion