Skip to content

Commit

Permalink
put the merlict related parts into plenoptics and mv it out of the ph…
Browse files Browse the repository at this point in the history
…antom_source
  • Loading branch information
relleums committed Feb 19, 2024
1 parent 182399a commit d86bf94
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 3 deletions.
95 changes: 95 additions & 0 deletions plenoptics/merlict.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import numpy as np
import os
import tempfile
import plenopy
import merlict_development_kit_python


PROPAGATION_CONFIG = {
"night_sky_background_ligth": {
"flux_vs_wavelength": [[250.0e-9, 1.0], [700.0e-9, 1.0]],
Expand All @@ -15,3 +22,91 @@
"single_photon_arrival_time_resolution": 0.416e-9,
},
}


def append_photons_to_space_seperated_values(
path, ids, supports, directions, wavelengths
):
"""
[0] id,
[1] [2] [3] support
[4] [5] [6] direction
[7] wavelength
"""
with open(path, "at") as f:
for i in range(len(ids)):
f.write(
"{:d} {:.3e} {:.3e} {:.3e} {:.9e} {:.9e} {:.9e} {:.3e}".format(
ids[i],
supports[i, 0],
supports[i, 1],
supports[i, 2],
directions[i, 0],
directions[i, 1],
directions[i, 2],
wavelengths[i],
)
)
f.write("\n")


def write_light_fields_to_space_seperated_values(light_fields, path):
curid = 0
for lf in light_fields:
sups = lf[0]
dirs = lf[1]
ids = np.arange(curid, curid + len(sups))
curid += len(sups)

append_photons_to_space_seperated_values(
path=path,
ids=ids,
supports=sups,
directions=dirs,
wavelengths=np.ones(len(sups)) * 433e-9,
)


def make_plenopy_event_and_read_light_field_geometry(
light_fields,
light_field_geometry_path,
merlict_propagate_config_path,
random_seed=0,
work_dir=None,
):
if work_dir == None:
work_dir_cleanup = True
tmpdir_handle = tempfile.TemporaryDirectory(prefix="phantom_source_")
work_dir = tmpdir_handle.name
else:
work_dir_cleanup = False
os.makedirs(work_dir, exist_ok=True)

photons_path = os.path.join(work_dir, "photons.ssv")
run_dir = os.path.join(work_dir, "run")

write_light_fields_to_space_seperated_values(
light_fields=light_fields,
path=photons_path,
)

rc = merlict_development_kit_python.plenoscope_propagator.plenoscope_propagator_raw_photons(
input_path=photons_path,
output_path=run_dir,
light_field_geometry_path=light_field_geometry_path,
merlict_plenoscope_propagator_config_path=merlict_propagate_config_path,
random_seed=0,
)

light_field_geometry = plenopy.LightFieldGeometry(
light_field_geometry_path
)
event = plenopy.Event(
os.path.join(run_dir, "1"),
light_field_geometry=light_field_geometry,
)

if work_dir_cleanup:
tmpdir_handle.cleanup()

return event, light_field_geometry
3 changes: 2 additions & 1 deletion plenoptics/sources/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json_utils
import os
from .. import utils
from .. import merlict


EXAMPLE_MESH_CONFIG = {
Expand Down Expand Up @@ -52,7 +53,7 @@ def make_response_to_mesh(
(
event,
light_field_geometry,
) = phantom_source.merlict.make_plenopy_event_and_read_light_field_geometry(
) = merlict.make_plenopy_event_and_read_light_field_geometry(
light_fields=light_fields,
light_field_geometry_path=light_field_geometry_path,
merlict_propagate_config_path=merlict_plenoscope_propagator_config_path,
Expand Down
1 change: 1 addition & 0 deletions plenoptics/sources/point.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import binning_utils
from . import mesh
from .. import utils
from .. import merlict


EXAMPLE_POINT_CONFIG = {
Expand Down
2 changes: 1 addition & 1 deletion plenoptics/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.7"
__version__ = "0.0.8"
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
install_requires=[
"perlin_noise",
"json_utils_sebastian-achim-mueller",
"merlict_development_kit_python_cherenkov-plenoscope-project>=0.0.1",
"merlict_development_kit_python_cherenkov-plenoscope-project>=0.0.3",
],
classifiers=[
"Programming Language :: Python :: 3",
Expand Down

0 comments on commit d86bf94

Please sign in to comment.