From 8286e01a5cdc23bd07cdc8a12bf6076bdf61e67d Mon Sep 17 00:00:00 2001 From: Joana Niermann Date: Fri, 27 Oct 2023 13:34:47 +0200 Subject: [PATCH] Cleanup in the python directories --- .gitignore | 9 ++++++++ .../{run_file_checker.py => file_checker.py} | 10 +++++---- ...l_validation.py => material_validation.py} | 21 +++++++------------ tests/validation/python/plotting/__init__.py | 4 ++++ .../python/{ => plotting}/plot_helpers.py | 0 .../python/{ => plotting}/pyplot_factory.py | 0 ...n_validation.py => ray_scan_validation.py} | 20 +++++++----------- .../validation/python/validation/__init__.py | 3 +++ .../python/validation/json_schema/__init__.py | 4 ++++ .../json_schema}/geometry.py | 0 .../json_schema}/homogeneous_material.py | 0 .../json_schema}/surface_grids.py | 0 .../{ => validation}/plot_material_scan.py | 7 +++---- .../python/{ => validation}/plot_ray_scan.py | 19 ++++++++--------- 14 files changed, 54 insertions(+), 43 deletions(-) rename tests/validation/python/{run_file_checker.py => file_checker.py} (91%) rename tests/validation/python/{run_material_validation.py => material_validation.py} (86%) create mode 100644 tests/validation/python/plotting/__init__.py rename tests/validation/python/{ => plotting}/plot_helpers.py (100%) rename tests/validation/python/{ => plotting}/pyplot_factory.py (100%) rename tests/validation/python/{run_ray_scan_validation.py => ray_scan_validation.py} (89%) create mode 100644 tests/validation/python/validation/__init__.py create mode 100644 tests/validation/python/validation/json_schema/__init__.py rename tests/validation/python/{json_schemas => validation/json_schema}/geometry.py (100%) rename tests/validation/python/{json_schemas => validation/json_schema}/homogeneous_material.py (100%) rename tests/validation/python/{json_schemas => validation/json_schema}/surface_grids.py (100%) rename tests/validation/python/{ => validation}/plot_material_scan.py (97%) rename tests/validation/python/{ => validation}/plot_ray_scan.py (91%) diff --git a/.gitignore b/.gitignore index c986b6bb2..917a2596f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,12 @@ +# data files +/data/*.csv +/data/*.cvf +/data/*.json + +# local working directories /bin /build +/run +# python files +**/__pycache__ diff --git a/tests/validation/python/run_file_checker.py b/tests/validation/python/file_checker.py similarity index 91% rename from tests/validation/python/run_file_checker.py rename to tests/validation/python/file_checker.py index e2992e943..113ab5fea 100644 --- a/tests/validation/python/run_file_checker.py +++ b/tests/validation/python/file_checker.py @@ -4,16 +4,18 @@ # # Mozilla Public License Version 2.0 +# detray json schema definitions +from validation.json_schema import geometry_schema +from validation.json_schema import homogeneous_material_schema +from validation.json_schema import surface_grid_schema + +# python includes import argparse import json import os import sys from jsonschema import validate -from json_schemas.geometry import geometry_schema -from json_schemas.homogeneous_material import homogeneous_material_schema -from json_schemas.surface_grids import surface_grid_schema - def __main__(): #----------------------------------------------------------------arg parsing diff --git a/tests/validation/python/run_material_validation.py b/tests/validation/python/material_validation.py similarity index 86% rename from tests/validation/python/run_material_validation.py rename to tests/validation/python/material_validation.py index 069a881c7..d515e3f8c 100644 --- a/tests/validation/python/run_material_validation.py +++ b/tests/validation/python/material_validation.py @@ -4,22 +4,17 @@ # # Mozilla Public License Version 2.0 -import plot_material_scan -from pyplot_factory import pyplot_factory +# detray includes +from validation import plot_material_scan as mat_plotter +from validation import plt_factory # python includes import argparse import logging -import numpy as np import pandas as pd import os import sys from datetime import datetime -import matplotlib.pyplot as plt - - -plt.rc('text', usetex=True) -plt.rc('text.latex', preamble=r'\usepackage{amsmath}') def __main__(): @@ -106,16 +101,16 @@ def __main__(): df = pd.read_csv(mat_scan_file) - plot_factory = pyplot_factory(outdir + "material_", logging) + plot_factory = plt_factory(outdir + "material_", logging) #------------------------------------------------------------------------run # The histograms are not re-weighted (if the rays are not evenly distributed # the material in some bins might be artificially high)! - plot_material_scan.X0_vs_eta_phi(df, detector_name, plot_factory, out_format) - plot_material_scan.L0_vs_eta_phi(df, detector_name, plot_factory, out_format) - plot_material_scan.X0_vs_eta(df, detector_name, plot_factory, out_format) - plot_material_scan.L0_vs_eta(df, detector_name, plot_factory, out_format) + mat_plotter.X0_vs_eta_phi(df, detector_name, plot_factory, out_format) + mat_plotter.L0_vs_eta_phi(df, detector_name, plot_factory, out_format) + mat_plotter.X0_vs_eta(df, detector_name, plot_factory, out_format) + mat_plotter.L0_vs_eta(df, detector_name, plot_factory, out_format) #------------------------------------------------------------------------------- diff --git a/tests/validation/python/plotting/__init__.py b/tests/validation/python/plotting/__init__.py new file mode 100644 index 000000000..c8e92bb9a --- /dev/null +++ b/tests/validation/python/plotting/__init__.py @@ -0,0 +1,4 @@ + +from .plot_helpers import filter_data +from .pyplot_factory import pyplot_factory +from .pyplot_factory import legend_options, get_legend_options diff --git a/tests/validation/python/plot_helpers.py b/tests/validation/python/plotting/plot_helpers.py similarity index 100% rename from tests/validation/python/plot_helpers.py rename to tests/validation/python/plotting/plot_helpers.py diff --git a/tests/validation/python/pyplot_factory.py b/tests/validation/python/plotting/pyplot_factory.py similarity index 100% rename from tests/validation/python/pyplot_factory.py rename to tests/validation/python/plotting/pyplot_factory.py diff --git a/tests/validation/python/run_ray_scan_validation.py b/tests/validation/python/ray_scan_validation.py similarity index 89% rename from tests/validation/python/run_ray_scan_validation.py rename to tests/validation/python/ray_scan_validation.py index 1bac732d2..e6c479757 100644 --- a/tests/validation/python/run_ray_scan_validation.py +++ b/tests/validation/python/ray_scan_validation.py @@ -4,8 +4,9 @@ # # Mozilla Public License Version 2.0 -import plot_ray_scan -from pyplot_factory import pyplot_factory +# detray includes +from validation import plot_ray_scan as scan_plotter +from validation import plt_factory # python includes import argparse @@ -15,11 +16,6 @@ import os import sys from datetime import datetime -import matplotlib.pyplot as plt - - -plt.rc('text', usetex=True) -plt.rc('text.latex', preamble=r'\usepackage{amsmath}') def __main__(): @@ -122,14 +118,14 @@ def __main__(): df = pd.read_csv(ray_scan_file) - plot_factory = pyplot_factory(outdir + "geometry_", logging) + plot_factory = plt_factory(outdir + "geometry_", logging) #------------------------------------------------------------------------run - plot_ray_scan.intersection_points_xy(args, df, detector_name, - scan_type, plot_factory, out_format) - plot_ray_scan.intersection_points_rz(args, df, detector_name, scan_type, - plot_factory, out_format) + scan_plotter.intersection_points_xy(args, df, detector_name, + scan_type, plot_factory, out_format) + scan_plotter.intersection_points_rz(args, df, detector_name, scan_type, + plot_factory, out_format) #------------------------------------------------------------------------------- diff --git a/tests/validation/python/validation/__init__.py b/tests/validation/python/validation/__init__.py new file mode 100644 index 000000000..4df048d93 --- /dev/null +++ b/tests/validation/python/validation/__init__.py @@ -0,0 +1,3 @@ + +import plotting as plotting +import plotting.pyplot_factory as plt_factory diff --git a/tests/validation/python/validation/json_schema/__init__.py b/tests/validation/python/validation/json_schema/__init__.py new file mode 100644 index 000000000..e18f2d886 --- /dev/null +++ b/tests/validation/python/validation/json_schema/__init__.py @@ -0,0 +1,4 @@ + +from .geometry import geometry_schema +from .homogeneous_material import homogeneous_material_schema +from .surface_grids import surface_grid_schema diff --git a/tests/validation/python/json_schemas/geometry.py b/tests/validation/python/validation/json_schema/geometry.py similarity index 100% rename from tests/validation/python/json_schemas/geometry.py rename to tests/validation/python/validation/json_schema/geometry.py diff --git a/tests/validation/python/json_schemas/homogeneous_material.py b/tests/validation/python/validation/json_schema/homogeneous_material.py similarity index 100% rename from tests/validation/python/json_schemas/homogeneous_material.py rename to tests/validation/python/validation/json_schema/homogeneous_material.py diff --git a/tests/validation/python/json_schemas/surface_grids.py b/tests/validation/python/validation/json_schema/surface_grids.py similarity index 100% rename from tests/validation/python/json_schemas/surface_grids.py rename to tests/validation/python/validation/json_schema/surface_grids.py diff --git a/tests/validation/python/plot_material_scan.py b/tests/validation/python/validation/plot_material_scan.py similarity index 97% rename from tests/validation/python/plot_material_scan.py rename to tests/validation/python/validation/plot_material_scan.py index f057375d9..f06556d57 100644 --- a/tests/validation/python/plot_material_scan.py +++ b/tests/validation/python/validation/plot_material_scan.py @@ -4,12 +4,11 @@ # # Mozilla Public License Version 2.0 -from pyplot_factory import get_legend_options +from . import plotting # python includes import numpy as np import math -import matplotlib.pyplot as plt """ Calculate edges of bins to plot the mateiral data """ @@ -105,7 +104,7 @@ def X0_vs_eta(df, detector, plotFactory, out_format = "pdf"): # Histogram bin edges xBinning, _ = get_n_bins(df) - lgd_ops = get_legend_options() + lgd_ops = plotting.get_legend_options() lgd_ops._replace(loc = 'upper center') hist_data = plotFactory.hist1D( @@ -140,7 +139,7 @@ def L0_vs_eta(df, detector, plotFactory, out_format = "pdf"): # Histogram bin edges xBinning, _ = get_n_bins(df) - lgd_ops = get_legend_options() + lgd_ops = plotting.get_legend_options() lgd_ops._replace(loc = 'upper center') hist_data = plotFactory.hist1D( diff --git a/tests/validation/python/plot_ray_scan.py b/tests/validation/python/validation/plot_ray_scan.py similarity index 91% rename from tests/validation/python/plot_ray_scan.py rename to tests/validation/python/validation/plot_ray_scan.py index 7359591af..00feb74cd 100644 --- a/tests/validation/python/plot_ray_scan.py +++ b/tests/validation/python/validation/plot_ray_scan.py @@ -4,8 +4,7 @@ # # Mozilla Public License Version 2.0 -import plot_helpers -from pyplot_factory import legend_options +from . import plotting # python includes import numpy as np @@ -24,13 +23,13 @@ def intersection_points_xy(opts, df, detector, scan_type, plotFactory, out_form portal_range = lambda data: ((data['z'] > min_z) & (data['z'] < max_z) & (data['type'] == 0)) passive_range = lambda data: ((data['z'] > min_z) & (data['z'] < max_z) & (data['type'] == 2)) - senstive_x, senstive_y = plot_helpers.filter_data( + senstive_x, senstive_y = plotting.filter_data( data = df, filter = sensitive_range, variables = ['x', 'y']) # Plot the xy coordinates of the filtered intersections points - lgd_ops = legend_options('upper center', 4, 0.4, 0.005) + lgd_ops = plotting.legend_options('upper center', 4, 0.4, 0.005) hist_data = plotFactory.scatter( figsize = (8, 8), x = senstive_x, @@ -44,7 +43,7 @@ def intersection_points_xy(opts, df, detector, scan_type, plotFactory, out_form # Portal surfaces if not opts.hide_portals: - portal_x, portal_y = plot_helpers.filter_data( + portal_x, portal_y = plotting.filter_data( data = df, filter = portal_range, variables = ['x', 'y']) @@ -54,7 +53,7 @@ def intersection_points_xy(opts, df, detector, scan_type, plotFactory, out_form # Passive surfaces if not opts.hide_passives: - passive_x, passive_y = plot_helpers.filter_data( + passive_x, passive_y = plotting.filter_data( data = df, filter = passive_range, variables = ['x', 'y']) @@ -90,13 +89,13 @@ def intersection_points_rz(opts, df, detector, scan_type, plotFactory, out_form portal_range = lambda data: (data['type'] == 0) passive_range = lambda data: (data['type'] == 2) - sensitive_x, sensitive_y, sensitive_z = plot_helpers.filter_data( + sensitive_x, sensitive_y, sensitive_z = plotting.filter_data( data = df, filter = sensitive_range, variables = ['x', 'y', 'z']) # Plot the xy coordinates of the filtered intersections points - lgd_ops = legend_options('upper center', 4, 0.8, 0.005) + lgd_ops = plotting.legend_options('upper center', 4, 0.8, 0.005) hist_data = plotFactory.scatter( figsize = (12, 6), x = sensitive_z, @@ -110,7 +109,7 @@ def intersection_points_rz(opts, df, detector, scan_type, plotFactory, out_form # Portal surfaces if not opts.hide_portals: - portal_x, portal_y, portal_z = plot_helpers.filter_data( + portal_x, portal_y, portal_z = plotting.filter_data( data = df, filter = portal_range, variables = ['x', 'y', 'z']) @@ -121,7 +120,7 @@ def intersection_points_rz(opts, df, detector, scan_type, plotFactory, out_form # Passive surfaces if not opts.hide_passives: - passive_x, passive_y, passive_z = plot_helpers.filter_data( + passive_x, passive_y, passive_z = plotting.filter_data( data = df, filter = passive_range, variables = ['x', 'y', 'z'])