Exemple #1
0
def _info_resources():
    """ display all known resources """

    print('\n*** ctapipe resources ***\n')

    print("ctapipe_resources version: {}".format(
        ctapipe_resources.__version__))

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

    all_resources = sorted(datasets.find_all_matching_datasets("\w.*"))
    locations = [
        os.path.dirname(datasets.get_dataset(name)) for name in all_resources
    ]
    home = os.path.expanduser("~")
    resource_dir = os.path.dirname(
        datasets.get_dataset("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))
Exemple #2
0
def test_datasets_in_custom_path(tmpdir_factory):
    """
    check that a dataset in a user-defined CTAPIPE_SVC_PATH is located
    """

    tmpdir1 = tmpdir_factory.mktemp('datasets1')
    tmpdir2 = tmpdir_factory.mktemp('datasets2')
    os.environ['CTAPIPE_SVC_PATH'] = ":".join([str(tmpdir1), str(tmpdir2)])

    # create a dummy dataset to search for:

    dataset_name = "test_dataset_1.txt"
    dataset_path = str(tmpdir1.join(dataset_name))

    with open(dataset_path, "w") as fp:
        fp.write("test test test")

    # try to find dummy dataset
    path = datasets.get_dataset(dataset_name)
    assert path == dataset_path

    with pytest.raises(FileNotFoundError):
        badpath = datasets.get_dataset("does_not_exist")

    # try using find_all_matching_datasets:

    ds = datasets.find_all_matching_datasets(
        "test.*", searchpath=os.environ['CTAPIPE_SVC_PATH'])
    assert dataset_name in ds
Exemple #3
0
def _info_resources():
    """ display all known resources """

    print('\n*** ctapipe resources ***\n')

    print("ctapipe_resources version: {}".format(ctapipe_resources.__version__))

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

    all_resources = sorted(datasets.find_all_matching_datasets("\w.*"))
    locations = [os.path.dirname(datasets.get_dataset(name))
                 for name in all_resources]
    home = os.path.expanduser("~")
    resource_dir = os.path.dirname(datasets.get_dataset(
        "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))
Exemple #4
0
def test_find_datasets():

    # find all datasets matching pattern
    r = datasets.find_all_matching_datasets("(.*)\.camgeom\.fits\.gz")
    assert len(r) > 3

    # get the full filename for a resrouces
    assert os.path.exists(datasets.get_dataset(r[0]))

    # try using a pattern
    r = datasets.find_all_matching_datasets("(.*)\.camgeom\.fits\.gz",
                                            regexp_group=1)
    assert not r[0].endswith("gz")
    print("============================================")
    print("n or [enter]    - go to Next event")
    print("d               - Display the event")
    print("p               - Print all event data")
    print("i               - event Info")
    print("s               - save event image")
    print("q               - Quit")
    return input("Choice: ")


if __name__ == '__main__':

    if len(sys.argv) > 1:
        filename = sys.argv.pop(1)
    else:
        filename = get_dataset("gamma_test_large.simtel.gz")

    plt.style.use("ggplot")
    plt.show(block=False)

    # loop over events and display menu at each event:
    source = event_source(filename)

    for event in source:

        print("EVENT_ID: ", event.r0.event_id, "TELS: ",
              event.r0.tels_with_data, "MC Energy:", event.mc.energy)

        while True:
            response = get_input()
            if response.startswith("d"):
from pywicta.denoising import inverse_transform_sampling
from pywicta.denoising.inverse_transform_sampling import EmpiricalDistribution

import ctapipe
from ctapipe.utils.datasets import get_dataset

###############################################################################
# Ignore warnings.

import warnings
warnings.filterwarnings('ignore')

###############################################################################
# Get images from ctapipe embedded datasets.

SIMTEL_FILE = get_dataset('gamma_test_large.simtel.gz')

###############################################################################
# Choose the instrument to use.

#cam_id = None
#cam_id = "ASTRICam"
#cam_id = "CHEC"
#cam_id = "DigiCam"
#cam_id = "FlashCam"
#cam_id = "NectarCam"
cam_id = "LSTCam"

###############################################################################
# Configure the trace integration as in the CTA Mars analysis.
Exemple #7
0
#!/usr/bin/env python3

import numpy as np
from astropy.table import Table
from matplotlib import pyplot as plt

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

if __name__ == '__main__':

    plt.style.use("ggplot")
    plt.figure(figsize=(10, 8))

    arrayfile = datasets.get_dataset("PROD2_telconfig.fits.gz")
    tels = Table.read(arrayfile, hdu="TELESCOPE_LEVEL0")

    adisp = ArrayDisplay(tels['TelX'],
                         tels['TelY'],
                         tels['MirrorArea'] * 2,
                         title='PROD2 telescopes',
                         autoupdate=True)
    plt.tight_layout()

    values = np.zeros(len(tels))

    # do a small animation to show various trigger patterns:

    for ii in range(20):

        # generate a random trigger pattern and integrated intensity:
Exemple #8
0
#!/usr/bin/env python3

import numpy as np
from astropy.table import Table
from ctapipe.utils import datasets
from ctapipe.visualization import ArrayDisplay
from matplotlib import pyplot as plt


if __name__ == '__main__':

    plt.style.use("ggplot")
    plt.figure(figsize=(10, 8))

    arrayfile = datasets.get_dataset("PROD2_telconfig.fits.gz")
    tels = Table.read(arrayfile, hdu="TELESCOPE_LEVEL0")

    adisp = ArrayDisplay(tels['TelX'], tels['TelY'], tels['MirrorArea'] * 2,
                         title='PROD2 telescopes', autoupdate=True)
    plt.tight_layout()

    values = np.zeros(len(tels))

    # do a small animation to show various trigger patterns:

    for ii in range(20):

        # generate a random trigger pattern and integrated intensity:
        ntrig = np.random.poisson(10)
        trigmask = np.random.random_integers(len(tels) - 1, size=ntrig)
        values[:] = 0