From 7143a254d0faabb6f4646cd63e62fb0629520541 Mon Sep 17 00:00:00 2001 From: Tamas Vami Date: Thu, 5 Sep 2024 21:35:37 -0700 Subject: [PATCH 1/2] Add validation installation to the just commands and rename the dir --- Validation/README.md | 34 +++++-------------- .../src/{Validation => Validate}/__init__.py | 0 .../src/{Validation => Validate}/__main__.py | 0 .../src/{Validation => Validate}/_differ.py | 0 .../src/{Validation => Validate}/_file.py | 0 .../src/{Validation => Validate}/_plotter.py | 0 .../src/{Validation => Validate}/dark_brem.py | 0 .../src/{Validation => Validate}/ecal.py | 0 .../src/{Validation => Validate}/hcal.py | 0 .../{Validation => Validate}/performance.py | 0 .../{Validation => Validate}/photonuclear.py | 0 .../{Validation => Validate}/simparticles.py | 0 .../src/{Validation => Validate}/trigscint.py | 0 justfile | 12 +++++++ 14 files changed, 21 insertions(+), 25 deletions(-) rename Validation/src/{Validation => Validate}/__init__.py (100%) rename Validation/src/{Validation => Validate}/__main__.py (100%) rename Validation/src/{Validation => Validate}/_differ.py (100%) rename Validation/src/{Validation => Validate}/_file.py (100%) rename Validation/src/{Validation => Validate}/_plotter.py (100%) rename Validation/src/{Validation => Validate}/dark_brem.py (100%) rename Validation/src/{Validation => Validate}/ecal.py (100%) rename Validation/src/{Validation => Validate}/hcal.py (100%) rename Validation/src/{Validation => Validate}/performance.py (100%) rename Validation/src/{Validation => Validate}/photonuclear.py (100%) rename Validation/src/{Validation => Validate}/simparticles.py (100%) rename Validation/src/{Validation => Validate}/trigscint.py (100%) diff --git a/Validation/README.md b/Validation/README.md index 518d62277..530bb9ddb 100644 --- a/Validation/README.md +++ b/Validation/README.md @@ -6,22 +6,10 @@ Python package focused on comparing two or more "similar" LDMX event or histogra One may use this python module either inside or outside the ldmx-sw development container. ### Inside `ldmx` -Since the environment inside of the container is a bit more restrictive, we need to -specifically tell `pip` some extra information that it cannot deduce on its own. +Run the dedicated `just` command to install ``` -ldmx python3 -m pip install Validation/ \ - --upgrade \ - --target install/python/ \ - --no-cache +just install-validation ``` -`python3 -m pip install Validation/` is the standard `pip` install method. -We add `--upgrade` to tell `pip` it should overwrite the package if it already has been -installed before which is helpful in the case where someone is updating the code and running -the new code within the container. The `--target install/python/` arguments tell `pip` -where to install the package. This directory is where we currently store our python modules -and is where the container expects them to be. The `--no-cache` argument tells `pip` to -not use a cache for downloading any dependencies from the internet which is necessary since -`pip` will not be able to write to the cache location within the container. ### Outside `ldmx` Outside container it is helpful to put the Validation module inside a virtual environment. @@ -44,18 +32,14 @@ Using Validation without a virtual environment and outside of the container is n ## Usage -This module _cannot_ be run from ldmx-sw directory. -`import Validation` prefers the local directory instead of the installed path so it tries to -load from the `ldmx-sw/Validation` directory. - -We could fix this by renaming the package inside Validation or renaming the directory. ### CLI The Validation module is constructed to do some common tasks quickly on the command line. Printing out its help message shows how to run it and gives you the details on what parameters to provide. ``` -python3 -m Validation -h +cd Validation/src +denv python3 -m Validate -h ``` which should be run with `ldmx` if the module was installed in the container. @@ -63,20 +47,20 @@ For example if you would like to compare the ECAL shower features, put the input e.g. `compareDir` with names that are separated with an underscore, e.g. `histo_new.root` and `histo_ref.root`, then run the following command. ``` -ldmx python3 -m Validation compareDir/ --systems ecal.shower_feats +denv python3 -m Validate compareDir/ --systems ecal.shower_feats ``` This will produce plots in the `compareDir` directory and will include "new" and "ref" in the plot legend. ### In Script -Similar to the CLI, you can develop your own python script using Validation. -Simply `import Validation` where you want to be using it. +Similar to the CLI, you can develop your own python script using Validate. +Simply `import Validate` where you want to be using it. **Remember**: The plotting functions assume the user is in an interactive notebook unless the `out_dir` parameter is provided. ### In Notebook -Again, accessing this module post-installation is the same as other modules `import Validation`. +Again, accessing this module post-installation is the same as other modules `import Validate`. This can help you develop plots that don't come pre-made within the Validation module. -**If you are developing Validation and testing within a notebook**, you will need to reboot +**If you are developing Validate and testing within a notebook**, you will need to reboot the python kernel anytime you wish to test changes to the Validation module. This is necessary because Jupyter keeps modules cached in memory during normal running in order to save time when re-executing cells with `import` statements. diff --git a/Validation/src/Validation/__init__.py b/Validation/src/Validate/__init__.py similarity index 100% rename from Validation/src/Validation/__init__.py rename to Validation/src/Validate/__init__.py diff --git a/Validation/src/Validation/__main__.py b/Validation/src/Validate/__main__.py similarity index 100% rename from Validation/src/Validation/__main__.py rename to Validation/src/Validate/__main__.py diff --git a/Validation/src/Validation/_differ.py b/Validation/src/Validate/_differ.py similarity index 100% rename from Validation/src/Validation/_differ.py rename to Validation/src/Validate/_differ.py diff --git a/Validation/src/Validation/_file.py b/Validation/src/Validate/_file.py similarity index 100% rename from Validation/src/Validation/_file.py rename to Validation/src/Validate/_file.py diff --git a/Validation/src/Validation/_plotter.py b/Validation/src/Validate/_plotter.py similarity index 100% rename from Validation/src/Validation/_plotter.py rename to Validation/src/Validate/_plotter.py diff --git a/Validation/src/Validation/dark_brem.py b/Validation/src/Validate/dark_brem.py similarity index 100% rename from Validation/src/Validation/dark_brem.py rename to Validation/src/Validate/dark_brem.py diff --git a/Validation/src/Validation/ecal.py b/Validation/src/Validate/ecal.py similarity index 100% rename from Validation/src/Validation/ecal.py rename to Validation/src/Validate/ecal.py diff --git a/Validation/src/Validation/hcal.py b/Validation/src/Validate/hcal.py similarity index 100% rename from Validation/src/Validation/hcal.py rename to Validation/src/Validate/hcal.py diff --git a/Validation/src/Validation/performance.py b/Validation/src/Validate/performance.py similarity index 100% rename from Validation/src/Validation/performance.py rename to Validation/src/Validate/performance.py diff --git a/Validation/src/Validation/photonuclear.py b/Validation/src/Validate/photonuclear.py similarity index 100% rename from Validation/src/Validation/photonuclear.py rename to Validation/src/Validate/photonuclear.py diff --git a/Validation/src/Validation/simparticles.py b/Validation/src/Validate/simparticles.py similarity index 100% rename from Validation/src/Validation/simparticles.py rename to Validation/src/Validate/simparticles.py diff --git a/Validation/src/Validation/trigscint.py b/Validation/src/Validate/trigscint.py similarity index 100% rename from Validation/src/Validation/trigscint.py rename to Validation/src/Validate/trigscint.py diff --git a/justfile b/justfile index fad754d76..3e0f9c269 100644 --- a/justfile +++ b/justfile @@ -174,3 +174,15 @@ compile ncpu=num_cpus() *CONFIG='': (configure CONFIG) (build ncpu) # re-build ldmx-sw and then run a config recompFire config_py *ARGS: build (fire config_py ARGS) + +# install the validation module +# `python3 -m pip install Validation/` is the standard `pip` install method. +# We add `--upgrade` to tell `pip` it should overwrite the package if it already has been +# installed before which is helpful in the case where someone is updating the code and running +# the new code within the container. The `--target install/python/` arguments tell `pip` +# where to install the package. This directory is where we currently store our python modules +# and is where the container expects them to be. The `--no-cache` argument tells `pip` to +# not use a cache for downloading any dependencies from the internet which is necessary since +# `pip` will not be able to write to the cache location within the container. +install-validation: + denv python3 -m pip install Validation/ --upgrade --target install/python/ --no-cache From e42bd85cc0e3ee643547b6a38d9bc71cc078b799 Mon Sep 17 00:00:00 2001 From: Tamas Vami Date: Fri, 6 Sep 2024 08:03:15 -0700 Subject: [PATCH 2/2] Update README, remove circ def of matplotlib --- Validation/README.md | 7 ++----- Validation/src/Validate/_differ.py | 7 +++---- justfile | 13 +++++++------ 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/Validation/README.md b/Validation/README.md index 530bb9ddb..13f26d832 100644 --- a/Validation/README.md +++ b/Validation/README.md @@ -5,13 +5,13 @@ Python package focused on comparing two or more "similar" LDMX event or histogra ## Installation One may use this python module either inside or outside the ldmx-sw development container. -### Inside `ldmx` +### Inside `ldmx-sw` Run the dedicated `just` command to install ``` just install-validation ``` -### Outside `ldmx` +### Outside `ldmx-sw` Outside container it is helpful to put the Validation module inside a virtual environment. This makes it easier to keep track of what you are doing and isolate the dependencies of `Validation` from other python packages that may be on your system. @@ -38,10 +38,8 @@ The Validation module is constructed to do some common tasks quickly on the comm Printing out its help message shows how to run it and gives you the details on what parameters to provide. ``` -cd Validation/src denv python3 -m Validate -h ``` -which should be run with `ldmx` if the module was installed in the container. For example if you would like to compare the ECAL shower features, put the input histograms into a directory, e.g. `compareDir` with names that are separated with an underscore, e.g. `histo_new.root` and `histo_ref.root`, @@ -63,4 +61,3 @@ This can help you develop plots that don't come pre-made within the Validation m **If you are developing Validate and testing within a notebook**, you will need to reboot the python kernel anytime you wish to test changes to the Validation module. This is necessary because Jupyter keeps modules cached in memory during normal running in order to save time -when re-executing cells with `import` statements. diff --git a/Validation/src/Validate/_differ.py b/Validation/src/Validate/_differ.py index 752c29e50..2f46206e7 100644 --- a/Validation/src/Validate/_differ.py +++ b/Validation/src/Validate/_differ.py @@ -5,7 +5,6 @@ import re # external dependencies -import matplotlib.pyplot as plt import matplotlib import uproot # us @@ -81,7 +80,7 @@ def plot1d(self, column, xlabel, grp_name from the constructor. If out_dir is not provided, we assume we are in a notebook and - simply `plt.show()` the figure. If out_dir is not None (i.e. it + simply `matplotlib.pyplot.show()` the figure. If out_dir is not None (i.e. it was defined), we assume we are in a non-interactive script and write the figure to a PDF in the output file and then clear the figure. @@ -107,7 +106,7 @@ def plot1d(self, column, xlabel, hist_kwargs : dict All other key-word arguments are passed into each File.plot1d """ - fig = plt.figure('differ',figsize=(11,8)) + fig = matplotlib.pyplot.figure('differ',figsize=(11,8)) raw_ax, ratio_ax = fig.subplots( nrows = 2, sharex = 'col', @@ -151,7 +150,7 @@ def plot1d(self, column, xlabel, ratio_ax.tick_params(axis='x', rotation=90) if out_dir is None : - plt.show() + matplotlib.pyplot.show() else : if file_name is None : if isinstance(column, str) : diff --git a/justfile b/justfile index 3e0f9c269..56ac2dfbf 100644 --- a/justfile +++ b/justfile @@ -178,11 +178,12 @@ recompFire config_py *ARGS: build (fire config_py ARGS) # install the validation module # `python3 -m pip install Validation/` is the standard `pip` install method. # We add `--upgrade` to tell `pip` it should overwrite the package if it already has been -# installed before which is helpful in the case where someone is updating the code and running -# the new code within the container. The `--target install/python/` arguments tell `pip` -# where to install the package. This directory is where we currently store our python modules -# and is where the container expects them to be. The `--no-cache` argument tells `pip` to -# not use a cache for downloading any dependencies from the internet which is necessary since -# `pip` will not be able to write to the cache location within the container. +# # installed before which is helpful in the case where someone is updating the code and running +# # the new code within the container. The `--target install/python/` arguments tell `pip` +# # where to install the package. This directory is where we currently store our python modules +# # and is where the container expects them to be. The `--no-cache` argument tells `pip` to +# # not use a cache for downloading any dependencies from the internet which is necessary since +# # `pip` will not be able to write to the cache location within the container. +# # install the python Validation plotting module install-validation: denv python3 -m pip install Validation/ --upgrade --target install/python/ --no-cache