Skip to content

Commit

Permalink
Merge pull request #579 from niermann999/feat-generate-detfiles
Browse files Browse the repository at this point in the history
ref: Cleanup in the python directories
  • Loading branch information
asalzburger authored Oct 27, 2023
2 parents f43b3ed + 8286e01 commit aaf1a49
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 43 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# data files
/data/*.csv
/data/*.cvf
/data/*.json

# local working directories
/bin
/build
/run

# python files
**/__pycache__
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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__():
Expand Down Expand Up @@ -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)

#-------------------------------------------------------------------------------

Expand Down
4 changes: 4 additions & 0 deletions tests/validation/python/plotting/__init__.py
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__():
Expand Down Expand Up @@ -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)

#-------------------------------------------------------------------------------

Expand Down
3 changes: 3 additions & 0 deletions tests/validation/python/validation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

import plotting as plotting
import plotting.pyplot_factory as plt_factory
4 changes: 4 additions & 0 deletions tests/validation/python/validation/json_schema/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

from .geometry import geometry_schema
from .homogeneous_material import homogeneous_material_schema
from .surface_grids import surface_grid_schema
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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'])
Expand All @@ -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'])
Expand Down Expand Up @@ -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,
Expand All @@ -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'])
Expand All @@ -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'])
Expand Down

0 comments on commit aaf1a49

Please sign in to comment.