Skip to content

Commit

Permalink
Merge pull request #13 from nstelter-slac/local_h5_test
Browse files Browse the repository at this point in the history
Add local test scripts for h5 and parallel slice
  • Loading branch information
nstelter-slac authored Jan 25, 2024
2 parents 9bfdc58 + b076f8f commit e78d4aa
Show file tree
Hide file tree
Showing 43 changed files with 68 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ jobs:
- name: Run tests
run: |
pytest tests/testFitFunctions.py
pytest tests/test_FitFunctions.py
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
tests/test
tests/scan

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
# beamtime-calibration-suite
[![Build Status](https://github.com/slaclab/beamtime-calibration-suite/actions/workflows/run-tests.yml/badge.svg?branch=main)](https://github.com/slaclab/beamtime-calibration-suite/actions/workflows/run-tests.yml)
[![Build Status](https://github.com/slaclab/beamtime-calibration-suite/actions/workflows/run-tests.yml/badge.svg?branch=main)](https://github.com/slaclab/beamtime-calibration-suite/actions/workflows/run-tests.yml)

To run tests:
ssh onto psana
source /sdf/group/lcls/ds/ana/sw/conda2/manage/bin/psconda.sh
clone this repo
cd beamtime-calibration-suite/tests
pytest .
8 changes: 7 additions & 1 deletion scripts/AnalyzeH5.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(self):
parser.add_argument(
"-f", "--files", type=str, default=None, help="run analysis on file or comma-separated files"
)
parser.add_argument("-s", "--slice_edges", type=str, help="two ints for row and col, separated by ','")
parser.add_argument("-L", "--label", type=str, default="testLabel", help="analysis label")
args = parser.parse_args()

Expand All @@ -54,6 +55,10 @@ def __init__(self):
self.files = args.files.replace(" ", "")
self.lowEnergyCut = 4 # fix - should be 0.5 photons or something
self.highEnergyCut = 30 # fix - should be 1.5 photons or something
self.sliceEdges = None
if args.slice_edges is not None:
self.sliceEdges = args.slice_edges.split(',')
self.sliceEdges = [int(curr) for curr in self.sliceEdges]
self.fileNameInfo = FileNamingInfo(args.path, self.__class__.__name__, args.run, 0, args.label,)
print("Output dir: " + self.fileNameInfo.outputDir)
logging.info("Output dir: " + self.fileNameInfo.outputDir)
Expand All @@ -77,7 +82,8 @@ def identifyAnalysis(self):
# do something useful here, maybe
# but for now
self.analysisType = "cluster"
self.sliceEdges = [288 - 270, 107 - 59]
if self.sliceEdges == None: # set if not already by cmdline args
self.sliceEdges = [288 - 270, 107 - 59]

def analyze(self):
if self.analysisType == "cluster":
Expand Down
Binary file added tests/OffXavierV4_2.npy
Binary file not shown.
Binary file added tests/XavierV4_2.npy
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
27 changes: 27 additions & 0 deletions tests/test_AnalyzeH5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import subprocess
import os
import shutil

def test_run_analyzeh5_and_compare():

# Delete existing 'test' directory if it exists and make new one
if os.path.exists('test'):
shutil.rmtree('test')
os.makedirs('test')

result = subprocess.run(["python", "../scripts/AnalyzeH5.py", "-f", "testData/lowFlux/SimpleClusters_c0_r334_n100.h5", "-p", "test", "-r", "666", "-s", "2,15"])

#print(result.stdout)
#print(result.stderr)

# List of file pairs
file_pairs = [
("test/AnalyzeH5_r666_c0_r1_c14_testLabel_E.png", "testData/expected/analyzeH5Expected/AnalyzeH5_r666_c0_r1_c14_testLabel_E.png"),
("test/AnalyzeH5_r666_c0_testLabel_E.png", "testData/expected/analyzeH5Expected/AnalyzeH5_r666_c0_testLabel_E.png"),
("test/AnalyzeH5_r666_c0_testLabel_gainDistribution.png", "testData/expected/analyzeH5Expected/AnalyzeH5_r666_c0_testLabel_gainDistribution.png"),
("test/AnalyzeH5_r666_c0_r1_c14_testLabel_fitInfo.npy", "testData/expected/analyzeH5Expected/AnalyzeH5_r666_c0_r1_c14_testLabel_fitInfo.npy")
]

for file1, file2 in file_pairs:
diff_result = subprocess.run(["diff", file1, file2])
assert diff_result.returncode == 0
22 changes: 22 additions & 0 deletions tests/test_EventScanParallelSlice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import subprocess
import os
import shutil

def test_run_event_scan_parallel_slice_and_compare():

# Delete existing 'scan' directory if it exists and make new one
if os.path.exists('scan'):
shutil.rmtree('scan')
os.makedirs('scan')

# run scripts
result1 = subprocess.run(["python", "../scripts/EventScanParallelSlice.py", "-r", "349", "-p", "scan", "--maxNevents", "10"])
result2 = subprocess.run(["python", "../scripts/EventScanParallelSlice.py", "-r", "349", "-f", "scan/EventScanParallel_c0_r349_n1.h5", "-p", "scan"])

#print(result1.stdout)
#print(result1.stderr)
#print(result2.stdout)
#print(result2.stderr)

diff_result = subprocess.run(["diff", "-r", "scan", "testData/expected/eventScanParallelSliceExpected/"])
assert diff_result.returncode == 0
File renamed without changes.

0 comments on commit e78d4aa

Please sign in to comment.