def _get_utm(self): """ get utm coordinates from lat and lon """ self.utm_zone, self.east, self.north = MTutm.LLtoUTM(self._utm_ellipsoid, self.lat, self.lon)
def latlon2xy(lat, lon, origin): """returns position in local rectangular coordinates. x is positive northwards, y positive eastwards, values given in meter origin must be given as a 2-tuple/-array in (lat,lon) form """ #using existing tool for conversion from lat/lon to northing/easting, then just take planar approximation #comment: to be checked for overlapping UTM zones!! dummy1, utm_local_east, utm_local_north = ll2utm.LLtoUTM(23, lat, lon) dummy2, utm_origin_east, utm_origin_north = ll2utm.LLtoUTM( 23, origin[0], origin[1]) x = utm_local_north - utm_origin_north y = utm_local_east - utm_origin_east return x, y
x = np.zeros(line_arr.shape[0]) y = np.zeros(line_arr.shape[0]) z = np.zeros(line_arr.shape[0]) mag = np.zeros(line_arr.shape[0]) #east_0 = 334460.0 #north_0 = 4173370.0 east_0 = 336800.0 north_0 = 4167525.0 for ii, l_arr in enumerate(line_arr[:-1]): lat = float(l_arr[7]) lon = float(l_arr[8]) depth = float(l_arr[9]) mag[ii] = float(l_arr[10]) zone, east, north = ll2utm.LLtoUTM(23, lat, lon) x[ii] = (east - east_0) / 1000. y[ii] = (north - north_0) / 1000. z[ii] = depth + 3 a2vtk.pointsToVTK( r"C:\Users\jpeacock\Documents\LV\lv_3d_models\2013_lin_relocated_eq", y, x, z, data={ 'depth': z, 'magnitude': mag })
dfn = r"c:\Users\jpeacock\Documents\Geothermal\Washington\MB\modem_inv\mb_rot_err03_tip02_cov03_NLCG_016.dat" save_root = 'mb_rot_m40' rot_angle = -40.0 #--> read model file mod_obj = modem.Model() mod_obj.read_model_file(mfn) #--> read data file d_obj = modem.Data() d_obj.read_data_file(dfn) #--> get center position model_center = d_obj.center_position c_zone, c_east, c_north = utm2ll.LLtoUTM(23, model_center[0], model_center[1]) #--> set padding east_pad = mod_obj.pad_east + 4 north_pad = mod_obj.pad_north + 4 z_pad = np.where(mod_obj.grid_z > 20000)[0][0] cos_ang = np.cos(np.deg2rad(rot_angle)) sin_ang = np.sin(np.deg2rad(rot_angle)) rot_matrix = np.matrix(np.array([[cos_ang, sin_ang], [-sin_ang, cos_ang]])) #--> write model xyz file lines = [] for kk, zz in enumerate(mod_obj.grid_z[0:z_pad]): for jj, yy in enumerate(mod_obj.grid_east[east_pad:-east_pad]): for ii, xx in enumerate(mod_obj.grid_north[north_pad:-north_pad]):
import mtpy.utils.latlongutmconversion as utm2ll from matplotlib.colorbar import * from matplotlib.patches import Ellipse import pickle #============================================================================== #============================================================================== # Inputs #============================================================================== plot_type = 'pseudo' #map of pseudo for map or pseudo section diff_yn = 'y' line_dir = 'ew' borehole_loc = (139.72851, -30.2128) bhz, bhe, bhn = utm2ll.LLtoUTM(23, borehole_loc[1], borehole_loc[0]) #============================================================================== # a few constants #============================================================================== refe = 23 #phase tensor map ptcmapdict = { 'red': ((0.0, 1.0, 1.0), (1.0, 1.0, 1.0)), 'green': ((0.0, 0.0, 1.0), (1.0, 0.0, 1.0)), 'blue': ((0.0, 0.0, 0.0), (1.0, 0.0, 0.0)) } ptcmap = LinearSegmentedColormap('ptcmap', ptcmapdict, 256) #phase tensor map for difference (reverse)
### --> gps Source locations # Newman 2009 feng_09 = {"lat": 37.678, "lon": -118.930, "depth": 6.0, "name": "Feng_2009"} # Langbein 1995 lb_95_01 = {"lat": 37.6869, "lon": -118.9150, "depth": 5.5, "name": "langbein_1995"} lb_95_02 = {"lat": 37.6325, "lon": -118.9353, "depth": 13, "name": "langbein_1995"} battaglia_03 = {"lat": 37.67856, "lon": -119.0164, "depth": 6, "name": "battaglia_2003"} mb_15 = {"lat": 37.67852, "lon": -118.914, "depth": 7, "name": "montgomery_brown_2015"} df = pd.DataFrame() line_list = [] for gps_dict in [feng_09, lb_95_01, lb_95_02, battaglia_03, mb_15]: zone, east, north = utm2ll.LLtoUTM(23, gps_dict["lat"], gps_dict["lon"]) gps_east = (east - east_0) / 1000.0 gps_north = (north - north_0) / 1000.0 gps_dict["model_east"] = gps_east gps_dict["model_north"] = gps_north line = "{0} center: {1:.2f} E, {2:.2f} N, Depth {3:.1f}".format( gps_dict["name"], gps_east, gps_north, gps_dict["depth"] ) if len(line_list) == 0: line_list.append(",".join([key for key in sorted(gps_dict.keys())])) line_str = ["{0}".format(gps_dict[key]) for key in sorted(gps_dict.keys())] line_list.append(",".join(line_str)) print(line)
### --> gps Source locations # Newman 2009 feng_09 = {'lat':37.678, 'lon':-118.930, 'depth': 6.0, 'name':'Feng_2009'} # Langbein 1995 lb_95_01 = {'lat':37.6869, 'lon':-118.9150, 'depth':5.5, 'name':'langbein_1995'} lb_95_02 = {'lat':37.6325, 'lon':-118.9353, 'depth':13, 'name':'langbein_1995'} battaglia_03 = {'lat':37.67856, 'lon':-119.0164, 'depth':6, 'name':'battaglia_2003'} mb_15 = {'lat':37.67852, 'lon':-118.914, 'depth':7, 'name':'montgomery_brown_2015'} df = pd.DataFrame() line_list = [] for gps_dict in [feng_09, lb_95_01, lb_95_02, battaglia_03, mb_15]: zone, east, north = utm2ll.LLtoUTM(23, gps_dict['lat'], gps_dict['lon']) gps_east = (east-east_0)/1000. gps_north = (north-north_0)/1000. gps_dict['model_east'] = gps_east gps_dict['model_north'] = gps_north line = '{0} center: {1:.2f} E, {2:.2f} N, Depth {3:.1f}'.format(gps_dict['name'], gps_east, gps_north, gps_dict['depth']) if len(line_list) == 0: line_list.append(','.join([key for key in sorted(gps_dict.keys())])) line_str = ['{0}'.format(gps_dict[key]) for key in sorted(gps_dict.keys())] line_list.append(','.join(line_str)) print(line)
""" Created on Thu Mar 20 17:28:04 2014 @author: jpeacock """ import os from evtk.hl import pointsToVTK import numpy as np import mtpy.utils.latlongutmconversion as utm2ll sfn = r"/mnt/hgfs/jpeacock/Documents/MountainPass/Maps/MountainPass_GIS/southern_california_earthquake_locations_crop.txt" mc_lat = 35.464 mc_lon = -115.472 zone, east_0, north_0 = utm2ll.LLtoUTM(23, mc_lat, mc_lon) s_array = np.loadtxt(sfn, delimiter=',', dtype=[('year', np.float), ('month', np.float), ('day', np.float), ('hour', np.float), ('minute', np.float), ('second', np.float), ('lat', np.float), ('lon', np.float), ('depth', np.float), ('mag', np.float)], skiprows=1) east = np.zeros(s_array.shape[0]) north = np.zeros(s_array.shape[0]) for ii, ss in enumerate(s_array): zz, ee, nn = utm2ll.LLtoUTM(23, ss['lat'], ss['lon'])
s_array = np.loadtxt(sfn, delimiter=',', dtype = [('year', np.float), ('month', np.float), ('day', np.float), ('lat', np.float), ('lon', np.float), ('depth', np.float), ('mag', np.float)], skiprows=1) east = np.zeros(s_array.shape[0]) north = np.zeros(s_array.shape[0]) for ii, ss in enumerate(s_array): zz, ee, nn = utm2ll.LLtoUTM(23, ss['lat'], ss['lon']) east[ii] = (ee-east_0)/1000. north[ii] = (nn-north_0)/1000. x = north.copy() y = east.copy() z = s_array['depth'].copy() mag = s_array['mag'].copy() for xx, yy, zz, mm in zip(x, y, z, mag): print 'N={0:.2f}, E={1:.2f}, Z={2:.2f}, M={3:.2f}'.format(xx, yy, zz, mm) pointsToVTK(r"/home/jpeacock/Documents/mb_LP_locations", x, y, z, data={'mag':mag, 'depth':z})
@author: jpeacock-pr """ import os import numpy as np import mtpy.core.edi as mtedi import mtpy.core.z as mtz import mtpy.utils.latlongutmconversion as utmll data_file = r"C:\Users\jpeacock-pr\Documents\MonoBasin\LV_Wannamaker\LVMTdat.txt" loc_file = r"c:\Users\jpeacock-pr\Documents\MonoBasin\LV_Wannamaker\LV-LOC.txt" well_loc = (-118.908611, 37.679722) save_path = r"c:\Users\jpeacock-pr\Documents\MonoBasin\LV_Wannamaker" well_zone, well_east, well_north = utmll.LLtoUTM(23, well_loc[1], well_loc[0]) dipole_len = 100 #============================================================================== # read location file #============================================================================== loc_fid = file(loc_file, 'r') loc_lines = loc_fid.readlines() ns = int(loc_lines[0].strip()) locations = np.zeros(ns, dtype=[('name', '|S10'), ('lat', np.float), ('lon', np.float)]) loc_dict = {} for ii, line in enumerate(loc_lines[1:ns + 1]):
for ii in range(1, int(ny) + 2): dline = dfid.readline() if len(str(dline)) > 1: # needs to be backwards because first line is the furthest north row. elevation[:, -ii] = np.array(dline.strip().split(" "), dtype="float") else: break dfid.close() # create lat and lon arrays from the dem fle lon = np.arange(x0, x0 + cs * (nx), cs) lat = np.arange(y0, y0 + cs * (ny), cs) # calculate the lower left and uper right corners of the grid in meters ll_en = ll2utm.LLtoUTM(23, lat[0], lon[0]) ur_en = ll2utm.LLtoUTM(23, lat[-1], lon[-1]) # estimate cell sizes for each dem measurement d_east = abs(ll_en[1] - ur_en[1]) / nx d_north = abs(ll_en[2] - ur_en[2]) / ny # calculate the number of new cells num_cells = int(cell_size / np.mean([d_east, d_north])) # make easting and northing arrays in meters corresponding to lat and lon east = np.arange(ll_en[1], ur_en[1], d_east) north = np.arange(ll_en[2], ur_en[2], d_north) # resample the data accordingly new_east = east[np.arange(0, east.shape[0], num_cells)]
# model center east_0 = 555703. - 253 north_0 = 5132626.0 + 26 with open(msh_eq_fn, 'r') as fid: lines = fid.readlines() eq_arr = np.zeros(len(lines) - 1, dtype=([('depth', np.float), ('east', np.float), ('north', np.float), ('mag', np.float)])) eq_df = pd.read_csv(msh_eq_fn) for ii in range(eq_df.shape[0]): eq = eq_df.iloc[ii] zone, east, north = utm2ll.LLtoUTM(23, eq.LATITUDE_D, eq.LONGITUDE_) eq_arr[ii]['east'] = (east - east_0) / 1000 eq_arr[ii]['north'] = (north - north_0) / 1000 eq_arr[ii]['depth'] = eq.EARTHQUA_1 eq_arr[ii]['mag'] = eq.EARTHQUA_2 pointsToVTK(msh_eq_fn[:-4], eq_arr['north'], eq_arr['east'], eq_arr['depth'], data={ 'depth': eq_arr['depth'], 'magnitude': eq_arr['mag'] })
model_vel = np.zeros((n_north, n_east, n_z)) model_vel_change = np.zeros((n_north, n_east, n_z)) # lin has west as positive and east as negative for v_arr in vel_arr: e_index = east_index_dict[v_arr["east"] * -1] n_index = north_index_dict[v_arr["north"]] z_index = z_index_dict[v_arr["depth"]] v_avg = vel_arr[np.where(vel_arr[:]["depth"] == v_arr["depth"])]["Vp"].mean() model_vel[n_index, e_index, z_index] = v_arr["Vp"] model_vel_change[n_index, e_index, z_index] = 100 * ((v_arr["Vp"] - v_avg) / v_avg) # find the shift between the center of each grid v_zone, v_east, v_north = ll2utm.LLtoUTM( 23, vel_arr["lat"].mean(), vel_arr["lon"].mean() ) shift_east = (v_east - mt_east) / 1000.0 shift_north = (v_north - mt_north) / 1000.0 # vel.reshape() a2vtk.gridToVTK( os.path.join(os.path.dirname(vp_fn), "lv_3d_models", "lin2015_vp_lvc"), north + shift_north, east + shift_east, z + 2, cellData={"Vp": model_vel, "Vp_change": model_vel_change}, ) # a2vtk.gridToVTK(os.path.join(os.path.dirname(vp_fn), 'lin2015_vp_change'), # north+shift_north, east+shift_east, z,
""" Created on Thu Mar 20 17:28:04 2014 @author: jpeacock """ import os from evtk.hl import pointsToVTK import numpy as np import mtpy.utils.latlongutmconversion as utm2ll sfn = r"/mnt/hgfs/jpeacock/Documents/MountainPass/Maps/MountainPass_GIS/southern_california_earthquake_locations_crop.txt" mc_lat = 35.464 mc_lon = -115.472 zone, east_0, north_0 = utm2ll.LLtoUTM(23, mc_lat, mc_lon) s_array = np.loadtxt( sfn, delimiter=",", dtype=[ ("year", np.float), ("month", np.float), ("day", np.float), ("hour", np.float), ("minute", np.float), ("second", np.float), ("lat", np.float), ("lon", np.float), ("depth", np.float), ("mag", np.float),
("year", np.float), ("month", np.float), ("day", np.float), ("lat", np.float), ("lon", np.float), ("depth", np.float), ("mag", np.float), ], skiprows=1, ) east = np.zeros(s_array.shape[0]) north = np.zeros(s_array.shape[0]) for ii, ss in enumerate(s_array): zz, ee, nn = utm2ll.LLtoUTM(23, ss["lat"], ss["lon"]) east[ii] = (ee - east_0) / 1000.0 north[ii] = (nn - north_0) / 1000.0 x = north.copy() y = east.copy() z = s_array["depth"].copy() mag = s_array["mag"].copy() for xx, yy, zz, mm in zip(x, y, z, mag): print "N={0:.2f}, E={1:.2f}, Z={2:.2f}, M={3:.2f}".format(xx, yy, zz, mm) pointsToVTK( r"/home/jpeacock/Documents/mb_LP_locations", x, y, z, data={"mag": mag, "depth": z}
loc_list = line.replace("w", " ").replace("n", " ").strip().split()[4:] loc_list = [float(jj) for jj in loc_list] eq_arr[ii][loc_header[0]] = loc_list[0] + loc_list[1] / 60.0 eq_arr[ii][loc_header[1]] = loc_list[2] + loc_list[3] / 60.0 eq_arr[ii][loc_header[2]] = loc_list[4] eq_arr[ii][loc_header[3]] = loc_list[5] eq_arr[ii][loc_header[4]] = loc_list[6] eq_arr[ii][loc_header[5]] = loc_list[7] eq_arr[ii][loc_header[6]] = loc_list[8] eq_arr[ii][loc_header[7]] = loc_list[9] eq_arr[ii][loc_header[8]] = loc_list[10] ##-> write vtk files # figure out shift in model centers # mt_zone, mt_east, mt_north = ll2utm.LLtoUTM(23, modem_center[0], modem_center[1]) v_zone, v_east, v_north = ll2utm.LLtoUTM(23, v_lat, v_lon - 0.29) shift_east = (mt_east - v_east + 4000) / 1000.0 shift_north = (mt_north - v_north + 1000) / 1000.0 # vtk_grid_east = np.append(grid_east, grid_east[-1]*1.1)-shift_east # vtk_grid_north = np.append(grid_north, grid_north[-1]*1.1)-shift_north vtk_grid_east = grid_east[1:-1] - shift_east vtk_grid_north = grid_north[1:-1] - shift_north vtk_grid_east = np.append(vtk_grid_east, vtk_grid_east[-1] * 1.1) vtk_grid_north = np.append(vtk_grid_north, vtk_grid_north[-1] * 1.1) vtk_gz = grid_z[2:-1] + 2 # vtk_vp = np.rot90(f_vp, 3) vtk_vp = np.flipud(np.fliplr(np.rot90(f_vp[1:-1, 1:-1, :], 1))) vtk_vs = np.flipud(np.fliplr(np.rot90(f_vs[1:-1, 1:-1, :], 1)))
lines = sfid.readlines() x = np.zeros(len_file) y = np.zeros(len_file) z = np.zeros(len_file) read_line = 0 east_0 = 336800.00 north_0 = 4167510.00 for sline in lines[14:]: slst = sline.strip().split() lat = float(slst[6]) lon = float(slst[7]) depth = float(slst[8]) zone, east, north = utm2ll.LLtoUTM(23, lat, lon) x[read_line] = (east-east_0)/1000. y[read_line] = (north-north_0)/1000. z[read_line] = depth read_line += 1 sfid.close() pointsToVTK(r"c:\Users\jpeacock\Documents\LV\lv_3d_models\shelly_2015_mm_eq_lcv", y, x, z, data={'depth':z})
model_vel = np.zeros((n_north, n_east, n_z)) model_vel_change = np.zeros((n_north, n_east, n_z)) # lin has west as positive and east as negative for v_arr in vel_arr: e_index = east_index_dict[v_arr['east'] * -1] n_index = north_index_dict[v_arr['north']] z_index = z_index_dict[v_arr['depth']] v_avg = vel_arr[np.where( vel_arr[:]['depth'] == v_arr['depth'])]['Vp'].mean() model_vel[n_index, e_index, z_index] = v_arr['Vp'] model_vel_change[n_index, e_index, z_index] = 100 * ((v_arr['Vp'] - v_avg) / v_avg) # find the shift between the center of each grid v_zone, v_east, v_north = ll2utm.LLtoUTM(23, vel_arr['lat'].mean(), vel_arr['lon'].mean()) shift_east = (v_east - mt_east) / 1000. shift_north = (v_north - mt_north) / 1000. #vel.reshape() a2vtk.gridToVTK(os.path.join(os.path.dirname(vp_fn), 'lv_3d_models', 'lin2015_vp_lvc'), north + shift_north, east + shift_east, z + 2, cellData={ 'Vp': model_vel, 'Vp_change': model_vel_change }) #a2vtk.gridToVTK(os.path.join(os.path.dirname(vp_fn), 'lin2015_vp_change'),