# 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/io.py
# def _remove_extension(f):
# def _unit_string(space_exponent,time_exponent):
# def _common_context(data_list):
# def pygeons_merge(input_files,output_stem=None):
# def pygeons_crop(input_file,start_date=None,stop_date=None,
#                  min_lat=-np.inf,max_lat=np.inf,
#                  min_lon=-np.inf,max_lon=np.inf,
#                  stations=None,output_stem=None):
# def pygeons_toh5(input_text_file,file_type='csv',output_stem=None):
# def pygeons_totext(input_file,output_stem=None):  
# def pygeons_info(input_file):
# 
# 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)


import numpy as np
import matplotlib.pyplot as plt
from pygeons.mjd import mjd
from pygeons.io.io import text_from_dict
from pygeons.basemap import make_basemap
np.random.seed(1)

## observation points
#####################################################################
pos_geo = np.array([[-83.74,42.28,0.0],
                    [-83.08,42.33,0.0],
                    [-83.33,41.94,0.0]])  
Nx = len(pos_geo)
bm = make_basemap(pos_geo[:,0],pos_geo[:,1])
pos_cart = np.array(bm(pos_geo[:,0],pos_geo[:,1])).T
dx = pos_cart[:,0] - pos_cart[0,0]
dy = pos_cart[:,1] - pos_cart[0,1]

dispdx = np.array([[0.0,1e-6,0.0]]).repeat(Nx,axis=0)
dispdy = np.array([[0.0,0.0,0.0]]).repeat(Nx,axis=0)
disp = dispdx*dx[:,None] + dispdy*dy[:,None]
u,v,z = disp.T
dudx,dvdx,dzdx = dispdx.T
dudy,dvdy,dzdy = dispdy.T

# make disp. time dependent
start_time = mjd('2015-07-01','%Y-%m-%d')

# 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/io.py
# def _remove_extension(f):
# def _unit_string(space_exponent,time_exponent):
# def _common_context(data_list):
# def pygeons_merge(input_files,output_stem=None):
# def pygeons_crop(input_file,start_date=None,stop_date=None,
#                  min_lat=-np.inf,max_lat=np.inf,
#                  min_lon=-np.inf,max_lon=np.inf,
#                  stations=None,output_stem=None):
# def pygeons_toh5(input_text_file,file_type='csv',output_stem=None):
# def pygeons_totext(input_file,output_stem=None):  
# def pygeons_info(input_file):
# 
# 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: demo/demo1/.write_synthetic.py
import numpy as np
import matplotlib.pyplot as plt
from pygeons.mjd import mjd
from pygeons.io.io import text_from_dict
from pygeons.basemap import make_basemap

np.random.seed(1)

## observation points
#####################################################################
pos_geo = np.array([[-83.74,42.28,0.0],
                    [-83.08,42.33,0.0],
                    [-83.33,41.94,0.0]])  
Nx = len(pos_geo)
bm = make_basemap(pos_geo[:,0],pos_geo[:,1])
pos_cart = np.array(bm(pos_geo[:,0],pos_geo[:,1])).T
dx = pos_cart[:,0] - pos_cart[0,0]
dy = pos_cart[:,1] - pos_cart[0,1]

dispdx = np.array([[0.0,1e-6,0.0]]).repeat(Nx,axis=0)
dispdy = np.array([[0.0,0.0,0.0]]).repeat(Nx,axis=0)
disp = dispdx*dx[:,None] + dispdy*dy[:,None]
u,v,z = disp.T
dudx,dvdx,dzdx = dispdx.T
dudy,dvdy,dzdy = dispdy.T

# make disp. time dependent
start_time = mjd('2015-07-01','%Y-%m-%d')

stop_time = mjd('2017-07-01','%Y-%m-%d')