Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
273 changes: 176 additions & 97 deletions notebooks/Access NectarCAM data using DIRAC API.ipynb

Large diffs are not rendered by default.

63 changes: 36 additions & 27 deletions notebooks/Access NectarCAM data using DIRAC API.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,52 @@
# format_version: '1.3'
# jupytext_version: 1.14.6
# kernelspec:
# display_name: nectarchain-ctapipe0.19
# display_name: Python 3 (ipykernel)
# language: python
# name: nectarchain-ctapipe0.19
# name: python3
# ---

# %% [markdown]
# # How to access NectarCAM data from the EGI grid directly using the DIRAC API ?
#
# In this short notebook, we will see how to access data stored on the grid using the
# DIRAC API, without the hassle of first manually downloading them locally.
# In this short notebook, we will see how to access data stored on the grid using the DIRAC API, without the hassle of first manually downloading them locally.
#
# In order to achieve this, you will obviously need a `conda` environment in which
# all relevant code is installed, such as `ctapipe`, `nectarchain`, but also
# `CTADIRAC` itself. Please refer to the `nectarchain` installation procedure at
# <https://github.com/cta-observatory/nectarchain> and follow the instructions to
# enable DIRAC support.
# In order to achieve this, you will obviously need a `conda` environment in which all relevant code is installed, such as `ctapipe`, `nectarchain`, but also `CTADIRAC` itself. Please refer to the
# `nectarchain` installation procedure at <https://github.com/cta-observatory/nectarchain> and follow the instructions to enable DIRAC support.
#
# You will also need to have an active proxy for EGI, initialized e.g. with:
#
# ```
# dirac-proxy-init -M -g cta_nectarcam
# ```
#
# You can also check whether you currently have an active proxy with the command
# `dirac-proxy-info`.
# You can also check whether you currently have an active proxy with the command `dirac-proxy-info`.

# %%
import os
from glob import glob

from ctapipe.coordinates import EngineeringCameraFrame
from ctapipe.instrument import CameraGeometry
from ctapipe.io import EventSeeker, EventSource
from ctapipe.visualization import CameraDisplay

# %%
# %matplotlib inline
from DIRAC.Interfaces.API.Dirac import Dirac

# %%
dirac = Dirac()

# %%
# dirac.getFile?
# ?dirac.getFile

# %%
lfns = [
"/vo.cta.in2p3.fr/nectarcam/2022/20220411/NectarCAM.Run3169.0000.fits.fz",
"/vo.cta.in2p3.fr/nectarcam/2022/20220411/NectarCAM.Run3169.0001.fits.fz",
"/vo.cta.in2p3.fr/nectarcam/2025/20250107/NectarCAM.Run5922.0000.fits.fz",
"/vo.cta.in2p3.fr/nectarcam/2025/20250107/NectarCAM.Run5922.0001.fits.fz",
"/vo.cta.in2p3.fr/nectarcam/2025/20250107/NectarCAM.Run5922.0002.fits.fz",
"/vo.cta.in2p3.fr/nectarcam/2025/20250107/NectarCAM.Run5922.0003.fits.fz",
"/vo.cta.in2p3.fr/nectarcam/2025/20250107/NectarCAM.Run5922.0004.fits.fz",
"/vo.cta.in2p3.fr/nectarcam/2025/20250107/NectarCAM.Run5922.0005.fits.fz",
"/vo.cta.in2p3.fr/nectarcam/2025/20250107/NectarCAM.Run5922.0006.fits.fz",
"/vo.cta.in2p3.fr/nectarcam/2025/20250107/NectarCAM.Run5922.0007.fits.fz",
]

# %%
tmpdir = f"/tmp/{os.environ['USER']}/scratch"
import os

tmpdir = f"/tmp/{os.environ['USER']}/scratch/runs"
if not os.path.isdir(tmpdir):
print(f"{tmpdir} does not exist yet, I will create it for you")
os.makedirs(tmpdir)
Expand All @@ -71,13 +64,24 @@
# **You are now ready to work with `ctapipe` as usual!**

# %%
# %matplotlib inline
import numpy as np
from matplotlib import pyplot as plt

from ctapipe.coordinates import EngineeringCameraFrame
from ctapipe.io import EventSource, EventSeeker
from ctapipe.instrument import CameraGeometry
from ctapipe.visualization import CameraDisplay

# %%
from glob import glob

path = glob(f"{tmpdir}/NectarCAM.*.fits.fz")
path.sort()
reader = EventSource(input_url=path[0])
seeker = EventSeeker(reader)

# Get some event, and display camera charges for the high gain channel
# (no time window optimization)
# Get some event, and display camera charges for the high gain channel (no time window optimization)
evt = seeker.get_event_index(10)
image = evt.r0.tel[0].waveform.sum(axis=2)
camera = CameraGeometry.from_name("NectarCam-003").transform_to(
Expand All @@ -86,3 +90,8 @@
disp = CameraDisplay(geometry=camera, image=image[0])

# %%
reader

# %%

# %%
46,476 changes: 46,384 additions & 92 deletions notebooks/Read_NectarCAM_events.ipynb

Large diffs are not rendered by default.

Loading