# Path: pygeons/units.py
# def unit_conversion(units,time='day',space='m'):
#   ''' 
#   Returns a factors that converts data with units of *units* (e.g.
#   km/hr) to units that are in terms of *time* and *space*. 
#   
#   Example
#   -------
#   >>> unit_conversion('mm/yr',time='day',space='m')
#       2.73785078713e-06
# 
#   '''
#   # replace carets with two asterisks
#   units = units.replace('^','**')
#   # converts to m
#   to_m = {'mm':1e-3,
#           'cm':1e-2,
#           'm':1e0,
#           'km':1e3}
#   # converts to seconds
#   to_s = {'s':1.0,
#           'min':60.0,
#           'hr':60.0*60.0,
#           'day':24.0*60.0*60.0,
#           'mjd':24.0*60.0*60.0,
#           'yr':365.25*24.0*60.0*60.0}
#   # converts to user-specified space units and time units
#   conv = dict([(k,v/to_m[space]) for k,v in to_m.iteritems()] +
#               [(k,v/to_s[time]) for k,v in to_s.iteritems()])
#   out = eval(units,conv)
#   return out


import numpy as np
import scipy.sparse as sp
import logging
from rbf.utils import get_arg_count
from rbf.gauss import (GaussianProcess,
                       _zero_mean,
                       _zero_covariance,
                       _empty_basis)
from pygeons.units import unit_conversion as conv
      # matrix dense
      out = np.zeros((N1,N2))
      out[rows,cols] = data
  
    else:
      # otherwise make it csc sparse    
      out = sp.csc_matrix((data,(rows,cols)),(N1,N2),dtype=float)
    
    if N1 > chunk_size:
      logger.debug(
        'Building covariance matrix (chunk size = %s) : 100.0%% '
        'complete' % chunk_size)
      
    return out  
  
  return cov_out      

 
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:

# Path: pygeons/units.py
# def unit_conversion(units,time='day',space='m'):
#   ''' 
#   Returns a factors that converts data with units of *units* (e.g.
#   km/hr) to units that are in terms of *time* and *space*. 
#   
#   Example
#   -------
#   >>> unit_conversion('mm/yr',time='day',space='m')
#       2.73785078713e-06
# 
#   '''
#   # replace carets with two asterisks
#   units = units.replace('^','**')
#   # converts to m
#   to_m = {'mm':1e-3,
#           'cm':1e-2,
#           'm':1e0,
#           'km':1e3}
#   # converts to seconds
#   to_s = {'s':1.0,
#           'min':60.0,
#           'hr':60.0*60.0,
#           'day':24.0*60.0*60.0,
#           'mjd':24.0*60.0*60.0,
#           'yr':365.25*24.0*60.0*60.0}
#   # converts to user-specified space units and time units
#   conv = dict([(k,v/to_m[space]) for k,v in to_m.iteritems()] +
#               [(k,v/to_s[time]) for k,v in to_s.iteritems()])
#   out = eval(units,conv)
#   return out


# Path: pygeons/main/gptools.py
import numpy as np
import scipy.sparse as sp
import logging
from rbf.utils import get_arg_count
from rbf.gauss import (GaussianProcess,
                       _zero_mean,
                       _zero_covariance,
                       _empty_basis)
from pygeons.units import unit_conversion as conv

      # matrix dense
      out = np.zeros((N1,N2))
      out[rows,cols] = data
  
    else:
      # otherwise make it csc sparse    
      out = sp.csc_matrix((data,(rows,cols)),(N1,N2),dtype=float)
    
    if N1 > chunk_size:
      logger.debug(
        'Building covariance matrix (chunk size = %s) : 100.0%% '
        'complete' % chunk_size)
      
    return out  
  
  return cov_out      

 
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)]