Skip to content

Commit 43bb86e

Browse files
committed
Fix problem with RFs expecting the same feature names as when they were
grown... Cast to numpy array of az and zd (solves error)
1 parent 3c29005 commit 43bb86e

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

lstchain/reco/dl1_to_dl2.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import joblib
1515
import numpy as np
1616
import pandas as pd
17+
import warnings
1718
from astropy.coordinates import SkyCoord, Angle
1819
from astropy.time import Time
1920
from pathlib import Path
@@ -78,8 +79,8 @@ def add_zd_interpolation_info(dl2table, training_pointings):
7879
7980
"""
8081

81-
alt_tel = dl2table['alt_tel']
82-
az_tel = dl2table['az_tel']
82+
alt_tel = np.array(dl2table['alt_tel'])
83+
az_tel = np.array(dl2table['az_tel'])
8384

8485
training_alt_rad = np.pi / 2 - training_pointings['zd'].to(u.rad).value
8586
training_az_rad = training_pointings['az'].to(u.rad).value
@@ -169,18 +170,24 @@ def predict_with_zd_interpolation(rf, param_array, features):
169170

170171
features_copy = features.copy()
171172
alt_index_in_features = features_copy.index('alt_tel')
172-
# First use alt_tel of closest MC training node:
173-
features_copy[alt_index_in_features] = 'alt0'
174-
if is_classifier:
175-
prediction_0 = rf.predict_proba(param_array[features_copy])
176-
else:
177-
prediction_0 = rf.predict(param_array[features_copy])
178-
# Now the alt_tel value of the second-closest node:
179-
features_copy[alt_index_in_features] = 'alt1'
180-
if is_classifier:
181-
prediction_1 = rf.predict_proba(param_array[features_copy])
182-
else:
183-
prediction_1 = rf.predict(param_array[features_copy])
173+
174+
with warnings.catch_warnings():
175+
warnings.simplefilter("ignore")
176+
# This is just to avoid the RFs to warn about the features
177+
# unnamed (passed as an array). We do this because we want to replace
178+
# alt_tel by alt0, then by alt1...
179+
# First use alt_tel of closest MC training node:
180+
features_copy[alt_index_in_features] = 'alt0'
181+
if is_classifier:
182+
prediction_0 = rf.predict_proba(param_array[features_copy].to_numpy())
183+
else:
184+
prediction_0 = rf.predict(param_array[features_copy].to_numpy())
185+
# Now the alt_tel value of the second-closest node:
186+
features_copy[alt_index_in_features] = 'alt1'
187+
if is_classifier:
188+
prediction_1 = rf.predict_proba(param_array[features_copy].to_numpy())
189+
else:
190+
prediction_1 = rf.predict(param_array[features_copy].to_numpy())
184191

185192
# Interpolated RF prediction:
186193
if is_classifier:

0 commit comments

Comments
 (0)