How to use the ctapipe.utils.datasets.get_dataset_path function in ctapipe

To help you get started, we’ve selected a few ctapipe examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cta-observatory / ctapipe / examples / plot_theta_square.py View on Github external
from astropy.coordinates.angle_utilities import angular_separation
from astropy.coordinates import SkyCoord, AltAz

from ctapipe.calib import CameraCalibrator
from ctapipe.image import hillas_parameters
from ctapipe.image import tailcuts_clean
from ctapipe.io import event_source
from ctapipe.reco import HillasReconstructor
from ctapipe.utils import datasets


if len(sys.argv) >= 2:
    filename = sys.argv[1]
else:
    # importing data from available datasets in ctapipe
    filename = datasets.get_dataset_path("gamma_test_large.simtel.gz")


# reading the Monte Carlo file for LST
source = event_source(filename, allowed_tels={1, 2, 3, 4})

reco = HillasReconstructor()
calib = CameraCalibrator(subarray=source.subarray)

horizon_frame = AltAz()

off_angles = []

for event in source:

    # calibrating the event
    calib(event)
github cta-observatory / ctapipe / examples / stereo_reconstruction.py View on Github external
from ctapipe.utils.datasets import get_dataset_path

import matplotlib.pyplot as plt
from ctapipe.visualization import ArrayDisplay


# unoptimized cleaning levels, copied from
# https://github.com/tudo-astroparticlephysics/cta_preprocessing
cleaning_level = {
    "LSTCam": (3.5, 7.5, 2),  # ?? (3, 6) for Abelardo...
    "FlashCam": (4, 8, 2),  # there is some scaling missing?
    "ASTRICam": (5, 7, 2),
}


input_url = get_dataset_path("gamma_test_large.simtel.gz")
event_source = event_source(input_url)

calibrator = CameraCalibrator(subarray=event_source.subarray)
horizon_frame = AltAz()

reco = HillasReconstructor()

for event in event_source:
    print("Event", event.count)
    calibrator(event)

    # mapping of telescope_id to parameters for stereo reconstruction
    hillas_containers = {}

    time_gradients = {}
github cta-observatory / ctapipe / examples / array_layout.py View on Github external
import matplotlib.pylab as plt
from astropy.table import Table
from numpy import ones_like

from ctapipe.utils import datasets
from ctapipe.visualization import ArrayDisplay

if __name__ == '__main__':

    plt.style.use("ggplot")
    plt.figure(figsize=(9.5, 8.5))

    # load up an example table that has the telescope positions and
    # mirror areas in it:
    arrayfile = datasets.get_dataset_path("PROD2_telconfig.fits.gz")
    tels = Table.read(arrayfile, hdu="TELESCOPE_LEVEL0")

    X = tels['TelX']
    Y = tels['TelY']
    A = tels['MirrorArea'] * 2  # exaggerate scale a bit

    # display the array, and set the color value to 50
    ad = ArrayDisplay(X, Y, A, title="Prod 2 Full Array")
    ad.values = ones_like(X) * 50

    # label them
    for tel in tels:
        name = "CT{tid}".format(tid=tel['TelID'])
        plt.text(tel['TelX'], tel['TelY'], name, fontsize=8)

    ad.axes.set_xlim(-1000, 1000)
github cta-observatory / ctapipe / examples / plot_showers_in_nominal.py View on Github external
import warnings

from ctapipe.coordinates import CameraFrame, NominalFrame, MissingFrameAttributeWarning


warnings.filterwarnings("ignore", category=MissingFrameAttributeWarning)


cleaning_level = {
    "LSTCam": (3.5, 7.5, 2),  # ?? (3, 6) for Abelardo...
    "FlashCam": (4, 8, 2),  # there is some scaling missing?
    "ASTRICam": (5, 7, 2),
}


input_url = get_dataset_path("gamma_test_large.simtel.gz")


with event_source(input_url=input_url) as source:
    calibrator = CameraCalibrator(subarray=source.subarray)

    for event in source:

        calibrator(event)

        nominal_frame = NominalFrame(
            origin=SkyCoord(alt=70 * u.deg, az=0 * u.deg, frame=AltAz)
        )

        nom_fov_lon = []
        nom_fov_lat = []
        photons = []
github cta-observatory / ctapipe / examples / plot_array_hillas.py View on Github external
from astropy import units as u

from ctapipe.calib import CameraCalibrator
from ctapipe.coordinates import TiltedGroundFrame, MissingFrameAttributeWarning
from ctapipe.image import hillas_parameters, tailcuts_clean, HillasParameterizationError
from ctapipe.image import timing_parameters
from ctapipe.io import event_source
from ctapipe.utils import datasets
from ctapipe.visualization import ArrayDisplay
import warnings

if __name__ == "__main__":
    warnings.filterwarnings("ignore", category=MissingFrameAttributeWarning)

    # importing data from avaiable datasets in ctapipe
    filename = datasets.get_dataset_path("gamma_test_large.simtel.gz")

    if len(sys.argv) > 1:
        filename = sys.argv[1]

    # reading the Monte Carlo file for LST
    source = event_source(filename)

    # pointing direction of the telescopes
    point_azimuth = {}
    point_altitude = {}

    subarray = source.subarray
    calib = CameraCalibrator(subarray=subarray)
    off_angles = []
    first_event = True
    markers = None
github cta-observatory / ctapipe / ctapipe / tools / info.py View on Github external
print("\n*** ctapipe resources ***\n")
    print("CTAPIPE_SVC_PATH: (directories where resources are searched)")
    if os.getenv("CTAPIPE_SVC_PATH") is not None:
        for directory in datasets.get_searchpath_dirs():
            print(f"\t * {directory}")
    else:
        print("\t no path is set")
    print("")

    all_resources = sorted(datasets.find_all_matching_datasets(r"\w.*"))
    locations = [
        os.path.dirname(datasets.get_dataset_path(name)) for name in all_resources
    ]
    home = os.path.expanduser("~")
    resource_dir = os.path.dirname(datasets.get_dataset_path("HESS-I.camgeom.fits.gz"))

    fmt = "{name:<30.30s} : {loc:<30.30s}"
    print(fmt.format(name="RESOURCE NAME", loc="LOCATION"))
    print("-" * 70)
    for name, loc in zip(all_resources, locations):
        if name.endswith(".py") or name.startswith("_"):
            continue
        loc = loc.replace(resource_dir, "[ctapipe_resources]")
        loc = loc.replace(home, "~")
        print(fmt.format(name=name, loc=loc))
github cta-observatory / ctapipe / ctapipe / tools / info.py View on Github external
def _info_resources():
    """ display all known resources """

    print("\n*** ctapipe resources ***\n")
    print("CTAPIPE_SVC_PATH: (directories where resources are searched)")
    if os.getenv("CTAPIPE_SVC_PATH") is not None:
        for directory in datasets.get_searchpath_dirs():
            print(f"\t * {directory}")
    else:
        print("\t no path is set")
    print("")

    all_resources = sorted(datasets.find_all_matching_datasets(r"\w.*"))
    locations = [
        os.path.dirname(datasets.get_dataset_path(name)) for name in all_resources
    ]
    home = os.path.expanduser("~")
    resource_dir = os.path.dirname(datasets.get_dataset_path("HESS-I.camgeom.fits.gz"))

    fmt = "{name:<30.30s} : {loc:<30.30s}"
    print(fmt.format(name="RESOURCE NAME", loc="LOCATION"))
    print("-" * 70)
    for name, loc in zip(all_resources, locations):
        if name.endswith(".py") or name.startswith("_"):
            continue
        loc = loc.replace(resource_dir, "[ctapipe_resources]")
        loc = loc.replace(home, "~")
        print(fmt.format(name=name, loc=loc))
github cta-observatory / ctapipe / examples / array_display.py View on Github external
import matplotlib.pylab as plt
import numpy as np
from astropy import units as u

from ctapipe.io import event_source
from ctapipe.utils import datasets
from ctapipe.visualization import ArrayDisplay

if __name__ == "__main__":

    plt.figure(figsize=(9.5, 8.5))

    # load up a single event, so we can get the subarray info:
    source = event_source(
        datasets.get_dataset_path("gamma_test_large.simtel.gz"), max_events=1,
    )

    event = next(iter(source))

    # display the array
    subarray = source.subarray
    ad = ArrayDisplay(subarray, tel_scale=3.0)

    print("Now setting vectors")
    plt.pause(1.0)
    plt.tight_layout()

    for phi in np.linspace(0, 360, 30) * u.deg:
        r = 200 * np.cos(phi / 2) * u.m
        ad.set_vector_rho_phi(r, phi)
        plt.pause(0.01)