def _make_plot(self, counter, feat, predicted, truth): try: td = TrainData_NanoML() #contains all dicts truths = td.createTruthDict(feat) feats = td.createFeatureDict(feat, addxycomb=False) data = {} data.update(truths) data.update(feats) data['recHitLogEnergy'] = np.log(data['recHitEnergy'] + 1) coords = predicted[self.use_prediction_idx] if not coords.shape[-1] == 3: print( "plotGravNetCoordsDuringTraining only supports 3D coordinates" ) #2D and >3D TBI return #not supported data['coord A'] = coords[:, 0:1] data['coord B'] = coords[:, 1:2] data['coord C'] = coords[:, 2:3] df = pd.DataFrame(np.concatenate([data[k] for k in data], axis=1), columns=[k for k in data]) shuffle_truth_colors(df) fig = px.scatter_3d( df, x="coord A", y="coord B", z="coord C", color="truthHitAssignementIdx", size="recHitLogEnergy", symbol="recHitID", #hover_data=[], template='plotly_dark', color_continuous_scale=px.colors.sequential.Rainbow) fig.update_traces(marker=dict(line=dict(width=0))) ccfile = self.outputfile + str( self.keep_counter) + "_coords_" + str( self.use_prediction_idx) + ".html" fig.write_html(ccfile) if self.publish is not None: publish(ccfile, self.publish) except Exception as e: print(e) raise e
def _make_plot(self, counter, feat, predicted, truth): #all these are lists and also include row splits try: td = TrainData_NanoML() #contains all dicts #row splits not needed feats = td.createFeatureDict(feat, addxycomb=False) backgather = predicted[self.use_backgather_idx] truths = td.createTruthDict(feat) data = {} data.update(feats) data.update(truths) if len(backgather.shape) < 2: backgather = np.expand_dims(backgather, axis=1) data['recHitLogEnergy'] = np.log(data['recHitEnergy'] + 1) data['hitBackGatherIdx'] = backgather from globals import cluster_space as cs removednoise = np.logical_and(data["recHitX"] == cs.noise_coord, data["recHitY"] == cs.noise_coord) removednoise = np.logical_and(data["recHitZ"] == cs.noise_coord, removednoise) #remove removed noise for k in data.keys(): data[k] = data[k][not removednoise] df = pd.DataFrame(np.concatenate([data[k] for k in data], axis=1), columns=[k for k in data]) shuffle_truth_colors(df) fig = px.scatter_3d( df, x="recHitX", y="recHitZ", z="recHitY", color="truthHitAssignementIdx", size="recHitLogEnergy", symbol="recHitID", #template='plotly_dark', color_continuous_scale=px.colors.sequential.Rainbow) fig.update_traces(marker=dict(line=dict(width=0))) fig.write_html(self.outputfile + str(self.keep_counter) + "_truth.html") bgfile = self.outputfile + str( self.keep_counter) + "_backgather.html" #now the cluster indices shuffle_truth_colors(df, "hitBackGatherIdx") fig = px.scatter_3d( df, x="recHitX", y="recHitZ", z="recHitY", color="hitBackGatherIdx", size="recHitLogEnergy", #template='plotly_dark', color_continuous_scale=px.colors.sequential.Rainbow) fig.update_traces(marker=dict(line=dict(width=0))) fig.write_html(bgfile) if self.publish is not None: publish(bgfile, self.publish) except Exception as e: print(e) raise e
def _make_plot(self, counter, feat, predicted, truth): try: ''' [pred_beta, pred_ccoords, pred_energy, pred_pos, pred_time, pred_id ''' td = TrainData_NanoML() #contains all dicts #row splits not needed feats = td.createFeatureDict(feat, addxycomb=False) truths = td.createTruthDict(feat) predBeta = predicted['pred_beta'] print('>>>> plotting cluster coordinates... average beta', np.mean(predBeta), ' lowest beta ', np.min(predBeta), 'highest beta', np.max(predBeta)) #for later predEnergy = predicted['pred_energy_corr_factor'] predX = predicted['pred_pos'][:, 0:1] predY = predicted['pred_pos'][:, 1:2] predT = predicted['pred_time'] predD = predicted['pred_dist'] data = {} data.update(feats) data.update(truths) predCCoords = predicted['pred_ccoords'] data['recHitLogEnergy'] = np.log(data['recHitEnergy'] + 1) data['predBeta'] = predBeta data[ 'predBeta+0.05'] = predBeta + 0.05 #so that the others don't disappear data['predEnergy'] = predEnergy data['predX'] = predX data['predY'] = predY data['predT'] = predT data['predD'] = predD data['(predBeta+0.05)**2'] = data['predBeta+0.05']**2 data['(thresh(predBeta)+0.05))**2'] = np.where( predBeta > self.beta_threshold, data['(predBeta+0.05)**2'], 0.) if not predCCoords.shape[-1] == 3: self.projection_plot(data, predCCoords) return data['predCCoordsX'] = predCCoords[:, 0:1] data['predCCoordsY'] = predCCoords[:, 1:2] data['predCCoordsZ'] = predCCoords[:, 2:3] from globals import cluster_space as cs removednoise = np.logical_and( data["predCCoordsX"] == cs.noise_coord, data["predCCoordsY"] == cs.noise_coord) removednoise = np.logical_and( data["predCCoordsZ"] == cs.noise_coord, removednoise) removednoise = np.where(removednoise[:, 0], False, True) #remove removed noise for k in data.keys(): data[k] = data[k][removednoise] df = pd.DataFrame(np.concatenate([data[k] for k in data], axis=1), columns=[k for k in data]) #fig = px.scatter_3d(df, x="recHitX", y="recHitZ", z="recHitY", color="truthHitAssignementIdx", size="recHitLogEnergy") #fig.write_html(self.outputfile + str(self.keep_counter) + "_truth.html") shuffle_truth_colors(df) #now the cluster indices hover_data = [ 'predBeta', 'predD', 'predEnergy', 'truthHitAssignedEnergies', 'predT', 'truthHitAssignedT', 'predX', 'truthHitAssignedX', 'predY', 'truthHitAssignedY', 'truthHitAssignementIdx' ] fig = px.scatter_3d( df, x="predCCoordsX", y="predCCoordsY", z="predCCoordsZ", color="truthHitAssignementIdx", size="recHitLogEnergy", symbol="recHitID", hover_data=hover_data, template='plotly_dark', color_continuous_scale=px.colors.sequential.Rainbow) fig.update_traces(marker=dict(line=dict(width=0))) ccfile = self.outputfile + str(self.keep_counter) + "_ccoords.html" fig.write_html(ccfile) if self.publish is not None: publish(ccfile, self.publish) fig = px.scatter_3d( df, x="predCCoordsX", y="predCCoordsY", z="predCCoordsZ", color="truthHitAssignementIdx", size="(predBeta+0.05)**2", hover_data=hover_data, symbol="recHitID", template='plotly_dark', color_continuous_scale=px.colors.sequential.Rainbow) fig.update_traces(marker=dict(line=dict(width=0))) ccfile = self.outputfile + str( self.keep_counter) + "_ccoords_betasize.html" fig.write_html(ccfile) if self.publish is not None: publish(ccfile, self.publish) # thresholded fig = px.scatter_3d( df, x="recHitX", y="recHitZ", z="recHitY", color="truthHitAssignementIdx", size="recHitLogEnergy", symbol="recHitID", hover_data=[ 'predBeta', 'predEnergy', 'predX', 'predY', 'truthHitAssignementIdx', 'truthHitAssignedEnergies', 'truthHitAssignedX', 'truthHitAssignedY' ], template='plotly_dark', color_continuous_scale=px.colors.sequential.Rainbow) fig.update_traces(marker=dict(line=dict(width=0))) ccfile = self.outputfile + str(self.keep_counter) + "_truth.html" fig.write_html(ccfile) if self.publish is not None: publish(ccfile, self.publish) except Exception as e: print(e) raise e