def parse_sparse3d_scn(data): """ A function to retrieve sparse tensor input from larcv::EventSparseTensor3D object Returns the data in format to pass to SCN Args: array of larcv::EventSparseTensor3D Return: voxels - numpy array(int32) with shape (N,3) - coordinates data - numpy array(float32) with shape (N,C) - pixel values/channels """ meta = None output = [] np_voxels = None for event_tensor3d in data: num_point = event_tensor3d.as_vector().size() if meta is None: meta = event_tensor3d.meta() np_voxels = np.empty(shape=(num_point, 3), dtype=np.int32) larcv.fill_3d_voxels(event_tensor3d, np_voxels) else: assert meta == event_tensor3d.meta() np_data = np.empty(shape=(num_point, 1), dtype=np.float32) larcv.fill_3d_pcloud(event_tensor3d, np_data) output.append(np_data) return np_voxels, np.concatenate(output, axis=-1)
def parse_sparse3d(event_tensor3d): """ A function to retrieve sparse tensor from larcv::EventSparseTensor3D object Args: event_tensor3d (larcv::EventSparseTensor3D): larcv C++ object for a 3d sparse tensor object Return: a pair of numpy arrays (coords,value), where coords has shape (N,3) representing 3D pixel coordinate and value (N,1) stores pixel values. """ num_point = event_tensor3d.as_vector().size() np_voxels = np.zeros(shape=(num_point, 3), dtype=np.int32) np_data = np.zeros(shape=(num_point, 1), dtype=np.float32) larcv.fill_3d_voxels(event_tensor3d, np_voxels) larcv.fill_3d_pcloud(event_tensor3d, np_data) return np_voxels, np_data
def parse_sparse3d_scn(data): """ A function to retrieve sparse tensor input from larcv::EventSparseTensor3D object Returns the data in format to pass to SCN Args: length 1 array of larcv::EventSparseTensor3D Return: voxels - numpy array(int32) with shape (N,3) - coordinates data - numpy array(float32) with shape (N,1) - pixel value """ event_tensor3d = data[0] num_point = event_tensor3d.as_vector().size() np_voxels = np.empty(shape=(num_point, 3), dtype=np.int32) np_data = np.empty(shape=(num_point, 1), dtype=np.float32) larcv.fill_3d_voxels(event_tensor3d, np_voxels) larcv.fill_3d_pcloud(event_tensor3d, np_data) return np_voxels, np_data
def parse_sparse3d(data): """ A function to retrieve sparse tensor from larcv::EventSparseTensor3D object Args: array of larcv::EventSparseTensor3D (one per channel) Return: a numpy array with the shape (N,3+C) where 3+C represents (x,y,z) coordinate and C stored pixel values (channels). """ meta = None output = [] for event_tensor3d in data: num_point = event_tensor3d.as_vector().size() if meta is None: meta = event_tensor3d.meta() np_voxels = np.empty(shape=(num_point, 3), dtype=np.int32) larcv.fill_3d_voxels(event_tensor3d, np_voxels) output.append(np_voxels) else: assert meta == event_tensor3d.meta() np_values = np.empty(shape=(num_point, 1), dtype=np.float32) larcv.fill_3d_pcloud(event_tensor3d, np_values) output.append(np_values) return np.concatenate(output, axis=-1)
def process(input_data, output_data): """ input_data and output_data types should be larcv.SparseTensor3D. input_data holds 3D segmentation label values per voxel, (0,1,2,3,4) = (HIP,MIP,Shower,Delta,Michel) output_data should be empty (or will be overwritten) return is None This function will change some voxels of (Delta,Michel) into Shower. Those remain unchanged are the primary ionization trajectories attached to (HIP,MIP) pixels. """ if input_data.as_vector().size() < 1: output_data.set(input_data, input_data.meta()) return #t0=time.time() voxels = np.zeros(shape=[input_data.as_vector().size(), 3], dtype=np.int32) values = np.zeros(shape=[input_data.as_vector().size(), 1], dtype=np.float32) #if debug>0: print('c0', time.time()-t0) #t0=time.time() from larcv import larcv larcv.fill_3d_voxels(input_data, voxels) larcv.fill_3d_pcloud(input_data, values) #if debug>0: print('c1', time.time()-t0) values = values.squeeze(axis=1) #t0=time.time() no_correction = len(np.where(values > 2)[0]) == 0 trivial_correction = len(np.where(values < 3)[0]) == 0 #if debug>0: print('c2', time.time()-t0) # Nothing to correct, return if no_correction: output_data.set(input_data, input_data.meta()) return # Only michel/delta ray, make them all shower if trivial_correction: values[:] = 2. vs = larcv.as_tensor3d(voxels, values, input_data.meta(), -1.) output_data.set(vs, input_data.meta()) return # Reaching here means something to correct. # DBSCAN #t0=time.time() others_idx, others_vox = dbscan(voxels, values, find_valmax=1.) deltas_idx, deltas_vox = dbscan(voxels, values, find_val=3., min_samples=1) michels_idx, michels_vox = dbscan(voxels, values, find_val=4., min_samples=1) #if debug>0: print('c3', time.time()-t0) #t0=time.time() correlated_deltas = correlate(others_vox, deltas_vox) #if debug>0: print('c4', time.time()-t0) #t0=time.time() correlated_michels = correlate(others_vox, michels_vox) #if debug>0: print('c5', time.time()-t0) #t0=time.time() for i, correlation in enumerate(correlated_deltas): if correlation > 0: continue values[deltas_idx[i]] = 2. for i, correlation in enumerate(correlated_michels): if correlation > 0: continue values[michels_idx[i]] = 2. #if debug>0: print('c6', time.time()-t0) vs = larcv.as_tensor3d(voxels, values, input_data.meta(), -1.) output_data.set(vs, input_data.meta()) return