Skip to content

Commit

Permalink
Merge branch 'master' into upgrade_python_3
Browse files Browse the repository at this point in the history
  • Loading branch information
HealthyPear committed Nov 24, 2021
2 parents 119aae1 + 1885526 commit bcd8787
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
4 changes: 3 additions & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
# were 'realpath' is defined, but just in case...
if [[ ( "$OSTYPE" == "darwin"* ) && ( -z "$(command -v realpath)" ) ]]; then
echo "ERROR: realpath command not found!"
echo "Please, check that you are using the Docker container."
echo "Please,"
echo " - either use the Docker Container,"
echo " - or install the command using Homebrew (brew install coreutils)."
return 1
fi

Expand Down
75 changes: 75 additions & 0 deletions tests/test_merge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# make 2 HDF5 files

import glob
import subprocess

import tables as tb
import numpy as np

def create_mock_file(tmpdir, filename):

filepath = tmpdir.join(filename)
outfile = tb.open_file(filepath.strpath, mode="w", title="Run_1")

cameras = ["NectarCam", "CHEC"]

output_variables = dict(
n=tb.Int16Col(dflt=-1, pos=0)
)

outdata = {}
out_table = {}
for cam_id in cameras:
if cam_id not in outdata:
out_table[cam_id] = outfile.create_table(
"/", cam_id, output_variables,
)
outdata[cam_id] = out_table[cam_id].row
for n_image in range(50):
outdata[cam_id]["n"] = 0
outdata[cam_id].append()

outfile.close()

return None

def test_merge(tmpdir):

print(tmpdir.strpath)

# create 1st file
create_mock_file(tmpdir, "run1.h5")
# create 2nd file
create_mock_file(tmpdir, "run2.h5")
# define merged file
merged_file_path = tmpdir.join("merged_file.h5").strpath

# call script to merge
subprocess.check_call(["python",
"merge_tables.py",
"--indir", tmpdir.strpath,
"--template_file_name", "*run*",
"--outfile", merged_file_path
])

cameras = ["NectarCam", "CHEC"]
n_images_from_runs = dict.fromkeys(cameras, 0)
n_tot_images = dict.fromkeys(cameras, 0)

single_files = glob.glob("{}/*run*.h5".format(tmpdir.strpath))

# Get total number of table rows cumulatively from each files per table
for file in single_files:
with tb.open_file(file, "r") as f:
table_name_list = [table.name for table in f.root]
assert sorted(table_name_list) == sorted(cameras)
for child in f.root:
n_images_from_runs[child._v_name] += len(child)

# Get total number of table rows from merged file
with tb.open_file(merged_file_path, "r") as f:
for child in f.root:
n_tot_images[child._v_name] = len(child)

for camera in cameras:
assert n_images_from_runs[camera] == n_tot_images[camera]

0 comments on commit bcd8787

Please sign in to comment.