os.path.basename(fpath).replace(".h5.npz", ".h5_integrated.refl")) # integrated reflections on this shot (by DIALS) _R_shot_int = flex.reflection_table.from_file(int_refl_path) # strong reflections on this shot _R_shot_strong = Rmaster.select(Rmaster['id'] == i_shot) for _pid in range(len(DET)): xstrong, ystrong = [], [] x0, y0 = [], [] x, y = [], [] # get nanoBragg spot prediction positions rpp = prediction_utils.refls_by_panelname(refls_predict) if _pid in rpp: x, y, _ = map(lambda x: np.array(x) - 0.5, prediction_utils.xyz_from_refl(rpp[_pid])) # get strong spot pos _R_shot_strong_panel = _R_shot_strong.select( _R_shot_strong["panel"] == _pid) if len(_R_shot_strong_panel) > 0: xstrong, ystrong, _ = map( lambda x: np.array(x) - 0.5, prediction_utils.xyz_from_refl(_R_shot_strong_panel)) # get stills process prediction positions _R_panel = _R_shot_int.select(_R_shot_int["panel"] == _pid) if len(_R_panel) > 0: x0, y0, _ = map(lambda x: np.array(x) - 0.5, prediction_utils.xyz_from_refl(_R_panel))
alist_panels = list(panels_with_spots) #alist_panels = list(range(64,72)) panels_with_spots = [i for i in panels_with_spots if i in alist_panels] rois_perpanel = {} panel_keys = {} counts_perpanel = {} refl_ids = {} for ii, pid in enumerate(panels_with_spots): rois_perpanel[ii] = [] refl_ids[ii] = [] counts_perpanel[ii] = np.zeros((sdim, fdim)) panel_keys[pid] = ii centroid_x, centroid_y, _ = map( lambda x: np.array(x) - 0.5, prediction_utils.xyz_from_refl(exper_refls_strong)) for i_ref, (i, j, pid) in enumerate(zip(centroid_x, centroid_y, panel_ids)): if pid not in alist_panels: continue i1 = int(max(0, i - bb)) i2 = int(min(fdim, i + bb)) j1 = int(max(0, j - bb)) j2 = int(min(sdim, j + bb)) roi = (i1, i2), (j1, j2) ii = panel_keys[pid] rois_perpanel[ii].append(roi) counts_perpanel[ii][j1:j2, i1:i2] += 1 refl_ids[ii].append(i_ref) # <><><><><><><><><>
height=y2 - y1, fc='none', ec='r') plt.gca().add_patch(patch) plt.title("Panel=%d" % pid) # get the ground truth background plane and plot if args.savefigdir is not None: plt.savefig( os.path.join(args.savefigdir, "_figure%d.png" % pid)) plt.draw() plt.pause(args.plot) r_on_panel = Rpp[pid] x, y, _ = prediction_utils.xyz_from_refl(r_on_panel) x = np.array(x) - 0.5 y = np.array(y) - 0.5 Hi_on_panel = np.array(Hi)[np.array(bbox_panel_ids) == pid] for i_spot, (x1, x2, y1, y2) in enumerate(bb_on_panel): inX = np.logical_and(x1 < x, x < x2) inY = np.logical_and(y1 < y, y < y2) in_bb = inX & inY if not any(in_bb): continue pos = np.where(in_bb)[0] for p in pos: h_pred_nb = Hi_on_panel[i_spot] h_pred_stills = r_on_panel[p]["miller_index"]
panels_with_spots = set(panel_ids) alist_panels = list(panels_with_spots) # alist_panels = list(range(64,72)) panels_with_spots = [i for i in panels_with_spots if i in alist_panels] rois_perpanel = {} panel_keys = {} counts_perpanel = {} refl_ids = {} for ii, pid in enumerate(panels_with_spots): rois_perpanel[ii] = [] refl_ids[ii] = [] counts_perpanel[ii] = np.zeros((sdim, fdim)) panel_keys[pid] = ii centroid_x, centroid_y, _ = map(lambda x: np.array(x)-0.5, prediction_utils.xyz_from_refl(exper_refls_strong)) for i_ref, (i,j, pid) in enumerate(zip(centroid_x, centroid_y, panel_ids)): if pid not in alist_panels: continue i1 = int(max(0, i-bb)) i2 = int(min(fdim, i+bb)) j1 = int(max(0, j-bb)) j2 = int(min(sdim, j+bb)) roi = (i1, i2), (j1, j2) ii = panel_keys[pid] rois_perpanel[ii].append(roi) counts_perpanel[ii][j1:j2, i1:i2] += 1 refl_ids[ii].append(i_ref) # <><><><><><><><><> # DO THE SIMULATION