diff --git a/plenoirf/summary/figure.py b/plenoirf/summary/figure.py index 15040af..3b7c51e 100644 --- a/plenoirf/summary/figure.py +++ b/plenoirf/summary/figure.py @@ -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} @@ -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 = [] @@ -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 diff --git a/plenoirf/summary/scripts/0212_trajectory_debugging_with_example_events.py b/plenoirf/summary/scripts/0212_trajectory_debugging_with_example_events.py index 1a4ba5c..20854f3 100644 --- a/plenoirf/summary/scripts/0212_trajectory_debugging_with_example_events.py +++ b/plenoirf/summary/scripts/0212_trajectory_debugging_with_example_events.py @@ -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 + ) ) diff --git a/plenoirf/summary/scripts/1100_plot_summation_lixels_into_seven_pixels.py b/plenoirf/summary/scripts/1100_plot_summation_lixels_into_seven_pixels.py index ebb0c5a..f09b71e 100644 --- a/plenoirf/summary/scripts/1100_plot_summation_lixels_into_seven_pixels.py +++ b/plenoirf/summary/scripts/1100_plot_summation_lixels_into_seven_pixels.py @@ -5,20 +5,45 @@ 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]} @@ -26,7 +51,7 @@ 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 @@ -56,7 +81,7 @@ 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, @@ -64,22 +89,25 @@ def lixel_in_region_of_interest( ) +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 ) @@ -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): @@ -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, ) @@ -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, ) @@ -179,7 +208,7 @@ 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( [ @@ -187,7 +216,7 @@ def lixel_in_region_of_interest( 1, ], [-0.1, -0.1], - color="white", + color=backc, linewidth=10, alpha=1.0, ) @@ -197,7 +226,7 @@ def lixel_in_region_of_interest( 1.0, ], [0, 0], - color="k", + color=stroke, linewidth=0.5 * linewidths, ) @@ -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") diff --git a/plenoirf/summary/scripts/1110_plot_summation_photo_sensors_into_pixels_to_compensate_aberrations.py b/plenoirf/summary/scripts/1110_plot_summation_photo_sensors_into_pixels_to_compensate_aberrations.py index 63a0f06..b0fdc30 100644 --- a/plenoirf/summary/scripts/1110_plot_summation_photo_sensors_into_pixels_to_compensate_aberrations.py +++ b/plenoirf/summary/scripts/1110_plot_summation_photo_sensors_into_pixels_to_compensate_aberrations.py @@ -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 @@ -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"] @@ -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, ) @@ -110,7 +133,7 @@ polygons=lixel_polygons, I=pixel["photosensor_mask"], ax=ax, - cmap="binary", + cmap=cmap, edgecolors="grey", linewidths=0.33, xlim=xlim, @@ -125,7 +148,7 @@ y=_y, r_outer=eye_outer_radius_m, orientation_deg=0, - color="black", + color=stroke, linestyle="-", linewidth=0.5, ) @@ -145,8 +168,8 @@ 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 ), ), ) @@ -154,7 +177,9 @@ # 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( @@ -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, ) @@ -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, @@ -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