#ws_mesh = ws.WSMesh()
#ws_mesh.read_initial_file(r"/home/jpeacock/Documents/wsinv3d/LV/WSInitialModel_small")
#ws_mesh.station_fn = r"/home/jpeacock/Documents/wsinv3d/LV/WS_Station_Locations_small.txt"
#ws_stations = ws.WSStation()
#ws_stations.read_station_file(ws_mesh.station_fn)
#ws_mesh.station_locations = ws_stations.station_locations.copy()
#ws_mesh.plot_mesh()

#--> make data files
folder = 'sm_modem_inv1'
ws_data = ws.WSData(edi_list=edi_list,
                    period_list=inv_periods,
                    station_fn=ws_mesh.station_fn)
ws_data.n_z = 8
ws_data.z_err = .07
ws_data.z_err_map = [10, 1, 1, 10]
ws_data.z_err_floor = .07
sv_path = os.path.join(save_path, '{0}'.format(folder))
if not os.path.isdir(sv_path):
    os.mkdir(sv_path)
ws_data.write_data_file(save_path=sv_path,
                        data_basename='WS_data_{0}_8_small.dat'.format(folder))

ws_data_fn = os.path.join(save_path, 'Inv1_{0}'.format(folder),
                          'WS_data_{0}_8_small.dat'.format(folder))
ws_startup = ws.WSStartup(data_fn=os.path.basename(ws_data_fn),
                          initial_fn=os.path.basename(ws_mesh.initial_fn))
ws_startup.output_stem = 'lv_{0}'.format(folder)
ws_startup.save_path = sv_path
ws_startup.write_startup_file()
save_path = r"c:\Users\jrpeacock\Documents\kates_data\Inv_01"
# 2) make a grid from the stations themselves with 200m cell spacing
wsmesh = ws.WSMesh(edi_list=edi_list, cell_size_east=12500, cell_size_north=12500)
wsmesh.save_path = save_path
wsmesh.make_mesh()
# check to see if the mesh is what you think it should be
# wsmesh.plot_mesh()
# all is good write the mesh file
wsmesh.res_list = np.logspace(-1, 3, 8)
wsmesh.write_initial_file(save_path=save_path)
# note this will write a file with relative station locations
# change the starting model to be different than a halfspace

mm = ws.WSModelManipulator(initial_fn=wsmesh.initial_fn)
# an interactive gui will pop up to change the resistivity model
# once finished write a new initial file
mm.rewrite_initial_file()
# 3) write data file
wsdata = ws.WSData(edi_list=edi_list, period_list=p_list, station_fn=wsmesh.station_fn)
wsdata.save_path = save_path
wsdata.write_data_file()

# 4) plot mt response to make sure everything looks ok
# rp = ws.PlotResponse(data_fn=wsdata.data_fn)
# 5) make startup file
sws = ws.WSStartup(data_fn=wsdata.data_fn, initial_fn=mm.initial_fn)
sws.save_path = save_path
sws.error_tol = 5
sws.write_startup_file()