Rect_Prism creates a MxNxD matrix, but in this case NxNxN. The way I use the above code is: cube = Rect_Prism(20, 20, 20) # creates a 3d array similar to above example, just bigger Rotated = np.empty((new_depth + 1, new_height + 1, new_width + 1)) New_coords.append((val, new_x, new_y, new_z)) New_y = int(round(x*sin(angle) + y*cos(angle))) New_x = int(round(x*cos(angle) - y*sin(angle))) New_z = int(round(z*cos(angle) - x*sin(angle))) New_x = int(round(z*sin(angle) + x*cos(angle))) New_z = int(round(y*sin(angle) + z*cos(angle))) New_y = int(round(y*cos(angle) - z*sin(angle))) (1600, 1600, -76.322, 30.After some trial and error I came up with some code for my purposes (0 means empty in the array, another number will mean a filled voxel. You can interpolate the two axes independently like: Code def findxy (p1, p2, z): x1, y1, z1 p1 x2, y2, z2 p2 if z2 < z1: return findxy (p2, p1, z) x np.interp (z, (z1, z2), (x1, x2)) y np. Parser.add_argument("filename",help='raster file from which to interpolate a (1/3,1/3) point from from') Parameters left and right are ignored if period is specified. Thank you for the hints in your question. This parameter allows the proper interpolation of angular x-coordinates. version = 0.14.0, it happily works on some 1600x1600 model output. I get the same error as you do with scipy. I think older versions assume irregular grids and don't take advantage of the regular grids. astype(band_array.dtype) to make the output data type the same as the input array. Note that the result will be returned with an apparent higher precision than the source data, since it is up-classed to NumPy's dtype('float64') data type. # Use the differences to weigh the four raster values It performs 'natural neighbor interpolation' of irregularly spaced data a regular grid, which you can then plot with contour, imshow or pcolor. As of version 0.98.3, matplotlib provides a griddata function that behaves similarly to the matlab version. # Calculate differences from point to bounding raster midpoints The answer is, first you interpolate it to a regular grid. It may have one or more negative-space holes which are also bounded by linear rings. A polygon is a two-dimensional feature and has a non-zero area. # Test array bounds to ensure point is within raster midpoints The formula to interpolate between x1 and x2 is (1 - t) x1 + t x2 where t ranges from 0 to 1. A geometry type representing an area that is enclosed by a linear ring. # Special case where point is on upper bounds # Calculate raster lower bound indices from point I've translated the formula below (from Wikipedia) into Python-speak to yield the following algorithm, which appears to work. but I much prefer bilinear interpolation methods) (Note: the nearest neighbor interpolation algorithm is easy cake: from numpy import argmin, NANĭef nearest_neighbor(px, py, no_data=NAN): Has anyone come across a good bilinear interpolation algorithm, preferably in Python, possibly tailored with NumPy? Any hints or advice? I don't see why I should have a memory error, since my raster is 317×301, and the bilinear algorithm should not be difficult. I'll admit, I have limited confidence in this SciPy function, as the bounds_error or fill_value parameters don't work as documented. Self.tck = fitpack.bisplrep(self.x, self.y, self.z, kx=kx, ky=ky, s=0.)įile "C:\Python25\Lib\site-packages\scipy\interpolate\fitpack.py", line 873, in bisplrep Its a valid approach except to minimize overhead you should be resolving the record to a cell rather than generating a point start with a numpy array the size of your raster, with origin and cell size, read each LAS record and calculate the cell it falls on, test that index in your array and populate or overwrite then when youre all done read. However I get a memory error on my 32-bit Windows system with a 317×301 raster: Traceback (most recent call last):įile "C:\Python25\Lib\site-packages\scipy\interpolate\interpolate.py", line 125, in _init_ I have created the python code but its taking only one Z field for. Up to now, I've tried SciPy's interp2d function: from scipy import interpolateīilinterp = interpolate.interp2d(ax, ay, band_array, kind='linear') Spatial interpolation is used to predicts values for cells in a raster from a. Nx, ny = source.RasterXSize, source.RasterYSizeīand_array = source.GetRasterBand(1).ReadAsArray()Īx = array( + ix*gt + gt/2.0 for ix in range(nx)])Īy = array( + iy*gt + gt/2.0 for iy in range(ny)]) import numpy as np from scipy.interpolate import griddata import matplotlib.pyplot as plt import numpy.ma as ma from numpy. Here is where I'm at: from osgeo import gdal I have a raster that I'd like to do some point interpolations with.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |