def test_project_points_ll2utm(self): easting, northing, zone = project_points_ll2utm( np.ones(5) * self.lat, np.ones(5) * self.lon) print((zone, easting, northing)) self.assertTrue(zone == self.zone) self.assertTrue( np.sum(np.isclose(easting, np.ones(5) * self.easting)) == 5) self.assertTrue( np.sum(np.isclose(northing, np.ones(5) * self.northing)) == 5)
# -*- coding: utf-8 -*- """ Created on Wed Jul 3 11:10:43 2019 @author: jpeacock """ import pandas as pd from mtpy.utils import gis_tools from pyevtk.hl import pointsToVTK import numpy as np fn = r"c:\Users\jpeacock\OneDrive - DOI\Geysers\Top_Felsite_Points_WGS84.csv" model_center = (38.831979, -122.828190) model_east, model_north, zone = gis_tools.project_point_ll2utm( model_center[0], model_center[1] ) df = pd.read_csv( fn, delimiter=",", usecols=[0, 1, 2], names=["lat", "lon", "depth"], skiprows=1 ) east, north, zone = gis_tools.project_points_ll2utm(df.lat, df.lon) x = (east - model_east) / 1000.0 y = (north - model_north) / 1000.0 z = (df.depth.to_numpy() / 3.25) / 1000.0 pointsToVTK(fn[:-4], y, x, z, {"depth": z})
dfn = r"c:\Users\jpeacock\Documents\MountainPass\modem_inv\inv_07\mp_modem_data_z03_topo_edit.dat" if dfn is not None: d_obj = modem.Data() d_obj.read_data_file(dfn) # ============================================================================= # Load in file # ============================================================================= a = np.loadtxt(fn, skiprows=3, dtype=np.float, delimiter=None).T ### compute the lower left hand corner of the raster lower_left = gis_tools.project_point_utm2ll(a[1].min(), a[0].min(), utm_zone) lower_left = (a[1].min(), a[0].min()) east, north, zone = gis_tools.project_points_ll2utm(a[1], a[0], datum='NAD27') ### make equally spaced points on regular grid x_new = np.linspace(east.min(), east.max(), num=(east.max() - east.min()) / d) y_new = np.linspace(north.min(), north.max(), num=(north.max() - north.min()) / d) xg, yg = np.meshgrid(x_new, y_new) ### interpolate the data onto a regular grid basement = interpolate.griddata((east, north), -1 * a[2], (xg, yg), method='cubic') ### make raster
model_center = (38.831979, -122.828190) model_east, model_north, zone = gis_tools.project_point_ll2utm(38.831979, -122.828190, epsg=32610) df = pd.read_csv( fn, names=["lat", "lon", "elev"], usecols=[0, 1, 2], skiprows=1, dtype={ "lat": np.float, "lon": np.float, "elev": np.float }, ) east, north, zone = gis_tools.project_points_ll2utm(df.lat.to_numpy(), df.lon.to_numpy(), epsg=32610) y = (east - model_east) / 1000 x = (north - model_north) / 1000 z = (df.elev.to_numpy() * 0.3048) / 1000 pointsToVTK(fn[:-4], x, y, z, {"depth": z}) df_new = pd.DataFrame({"northing": x, "easting": y, "depth": z}) df_new.to_csv(fn[:-4] + "_mc.csv", index=False)
def interpolate_elevation_to_grid(grid_east, grid_north, epsg=None, utm_zone=None, surfacefile=None, surface=None, method='linear', fast=True): """ project a surface to the model grid and add resulting elevation data to a dictionary called surface_dict. Assumes the surface is in lat/long coordinates (wgs84) The 'fast' method extracts a subset of the elevation data that falls within the mesh-bounds and interpolates them onto mesh nodes. This approach significantly speeds up (~ x5) the interpolation procedure. **returns** nothing returned, but surface data are added to surface_dict under the key given by surfacename. **inputs** choose to provide either surface_file (path to file) or surface (tuple). If both are provided then surface tuple takes priority. surface elevations are positive up, and relative to sea level. surface file format is: ncols 3601 nrows 3601 xllcorner -119.00013888889 (longitude of lower left) yllcorner 36.999861111111 (latitude of lower left) cellsize 0.00027777777777778 NODATA_value -9999 elevation data W --> E N | V S Alternatively, provide a tuple with: (lon,lat,elevation) where elevation is a 2D array (shape (ny,nx)) containing elevation points (order S -> N, W -> E) and lon, lat are either 1D arrays containing list of longitudes and latitudes (in the case of a regular grid) or 2D arrays with same shape as elevation array containing longitude and latitude of each point. other inputs: surfacename = name of surface for putting into dictionary surface_epsg = epsg number of input surface, default is 4326 for lat/lon(wgs84) method = interpolation method. Default is 'nearest', if model grid is dense compared to surface points then choose 'linear' or 'cubic' """ # read the surface data in from ascii if surface not provided if surface is None: surface = mtfh.read_surface_ascii(surfacefile) x, y, elev = surface # if lat/lon provided as a 1D list, convert to a 2d grid of points if len(x.shape) == 1: x, y = np.meshgrid(x, y) if len(grid_east.shape) == 1: grid_east, grid_north = np.meshgrid(grid_east, grid_north) if (fast): buffer = 1 # use a buffer of 1 degree around mesh-bounds mlatmin, mlonmin = gis_tools.project_point_utm2ll(grid_east.min(), grid_north.min(), epsg=epsg, utm_zone=utm_zone) mlatmax, mlonmax = gis_tools.project_point_utm2ll(grid_east.max(), grid_north.max(), epsg=epsg, utm_zone=utm_zone) subsetIndices = (x >= mlonmin-buffer) & \ (x <= mlonmax+buffer) & \ (y >= mlatmin-buffer) & \ (y <= mlatmax+buffer) x = x[subsetIndices] y = y[subsetIndices] elev = elev[subsetIndices] # end if xs, ys, utm_zone = gis_tools.project_points_ll2utm(y, x, epsg=epsg, utm_zone=utm_zone) # elevation in model grid # first, get lat,lon points of surface grid points = np.vstack([arr.flatten() for arr in [xs, ys]]).T # corresponding surface elevation points values = elev.flatten() # xi, the model grid points to interpolate to xi = np.vstack([arr.flatten() for arr in [grid_east, grid_north]]).T # elevation on the centre of the grid nodes elev_mg = spi.griddata(points, values, xi, method=method).reshape(grid_north.shape) return elev_mg