@@ -123,108 +123,6 @@ def split_on_off_source_independent(
123
123
return on_data , off_data
124
124
125
125
126
- def calc_run_summary_source_dependent (
127
- events , runs ,
128
- prediction_threshold ,
129
- on_prediction_key = 'gamma_prediction' ,
130
- off_prediction_keys = default_prediction_off_keys ,
131
- ):
132
- '''
133
- Calculate run summaries for the given signal prediction cuts.
134
- This function needs to be used, if source dependent features like
135
- Theta were used for the classification.
136
-
137
- Parameters
138
- ----------
139
- events: pd.DataFrame
140
- DataFrame with event data, needs to contain the columns
141
- `'night'`, `'run'`, `theta_key` and the `theta_off_keys`
142
- prediction_threshold: float
143
- Threshold for the signalness prediction
144
- on_prediction_key: str
145
- Key to the classifier prediction for the on region
146
- off_prediction_keys: list[str]
147
- Iterable of keys to the classifier predictions for the off regions
148
- '''
149
-
150
- runs = runs .set_index (['night' , 'run_id' ])
151
- runs .sort_index (inplace = True )
152
-
153
- on_data , off_data = split_on_off_source_dependent (
154
- events , prediction_threshold , on_prediction_key , off_prediction_keys
155
- )
156
-
157
- alpha = 1 / len (off_prediction_keys )
158
-
159
- runs ['n_on' ] = on_data .groupby (['night' , 'run_id' ]).size ()
160
- runs ['n_on' ].fillna (0 , inplace = True )
161
-
162
- runs ['n_off' ] = off_data .groupby (['night' , 'run_id' ]).size ()
163
- runs ['n_off' ].fillna (0 , inplace = True )
164
-
165
- runs ['significance' ] = li_ma_significance (
166
- runs ['n_on' ], runs ['n_off' ], alpha
167
- )
168
-
169
- runs ['n_excess' ] = runs ['n_on' ] - alpha * runs ['n_off' ]
170
- runs ['n_excess_err' ] = np .sqrt (runs ['n_on' ] + alpha ** 2 * runs ['n_off' ])
171
-
172
- runs ['excess_rate_per_h' ] = runs ['n_excess' ] / runs ['ontime' ] / 3600
173
- runs ['excess_rate_per_h_err' ] = runs ['n_excess_err' ] / runs ['ontime' ] / 3600
174
-
175
- runs .reset_index (inplace = True )
176
-
177
- return runs
178
-
179
-
180
- def split_on_off_source_dependent (
181
- events ,
182
- prediction_threshold ,
183
- on_prediction_key = 'gamma_prediction' ,
184
- off_prediction_keys = default_prediction_off_keys ,
185
- ):
186
- '''
187
- Split events dataframe into on and off region
188
- For the off regions, keys are renamed to their "on" equivalents
189
- and the "off" keys are dropped.
190
-
191
- Parameters
192
- ----------
193
- events: pd.DataFrame
194
- DataFrame containing event information, required are
195
- `theta_key` and `theta_off_keys`.
196
- prediction_threshold: float
197
- Threshold for the signalness prediction
198
- on_prediction_key: str
199
- Key to the classifier prediction for the on region
200
- off_prediction_keys: list[str]
201
- Iterable of keys to the classifier predictions for the off regions
202
- '''
203
- on_data = events .query ('{} >= {}' .format (
204
- on_prediction_key , prediction_threshold )
205
- ).copy ()
206
-
207
- off_dfs = []
208
- for region , off_key in enumerate (off_prediction_keys , start = 1 ):
209
- off_df = events .query ('{} >= {}' .format (
210
- off_key , prediction_threshold )
211
- ).copy ()
212
-
213
- off_df ['off_region' ] = region
214
-
215
- off_df .drop (on_prediction_key , axis = 1 , inplace = True )
216
- off_df [on_prediction_key ] = off_df [off_key ]
217
- off_df .drop (off_key , axis = 1 , inplace = True )
218
-
219
- drop_off_columns (off_df , region , inplace = True )
220
-
221
- off_dfs .append (off_df )
222
-
223
- off_data = pd .concat (off_dfs )
224
-
225
- return on_data , off_data
226
-
227
-
228
126
def drop_off_columns (df , off_region , inplace = False ):
229
127
'''
230
128
Replace the "On" column with the column
0 commit comments