Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to get point on shower axis in altaz #2537

Merged
merged 8 commits into from Apr 24, 2024
Merged

Conversation

maxnoe
Copy link
Member

@maxnoe maxnoe commented Apr 22, 2024

This can be used to compute the shower axis in telescope / camera frame, e.g. like this:

import astropy.units as u
from astropy.coordinates import AltAz
import matplotlib.pyplot as plt

from ctapipe.calib import CameraCalibrator
from ctapipe.io import EventSource
from ctapipe.coordinates import get_point_on_shower_axis, TelescopeFrame
from ctapipe.visualization import CameraDisplay


plt.style.use("dark_background")
plt.rcParams["savefig.facecolor"] = "0.15"

path = "dataset://lst_prod3_calibration_and_mcphotons.simtel.zst"

if __name__ == "__main__":
    with EventSource(path, focal_length_choice="EQUIVALENT") as source:
        it = iter(source)
        for _ in range(2):
            e = next(it)
        subarray = source.subarray

    calib = CameraCalibrator(subarray)
    calib(e)

    shower = e.simulation.shower
    distance = 5 * u.km

    fig, axs = plt.subplots(2, 2, layout="constrained", figsize=(8, 8))

    telescope_positions = source.subarray.tel_coords
    axis_point = get_point_on_shower_axis(
        core_x=shower.core_x,
        core_y=shower.core_y,
        alt=shower.alt,
        az=shower.az,
        telescope_position=telescope_positions,
        distance=distance,
    )

    for ax, (tel_id, dl1) in zip(axs.flat, e.dl1.tel.items()):
        tel_index = source.subarray.tel_ids_to_indices(tel_id)[0]

        pointing = AltAz(
            alt=e.pointing.tel[tel_id].altitude, az=e.pointing.tel[tel_id].azimuth
        )
        tel_frame = TelescopeFrame(telescope_pointing=pointing)

        geometry = source.subarray.tel[tel_id].camera.geometry
        disp = CameraDisplay(geometry.transform_to(tel_frame), image=dl1.image, ax=ax)

        ax.set_title(f"LST-{tel_id}")
        ax.set_axis_off()
        ax.set_ylabel("")
        ax.set_xlabel("")

        source_tel_frame = AltAz(alt=shower.alt, az=shower.az).transform_to(tel_frame)
        p = axis_point[tel_index].transform_to(tel_frame)

        disp.axes.plot(
            [source_tel_frame.fov_lon.deg, p.fov_lon.deg],
            [source_tel_frame.fov_lat.deg, p.fov_lat.deg],
            color="xkcd:baby blue",
            marker=".",
        )
        disp.overlay_coordinate(source_tel_frame, color="xkcd:light yellow")

    fig.suptitle(
        f"$E={{}}${shower.energy.to(u.GeV):.0f}, Impact = ({shower.core_x:.0f}, {shower.core_y:.0f})"
    )

    plt.savefig("shower_axis.png", dpi=200)

shower_axis

@maxnoe maxnoe added this to the v0.21.0 milestone Apr 22, 2024
@maxnoe maxnoe requested review from kosack and moralejo April 22, 2024 11:50

This comment has been minimized.

1 similar comment

This comment has been minimized.

This comment has been minimized.

moralejo
moralejo previously approved these changes Apr 22, 2024
Copy link
Contributor

@moralejo moralejo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Can you show an example with larger images?

src/ctapipe/coordinates/ground_frames.py Outdated Show resolved Hide resolved
@maxnoe
Copy link
Member Author

maxnoe commented Apr 22, 2024

Looks good to me. Can you show an example with larger images?

Here is a 5 TeV shower:

impact_5tev

@maxnoe
Copy link
Member Author

maxnoe commented Apr 23, 2024

This is at the moment relatively slow (using this for Algorithm 6 of the reconstruction comparison paper takes around 400 ms per event) but most time is spent in astropy coordinate transformations, which is directly affected by a patch made to improve performance there in the next astropy release.

@moralejo
Copy link
Contributor

moralejo commented Apr 23, 2024

Looks good to me. Can you show an example with larger images?

Here is a 5 TeV shower:

Thanks, the lower-E one was not so convincing because the pixelation on small images makes the effect of a misalignment, but this one looks very convincing.

This comment has been minimized.

Copy link

Passed

Analysis Details

0 Issues

  • Bug 0 Bugs
  • Vulnerability 0 Vulnerabilities
  • Code Smell 0 Code Smells

Coverage and Duplications

  • Coverage 100.00% Coverage (92.80% Estimated after merge)
  • Duplications 0.00% Duplicated Code (0.70% Estimated after merge)

Project ID: cta-observatory_ctapipe_AY52EYhuvuGcMFidNyUs

View in SonarQube

@maxnoe maxnoe requested a review from moralejo April 24, 2024 14:19
@maxnoe maxnoe merged commit 7216207 into main Apr 24, 2024
12 checks passed
@maxnoe maxnoe deleted the shower_axis_point branch April 24, 2024 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants