def testHighRes(self): grid = DataGrid((GRIDSIZE, GRIDSIZE, GRIDSIZE), np.identity(4)) plane = OrthoSlice(grid, YAXIS, SLICEPOS) data = np.random.rand(GRIDSIZE * 2, GRIDSIZE * 2, GRIDSIZE * 2) datagrid = DataGrid((GRIDSIZE * 2, GRIDSIZE * 2, GRIDSIZE * 2), np.identity(4) / 2) qpd = NumpyData(data, name="test", grid=datagrid) qpd.slice_data(plane)
def get_summary_stats(self, data, roi=None, hist_bins=20, hist_range=None, slice_loc=None): """ Get summary statistics :param data: QpData instance for the data to get stats from :param roi: Restrict data to within this roi :return: Sequence of summary stats dictionary, roi labels """ # Checks if either ROI or data is None if roi is not None: roi = roi.resample(data.grid) else: roi = NumpyData(np.ones(data.grid.shape[:3]), data.grid, "temp", roi=True) if data is None: stat1 = { 'mean': [0], 'median': [0], 'std': [0], 'max': [0], 'min': [0] } return stat1, list(roi.regions.keys()), np.array([0, 0]), np.array( [0, 1]) stat1 = {'mean': [], 'median': [], 'std': [], 'max': [], 'min': []} hist1 = [] hist1x = [] if slice_loc is None: data_arr = data.raw() roi_arr = roi.raw() else: data_arr, _, _, _ = data.slice_data(slice_loc) roi_arr, _, _, _ = roi.slice_data(slice_loc) regions = [] for region, name in roi.regions.items(): # get data for a single label of the roi in_roi = data_arr[roi_arr == region] if in_roi.size > 0: mean, med, std = np.mean(in_roi), np.median(in_roi), np.std( in_roi) mx, mn = np.max(in_roi), np.min(in_roi) else: mean, med, std, mx, mn = 0, 0, 0, 0, 0 stat1['mean'].append(mean) stat1['median'].append(med) stat1['std'].append(std) stat1['max'].append(mx) stat1['min'].append(mn) regions.append(name) y, x = np.histogram(in_roi, bins=hist_bins, range=hist_range) hist1.append(y) hist1x.append(x) return stat1, regions, hist1, hist1x