![]() So I defined a function that takes care of this: def fixCoordinates(coord, shape):Īnd if you modify your code slightly, you can use the same strategy as before: # your codeĬoord_rotd = quaternion.rotate_vectors(rotation, coord_rotd)Ĭoord_rotd = fixCoordinates(coord_rotd, mask. ![]() You have to fix your coordinates, because they can be out of your scenery. How would you know (only knowing how the ellipsoid looks), how large the cube is? Just imagine having your ellipsoid at a corner of a huge cube. Because you loose information of what is not filled. If you ask, if you can reconstruct your mask only knowing x, y and z, this is not possible. Next, set each coordinate defined by x, y and z to True: new_mask = np.zeros_like(mask) First, use a new array with the same shape as your mask. You can use directly x, y and z to reconstruct your mask. Rotation = np.exp(quaternion.quaternion(0,0, 1) * angle1*(np.pi/180) / 2)Ĭoord_rotd = quaternion.rotate_vectors(rotation, coord) Now if I rotate my coordinates using quaternion which will give me new set of coordinates and then with new coordinates x1,y1,z1 I want to construct my boolean mask of shape (23,27,39) as that of original mask ? How can that be done ? import quaternion I would like to modify the question above a bit. The above code gives me boolean mask of the shape (23, 27, 39) and now I want to construct the same mask of exactly same shape using x, y, z coordinates. My question is how can I get my mask back (in the form of 3d numpy or boolean array of the same shape) from the coordinates x, y, z ? import numpy as np It's 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 you're all done read. The coordinates can be assigned as x, y, z as in the example code. I have extracted the coordinates of the mask using np.argwhere. Parser.add_argument("filename",help='raster file from which to interpolate a (1/3,1/3) point from from') Thank you for the hints in your question. 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. If x and y represent a regular grid, consider using RectBivariateSpline. This class returns a function whose call method uses spline interpolation to find the value of new points. astype(band_array.dtype) to make the output data type the same as the input array. x, y and z are arrays of values used to approximate some function f: z f (x, y). 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 Extrapolation tips and tricks interp1d : replicate numpy. # Calculate differences from point to bounding raster midpoints # Test array bounds to ensure point is within raster midpoints # 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 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_ Up to now, I've tried SciPy's interp2d function: from scipy import interpolateīilinterp = interpolate.interp2d(ax, ay, band_array, kind='linear') 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)]) 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 |