Skip to content

Commit

Permalink
Fixed tests (now they don't fail, locally)
Browse files Browse the repository at this point in the history
  • Loading branch information
Elisa-Visentin committed Sep 27, 2023
1 parent 31aa48c commit 19760ac
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 13 deletions.
5 changes: 3 additions & 2 deletions magicctapipe/io/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import pandas as pd



def test_format_object():
"""
Simple check on a string
Expand Down Expand Up @@ -94,7 +95,7 @@ def test_load_train_data_files_g(gamma_stereo):
"""

events = load_train_data_files(str(gamma_stereo[0]))
assert list(events.keys()) == ["LST1_M1", "LST1_M2", "LST1_M1_M2"]
assert list(events.keys()) == ["M1_M2", "LST1_M1", "LST1_M2", "LST1_M1_M2"]
data = events["LST1_M1"]
assert np.all(data["combo_type"]) == 1
assert "off_axis" in data.columns
Expand Down Expand Up @@ -221,7 +222,7 @@ def test_load_irf_files(IRF):
"""
Check on IRF dictionaries
"""

irf, header = load_irf_files(str(IRF))
assert set(list(irf.keys())).issubset(
set(
Expand Down
6 changes: 3 additions & 3 deletions magicctapipe/io/tests/test_io_monly.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_get_stereo_events_mc(gamma_stereo_monly, p_stereo_monly, config_gen):
event_data.sort_index(inplace=True)
data = get_stereo_events(event_data, config_gen)
assert np.all(data["multiplicity"] == 2)
assert np.all(data["combo_type"] == 0)
assert np.all(data["combo_type"] == 3)


def test_get_stereo_events_mc_cut(gamma_stereo_monly, p_stereo_monly, config_gen):
Expand Down Expand Up @@ -334,8 +334,8 @@ def test_get_stereo_events_data(stereo_monly, config_gen):
event_data.set_index(["obs_id", "event_id", "tel_id"], inplace=True)
event_data.sort_index(inplace=True)
data = get_stereo_events(event_data, config_gen)
assert np.all(data["multiplicity"] == 2)
assert np.all(data["combo_type"] == 0)
assert np.all(data["multiplicity"] == 2)
assert np.all(data["combo_type"] == 3)


def test_get_stereo_events_data_cut(stereo_monly, config_gen):
Expand Down
6 changes: 5 additions & 1 deletion magicctapipe/resources/config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
mc_tel_ids:
LST-1: 1
LST-2: 0
LST-3: 0
LST-4: 0
MAGIC-I: 2
MAGIC-II: 3


LST:
image_extractor:
type: "LocalPeakWindowSum"
Expand Down Expand Up @@ -240,6 +242,8 @@ create_irf:

dl2_to_dl3:
interpolation_method: "nearest" # select "nearest", "linear" or "cubic"
interpolation_scheme: "cosZdAz" # select "cosZdAz" or "cosZd"
max_distance: "45. deg" # angle type Quantity, or comment out to remove the cut
source_name: "Crab"
source_ra: null # used when the source name cannot be resolved
source_dec: null # used when the source name cannot be resolved
5 changes: 5 additions & 0 deletions magicctapipe/resources/config_monly.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
mc_tel_ids:
LST-1: 1
LST-2: 0
LST-3: 0
LST-4: 0
MAGIC-I: 2
MAGIC-II: 3

Expand Down Expand Up @@ -240,6 +243,8 @@ create_irf:

dl2_to_dl3:
interpolation_method: "nearest" # select "nearest", "linear" or "cubic"
interpolation_scheme: "cosZdAz" # select "cosZdAz" or "cosZd"
max_distance: "45. deg" # angle type Quantity, or comment out to remove the cut
source_name: "Crab"
source_ra: null # used when the source name cannot be resolved
source_dec: null # used when the source name cannot be resolved
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from astropy.coordinates import AltAz, SkyCoord, angular_separation
from ctapipe.coordinates import TelescopeFrame
from ctapipe.instrument import SubarrayDescription
from magicctapipe.io import get_stereo_events, save_pandas_data_in_table
from magicctapipe.io import get_stereo_events_old, save_pandas_data_in_table
from magicctapipe.reco import DispRegressor, EnergyRegressor, EventClassifier

__all__ = ["apply_rfs", "reconstruct_arrival_direction", "dl1_stereo_to_dl2"]
Expand Down Expand Up @@ -266,7 +266,7 @@ def dl1_stereo_to_dl2(input_file_dl1, input_dir_rfs, output_dir):
is_simulation = "true_energy" in event_data.columns
logger.info(f"\nIs simulation: {is_simulation}")

event_data = get_stereo_events(event_data)
event_data = get_stereo_events_old(event_data)

subarray = SubarrayDescription.from_hdf(input_file_dl1)
tel_descriptions = subarray.tel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def event_coincidence(input_file_lst, input_dir_magic, output_dir, config):

if pre_offset_search:
logger.info("\nPre offset search will be performed.")
n_pre_offset_search_events = config_coinc["n_pre_offset_search_events"]
n_pre_offset_search_events = config_coinc["n_pre_offset_search_events"] #n_pre_offset_search_events is the number of events used to estimate the time offset. Around 100 events may be enough
else:
logger.info("\noffset scan range defined in the config file will be used.")
offset_start = u.Quantity(config_coinc["time_offset"]["start"])
Expand Down Expand Up @@ -245,7 +245,7 @@ def event_coincidence(input_file_lst, input_dir_magic, output_dir, config):
)

logger.info(
f"\nExtracting the {tel_name} events taken when LST-1 observed for pre offset search..."
f"\nExtracting the {tel_name} events taken when LST observed for pre offset search..."
)

time_lolim = timestamps_lst[0] - window_half_width
Expand Down Expand Up @@ -349,8 +349,8 @@ def event_coincidence(input_file_lst, input_dir_magic, output_dir, config):

time_offsets = u.Quantity(time_offsets.round(), unit="ns", dtype=int)

# Extract the MAGIC events taken when LST-1 observed
logger.info(f"\nExtracting the {tel_name} events taken when LST-1 observed...")
# Extract the MAGIC events taken when LST observed
logger.info(f"\nExtracting the {tel_name} events taken when LST observed...")

time_lolim = timestamps_lst[0] + time_offsets[0] - window_half_width
time_uplim = timestamps_lst[-1] + time_offsets[-1] + window_half_width
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def mc_dl0_to_dl1(input_file, output_dir, config, focal_length):
LSTs_in_use = ''.join(str(k) for k in LSTs_in_use)
elif len(LSTs_in_use) > 0:
LSTs_in_use = 'LST'+'_LST'.join(str(k) for k in LSTs_in_use)
print('lst',LSTs_in_use)

MAGICs_IDs = np.asarray(list(assigned_tel_ids.values())[4:6])
MAGICs_in_use = np.where(MAGICs_IDs > 0)[0] + 1 #Here we select which MAGICs are/is in use

Expand Down

0 comments on commit 19760ac

Please sign in to comment.