Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into copy_columns
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnoe committed May 29, 2017
2 parents 481293e + 486a9ed commit 916430e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion fact/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.10.6
0.11.0
28 changes: 13 additions & 15 deletions fact/analysis/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@

from .statistics import li_ma_significance

default_theta_off_keys = tuple('Theta_Off_{}_deg'.format(i) for i in range(1, 6))
default_theta_off_keys = tuple('theta_deg_off_{}'.format(i) for i in range(1, 6))
default_prediction_off_keys = tuple(
'background_prediction_{}'.format(i) for i in range(1, 6)
'gamma_prediction_off_{}'.format(i) for i in range(1, 6)
)


off_key_re = re.compile('([a-zA-z1-9]+)_Off_([0-9])(_deg)?')
off_key_re = re.compile('([a-zA-z1-9]+_deg)_off_([0-9])?')


def calc_run_summary_source_independent(
events, runs,
prediction_threshold,
theta2_cut,
prediction_key='signal_prediction',
theta_key='Theta_deg',
prediction_key='gamma_prediction',
theta_key='theta_deg',
theta_off_keys=default_theta_off_keys,
):

'''
Calculate run summaries for the given theta^2 and signal prediction cuts.
This function requires, that no source dependent features,
Expand Down Expand Up @@ -82,7 +83,7 @@ def calc_run_summary_source_independent(
def split_on_off_source_independent(
events,
theta2_cut,
theta_key='Theta_deg',
theta_key='theta_deg',
theta_off_keys=default_theta_off_keys,
):
'''
Expand Down Expand Up @@ -125,7 +126,7 @@ def split_on_off_source_independent(
def calc_run_summary_source_dependent(
events, runs,
prediction_threshold,
on_prediction_key='signal_prediction',
on_prediction_key='gamma_prediction',
off_prediction_keys=default_prediction_off_keys,
):
'''
Expand Down Expand Up @@ -179,7 +180,7 @@ def calc_run_summary_source_dependent(
def split_on_off_source_dependent(
events,
prediction_threshold,
on_prediction_key='signal_prediction',
on_prediction_key='gamma_prediction',
off_prediction_keys=default_prediction_off_keys,
):
'''
Expand Down Expand Up @@ -228,20 +229,17 @@ def drop_off_columns(df, off_region, inplace=False):
'''
Replace the "On" column with the column
of the respective off region.
For example for `off_region = 1`, `Theta` is replaced by
Theta_Off_1 and all Theta_Off_<N> columns are dropped.
Same for all other columns, containing the pattern `_Off_<N>`
For example for `off_region = 1`, `theta` is replaced by
theta_off_1 and all theta_off_<N> columns are dropped.
Same for all other columns, containing the pattern `_off_<N>`
'''
if inplace is False:
df = df.copy()

for col in df.columns:
m = off_key_re.match(col)
if m:
on_key, key_region, deg = m.groups()
if deg:
on_key += deg

on_key, key_region = m.groups()
if int(key_region) == off_region:
df.drop(on_key, axis=1, inplace=True)
df[on_key] = df[col]
Expand Down

0 comments on commit 916430e

Please sign in to comment.