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

MCP upgrades: semi-automatic scripts and update of the current scripts (1 LST -> 4 LSTs); Torino team #154

Merged
merged 77 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
72cdd35
DL0 to DL1 reduction
ranieremenezes Sep 26, 2023
f93a73a
Add files via upload
ranieremenezes Sep 26, 2023
a22c872
Add files via upload
ranieremenezes Sep 26, 2023
d9c69d8
"Merge" with master
Elisa-Visentin Sep 26, 2023
493ad1c
remove duplicate function (io, gadf)
Elisa-Visentin Sep 27, 2023
37027e3
pyflakes
Elisa-Visentin Sep 27, 2023
89cac19
trying to fix tests
Elisa-Visentin Sep 27, 2023
ea94f71
Try to fix tests
Elisa-Visentin Sep 27, 2023
7fb3dc3
tests
Elisa-Visentin Sep 27, 2023
8d8849f
Fix test functions
Elisa-Visentin Sep 27, 2023
14786b9
pyflakes
Elisa-Visentin Sep 27, 2023
c0395e5
readme + bug
Elisa-Visentin Sep 27, 2023
ef7822b
test (gamma combo_types)
Elisa-Visentin Sep 27, 2023
31aa48c
use pre-offset search in automatic script
Elisa-Visentin Sep 27, 2023
19760ac
Fixed tests (now they don't fail, locally)
Elisa-Visentin Sep 27, 2023
f2f634d
Update README.md
ranieremenezes Sep 27, 2023
332500d
Updated README
ranieremenezes Sep 27, 2023
e2c6c31
failed git test
Elisa-Visentin Sep 27, 2023
24cbdf6
Remove commented functions + remove get_stereo()
Elisa-Visentin Sep 28, 2023
93d729a
config.yaml default
Elisa-Visentin Sep 28, 2023
fe69420
LST_version
Elisa-Visentin Sep 28, 2023
517a046
calib module for Calibration functions
Elisa-Visentin Sep 28, 2023
75093a6
Focal length (MCs)
Elisa-Visentin Sep 28, 2023
756782e
Config and scripts paths + setup.py
Elisa-Visentin Sep 28, 2023
cded8f5
partial analysis
Elisa-Visentin Sep 28, 2023
5313599
Bug
Elisa-Visentin Sep 28, 2023
0913458
config file in resources
Elisa-Visentin Sep 28, 2023
c487e0d
readme and resources
Elisa-Visentin Sep 28, 2023
2bdf63b
README + analysis_type + 'with open...'
Elisa-Visentin Oct 2, 2023
10e8849
env name, minor fixes
Elisa-Visentin Oct 2, 2023
85dbbb6
minor fixes
Elisa-Visentin Oct 2, 2023
76fb3fd
f_string
Elisa-Visentin Oct 2, 2023
0911807
f-string
Elisa-Visentin Oct 2, 2023
273690b
Console scripts in bash
Elisa-Visentin Oct 2, 2023
5f96f5b
Calibration docstring
Elisa-Visentin Oct 2, 2023
174e377
Fixed Calibrate_LST (input)
Elisa-Visentin Oct 2, 2023
9923e48
Bug
Elisa-Visentin Oct 2, 2023
972ee8d
one single Calibrate function
Elisa-Visentin Oct 2, 2023
1a486e4
Bug (bash scripts)
Elisa-Visentin Oct 3, 2023
733afad
Writing bash script with writelines()
ranieremenezes Oct 3, 2023
aaaa867
List of functions in alphabetical order
ranieremenezes Oct 3, 2023
06e3f6c
List of functions in alphabetical order
ranieremenezes Oct 3, 2023
5d24322
List of functions in alphabetical order
ranieremenezes Oct 3, 2023
9a56f9e
List of functions in alphabetical order
ranieremenezes Oct 3, 2023
937f025
Standardized inline comments
ranieremenezes Oct 3, 2023
69e7b6f
Moved IT scripts to a different folder
Elisa-Visentin Oct 3, 2023
c5cfff6
Moving tutorial
Elisa-Visentin Oct 3, 2023
da99132
Update README.md
ranieremenezes Oct 3, 2023
cd9b396
Remove IT scripts
Elisa-Visentin Oct 4, 2023
e0756c5
Calibrate (MAGIC & LST)
Elisa-Visentin Oct 4, 2023
ece3300
Minor fixes + calib Docstring
Elisa-Visentin Oct 4, 2023
69ca7c1
calib exception (+ minor fixes)
Elisa-Visentin Oct 4, 2023
ee00aaa
Bug
Elisa-Visentin Oct 4, 2023
8c9a75c
Update ci.yml
Elisa-Visentin Oct 5, 2023
b47ee02
Minor fixes + test tel. combinations
Elisa-Visentin Oct 5, 2023
03d5cbb
removed max_multiplicity in get_stereo
Elisa-Visentin Oct 5, 2023
334ed6d
tests
Elisa-Visentin Oct 6, 2023
bb44aff
minor fixes
Elisa-Visentin Oct 6, 2023
db0f298
bug
Elisa-Visentin Oct 6, 2023
6f8223c
Bug calib function
Elisa-Visentin Oct 6, 2023
d6ab37f
Bug magic-only
Elisa-Visentin Oct 6, 2023
52d6222
fixed test
Elisa-Visentin Oct 6, 2023
03f6e98
updated config files
ranieremenezes Oct 6, 2023
8de7c67
Info on high level analysis in README
ranieremenezes Oct 6, 2023
183da71
Tel. name exception
Elisa-Visentin Oct 6, 2023
7dce9ba
calib: test + bug fix
Elisa-Visentin Oct 6, 2023
15376a5
tel_positions
Elisa-Visentin Oct 7, 2023
ff8ee4a
Check if the input telescope list is fine
ranieremenezes Oct 9, 2023
b604768
New function to check telescope list
ranieremenezes Oct 9, 2023
cf92a25
Just fixing a typo
ranieremenezes Oct 9, 2023
48ae576
Minor fixes
Elisa-Visentin Oct 12, 2023
93c6dd7
Minor fixes+tests (check_list, tel-wise training)
Elisa-Visentin Oct 13, 2023
f4fde0f
Output file name
Elisa-Visentin Oct 13, 2023
4ff0885
Pyflakes error
Elisa-Visentin Oct 13, 2023
fff4a84
calib fixes
Elisa-Visentin Oct 13, 2023
df96e74
Check_input_list test
Elisa-Visentin Oct 16, 2023
ddfdcf3
Merge branch 'master' into Torino
Elisa-Visentin Oct 25, 2023
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
2 changes: 1 addition & 1 deletion environment.yml
aleberti marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# A conda environment with all useful package for ctapipe developers
name: magic-lst1
name: magic-lst
channels:
- default
- conda-forge
Expand Down
9 changes: 9 additions & 0 deletions magicctapipe/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from math import trunc
from ctapipe.utils.download import download_file_cached
from magicctapipe.utils import resource_file
import yaml

maxjoint = 13000
maxmonly = 500
Expand Down Expand Up @@ -50,6 +51,7 @@
@pytest.fixture(scope="session")
def temp_DL1_gamma(tmp_path_factory):
return tmp_path_factory.mktemp("DL1_gammas")

gabemery marked this conversation as resolved.
Show resolved Hide resolved


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -384,6 +386,13 @@ def config_monly():
config_path = resource_file("config_monly.yaml")
return config_path

@pytest.fixture(scope="session")
def config_gen():
config_path = resource_file("config_general.yaml")
jsitarek marked this conversation as resolved.
Show resolved Hide resolved
with open(config_path, "rb") as f:
config = yaml.safe_load(f)
return config


"""
Data processing
Expand Down
21 changes: 15 additions & 6 deletions magicctapipe/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,29 @@
RealEventInfoContainer,
SimEventInfoContainer,
)
from .gadf import (
create_event_hdu,
create_gh_cuts_hdu,
create_gti_hdu,
create_pointing_hdu,
)
from .io import (
telescope_combinations,
format_object,
get_dl2_mean,
get_stereo,
get_stereo_events,
get_stereo_events_old,
load_dl2_data_file,
load_irf_files,
load_lst_dl1_data_file,
load_magic_dl1_data_files,
load_mc_dl2_data_file,
load_train_data_files,
load_train_data_files_tel,
save_pandas_data_in_table,
)
from .gadf import (
create_event_hdu,
create_gh_cuts_hdu,
create_gti_hdu,
create_pointing_hdu,
)


aleberti marked this conversation as resolved.
Show resolved Hide resolved
__all__ = [
"BaseEventInfoContainer",
Expand All @@ -33,14 +38,18 @@
"create_gh_cuts_hdu",
"create_gti_hdu",
"create_pointing_hdu",
"telescope_combinations",
"format_object",
"get_dl2_mean",
"get_stereo",
"get_stereo_events",
"get_stereo_events_old",
"load_dl2_data_file",
"load_irf_files",
"load_lst_dl1_data_file",
"load_magic_dl1_data_files",
"load_mc_dl2_data_file",
"load_train_data_files",
"load_train_data_files_tel",
"save_pandas_data_in_table",
]
157 changes: 154 additions & 3 deletions magicctapipe/io/gadf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
from astropy.table import QTable
from astropy.time import Time
from magicctapipe import __version__
from magicctapipe.io.io import TEL_COMBINATIONS
from magicctapipe.utils.functions import HEIGHT_ORM, LAT_ORM, LON_ORM
from pyirf.binning import split_bin_lo_hi

#from .io import telescope_combinations
__all__ = [
"create_gh_cuts_hdu",
"create_event_hdu",
"create_gti_hdu",
"create_pointing_hdu",
]


logger = logging.getLogger(__name__)
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.INFO)
Expand All @@ -29,6 +29,7 @@
MJDREF = Time(0, format="unix", scale="utc")



gabemery marked this conversation as resolved.
Show resolved Hide resolved
@u.quantity_input
def create_gh_cuts_hdu(
gh_cuts, reco_energy_bins: u.TeV, fov_offset_bins: u.deg, **header_cards
Expand Down Expand Up @@ -88,7 +89,6 @@ def create_gh_cuts_hdu(

return gh_cuts_hdu


def create_event_hdu(
event_table, on_time, deadc, source_name, source_ra=None, source_dec=None
):
Expand Down Expand Up @@ -125,6 +125,12 @@ def create_event_hdu(
If the source name cannot be resolved and also either or both of
source RA/Dec coordinate is set to None
"""
TEL_COMBINATIONS = {
"M1_M2": [2, 3], # combo_type = 0
"LST1_M1": [1, 2], # combo_type = 1
"LST1_M2": [1, 3], # combo_type = 2
"LST1_M1_M2": [1, 2, 3], # combo_type = 3
} #####TO BE REMOVED WHEN SWITCHING TO THE NEW RFs IMPLEMENTTATION (1 RF PER TELESCOPE) !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
gabemery marked this conversation as resolved.
Show resolved Hide resolved

mjdreff, mjdrefi = np.modf(MJDREF.mjd)

Expand Down Expand Up @@ -228,6 +234,151 @@ def create_event_hdu(
return event_hdu



aleberti marked this conversation as resolved.
Show resolved Hide resolved
'''

def create_event_hdu(
event_table, config, on_time, deadc, source_name, source_ra=None, source_dec=None
):
"""
Creates a fits binary table HDU for shower events.

Parameters
----------
event_table: astropy.table.table.QTable
Table of the DL2 events surviving gammaness cuts
config: dict
yaml file with information about the telescope IDs. Typically called evoked from "config_DL3.yaml" in the main scripts.
on_time: astropy.table.table.QTable
ON time of the input data
deadc: float
Dead time correction factor
source_name: str
Name of the observed source
source_ra: str
Right ascension of the observed source, whose format should be
acceptable by `astropy.coordinates.sky_coordinate.SkyCoord`
(Used only when the source name cannot be resolved)
source_dec: str
Declination of the observed source, whose format should be
acceptable by `astropy.coordinates.sky_coordinate.SkyCoord`
(Used only when the source name cannot be resolved)

Returns
-------
event_hdu: astropy.io.fits.hdu.table.BinTableHDU
Event HDU

Raises
------
ValueError
If the source name cannot be resolved and also either or both of
source RA/Dec coordinate is set to None
"""
_, TEL_COMBINATIONS = telescope_combinations(config)

mjdreff, mjdrefi = np.modf(MJDREF.mjd)

time_start = Time(event_table["timestamp"][0], format="unix", scale="utc")
time_start_iso = time_start.to_value("iso", "date_hms")

time_end = Time(event_table["timestamp"][-1], format="unix", scale="utc")
time_end_iso = time_end.to_value("iso", "date_hms")

# Calculate the elapsed and effective time
elapsed_time = time_end - time_start
effective_time = on_time * deadc

# Get the instruments used for the observation
combo_types_unique = np.unique(event_table["combo_type"])
tel_combos = np.array(list(TEL_COMBINATIONS.keys()))[combo_types_unique]

tel_list = [tel_combo.split("_") for tel_combo in tel_combos]
tel_list_unique = np.unique(sum(tel_list, []))

instruments = "_".join(tel_list_unique)

# Transfer the RA/Dec directions to the galactic coordinate
event_coords = SkyCoord(
ra=event_table["reco_ra"], dec=event_table["reco_dec"], frame="icrs"
)

event_coords = event_coords.galactic

try:
# Try to get the source coordinate from the input name
source_coord = SkyCoord.from_name(source_name, frame="icrs")

except Exception:
logger.warning(
f"WARNING: The source name '{source_name}' could not be resolved. "
f"Setting the input RA/Dec coordinate ({source_ra}, {source_dec})..."
)

if (source_ra is None) or (source_dec is None):
raise ValueError("The input RA/Dec coordinate is set to `None`.")

source_coord = SkyCoord(ra=source_ra, dec=source_dec, frame="icrs")

# Create a table
qtable = QTable(
data={
"EVENT_ID": event_table["event_id"],
"TIME": event_table["timestamp"],
"RA": event_table["reco_ra"],
"DEC": event_table["reco_dec"],
"ENERGY": event_table["reco_energy"],
"GAMMANESS": event_table["gammaness"],
"MULTIP": event_table["multiplicity"],
"GLON": event_coords.l.to("deg"),
"GLAT": event_coords.b.to("deg"),
"ALT": event_table["reco_alt"].to("deg"),
"AZ": event_table["reco_az"].to("deg"),
}
)

# Create a header
header = fits.Header(
cards=[
("CREATED", Time.now().utc.iso),
("HDUCLAS1", "EVENTS"),
("OBS_ID", np.unique(event_table["obs_id"])[0]),
("DATE-OBS", time_start_iso[:10]),
("TIME-OBS", time_start_iso[11:]),
("DATE-END", time_end_iso[:10]),
("TIME-END", time_end_iso[11:]),
("TSTART", time_start.value),
("TSTOP", time_end.value),
("MJDREFI", mjdrefi),
("MJDREFF", mjdreff),
("TIMEUNIT", "s"),
("TIMESYS", "UTC"),
("TIMEREF", "TOPOCENTER"),
("ONTIME", on_time.value),
("TELAPSE", elapsed_time.to_value("s")),
("DEADC", deadc),
("LIVETIME", effective_time.value),
("OBJECT", source_name),
("OBS_MODE", "WOBBLE"),
("N_TELS", np.max(event_table["multiplicity"])),
("TELLIST", instruments),
("INSTRUME", instruments),
("RA_PNT", event_table["pointing_ra"][0].value, "deg"),
("DEC_PNT", event_table["pointing_dec"][0].value, "deg"),
("ALT_PNT", event_table["pointing_alt"][0].to_value("deg"), "deg"),
("AZ_PNT", event_table["pointing_az"][0].to_value("deg"), "deg"),
("RA_OBJ", source_coord.ra.to_value("deg"), "deg"),
("DEC_OBJ", source_coord.dec.to_value("deg"), "deg"),
("FOVALIGN", "RADEC"),
]
)

# Create a HDU
event_hdu = fits.BinTableHDU(qtable, header=header, name="EVENTS")

return event_hdu
'''

def create_gti_hdu(event_table):
"""
Creates a fits binary table HDU for Good Time Interval (GTI).
Expand Down
Loading