hylite.io.pmaps
Store projection maps binding image data to point cloud data during e.g. the correction of pushbroom UAV datasets.
1""" 2Store projection maps binding image data to point cloud data during e.g. the correction of pushbroom UAV datasets. 3""" 4 5import numpy as np 6import os 7 8def savePMap(path, pmap): 9 """ 10 Save a PMap instance using numpy. 11 12 Args: 13 path: the path to save to. 14 pmap: the PMap instance to save. 15 """ 16 pnt,pix,z = pmap.get_flat() 17 dims = np.array([pmap.xdim, pmap.ydim, pmap.npoints]) 18 np.savez_compressed( path, dims=dims, points=pnt, pixels=pix, depths=z ) 19 20def loadPMap(path): 21 """ 22 Load a PMap instance using numpy. 23 24 Args: 25 path: the file path to load from. 26 27 Returns: 28 a PMap instance loaded from the file. 29 """ 30 31 # check extension 32 if not os.path.exists(path): 33 path += ".npz" # try adding npz extension to see if that helps 34 35 assert os.path.exists(path), "Error - file not found: %s" % path 36 37 # load data 38 data = np.load( path ) 39 40 # check attributes 41 if 'dims' not in data: 42 data.close() 43 assert False, "Error - npz does not contain a 'dims' attribute." 44 if 'points' not in data: 45 data.close() 46 assert False, "Error - npz does not contain a 'points' attribute." 47 if 'pixels' not in data: 48 data.close() 49 assert False, "Error - npz does not contain a 'pixels' attribute." 50 if 'depths' not in data: 51 data.close() 52 assert False, "Error - npz does not contain a 'depths' attribute." 53 54 # extract attrubites 55 xdim, ydim, npoints = data[ "dims" ] 56 points = data[ "points" ] 57 pixels = data[ "pixels" ] 58 depths = data[ "depths" ] 59 60 # close file 61 data.close() 62 63 # create new PMap and populate with data 64 from hylite.project import PMap 65 pm = PMap( xdim, ydim, npoints ) 66 pm.set_flat( points, pixels, depths ) 67 return pm
def
savePMap(path, pmap):
9def savePMap(path, pmap): 10 """ 11 Save a PMap instance using numpy. 12 13 Args: 14 path: the path to save to. 15 pmap: the PMap instance to save. 16 """ 17 pnt,pix,z = pmap.get_flat() 18 dims = np.array([pmap.xdim, pmap.ydim, pmap.npoints]) 19 np.savez_compressed( path, dims=dims, points=pnt, pixels=pix, depths=z )
Save a PMap instance using numpy.
Arguments:
- path: the path to save to.
- pmap: the PMap instance to save.
def
loadPMap(path):
21def loadPMap(path): 22 """ 23 Load a PMap instance using numpy. 24 25 Args: 26 path: the file path to load from. 27 28 Returns: 29 a PMap instance loaded from the file. 30 """ 31 32 # check extension 33 if not os.path.exists(path): 34 path += ".npz" # try adding npz extension to see if that helps 35 36 assert os.path.exists(path), "Error - file not found: %s" % path 37 38 # load data 39 data = np.load( path ) 40 41 # check attributes 42 if 'dims' not in data: 43 data.close() 44 assert False, "Error - npz does not contain a 'dims' attribute." 45 if 'points' not in data: 46 data.close() 47 assert False, "Error - npz does not contain a 'points' attribute." 48 if 'pixels' not in data: 49 data.close() 50 assert False, "Error - npz does not contain a 'pixels' attribute." 51 if 'depths' not in data: 52 data.close() 53 assert False, "Error - npz does not contain a 'depths' attribute." 54 55 # extract attrubites 56 xdim, ydim, npoints = data[ "dims" ] 57 points = data[ "points" ] 58 pixels = data[ "pixels" ] 59 depths = data[ "depths" ] 60 61 # close file 62 data.close() 63 64 # create new PMap and populate with data 65 from hylite.project import PMap 66 pm = PMap( xdim, ydim, npoints ) 67 pm.set_flat( points, pixels, depths ) 68 return pm
Load a PMap instance using numpy.
Arguments:
- path: the file path to load from.
Returns:
a PMap instance loaded from the file.