opengate.tests.utility ====================== .. py:module:: opengate.tests.utility Attributes ---------- .. autoapisummary:: opengate.tests.utility.plt Classes ------- .. autoapisummary:: opengate.tests.utility.RootComparison Functions --------- .. autoapisummary:: opengate.tests.utility.test_ok opengate.tests.utility.read_stat_file opengate.tests.utility.read_stat_file_json opengate.tests.utility.read_stat_file_legacy opengate.tests.utility.print_test opengate.tests.utility.assert_stats opengate.tests.utility.assert_stats_json opengate.tests.utility.plot_img_axis opengate.tests.utility.plot_img_z opengate.tests.utility.plot_img_y opengate.tests.utility.plot_img_x opengate.tests.utility.assert_images_properties opengate.tests.utility.assert_images opengate.tests.utility.plot_hist opengate.tests.utility.plot_profile opengate.tests.utility.assert_filtered_imagesprofile1D opengate.tests.utility.exponential_func opengate.tests.utility.fit_exponential_decay opengate.tests.utility.get_new_key_name opengate.tests.utility.get_keys_correspondence opengate.tests.utility.rel_diff opengate.tests.utility.rel_diff_range opengate.tests.utility.get_branch opengate.tests.utility.compare_branches opengate.tests.utility.compare_branches_values opengate.tests.utility.compare_trees opengate.tests.utility.get_default_test_paths opengate.tests.utility.compare_root2 opengate.tests.utility.compare_root opengate.tests.utility.compare_root3 opengate.tests.utility.compare_root4 opengate.tests.utility.open_root_as_np opengate.tests.utility.dict_compare opengate.tests.utility.write_gauss_param_to_file opengate.tests.utility.get_gauss_param_xy opengate.tests.utility.extract_gauss_param_1D opengate.tests.utility.plot_gauss_fit opengate.tests.utility.create_position_vector opengate.tests.utility.gauss_func opengate.tests.utility.gaussian_fit opengate.tests.utility.read_mhd opengate.tests.utility.plot2D opengate.tests.utility.create_2D_Edep_colorMap opengate.tests.utility.compareGaussParamFromFile opengate.tests.utility.compareGaussParamArrays opengate.tests.utility.test_weights opengate.tests.utility.test_tps_spot_size_positions opengate.tests.utility.scale_dose opengate.tests.utility.check_dose_grid_geometry opengate.tests.utility.arangeDx opengate.tests.utility.interpolate1Dprofile opengate.tests.utility.getRange opengate.tests.utility.get_range_from_image opengate.tests.utility.compareRange opengate.tests.utility.get_1D_profile opengate.tests.utility.compare_dose_at_points opengate.tests.utility.assert_img_sum opengate.tests.utility.assert_images_ratio opengate.tests.utility.assert_images_ratio_per_voxel opengate.tests.utility.check_diff opengate.tests.utility.check_diff_abs opengate.tests.utility.root_compare_param_tree opengate.tests.utility.root_compare_param opengate.tests.utility.root_compare4 opengate.tests.utility.compare_trees4 opengate.tests.utility.get_gpu_mode_for_tests opengate.tests.utility.np_img_window_level opengate.tests.utility.np_img_crop opengate.tests.utility.np_plot_slice opengate.tests.utility.np_plot_slice_h_line opengate.tests.utility.np_plot_slice_v_line opengate.tests.utility.add_colorbar opengate.tests.utility.np_plot_integrated_profile opengate.tests.utility.np_plot_profile_X opengate.tests.utility.np_plot_profile_Y opengate.tests.utility.np_get_circle_mean_value opengate.tests.utility.add_circle opengate.tests.utility.add_border opengate.tests.utility.plot_compare_profile Module Contents --------------- .. py:data:: plt .. py:function:: test_ok(is_ok=False) .. py:function:: read_stat_file(filename, encoder=None) .. py:function:: read_stat_file_json(filename) .. py:function:: read_stat_file_legacy(filename) .. py:function:: print_test(b, s) .. py:function:: assert_stats(stats_actor_1, stats_actor_2, tolerance=0) .. py:function:: assert_stats_json(stats_actor_1, stats_actor_2, tolerance=0, track_types_flag=None) .. py:function:: plot_img_axis(ax, img, label, axis='z') .. py:function:: plot_img_z(ax, img, label) .. py:function:: plot_img_y(ax, img, label) .. py:function:: plot_img_x(ax, img, label) .. py:function:: assert_images_properties(info1, info2) .. py:function:: assert_images(ref_filename1, filename2, stats=None, tolerance=0, ignore_value=0, axis='z', fig_name=None, sum_tolerance=5, scaleImageValuesFactor=None, sad_profile_tolerance=None) .. py:function:: plot_hist(ax, data, label, bins=100) .. py:function:: plot_profile(ax, y, y_spacing=1, label='') .. py:function:: assert_filtered_imagesprofile1D(ref_filter_filename1, ref_filename1, filename2, stats=None, tolerance=0, ignore_value=0, fig_name=None, sum_tolerance=5, plt_ylim=None) .. py:function:: exponential_func(x, a, b) .. py:function:: fit_exponential_decay(data, start, end) .. py:function:: get_new_key_name(key) .. py:function:: get_keys_correspondence(keys) .. py:function:: rel_diff(a, b) .. py:function:: rel_diff_range(a, b) .. py:function:: get_branch(tree, keys, key) Return a branch whether it is a numpy or a uproot tree .. py:function:: compare_branches(tree1, keys1, tree2, keys2, key1, key2, tol=0.8, scaling1=1, scaling2=1, ax=False, nb_bins=200) Compare with Wasserstein distance Works well, but not easy to set the tolerance value. .. py:function:: compare_branches_values(b1, b2, key1, key2, tol=0.8, ax=False, nb_bins=200) Compare with Wasserstein distance Works well, but not easy to set the tolerance value. .. py:function:: compare_trees(tree1, allkeys1, tree2, allkeys2, keys1, keys2, tols, scalings1, scalings2, fig=False, nb_bins=200) .. py:function:: get_default_test_paths(f, gate_folder=None, output_folder=None) .. py:function:: compare_root2(root1, root2, branch1, branch2, keys, img_filename, n_tol=3) .. py:function:: compare_root(root1, root2, branch1, branch2, checked_keys, img) .. py:function:: compare_root3(root1, root2, branch1, branch2, keys1, keys2, tols, scalings1, scalings2, img, hits_tol=6, nb_bins=200) .. py:function:: compare_root4(ref_root_filename, root_filename, attributes, branch1, branch2=None, img='root.png', hits_tol=6, nb_bins=200) .. py:function:: open_root_as_np(root_file, tree_name) .. py:function:: dict_compare(d1, d2) .. py:function:: write_gauss_param_to_file(output_file_pathV, planePositionsV, saveFig=False) .. py:function:: get_gauss_param_xy(data, spacing, shape, filepath=None, saveFig=False) .. py:function:: extract_gauss_param_1D(data, length, spacing, axis=1, createFig=False) .. py:function:: plot_gauss_fit(positionVec, dose, fit, show=False) .. py:function:: create_position_vector(length, spacing, centered=True) .. py:function:: gauss_func(x, A, x0, sigma) .. py:function:: gaussian_fit(positionVec, dose) .. py:function:: read_mhd(filename) .. py:function:: plot2D(twodarray, label, show=False) .. py:function:: create_2D_Edep_colorMap(filepath, show=False, axis='z') .. py:function:: compareGaussParamFromFile(sigma, ref, rel_tol=0, abs_tol=0, verb=False) .. py:function:: compareGaussParamArrays(paramTestV, paramRefV, rel_tol=0, abs_tol=0, verb=False) .. py:function:: test_weights(expected_ratio, mhd_1, mhd_2, thresh=0.1) .. py:function:: test_tps_spot_size_positions(data, ref, spacing, thresh=0.1, abs_tol=0.3) .. py:function:: scale_dose(path, scaling, outpath='') .. py:function:: check_dose_grid_geometry(dose_mhd_path, dose_actor) .. py:function:: arangeDx(dx, xV, includeUB=False, lb=[], ub=[]) .. py:function:: interpolate1Dprofile(xV, dV, dx=0.01, interpolMethod='cubic') .. py:function:: getRange(xV, dV, percentLevel=0.8) .. py:function:: get_range_from_image(volume, shape, spacing, axis='y') .. py:function:: compareRange(volume1, volume2, shape1, shape2, spacing1, spacing2, axis1='y', axis2='y', thresh=2.0) .. py:function:: get_1D_profile(data, shape, spacing, axis='z') .. py:function:: compare_dose_at_points(pointsV, dose1, dose2, shape1, shape2, spacing1, spacing2, axis1='z', axis2='z', rel_tol=0.03) .. py:function:: assert_img_sum(img1, img2, sum_tolerance=5) .. py:function:: assert_images_ratio(expected_ratio, mhd_1, mhd_2, abs_tolerance=0.1, fn_to_apply=None) .. py:function:: assert_images_ratio_per_voxel(expected_ratio, mhd_1, mhd_2, abs_tolerance=0.1, mhd_is_path=True) .. py:function:: check_diff(value1, value2, tolerance, txt) .. py:function:: check_diff_abs(value1, value2, tolerance, txt) .. py:function:: root_compare_param_tree(filename, tree_name, keys) .. py:function:: root_compare_param(keys, fig) .. py:function:: root_compare4(p1, p2, param) Compare two root trees. p1 and p2 contain = the root filename, the tree name, a list of branch names (see root_compare_param_tree) Also, each branch can be scaled and clip to a min/max range. param contains: the tolerance values (for all branches), the fig name, the nb of bins of the histograms, the tolerance for the nb of hits (see root_compare_param) .. py:function:: compare_trees4(p1, p2, param) .. py:function:: get_gpu_mode_for_tests() return "auto" except if the test runs with macos and github actions On macos and github actions, mps is detected but not usable and lead to errors. So we choose "cpu" in such a case .. py:function:: np_img_window_level(img, window_width, window_level) Clip and rescale the grey level values of the image according to window width/level. Output image is within the range [0, 1] Parameters ---------- img an image as a numpy array window_width window_level Returns the clipped and normalized image (range [0, 1]) ------- .. py:function:: np_img_crop(img, crop_center, crop_width) .. py:function:: np_plot_slice(ax, img, num_slice, window_width, window_level, crop_center, crop_width, spacing=(1, 1)) .. py:function:: np_plot_slice_h_line(ax, hline, crop_center, crop_width) .. py:function:: np_plot_slice_v_line(ax, vline, crop_center, crop_width) .. py:function:: add_colorbar(imshow, window_level, window_width) .. py:function:: np_plot_integrated_profile(ax, img, axis, num_slice, crop_center, crop_width, label, spacing) .. py:function:: np_plot_profile_X(ax, img, hline, num_slice, crop_center, crop_width, label, width) .. py:function:: np_plot_profile_Y(ax, img, vline, num_slice, crop_center, crop_width, label, width) .. py:function:: np_get_circle_mean_value(img, center, radius) .. py:function:: add_circle(ax, img, crop_center, crop_width, center, radius) .. py:function:: add_border(ax, border_color, border_width) .. py:function:: plot_compare_profile(ref_names, test_names, options) .. py:class:: RootComparison(ref_filename, filename) .. py:attribute:: root_ref .. py:attribute:: root_cmp