# Path: pygeons/plot/quiver.py
# class Quiver(_Quiver):
#   def __init__(self,ax,*args,**kwargs):
#     if 'sigma' in kwargs:
#       scale_units = kwargs.get('scale_units','xy')
#       kwargs['scale_units'] = scale_units
#       if kwargs['scale_units'] != 'xy':
#         raise ValueError('scale units must be "xy" when sigma is given')
# 
#       angles = kwargs.get('angles','xy')
#       kwargs['angles'] = angles
#       if kwargs['angles'] != 'xy':
#         raise ValueError('angles must be "xy" when sigma is given')
# 
#     sigma = kwargs.pop('sigma',None)
# 
#     ellipse_kwargs = kwargs.pop('ellipse_kwargs',{})
#     if 'offsets' in ellipse_kwargs:
#       raise ValueError('cannot specify ellipse offsets')
#     if 'units' in ellipse_kwargs:
#       raise ValueError('cannot specify ellipse units')
#     
#     self.ellipse_kwargs = {'edgecolors':'k',
#                            'facecolors':'none',
#                            'linewidths':1.0}
#     self.ellipse_kwargs.update(ellipse_kwargs)
#     
#     self.ellipsoids = None
# 
#     _Quiver.__init__(self,ax,*args,**kwargs)
# 
#     if sigma is not None:
#       if self.scale is None:
#         self.scale = _estimate_scale(self.X,self.Y,self.U,self.V)
#         
#       su,sv,rho = sigma[0],sigma[1],sigma[2]
#       self._update_ellipsoids(su,sv,rho)
# 
# 
#   def _update_ellipsoids(self,su,sv,rho):
#     self.scale_units = 'xy'
#     self.angles = 'xy'
#     tips_x = self.X + self.U/self.scale
#     tips_y = self.Y + self.V/self.scale
#     tips = np.array([tips_x,tips_y]).transpose()
#     a,b,angle = compute_abphi(su,sv,rho)
#     width = 2.0*a/self.scale
#     height = 2.0*b/self.scale
#     if self.ellipsoids is not None: 
#       self.ellipsoids.remove()
# 
#     # do not draw ellipses which are too small  
#     too_small = 0.001
#     length = np.sqrt((self.U/self.scale)**2 + (self.V/self.scale)**2)
#     with warnings.catch_warnings():
#       # do not print out zero division warning
#       warnings.simplefilter("ignore")
#       is_not_too_small = ((np.nan_to_num(width/length) > too_small) | 
#                           (np.nan_to_num(height/length) > too_small))
# 
#     width = width[is_not_too_small]
#     height = height[is_not_too_small]
#     angle = angle[is_not_too_small]
#     tips = tips[is_not_too_small]    
#     
#     # dont add ellipses if there are no ellipses to add
#     if any(is_not_too_small):
#       self.ellipsoids = EllipseCollection(width,height,angle,
#                                           units=self.scale_units,
#                                           offsets = tips,
#                                           transOffset=self.ax.transData,
#                                           **self.ellipse_kwargs)
# 
#       self.ax.add_collection(self.ellipsoids)
# 
#     else:
#       self.ellipsoids = None      
# 
#   def set_UVC(self,u,v,C=None,sigma=None):
#     if C is None:
#       _Quiver.set_UVC(self,u,v)
#     else:
#       _Quiver.set_UVC(self,u,v,C)
# 
#     if sigma is not None:
#       su,sv,rho = sigma[0],sigma[1],sigma[2]
#       self._update_ellipsoids(su,sv,rho)
#       
#   def remove(self):  
#     # remove the quiver and ellipsoid collection
#     _Quiver.remove(self)    
#     if self.ellipsoids is not None:
#       self.ellipsoids.remove()


import matplotlib.pyplot as plt
import numpy as np
import logging
import sys
import scipy.interpolate
from pygeons.plot.quiver import Quiver
from matplotlib.cm import ScalarMappable
from matplotlib.colors import ListedColormap
from code import InteractiveConsole
from scipy.spatial import cKDTree
from textwrap import wrap
  from PyQt4.QtCore import pyqtRemoveInputHook, pyqtRestoreInputHook
  from PyQt5.QtCore import pyqtRemoveInputHook, pyqtRestoreInputHook
try:
except ImportError:
  
logger = logging.getLogger(__name__)

# this is an entirely white colormap. This is used to hide the 
# vertical deformation.
_blank_cmap = ListedColormap([[1.0,1.0,1.0,0.0]])

def _roll(lst):
  # rolls elements by 1 to the right. does not convert lst to an array
  lst = list(lst)
  out = [lst[-1]] + lst[:-1]
  return out


def _grid_interp_data(u,pnts,x,y):
  u = np.asarray(u)
  pnts = np.asarray(pnts)
  x = np.asarray(x)  
  y = np.asarray(y)

  pnts = pnts[np.isfinite(u)]
  u = u[np.isfinite(u)] 
  # return an array of zeros if all data is masked or if there is no 
  # data

# Path: pygeons/plot/quiver.py
# class Quiver(_Quiver):
#   def __init__(self,ax,*args,**kwargs):
#     if 'sigma' in kwargs:
#       scale_units = kwargs.get('scale_units','xy')
#       kwargs['scale_units'] = scale_units
#       if kwargs['scale_units'] != 'xy':
#         raise ValueError('scale units must be "xy" when sigma is given')
# 
#       angles = kwargs.get('angles','xy')
#       kwargs['angles'] = angles
#       if kwargs['angles'] != 'xy':
#         raise ValueError('angles must be "xy" when sigma is given')
# 
#     sigma = kwargs.pop('sigma',None)
# 
#     ellipse_kwargs = kwargs.pop('ellipse_kwargs',{})
#     if 'offsets' in ellipse_kwargs:
#       raise ValueError('cannot specify ellipse offsets')
#     if 'units' in ellipse_kwargs:
#       raise ValueError('cannot specify ellipse units')
#     
#     self.ellipse_kwargs = {'edgecolors':'k',
#                            'facecolors':'none',
#                            'linewidths':1.0}
#     self.ellipse_kwargs.update(ellipse_kwargs)
#     
#     self.ellipsoids = None
# 
#     _Quiver.__init__(self,ax,*args,**kwargs)
# 
#     if sigma is not None:
#       if self.scale is None:
#         self.scale = _estimate_scale(self.X,self.Y,self.U,self.V)
#         
#       su,sv,rho = sigma[0],sigma[1],sigma[2]
#       self._update_ellipsoids(su,sv,rho)
# 
# 
#   def _update_ellipsoids(self,su,sv,rho):
#     self.scale_units = 'xy'
#     self.angles = 'xy'
#     tips_x = self.X + self.U/self.scale
#     tips_y = self.Y + self.V/self.scale
#     tips = np.array([tips_x,tips_y]).transpose()
#     a,b,angle = compute_abphi(su,sv,rho)
#     width = 2.0*a/self.scale
#     height = 2.0*b/self.scale
#     if self.ellipsoids is not None: 
#       self.ellipsoids.remove()
# 
#     # do not draw ellipses which are too small  
#     too_small = 0.001
#     length = np.sqrt((self.U/self.scale)**2 + (self.V/self.scale)**2)
#     with warnings.catch_warnings():
#       # do not print out zero division warning
#       warnings.simplefilter("ignore")
#       is_not_too_small = ((np.nan_to_num(width/length) > too_small) | 
#                           (np.nan_to_num(height/length) > too_small))
# 
#     width = width[is_not_too_small]
#     height = height[is_not_too_small]
#     angle = angle[is_not_too_small]
#     tips = tips[is_not_too_small]    
#     
#     # dont add ellipses if there are no ellipses to add
#     if any(is_not_too_small):
#       self.ellipsoids = EllipseCollection(width,height,angle,
#                                           units=self.scale_units,
#                                           offsets = tips,
#                                           transOffset=self.ax.transData,
#                                           **self.ellipse_kwargs)
# 
#       self.ax.add_collection(self.ellipsoids)
# 
#     else:
#       self.ellipsoids = None      
# 
#   def set_UVC(self,u,v,C=None,sigma=None):
#     if C is None:
#       _Quiver.set_UVC(self,u,v)
#     else:
#       _Quiver.set_UVC(self,u,v,C)
# 
#     if sigma is not None:
#       su,sv,rho = sigma[0],sigma[1],sigma[2]
#       self._update_ellipsoids(su,sv,rho)
#       
#   def remove(self):  
#     # remove the quiver and ellipsoid collection
#     _Quiver.remove(self)    
#     if self.ellipsoids is not None:
#       self.ellipsoids.remove()


# Path: pygeons/plot/ivector.py
import matplotlib.pyplot as plt
import numpy as np
import logging
import sys
import scipy.interpolate
from pygeons.plot.quiver import Quiver
from matplotlib.cm import ScalarMappable
from matplotlib.colors import ListedColormap
from code import InteractiveConsole
from scipy.spatial import cKDTree
from textwrap import wrap
  from PyQt4.QtCore import pyqtRemoveInputHook, pyqtRestoreInputHook
  from PyQt5.QtCore import pyqtRemoveInputHook, pyqtRestoreInputHook

try:
except ImportError:
  
logger = logging.getLogger(__name__)

# this is an entirely white colormap. This is used to hide the 
# vertical deformation.
_blank_cmap = ListedColormap([[1.0,1.0,1.0,0.0]])

def _roll(lst):
  # rolls elements by 1 to the right. does not convert lst to an array
  lst = list(lst)
  out = [lst[-1]] + lst[:-1]
  return out


def _grid_interp_data(u,pnts,x,y):
  u = np.asarray(u)
  pnts = np.asarray(pnts)
  x = np.asarray(x)  
  y = np.asarray(y)

  pnts = pnts[np.isfinite(u)]
  u = u[np.isfinite(u)] 
  # return an array of zeros if all data is masked or if there is no 
  # data

  if pnts.shape[0] == 0: