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