) ang_width = np.empty((len(threshold), nb_dir)) for idx, thres in enumerate(threshold): # apply the threshold tmp_obj = np.copy(obj) tmp_obj[tmp_obj < thres] = 0 if ndim == 3: # project the object tmp_obj = tmp_obj.sum(axis=sum_axis) tmp_obj = abs(tmp_obj) / abs( tmp_obj).max() # normalize the modulus to 1 for idy, direction in enumerate(directions): # get the distances and the modulus values along the linecut distance, cut = util.linecut(array=tmp_obj, point=origin, direction=direction, voxel_size=voxel_size) # get the indices where the linecut is non_zero indices = np.nonzero(cut) # get the width along the cut for that threshold ang_width[idx, idy] = distance[max(indices[0])] - distance[min( indices[0])] # store the result in the dictionary result["ang_width_threshold"] = ang_width ################################################### # 2D case (SEM): one can create the linecut for # # each direction first and apply thresholds later # ################################################### else:
else: gu.multislices_plot(array=obj, sum_frames=False, plot_colorbar=True, reciprocal_space=False, is_orthogonal=True, slice_position=(25, 37, 25)) ##################################### # create the linecut for each point # ##################################### result = dict() for point in points: # get the distances and the modulus values along the linecut distance, cut = util.linecut(array=obj, point=point, direction=direction, voxel_size=voxel_size) # store the result in a dictionary (cuts can have different lengths depending on the direction) result[f'voxel {point}'] = {'distance': distance, 'cut': cut} ###################### # plot the linecuts # ###################### fig = plt.figure(figsize=fig_size) ax = plt.subplot(111) plot_nb = 0 for key, value in result.items(): # value is a dictionary {'distance': 1D array, 'cut': 1D array} line, = ax.plot(value['distance'], value['cut'], color=colors[plot_nb % len(colors)],
slice_position=psf_cen) fig.savefig(savedir + f'psf_slices_{rl_iterations}' + comment + '.png') fig, ax = plt.subplots(figsize=(12, 9)) ax.plot(error, 'r.') ax.set_yscale('log') ax.set_xlabel('iteration number') ax.set_ylabel('difference between consecutive iterates') fig.savefig(savedir + f'error_metric_{rl_iterations}' + comment + '.png') ####################################################################################### # calculate linecuts of the blurring function through its center of mass and fit them # ####################################################################################### # create linecuts in the three orthogonal directions width_z, cut_z = util.linecut(array=psf_partial_coh, point=psf_cen, direction=(1, 0, 0), voxel_size=voxel_size) width_y, cut_y = util.linecut(array=psf_partial_coh, point=psf_cen, direction=(0, 1, 0), voxel_size=voxel_size) width_x, cut_x = util.linecut(array=psf_partial_coh, point=psf_cen, direction=(0, 0, 1), voxel_size=voxel_size) linecuts_dict = OrderedDict([('width_z', width_z), ('width_y', width_y), ('width_x', width_x), ('cut_z', cut_z), ('cut_y', cut_y), ('cut_x', cut_x)]) # define the maximum identical length that can share the linecuts (we need to concatenate them) width_length = min(width_z.size, width_y.size, width_x.size)