# Path: pygeons/basemap.py
# def make_basemap(lon,lat,resolution=None):
#   ''' 
#   Creates a transverse mercator projection which is centered about the 
#   given positions. 
# 
#   Modifying this function should be sufficient to change the way that 
#   all map projections are generated in PyGeoNS
#   '''
#   lon = np.asarray(lon)
#   lat = np.asarray(lat)
#   n = lon.shape[0]
#   # the buffer should be the average shortest distance between 
#   # points... but this is good enough
#   lon_buff = max(0.1,lon.ptp()/np.sqrt(n))
#   lat_buff = max(0.1,lat.ptp()/np.sqrt(n))
#   llcrnrlon = min(lon) - lon_buff
#   llcrnrlat = min(lat) - lat_buff
#   urcrnrlon = max(lon) + lon_buff
#   urcrnrlat = max(lat) + lat_buff
#   lon_0 = (llcrnrlon + urcrnrlon)/2.0
#   lat_0 = (llcrnrlat + urcrnrlat)/2.0
#   return Basemap(projection='tmerc',
#                  resolution=resolution,
#                  lon_0 = lon_0,
#                  lat_0 = lat_0,
#                  llcrnrlon = llcrnrlon,
#                  llcrnrlat = llcrnrlat,
#                  urcrnrlon = urcrnrlon,
#                  urcrnrlat = urcrnrlat)
# 
# 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/convert.py
# def text_from_dict(outfile,data):
#   ''' 
#   Writes a text file from a data dictionary. The text file contains a 
#   csv string for each station separated by "***".
#   
#   Parameters
#   ----------
#   outfile : string
#     Name of the output text file
# 
#   data : dict
#     Data dictionary 
# 
#   '''
#   check_data(data)
#   Nx = len(data['id'])
#   strs = []
#   for i in range(Nx):
#     # create a subdictionary for each station
#     dict_i = {}
#     mask = (np.isinf(data['north_std_dev'][:,i]) &
#             np.isinf(data['east_std_dev'][:,i]) &
#             np.isinf(data['vertical_std_dev'][:,i]))
#     # do not write data for this station if the station has no data
#     if np.all(mask):
#       continue
# 
#     dict_i['id'] = data['id'][i]
#     dict_i['longitude'] = data['longitude'][i]
#     dict_i['latitude'] = data['latitude'][i]
#     dict_i['time'] = data['time'][~mask]
#     dict_i['east'] = data['east'][~mask,i]
#     dict_i['north'] = data['north'][~mask,i]
#     dict_i['vertical'] = data['vertical'][~mask,i]
#     dict_i['east_std_dev'] = data['east_std_dev'][~mask,i]
#     dict_i['north_std_dev'] = data['north_std_dev'][~mask,i]
#     dict_i['vertical_std_dev'] = data['vertical_std_dev'][~mask,i]
#     dict_i['time_exponent'] = data['time_exponent']
#     dict_i['space_exponent'] = data['space_exponent']
#     strs += [_write_csv(dict_i)]
#     
#   out = '***\n'.join(strs)
#   fout = open(outfile,'w')
#   fout.write(out)
#   fout.close()
#   return


import numpy as np
from pygeons.basemap import make_basemap
from pygeons.mjd import mjd
from pygeons.io.convert import text_from_dict
# This script generates the synthetic data file data.csv

np.random.seed(1)

def make_data(pos,times):
  ''' 
  1 microstrain per year = 3 * 10^-9 strain per day
  '''  
  ms = 2.737e-9
  x,y = pos.T
  _,xg = np.meshgrid(times,x,indexing='ij')
  tg,yg = np.meshgrid(times,y,indexing='ij')
  u = 0.0*ms*tg*xg + 0.0*ms*tg*yg
  v = 0.0*ms*tg*xg + 3.0*ms*tg*yg
  z = 0.0*tg
  u = u - u[0,:]
  v = v - v[0,:]
  z = z - z[0,:]
  return u,v,z

lon = np.array([-83.3,-82.75,-85.26,-83.36])
lat = np.array([42.31,42.91,45.20,42.92])
id = np.array(['STA1','STA2','STA3','STA4'])
bm = make_basemap(lon,lat)
x,y = bm(lon,lat)
xy = np.array([x,y]).T
start_date = mjd('2000-01-01','%Y-%m-%d')

# Path: pygeons/basemap.py
# def make_basemap(lon,lat,resolution=None):
#   ''' 
#   Creates a transverse mercator projection which is centered about the 
#   given positions. 
# 
#   Modifying this function should be sufficient to change the way that 
#   all map projections are generated in PyGeoNS
#   '''
#   lon = np.asarray(lon)
#   lat = np.asarray(lat)
#   n = lon.shape[0]
#   # the buffer should be the average shortest distance between 
#   # points... but this is good enough
#   lon_buff = max(0.1,lon.ptp()/np.sqrt(n))
#   lat_buff = max(0.1,lat.ptp()/np.sqrt(n))
#   llcrnrlon = min(lon) - lon_buff
#   llcrnrlat = min(lat) - lat_buff
#   urcrnrlon = max(lon) + lon_buff
#   urcrnrlat = max(lat) + lat_buff
#   lon_0 = (llcrnrlon + urcrnrlon)/2.0
#   lat_0 = (llcrnrlat + urcrnrlat)/2.0
#   return Basemap(projection='tmerc',
#                  resolution=resolution,
#                  lon_0 = lon_0,
#                  lat_0 = lat_0,
#                  llcrnrlon = llcrnrlon,
#                  llcrnrlat = llcrnrlat,
#                  urcrnrlon = urcrnrlon,
#                  urcrnrlat = urcrnrlat)
# 
# 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/convert.py
# def text_from_dict(outfile,data):
#   ''' 
#   Writes a text file from a data dictionary. The text file contains a 
#   csv string for each station separated by "***".
#   
#   Parameters
#   ----------
#   outfile : string
#     Name of the output text file
# 
#   data : dict
#     Data dictionary 
# 
#   '''
#   check_data(data)
#   Nx = len(data['id'])
#   strs = []
#   for i in range(Nx):
#     # create a subdictionary for each station
#     dict_i = {}
#     mask = (np.isinf(data['north_std_dev'][:,i]) &
#             np.isinf(data['east_std_dev'][:,i]) &
#             np.isinf(data['vertical_std_dev'][:,i]))
#     # do not write data for this station if the station has no data
#     if np.all(mask):
#       continue
# 
#     dict_i['id'] = data['id'][i]
#     dict_i['longitude'] = data['longitude'][i]
#     dict_i['latitude'] = data['latitude'][i]
#     dict_i['time'] = data['time'][~mask]
#     dict_i['east'] = data['east'][~mask,i]
#     dict_i['north'] = data['north'][~mask,i]
#     dict_i['vertical'] = data['vertical'][~mask,i]
#     dict_i['east_std_dev'] = data['east_std_dev'][~mask,i]
#     dict_i['north_std_dev'] = data['north_std_dev'][~mask,i]
#     dict_i['vertical_std_dev'] = data['vertical_std_dev'][~mask,i]
#     dict_i['time_exponent'] = data['time_exponent']
#     dict_i['space_exponent'] = data['space_exponent']
#     strs += [_write_csv(dict_i)]
#     
#   out = '***\n'.join(strs)
#   fout = open(outfile,'w')
#   fout.write(out)
#   fout.close()
#   return


# Path: demo/junk/demo1/make_data.py
import numpy as np
from pygeons.basemap import make_basemap
from pygeons.mjd import mjd
from pygeons.io.convert import text_from_dict

# This script generates the synthetic data file data.csv

np.random.seed(1)

def make_data(pos,times):
  ''' 
  1 microstrain per year = 3 * 10^-9 strain per day
  '''  
  ms = 2.737e-9
  x,y = pos.T
  _,xg = np.meshgrid(times,x,indexing='ij')
  tg,yg = np.meshgrid(times,y,indexing='ij')
  u = 0.0*ms*tg*xg + 0.0*ms*tg*yg
  v = 0.0*ms*tg*xg + 3.0*ms*tg*yg
  z = 0.0*tg
  u = u - u[0,:]
  v = v - v[0,:]
  z = z - z[0,:]
  return u,v,z

lon = np.array([-83.3,-82.75,-85.26,-83.36])
lat = np.array([42.31,42.91,45.20,42.92])
id = np.array(['STA1','STA2','STA3','STA4'])
bm = make_basemap(lon,lat)
x,y = bm(lon,lat)
xy = np.array([x,y]).T
start_date = mjd('2000-01-01','%Y-%m-%d')

stop_date = mjd('2000-02-01','%Y-%m-%d')