Skip to content

Commit

Permalink
reduce ground grid intensity
Browse files Browse the repository at this point in the history
  • Loading branch information
relleums committed Jul 1, 2024
1 parent db8e851 commit e054d45
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
53 changes: 49 additions & 4 deletions plenoirf/reduction/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import glob
import rename_after_writing as rnw
import sparse_numeric_table as snt
import sequential_tar
import gzip
import plenopy

Expand All @@ -16,6 +17,8 @@ def list_items():
return [
"event_table.zip",
"reconstructed_cherenkov.tar",
"ground_grid_intensity.zip",
"ground_grid_intensity_roi.zip",
]


Expand All @@ -25,11 +28,19 @@ def reduce_item(map_dir, out_path, item_key):
recude_event_table(run_paths=run_paths, out_path=out_path)
elif item_key == "reconstructed_cherenkov.tar":
reduce_reconstructed_cherenkov(run_paths=run_paths, out_path=out_path)
elif item_key == "ground_grid_intensity.zip":
reduce_ground_grid_intensity(
run_paths=run_paths, out_path=out_path, roi=False
)
elif item_key == "ground_grid_intensity_roi.zip":
reduce_ground_grid_intensity(
run_paths=run_paths, out_path=out_path, roi=True
)
else:
raise KeyError(f"No such item_key '{item_key}'.")


def make_jobs(plenoirf_dir, config=None):
def make_jobs(plenoirf_dir, config=None, lazy=False):
if config is None:
config = configuration.read(plenoirf_dir)

Expand All @@ -38,6 +49,17 @@ def make_jobs(plenoirf_dir, config=None):
for site_key in config["sites"]["instruemnt_response"]:
for particle_key in config["particles"]:
for item_key in list_items():
if lazy:
job_out_path = os.path.join(
plenoirf_dir,
"response",
instrument_key,
"site_key",
"particle_key",
item_key,
)
if os.path.exists(job_out_path):
continue
job = {
"plenoirf_dir": plenoirf_dir,
"instrument_key": instrument_key,
Expand Down Expand Up @@ -94,18 +116,41 @@ def recude_event_table(run_paths, out_path):


def reduce_reconstructed_cherenkov(run_paths, out_path):
opj = os.path.join

with plenopy.photon_stream.loph.LopfTarWriter(path=out_path) as lout:
for run_path in run_paths:
run_basename = os.path.basename(run_path)
run_id_str = os.path.splitext(run_basename)[0]
buff = zip_read_BytesIo(
file=run_path,
internal_path=opj(run_id_str, "reconstructed_cherenkov.tar"),
internal_path=os.path.join(
run_id_str, "reconstructed_cherenkov.tar"
),
mode="r",
)
with plenopy.photon_stream.loph.LopfTarReader(fileobj=buff) as lin:
for event in lin:
uid, phs = event
lout.add(uid=uid, phs=phs)


def reduce_ground_grid_intensity(run_paths, out_path, roi=False):
with zipfile.ZipFile(out_path, "w") as zout:
for run_path in run_paths:
run_basename = os.path.basename(run_path)
run_id_str = os.path.splitext(run_basename)[0]

suff = "_roi" if roi else ""
internal_path = os.path.join(
run_id_str,
"plenoirf.production.simulate_shower_and_collect_cherenkov_light_in_grid",
f"ground_grid_intensity{suff:s}.tar",
)
buff = zip_read_BytesIo(
file=run_path,
internal_path=internal_path,
mode="r",
)
with sequential_tar.open(fileobj=buff, mode="r") as tarin:
for item in tarin:
with zout.open(item.name, "w") as fout:
fout.write(item.read(mode="rb"))
2 changes: 1 addition & 1 deletion plenoirf/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.4.2"
__version__ = "1.4.3"

0 comments on commit e054d45

Please sign in to comment.