# Path: pygeons/main/gptools.py
# def set_units(units):
#   ''' 
#   Wrapper for Gaussian process constructors which sets the
#   hyperparameter units. When a wrapped constructor is called, the
#   hyperparameters are converted to be in terms of *m* and *day*. The
#   constructor is also given the key word argument *convert*, which can
#   be set to False if no conversion is desired.
#   '''
#   def decorator(fin):
#     def fout(*args,**kwargs):
#       convert = kwargs.pop('convert',True)
#       if convert:
#         args = [a*conv(u,time='day',space='m') for a,u in zip(args,units)]
#         
#       return fin(*args)
# 
#     fout.units = units
#     fout.nargs = get_arg_count(fin)
#     fout.__doc__ = fin.__doc__
#     fout.__name__ = fin.__name__
#     if fout.nargs != len(fout.units):
#       raise ValueError(
#         'the number of arguments must be equal to the number of unit '
#         'specifications') 
#     
#     return fout  
# 
#   return decorator  
# 
# def kernel_product(gp1,gp2):
#   ''' 
#   Returns a GaussianProcess with zero mean and covariance that is the
#   product of the two inputs. The first GP must be 1D and the second
#   must be 2D.
#   '''
#   def mean(x,diff):
#     return np.zeros(x.shape[0])
# 
#   def covariance(x1,x2,diff1,diff2):
#     cov1  = gp1._covariance(x1[:,[0]],x2[:,[0]],
#                             diff1[[0]],diff2[[0]])
#     cov2  = gp2._covariance(x1[:,[1,2]],x2[:,[1,2]],
#                             diff1[[1,2]],diff2[[1,2]])
#     # There are two conditions to consider: (1) cov1 and cov2 are
#     # dense, and (2) at least one of the matrices is sparse. If (1)
#     # then use *np.multiply* for element-wise multiplication. If (2)
#     # then use the *multiply* method of the sparse matrix.
#     if (not sp.issparse(cov1)) & (not sp.issparse(cov2)):
#       # both are dense. The output will be a dense array
#       out = np.multiply(cov1,cov2)
# 
#     else:
#       # at least one is sparse. THe output will be a sparse array
#       if sp.issparse(cov1):
#         out = cov1.multiply(cov2).tocsc()
#       else:
#         # cov2 is sparse
#         out = cov2.multiply(cov1).tocsc()
#              
#     return out
#   
#   return GaussianProcess(mean,covariance,dim=3)  
# 
# Path: pygeons/main/gpstation.py
# def const():
#   def basis(x,diff):
# def linear():
#   def basis(x,diff):
# def per():
#   def basis(x):
# def step(t0):
#   def basis(x,diff):
# def mat32(sigma,cts):
# def mat52(sigma,cts):
# def wen11(sigma,cts):
# def wen12(sigma,cts):
# def wen30(sigma,cts):
# def spwen11(sigma,cts):
# def spwen12(sigma,cts):
# def spwen30(sigma,cts):
# def se(sigma,cts):
# def exp(sigma,cts):
# def fogm(sigma,w):
# def bm(sigma,t0):
#   def mean(x):
#   def cov(x1,x2):
# def ibm(sigma,t0):
#   def mean(x,diff):
#   def cov(x1,x2,diff1,diff2):
# CONSTRUCTORS = {'const':const,
#                 'linear':linear,
#                 'per':per, 
#                 'step':step,
#                 'bm':bm,
#                 'ibm':ibm,
#                 'fogm':fogm,
#                 'mat32':mat32,
#                 'mat52':mat52,
#                 'wen11':wen11,
#                 'wen12':wen12,
#                 'wen30':wen30,
#                 'spwen11':spwen11,
#                 'spwen12':spwen12,
#                 'spwen30':spwen30,
#                 'se':se,
#                 'exp':exp}


import rbf.basis
import rbf.poly
from rbf import gauss
from pygeons.main.gptools import set_units,kernel_product
from pygeons.main import gpstation
@set_units(['mm','yr','km'])
def se_se(sigma,cts,cls):
  ''' 
  Squared exponential for temporal and spatial covariance.
  
  Parameters
  ----------
  sigma [mm] : Standard deviation of displacements
  cts [yr] : Characteristic time-scale
  cls [km] : Characteristic length-scale
  '''
  tgp = gpstation.se(sigma,cts,convert=False)
  sgp = se(1.0,cls)
  return kernel_product(tgp,sgp)


@set_units(['mm','yr','km'])
def exp_se(sigma,cts,cls):
  ''' 
  Exponetial for temporal covariance. Squared exponential for spatial
  covariance.
  
  Parameters
  ----------
  sigma [mm] : Standard deviation of displacements
  cts [yr] : Characteristic time-scale
  cls [km] : Characteristic length-scale
  '''
  tgp = gpstation.exp(sigma,cts,convert=False)
  sgp = se(1.0,cls)

# Path: pygeons/main/gptools.py
# def set_units(units):
#   ''' 
#   Wrapper for Gaussian process constructors which sets the
#   hyperparameter units. When a wrapped constructor is called, the
#   hyperparameters are converted to be in terms of *m* and *day*. The
#   constructor is also given the key word argument *convert*, which can
#   be set to False if no conversion is desired.
#   '''
#   def decorator(fin):
#     def fout(*args,**kwargs):
#       convert = kwargs.pop('convert',True)
#       if convert:
#         args = [a*conv(u,time='day',space='m') for a,u in zip(args,units)]
#         
#       return fin(*args)
# 
#     fout.units = units
#     fout.nargs = get_arg_count(fin)
#     fout.__doc__ = fin.__doc__
#     fout.__name__ = fin.__name__
#     if fout.nargs != len(fout.units):
#       raise ValueError(
#         'the number of arguments must be equal to the number of unit '
#         'specifications') 
#     
#     return fout  
# 
#   return decorator  
# 
# def kernel_product(gp1,gp2):
#   ''' 
#   Returns a GaussianProcess with zero mean and covariance that is the
#   product of the two inputs. The first GP must be 1D and the second
#   must be 2D.
#   '''
#   def mean(x,diff):
#     return np.zeros(x.shape[0])
# 
#   def covariance(x1,x2,diff1,diff2):
#     cov1  = gp1._covariance(x1[:,[0]],x2[:,[0]],
#                             diff1[[0]],diff2[[0]])
#     cov2  = gp2._covariance(x1[:,[1,2]],x2[:,[1,2]],
#                             diff1[[1,2]],diff2[[1,2]])
#     # There are two conditions to consider: (1) cov1 and cov2 are
#     # dense, and (2) at least one of the matrices is sparse. If (1)
#     # then use *np.multiply* for element-wise multiplication. If (2)
#     # then use the *multiply* method of the sparse matrix.
#     if (not sp.issparse(cov1)) & (not sp.issparse(cov2)):
#       # both are dense. The output will be a dense array
#       out = np.multiply(cov1,cov2)
# 
#     else:
#       # at least one is sparse. THe output will be a sparse array
#       if sp.issparse(cov1):
#         out = cov1.multiply(cov2).tocsc()
#       else:
#         # cov2 is sparse
#         out = cov2.multiply(cov1).tocsc()
#              
#     return out
#   
#   return GaussianProcess(mean,covariance,dim=3)  
# 
# Path: pygeons/main/gpstation.py
# def const():
#   def basis(x,diff):
# def linear():
#   def basis(x,diff):
# def per():
#   def basis(x):
# def step(t0):
#   def basis(x,diff):
# def mat32(sigma,cts):
# def mat52(sigma,cts):
# def wen11(sigma,cts):
# def wen12(sigma,cts):
# def wen30(sigma,cts):
# def spwen11(sigma,cts):
# def spwen12(sigma,cts):
# def spwen30(sigma,cts):
# def se(sigma,cts):
# def exp(sigma,cts):
# def fogm(sigma,w):
# def bm(sigma,t0):
#   def mean(x):
#   def cov(x1,x2):
# def ibm(sigma,t0):
#   def mean(x,diff):
#   def cov(x1,x2,diff1,diff2):
# CONSTRUCTORS = {'const':const,
#                 'linear':linear,
#                 'per':per, 
#                 'step':step,
#                 'bm':bm,
#                 'ibm':ibm,
#                 'fogm':fogm,
#                 'mat32':mat32,
#                 'mat52':mat52,
#                 'wen11':wen11,
#                 'wen12':wen12,
#                 'wen30':wen30,
#                 'spwen11':spwen11,
#                 'spwen12':spwen12,
#                 'spwen30':spwen30,
#                 'se':se,
#                 'exp':exp}


# Path: pygeons/main/gpnetwork.py
import rbf.basis
import rbf.poly
from rbf import gauss
from pygeons.main.gptools import set_units,kernel_product
from pygeons.main import gpstation

@set_units(['mm','yr','km'])
def se_se(sigma,cts,cls):
  ''' 
  Squared exponential for temporal and spatial covariance.
  
  Parameters
  ----------
  sigma [mm] : Standard deviation of displacements
  cts [yr] : Characteristic time-scale
  cls [km] : Characteristic length-scale
  '''
  tgp = gpstation.se(sigma,cts,convert=False)
  sgp = se(1.0,cls)
  return kernel_product(tgp,sgp)


@set_units(['mm','yr','km'])
def exp_se(sigma,cts,cls):
  ''' 
  Exponetial for temporal covariance. Squared exponential for spatial
  covariance.
  
  Parameters
  ----------
  sigma [mm] : Standard deviation of displacements
  cts [yr] : Characteristic time-scale
  cls [km] : Characteristic length-scale
  '''
  tgp = gpstation.exp(sigma,cts,convert=False)
  sgp = se(1.0,cls)

  return kernel_product(tgp,sgp)