# 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
    # CALL THIS AFTER *_init_image*
    #
    if len(self.data_sets) < 2:
      self.scatter = None 
      return

    sm = ScalarMappable(norm=self.cbar.norm,cmap=self.cbar.get_cmap())
    # use scatter points to show z for second data set 
    colors = sm.to_rgba(self.data_sets[1][self.tidx,:,2])
    self.scatter = self.map_ax.scatter(self.x[:,0],self.x[:,1],
                                       c=colors,s=self.scatter_size,
                                       zorder=2,edgecolor=self.colors[1])

  def _update_scatter(self):
    # Updates the scatter points for changes in *tidx* or *xidx*. This 
    # just changes the face color
    # 
    # CALL THIS AFTER *_update_image*
    #
    if len(self.data_sets) < 2:
      return

    sm = ScalarMappable(norm=self.cbar.norm,cmap=self.cbar.get_cmap())
    colors = sm.to_rgba(self.data_sets[1][self.tidx,:,2])
    self.scatter.set_facecolors(colors)

  def _init_quiver(self):
    # Initially plots the horizontal deformation vectors and a key
    self.quiver = []
    for si in range(len(self.data_sets)):

# 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

    # CALL THIS AFTER *_init_image*
    #
    if len(self.data_sets) < 2:
      self.scatter = None 
      return

    sm = ScalarMappable(norm=self.cbar.norm,cmap=self.cbar.get_cmap())
    # use scatter points to show z for second data set 
    colors = sm.to_rgba(self.data_sets[1][self.tidx,:,2])
    self.scatter = self.map_ax.scatter(self.x[:,0],self.x[:,1],
                                       c=colors,s=self.scatter_size,
                                       zorder=2,edgecolor=self.colors[1])

  def _update_scatter(self):
    # Updates the scatter points for changes in *tidx* or *xidx*. This 
    # just changes the face color
    # 
    # CALL THIS AFTER *_update_image*
    #
    if len(self.data_sets) < 2:
      return

    sm = ScalarMappable(norm=self.cbar.norm,cmap=self.cbar.get_cmap())
    colors = sm.to_rgba(self.data_sets[1][self.tidx,:,2])
    self.scatter.set_facecolors(colors)

  def _init_quiver(self):
    # Initially plots the horizontal deformation vectors and a key
    self.quiver = []
    for si in range(len(self.data_sets)):

      q = Quiver(self.map_ax,self.x[:,0],self.x[:,1],