Skip to content

Commit

Permalink
allow darkmode and update plotting the lixel summation
Browse files Browse the repository at this point in the history
  • Loading branch information
relleums committed Aug 30, 2024
1 parent 2d6d9cc commit c546c6e
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 48 deletions.
18 changes: 10 additions & 8 deletions plenoirf/summary/figure.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
from plenopy.light_field_geometry.LightFieldGeometry import init_lixel_polygons


FIGURE_STYLE = {"rows": 720, "cols": 1280, "fontsize": 1.0}
Expand Down Expand Up @@ -113,15 +114,12 @@ def is_in_roi(x, y, roi, margin=0.1):
return False


def position_of_eye(light_field_geometry, eye_id):
def position_of_eye(light_field_geometry, lixel_polygons, eye_id):
poly = lixel_polygons
num_pax = light_field_geometry.number_paxel
start = eye_id * num_pax
stop = (eye_id + 1) * num_pax
poly = plenopy.light_field_geometry.init_lixel_polygons(
lixel_positions_x=light_field_geometry.lixel_positions_x,
lixel_positions_y=light_field_geometry.lixel_positions_y,
lixel_outer_radius=light_field_geometry.lixel_outer_radius,
)

poly = poly[start:stop]
poly = np.array(poly)
pp = []
Expand All @@ -135,11 +133,15 @@ def position_of_eye(light_field_geometry, eye_id):
return np.array([x_mean, y_mean])


def positions_of_eyes_in_roi(light_field_geometry, roi, margin=0.1):
def positions_of_eyes_in_roi(
light_field_geometry, lixel_polygons, roi, margin=0.1
):
positions_of_eyes = {}
for eye_id in range(light_field_geometry.number_pixel):
pos = position_of_eye(
light_field_geometry=light_field_geometry, eye_id=eye_id
light_field_geometry=light_field_geometry,
lixel_polygons=lixel_polygons,
eye_id=eye_id,
)
if is_in_roi(x=pos[0], y=pos[1], roi=roi, margin=margin):
positions_of_eyes[eye_id] = pos
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ def read_shower_maximum_object_distance(
structure=irf.table.STRUCTURE,
)

return irf.production.estimate_primary_trajectory.get_column_as_dict_by_index(
table=event_table, level_key="features", column_key=key
return (
irf.production.estimate_primary_trajectory.get_column_as_dict_by_index(
table=event_table, level_key="features", column_key=key
)
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,53 @@
import os
import numpy as np
import json_utils
import json
import sebastians_matplotlib_addons as seb
import matplotlib
from matplotlib.collections import PolyCollection
from plenopy.light_field_geometry.LightFieldGeometry import init_lixel_polygons

argv = irf.summary.argv_since_py(sys.argv)
pa = irf.summary.paths_from_argv(argv)

sum_config = irf.summary.read_summary_config(summary_dir=paths["analysis_dir"])
seb.matplotlib.rcParams.update(sum_config["plot"]["matplotlib"])
DARKMODE = True
rrr = 2

paths = irf.summary.paths_from_argv(sys.argv)
res = irf.summary.Resources.from_argv(sys.argv)
os.makedirs(paths["out_dir"], exist_ok=True)

if DARKMODE:
seb.plt.style.use("dark_background")
stroke = "white"
backc = "black"
EXT = ".dark.png"
cmap = "binary_r"
BEAM_ALPHA = 0.4
colors = ["gray", "g", "b", "r", "c", "m", "orange"]
else:
EXT = ".jpg"
stroke = "black"
backc = "white"
cmap = "binary"
BEAM_ALPHA = 0.2
colors = ["k", "g", "b", "r", "c", "m", "orange"]

seb.matplotlib.rcParams.update(res.analysis["plot"]["matplotlib"])

light_field_geometry = pl.LightFieldGeometry(
os.path.join(paths["plenoirf_dir"], "light_field_geometry")
os.path.join(
paths["plenoirf_dir"],
"plenoptics",
"instruments",
res.instrument_key,
"light_field_geometry",
)
)

region_of_interest_on_sensor_plane = {"x": [-0.35, 0.35], "y": [-0.35, 0.35]}

object_distances = [21e3, 29e3, 999e3]
# object_distances = [3e3, 5e3, 9e3, 15e3, 25e3, 999e3]
central_seven_pixel_ids = [4221, 4124, 4222, 4220, 4125, 4317, 4318]
colors = ["k", "g", "b", "r", "c", "m", "orange"]


XY_LABELS_ALWAYS = True

Expand Down Expand Up @@ -56,30 +81,33 @@
def lixel_in_region_of_interest(
light_field_geometry, lixel_id, roi, margin=0.1
):
return is_in_roi(
return irf.summary.figure.is_in_roi(
x=light_field_geometry.lixel_positions_x[lixel_id],
y=light_field_geometry.lixel_positions_y[lixel_id],
roi=roi,
margin=margin,
)


lixel_polygons = init_lixel_polygons(
lixel_positions_x=light_field_geometry.lixel_positions_x,
lixel_positions_y=light_field_geometry.lixel_positions_y,
lixel_outer_radius=light_field_geometry.lixel_outer_radius,
)

poseye = irf.summary.figure.positions_of_eyes_in_roi(
light_field_geometry=light_field_geometry,
lixel_polygons=lixel_polygons,
roi=region_of_interest_on_sensor_plane,
margin=0.2,
)

AXES_STYLE = {"spines": ["left", "bottom"], "axes": ["x", "y"], "grid": False}

lixel_polygons = pl.light_field_geometry.init_lixel_polygons(
lixel_positions_x=light_field_geometry.lixel_positions_x,
lixel_positions_y=light_field_geometry.lixel_positions_y,
lixel_outer_radius=light_field_geometry.lixel_outer_radius,
)

for obj, object_distance in enumerate(object_distances):
fig = seb.figure(style={"rows": 960, "cols": 1280, "fontsize": 1.244})
fig = seb.figure(
style={"rows": 960 * rrr, "cols": 1280 * rrr, "fontsize": 1.244 * rrr}
)
ax = seb.add_axes(
fig=fig, span=[0.15, 0.15, 0.85 * (3 / 4), 0.85], style=AXES_STYLE
)
Expand All @@ -104,9 +132,10 @@ def lixel_in_region_of_interest(
)
)

json_utils.write(path=cpath, out_dict=lixel_to_pixel, indent=None)
json_utils.write(cpath, lixel_to_pixel, indent=None)
else:
lixel_to_pixel = json_utils.read(path=cpath)
with open(cpath, "rt") as f:
lixel_to_pixel = json.loads(f.read())

colored_lixels = np.zeros(light_field_geometry.number_lixel, dtype=bool)
for i, pixel_id in enumerate(central_seven_pixel_ids):
Expand Down Expand Up @@ -143,7 +172,7 @@ def lixel_in_region_of_interest(

coll = PolyCollection(
not_colored_polygons,
facecolors=["w" for _ in range(len(not_colored_polygons))],
facecolors=[backc for _ in range(len(not_colored_polygons))],
edgecolors="gray",
linewidths=linewidths,
)
Expand All @@ -157,7 +186,7 @@ def lixel_in_region_of_interest(
y=_y,
r_outer=eye_outer_radius_m,
orientation_deg=0,
color="black",
color=stroke,
linestyle="-",
linewidth=linewidths * 2,
)
Expand All @@ -179,15 +208,15 @@ def lixel_in_region_of_interest(
N=9,
linewidth=4.7,
color=irf.summary.figure.COLOR_BEAM_RGBA,
alpha=0.2,
alpha=BEAM_ALPHA,
)
ax2.plot(
[
-1,
1,
],
[-0.1, -0.1],
color="white",
color=backc,
linewidth=10,
alpha=1.0,
)
Expand All @@ -197,7 +226,7 @@ def lixel_in_region_of_interest(
1.0,
],
[0, 0],
color="k",
color=stroke,
linewidth=0.5 * linewidths,
)

Expand All @@ -213,7 +242,9 @@ def lixel_in_region_of_interest(
fig.savefig(
os.path.join(
paths["out_dir"],
"refocus_lixel_summation_7_{obj:d}.jpg".format(obj=obj),
"refocus_lixel_summation_7_{obj:d}{ext:s}".format(
obj=obj, ext=EXT
),
)
)
seb.close("all")
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,39 @@
import json_utils
import numpy as np
import sebastians_matplotlib_addons as seb
from plenopy.light_field_geometry.LightFieldGeometry import init_lixel_polygons

argv = irf.summary.argv_since_py(sys.argv)
pa = irf.summary.paths_from_argv(argv)
DARKMODE = False
rrr = 1

sum_config = irf.summary.read_summary_config(summary_dir=paths["analysis_dir"])
seb.matplotlib.rcParams.update(sum_config["plot"]["matplotlib"])
paths = irf.summary.paths_from_argv(sys.argv)
res = irf.summary.Resources.from_argv(sys.argv)
os.makedirs(paths["out_dir"], exist_ok=True)

if DARKMODE:
seb.plt.style.use("dark_background")
stroke = "white"
EXT = ".dark.png"
cmap = "binary_r"
else:
EXT = ".jpg"
stroke = "black"
cmap = "binary"

seb.matplotlib.rcParams.update(res.analysis["plot"]["matplotlib"])

AXES_STYLE = {"spines": ["left", "bottom"], "axes": ["x", "y"], "grid": False}

os.makedirs(paths["out_dir"], exist_ok=True)

light_field_geometry = pl.LightFieldGeometry(
os.path.join(paths["plenoirf_dir"], "light_field_geometry")
os.path.join(
paths["plenoirf_dir"],
"plenoptics",
"instruments",
res.instrument_key,
"light_field_geometry",
)
)

OBJECT_DISTANCE = 999e3
Expand Down Expand Up @@ -86,14 +106,16 @@

ROI_RADIUS = 0.35

lixel_polygons = pl.light_field_geometry.init_lixel_polygons(
lixel_polygons = init_lixel_polygons(
lixel_positions_x=light_field_geometry.lixel_positions_x,
lixel_positions_y=light_field_geometry.lixel_positions_y,
lixel_outer_radius=light_field_geometry.lixel_outer_radius,
)

for pixel in pixels:
fig = seb.figure(style={"rows": 360, "cols": 360, "fontsize": 0.7})
fig = seb.figure(
style={"rows": 360 * rrr, "cols": 360 * rrr, "fontsize": 0.7 * rrr}
)
ax = seb.add_axes(fig=fig, span=[0.0, 0.0, 1, 1], style=AXES_STYLE)

_x, _y = pixel["mean_position_of_photosensors_on_sensor_plane"]
Expand All @@ -102,6 +124,7 @@

poseye = irf.summary.figure.positions_of_eyes_in_roi(
light_field_geometry=light_field_geometry,
lixel_polygons=lixel_polygons,
roi={"x": xlim, "y": ylim},
margin=0.2,
)
Expand All @@ -110,7 +133,7 @@
polygons=lixel_polygons,
I=pixel["photosensor_mask"],
ax=ax,
cmap="binary",
cmap=cmap,
edgecolors="grey",
linewidths=0.33,
xlim=xlim,
Expand All @@ -125,7 +148,7 @@
y=_y,
r_outer=eye_outer_radius_m,
orientation_deg=0,
color="black",
color=stroke,
linestyle="-",
linewidth=0.5,
)
Expand All @@ -145,16 +168,18 @@
fig.savefig(
os.path.join(
paths["out_dir"],
"aberration_pixel_{pixel:0d}_{angle:0d}mdeg.jpg".format(
pixel=pixel["id"], angle=off_axis_angle_mdeg
"aberration_pixel_{pixel:0d}_{angle:0d}mdeg{ext:s}".format(
pixel=pixel["id"], angle=off_axis_angle_mdeg, ext=EXT
),
),
)
seb.close("all")

# plot all pixels overview
# -------------------------
fig = fig = seb.figure(style={"rows": 720, "cols": 720, "fontsize": 0.7})
fig = fig = seb.figure(
style={"rows": 720 * rrr, "cols": 720 * rrr, "fontsize": 0.7 * rrr}
)
ax = seb.add_axes(fig=fig, span=[0.16, 0.16, 0.82, 0.82])

overview_photosensor_mask = np.zeros(
Expand All @@ -167,13 +192,14 @@
polygons=lixel_polygons,
I=overview_photosensor_mask,
ax=ax,
cmap="binary",
cmap=cmap,
edgecolors="grey",
linewidths=(0.02,),
)

poseye = irf.summary.figure.positions_of_eyes_in_roi(
light_field_geometry=light_field_geometry,
lixel_polygons=lixel_polygons,
roi={"x": [-10, 10], "y": [-10, 10]},
margin=0.2,
)
Expand All @@ -186,7 +212,7 @@
y=_y,
r_outer=eye_outer_radius_m,
orientation_deg=0,
color="black",
color=stroke,
linestyle="-",
alpha=0.5,
linewidth=0.2,
Expand Down Expand Up @@ -222,7 +248,7 @@
ax.set_xlabel("$x\\,/\\,$m")
ax.set_ylabel("$y\\,/\\,$m")

fig.savefig(os.path.join(paths["out_dir"], "aberration_overview.jpg"))
fig.savefig(os.path.join(paths["out_dir"], "aberration_overview" + EXT))
seb.close("all")

# export table
Expand Down

0 comments on commit c546c6e

Please sign in to comment.