def test_slice(self): print('TestTrainData: skim') a = self.createSimpleArray('int32', 600) b = self.createSimpleArray('float32', 600) d = self.createSimpleArray('float32', 600) a_slice = a.getSlice(2, 3) b_slice = b.getSlice(2, 3) d_slice = d.getSlice(2, 3) td = TrainData() td._store([a, b], [d], []) td_slice = td.getSlice(2, 3) fl = td_slice.transferFeatureListToNumpy(False) tl = td_slice.transferTruthListToNumpy(False) a_tdslice = SimpleArray(fl[0], fl[1]) b_tdslice = SimpleArray(fl[2], fl[3]) d_tdslice = SimpleArray(tl[0], tl[1]) self.assertEqual(a_slice, a_tdslice) self.assertEqual(b_slice, b_tdslice) self.assertEqual(d_slice, d_tdslice) #test skim td.skim(2) fl = td.transferFeatureListToNumpy(False) tl = td.transferTruthListToNumpy(False) a_tdslice = SimpleArray(fl[0], fl[1]) b_tdslice = SimpleArray(fl[2], fl[3]) d_tdslice = SimpleArray(tl[0], tl[1]) self.assertEqual(a_slice, a_tdslice) self.assertEqual(b_slice, b_tdslice) self.assertEqual(d_slice, d_tdslice)
def sub_test_store(self, readWrite): td = TrainData() x,y,w = self.createSimpleArray('int32'), self.createSimpleArray('float32'), self.createSimpleArray('int32') x_orig=x.copy() x2,y2,_ = self.createSimpleArray('float32'), self.createSimpleArray('float32'), self.createSimpleArray('int32') x2_orig=x2.copy() y_orig=y.copy() td._store([x,x2], [y,y2], [w]) if readWrite: td.writeToFile("testfile.tdjctd") td = TrainData() td.readFromFile("testfile.tdjctd") os.system('rm -f testfile.tdjctd') shapes = td.getNumpyFeatureShapes() self.assertEqual([[3, 5, 6], [1], [3, 5, 6], [1]], shapes,"shapes") self.assertEqual(2, td.nFeatureArrays()) self.assertEqual(2, td.nTruthArrays()) self.assertEqual(1, td.nWeightArrays()) f = td.transferFeatureListToNumpy(False) t = td.transferTruthListToNumpy(False) w = td.transferWeightListToNumpy(False) xnew = SimpleArray(f[0],np.array(f[1],dtype='int64')) self.assertEqual(x_orig, xnew) xnew = SimpleArray(f[2],np.array(f[3],dtype='int64')) self.assertEqual(x2_orig, xnew) ynew = SimpleArray(t[0],np.array(t[1],dtype='int64')) self.assertEqual(y_orig, ynew)
def test_TrainDataRead(self): print('TestCompatibility TrainData') td = TrainData() td.readFromFile('trainData_previous.djctd') self.assertEqual(td.nFeatureArrays(), 1) arr = np.load("np_arr.npy") rs = np.load("np_rs.npy") b = SimpleArray(arr, rs) a = td.transferFeatureListToNumpy(False) a, rs = a[0], a[1] a = SimpleArray(a, np.array(rs, dtype='int64')) self.assertEqual(a, b)
import matplotlib.patches as patches import math from numba import jit from inference import collect_condensates, make_inference_dict parser = ArgumentParser('make plots') parser.add_argument('inputFile') args = parser.parse_args() #use traindata as data storage td = TrainData() td.readFromFile(args.inputFile) td.x = td.transferFeatureListToNumpy() data = make_inference_dict(td.x[0], td.x[1], td.x[2]) betaselection = collect_condensates(data, 0.1, 0.8) #0.2/2.0 print('betaselection', betaselection.shape) def makeRectangle(size, pos, edgecolor='y'): return patches.Rectangle([pos[0] - size[0] / 2., pos[1] - size[1] / 2.], size[0], size[1], linewidth=1, edgecolor=edgecolor, facecolor='none')
#!/usr/bin/env python import numpy as np from argparse import ArgumentParser import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt parser = ArgumentParser('make plots') parser.add_argument('inputFile') args = parser.parse_args() from DeepJetCore.TrainData import TrainData from tools import make_particle_resolution_plots #just read the stored data td = TrainData() td.readFromFile(args.inputFile) indata = td.transferFeatureListToNumpy() pred, feat, truth = indata[0], indata[1], indata[2] del td print('pred', pred.shape) print('feat', feat.shape) print('truth', truth.shape) make_particle_resolution_plots(feat, pred, truth, outfile="reso.pdf")
from plotting_tools import plotevent import numpy as np parser = ArgumentParser('Make some plots') parser.add_argument('inputFile') args = parser.parse_args() infile = str(args.inputFile) from DeepJetCore.TrainData import TrainData import matplotlib.pyplot as plt td=TrainData() td.readFromFile(infile) feat = td.transferFeatureListToNumpy()[0] truth = td.transferTruthListToNumpy()[0] nevents = min(len(feat),10) for e in range(nevents): print('true energy', truth[e]) print('reco sum ', np.sum(feat[e,:,:,:,0])) fig = plt.figure() ax = fig.gca(projection='3d') ax.set_xlabel("x [idx]") ax.set_zlabel("y [idx]") ax.set_ylabel("z [idx]") ax.grid(False)