dQ = np.abs(ICCFT.getDQFracHKL(UBMatrix, frac=0.5)) dQ[0,:] = 0.05088 dQ[dQ>0.2]=0.2 nX = 32; nY = 32; nZ = 32 #qMask = pickle.load(open('/data/ml_peak_sets/peaks_tf_mltoolstest_limitedNoise_0p025_cutoff_0p5MaxNoise/qMask.pkl', 'rb')) qMask = pickle.load(open(baseDirectory+'qMask.pkl', 'rb')) cX, cY, cZ = np.array(qMask.shape)//2 dX, dY, dZ = nX//2, nY//2, nZ//2 qMaskSimulated = qMask[cX-dX:cX+dX, cY-dY:cY+dY, cZ-dZ:cZ+dZ] peak = peaks_ws.getPeak(peakToGet) MDdata = mltools.getMDData(peak, nxsTemplate, DetCalFile, None, q_frame) box = ICCFT.getBoxFracHKL(peak, peaks_ws, MDdata, UBMatrix, peakToGet, dQ, fracHKL=0.5, dQPixel=dQPixel, q_frame=q_frame); n_events_cropped, image = mltools.getImageFromBox(box, UBMatrix, peak, rebinToHKL=trainedOnHKL, qMaskSimulated=qMaskSimulated) peakMask, testim, blobs = mltools.getPeakMask(image, model, thresh=0.15) mltools.makeShowPredictedPeakFigure(image, peakMask, peakToGet) #Integration countsInPeak = np.sum(n_events_cropped[peakMask]) neigh_length_m = 3 convBox = 1.0*np.ones([neigh_length_m, neigh_length_m,neigh_length_m]) / neigh_length_m**3 conv_n_events_cropped = convolve(n_events_cropped,convBox) if not trainedOnHKL: bgIDX = reduce(np.logical_and, [~peakMask, qMaskSimulated, conv_n_events_cropped > 0]) else: bgIDX = np.logical_and(~peakMask, conv_n_events_cropped > 0) meanBG = n_events_cropped[bgIDX].mean() bgCountsInPeak = meanBG*np.sum(peakMask) intensity = countsInPeak - meanBG*np.sum(peakMask)
edgeConvBox = np.ones([3, 3, 3]) newMask = convolve(~np.isfinite(norm), edgeConvBox).copy() normData[newMask] = 0. mtd['dataMD'].setSignalArray(data) mtd['dataMD'].setErrorSquaredArray(errorsq) mtd['result'].setSignalArray(normData) normErrorSq = 1. * errorsq / norm / norm normErrorSq[newMask] = 0. mtd['result'].setErrorSquaredArray(normErrorSq) box = mtd['dataMD'] n_events_cropped, n_errorsq_cropped, image = mltools.getImageFromBox( box, UBMatrix, peak, rebinToHKL=trainedOnHKL, qMaskSimulated=qMaskSimulated, returnErrorSq=True) peakMask, testim, blobs = mltools.getPeakMask(image, model, thresh=thresh) box = mtd['result'] n_events_cropped, n_errorsq_cropped, image2 = mltools.getImageFromBox( box, UBMatrix, peak, rebinToHKL=trainedOnHKL, qMaskSimulated=qMaskSimulated, returnErrorSq=True)