# Path: pygeons/mjd.py
# @_memoize
# def mjd(s,fmt):
#   ''' 
#   Converts a date string into Modified Julian Date (MJD)
#   
#   Parameters
#   ----------
#   s : string
#     Date string
# 
#   fmt : string
#     Format string indicating how to parse *s*
#       
#   Returns
#   -------
#   out : int
#     Modified Julian Date
# 
#   '''
#   d = datetime.strptime(s,fmt)
#   out = (d - _REFERENCE_DATETIME).days
#   return out


import numpy as np
import logging
from pygeons.mjd import mjd
                       converters={0:date_conv},
                       delimiter=delim,
                       usecols=(0,1,2,3,4,5,6))
  output = {}
  output['id'] = id.upper()
  output['longitude'] = np.float(lon)
  output['latitude'] = np.float(lat)
  output['time'] = data[:,0].astype(int)
  # comvert from millimeters to meters  
  output['north'] = 0.001*data[:,1].astype(float)
  output['east'] = 0.001*data[:,2].astype(float)
  output['vertical'] = 0.001*data[:,3].astype(float)
  output['north_std_dev'] = 0.001*data[:,4].astype(float)
  output['east_std_dev'] = 0.001*data[:,5].astype(float)
  output['vertical_std_dev'] = 0.001*data[:,6].astype(float)
  # indicate that the data are in units of meters
  output['time_exponent'] = 0  
  output['space_exponent'] = 1
  return output 


def parse_tdecsv(file_str):
  ''' 
  Reads data from a single data file which has the format used by the 
  SCEC Geodetic Transient Detection Validation Exercise
  '''
  fmt = '%Y-%m-%d'
  delim = ','

  def date_conv(date_str): 

# Path: pygeons/mjd.py
# @_memoize
# def mjd(s,fmt):
#   ''' 
#   Converts a date string into Modified Julian Date (MJD)
#   
#   Parameters
#   ----------
#   s : string
#     Date string
# 
#   fmt : string
#     Format string indicating how to parse *s*
#       
#   Returns
#   -------
#   out : int
#     Modified Julian Date
# 
#   '''
#   d = datetime.strptime(s,fmt)
#   out = (d - _REFERENCE_DATETIME).days
#   return out


# Path: pygeons/io/parser.py
import numpy as np
import logging
from pygeons.mjd import mjd

                       converters={0:date_conv},
                       delimiter=delim,
                       usecols=(0,1,2,3,4,5,6))
  output = {}
  output['id'] = id.upper()
  output['longitude'] = np.float(lon)
  output['latitude'] = np.float(lat)
  output['time'] = data[:,0].astype(int)
  # comvert from millimeters to meters  
  output['north'] = 0.001*data[:,1].astype(float)
  output['east'] = 0.001*data[:,2].astype(float)
  output['vertical'] = 0.001*data[:,3].astype(float)
  output['north_std_dev'] = 0.001*data[:,4].astype(float)
  output['east_std_dev'] = 0.001*data[:,5].astype(float)
  output['vertical_std_dev'] = 0.001*data[:,6].astype(float)
  # indicate that the data are in units of meters
  output['time_exponent'] = 0  
  output['space_exponent'] = 1
  return output 


def parse_tdecsv(file_str):
  ''' 
  Reads data from a single data file which has the format used by the 
  SCEC Geodetic Transient Detection Validation Exercise
  '''
  fmt = '%Y-%m-%d'
  delim = ','

  def date_conv(date_str): 

    return float(mjd(date_str,fmt))