fact.analysis package¶
-
fact.analysis.
li_ma_significance
(n_on, n_off, alpha=0.2)[source]¶ Calculate the Li&Ma significance for given observations data
Parameters: - n_on (integer or array like) – Number of events for the on observations
- n_off (integer of array like) – Number of events for the off observations
- alpha (float) – Scaling factor for the off observations, for wobble observations this is 1 / number of off regions
-
fact.analysis.
ontime_binning
(runs, bin_width_minutes=20)[source]¶ Calculate bin numbers for given runs. A new bin is created if either a bin would have more ontime than bin_width_minutes or run_start of the next run is more than bin_width_minutes after run_stop of the last run.
Parameters: - runs (pd.DataFrame) – DataFrame containing analysis results and meta data for each run
- bin_width_minutes (number) – The desired amount of ontime in each bin. Note: The ontime in each bin will allways be slightly less than bin_width_minutes
-
fact.analysis.
qla_binning
(data, bin_width_minutes=20)[source]¶ The binning algorithm as used by lightcurve.c
-
fact.analysis.
groupby_observation_blocks
(runs)[source]¶ Groupby for consecutive runs of the same source
-
fact.analysis.
bin_runs
(runs, alpha=0.2, binning_function=<function ontime_binning>, **kwargs)[source]¶ Bin runs using binning_function to assign bins to the individual runs. Calculates n_on, n_off, ontime, n_excess, excess_rate_per_h, excess_rate_err, li_ma_significance and bin_width
Parameters: - runs (pandas.DataFrame) – The analysis results and necessary metadata for each run. Required are: ontime, n_on, n_off, run_start, run_stop, source
- alpha (float) – The weight for the off regions, e.g. 1 / number of off regions
- binning_function (function) – A function that takes the run df and returns a pd.Series containing bin ids with the index of the origininal dataframe
- **kwargs are passed to the binning function (All) –
-
fact.analysis.
calc_run_summary_source_independent
(events, runs, prediction_threshold, theta2_cut, prediction_key='signal_prediction', theta_key='Theta_deg', theta_off_keys=('Theta_Off_1_deg', 'Theta_Off_2_deg', 'Theta_Off_3_deg', 'Theta_Off_4_deg', 'Theta_Off_5_deg'))[source]¶ Calculate run summaries for the given theta^2 and signal prediction cuts. This function requires, that no source dependent features, like Theta were used in the classification.
Parameters: - events (pd.DataFrame) – DataFrame with event data, needs to contain the columns ‘night’, ‘run’, theta_key and the theta_off_keys
- prediction_threshold (float) – Threshold for the classifier prediction
- theta2_cut (float) – Selection cut for theta^2 in deg^2
- prediction_key (str:) – Key to the classifier prediction
- theta_key (str) – Column name of the column containing theta in degree
- theta_off_keys (list[str]) – Column names of the column containing theta in degree for all off regions
-
fact.analysis.
calc_run_summary_source_dependent
(events, runs, prediction_threshold, on_prediction_key='signal_prediction', off_prediction_keys=('background_prediction_1', 'background_prediction_2', 'background_prediction_3', 'background_prediction_4', 'background_prediction_5'))[source]¶ Calculate run summaries for the given signal prediction cuts. This function needs to be used, if source dependent features like Theta were used for the classification.
Parameters: - events (pd.DataFrame) – DataFrame with event data, needs to contain the columns ‘night’, ‘run’, theta_key and the theta_off_keys
- prediction_threshold (float) – Threshold for the signalness prediction
- on_prediction_key (str) – Key to the classifier prediction for the on region
- off_prediction_keys (list[str]) – Iterable of keys to the classifier predictions for the off regions
-
fact.analysis.
split_on_off_source_dependent
(events, prediction_threshold, on_prediction_key='signal_prediction', off_prediction_keys=('background_prediction_1', 'background_prediction_2', 'background_prediction_3', 'background_prediction_4', 'background_prediction_5'))[source]¶ Split events dataframe into on and off region For the off regions, keys are renamed to their “on” equivalents and the “off” keys are dropped.
Parameters: - events (pd.DataFrame) – DataFrame containing event information, required are theta_key and theta_off_keys.
- prediction_threshold (float) – Threshold for the signalness prediction
- on_prediction_key (str) – Key to the classifier prediction for the on region
- off_prediction_keys (list[str]) – Iterable of keys to the classifier predictions for the off regions
-
fact.analysis.
split_on_off_source_independent
(events, theta2_cut, theta_key='Theta_deg', theta_off_keys=('Theta_Off_1_deg', 'Theta_Off_2_deg', 'Theta_Off_3_deg', 'Theta_Off_4_deg', 'Theta_Off_5_deg'))[source]¶ Split events dataframe into on and off region
Parameters: - events (pd.DataFrame) – DataFrame containing event information, required are theta_key and theta_off_keys.
- theta2_cut (float) – Selection cut for theta^2 in deg^2
- theta_key (str) – Column name of the column containing theta in degree
- theta_off_keys (list[str]) – Column names of the column containing theta in degree for all off regions
Submodules¶
fact.analysis.binning module¶
-
fact.analysis.binning.
bin_runs
(runs, alpha=0.2, binning_function=<function ontime_binning>, **kwargs)[source]¶ Bin runs using binning_function to assign bins to the individual runs. Calculates n_on, n_off, ontime, n_excess, excess_rate_per_h, excess_rate_err, li_ma_significance and bin_width
Parameters: - runs (pandas.DataFrame) – The analysis results and necessary metadata for each run. Required are: ontime, n_on, n_off, run_start, run_stop, source
- alpha (float) – The weight for the off regions, e.g. 1 / number of off regions
- binning_function (function) – A function that takes the run df and returns a pd.Series containing bin ids with the index of the origininal dataframe
- **kwargs are passed to the binning function (All) –
-
fact.analysis.binning.
groupby_observation_blocks
(runs)[source]¶ Groupby for consecutive runs of the same source
-
fact.analysis.binning.
ontime_binning
(runs, bin_width_minutes=20)[source]¶ Calculate bin numbers for given runs. A new bin is created if either a bin would have more ontime than bin_width_minutes or run_start of the next run is more than bin_width_minutes after run_stop of the last run.
Parameters: - runs (pd.DataFrame) – DataFrame containing analysis results and meta data for each run
- bin_width_minutes (number) – The desired amount of ontime in each bin. Note: The ontime in each bin will allways be slightly less than bin_width_minutes
fact.analysis.core module¶
-
fact.analysis.core.
calc_run_summary_source_dependent
(events, runs, prediction_threshold, on_prediction_key='signal_prediction', off_prediction_keys=('background_prediction_1', 'background_prediction_2', 'background_prediction_3', 'background_prediction_4', 'background_prediction_5'))[source]¶ Calculate run summaries for the given signal prediction cuts. This function needs to be used, if source dependent features like Theta were used for the classification.
Parameters: - events (pd.DataFrame) – DataFrame with event data, needs to contain the columns ‘night’, ‘run’, theta_key and the theta_off_keys
- prediction_threshold (float) – Threshold for the signalness prediction
- on_prediction_key (str) – Key to the classifier prediction for the on region
- off_prediction_keys (list[str]) – Iterable of keys to the classifier predictions for the off regions
-
fact.analysis.core.
calc_run_summary_source_independent
(events, runs, prediction_threshold, theta2_cut, prediction_key='signal_prediction', theta_key='Theta_deg', theta_off_keys=('Theta_Off_1_deg', 'Theta_Off_2_deg', 'Theta_Off_3_deg', 'Theta_Off_4_deg', 'Theta_Off_5_deg'))[source]¶ Calculate run summaries for the given theta^2 and signal prediction cuts. This function requires, that no source dependent features, like Theta were used in the classification.
Parameters: - events (pd.DataFrame) – DataFrame with event data, needs to contain the columns ‘night’, ‘run’, theta_key and the theta_off_keys
- prediction_threshold (float) – Threshold for the classifier prediction
- theta2_cut (float) – Selection cut for theta^2 in deg^2
- prediction_key (str:) – Key to the classifier prediction
- theta_key (str) – Column name of the column containing theta in degree
- theta_off_keys (list[str]) – Column names of the column containing theta in degree for all off regions
-
fact.analysis.core.
drop_off_columns
(df, off_region, inplace=False)[source]¶ 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>
-
fact.analysis.core.
split_on_off_source_dependent
(events, prediction_threshold, on_prediction_key='signal_prediction', off_prediction_keys=('background_prediction_1', 'background_prediction_2', 'background_prediction_3', 'background_prediction_4', 'background_prediction_5'))[source]¶ Split events dataframe into on and off region For the off regions, keys are renamed to their “on” equivalents and the “off” keys are dropped.
Parameters: - events (pd.DataFrame) – DataFrame containing event information, required are theta_key and theta_off_keys.
- prediction_threshold (float) – Threshold for the signalness prediction
- on_prediction_key (str) – Key to the classifier prediction for the on region
- off_prediction_keys (list[str]) – Iterable of keys to the classifier predictions for the off regions
-
fact.analysis.core.
split_on_off_source_independent
(events, theta2_cut, theta_key='Theta_deg', theta_off_keys=('Theta_Off_1_deg', 'Theta_Off_2_deg', 'Theta_Off_3_deg', 'Theta_Off_4_deg', 'Theta_Off_5_deg'))[source]¶ Split events dataframe into on and off region
Parameters: - events (pd.DataFrame) – DataFrame containing event information, required are theta_key and theta_off_keys.
- theta2_cut (float) – Selection cut for theta^2 in deg^2
- theta_key (str) – Column name of the column containing theta in degree
- theta_off_keys (list[str]) – Column names of the column containing theta in degree for all off regions
fact.analysis.statistics module¶
-
fact.analysis.statistics.
li_ma_significance
(n_on, n_off, alpha=0.2)[source]¶ Calculate the Li&Ma significance for given observations data
Parameters: - n_on (integer or array like) – Number of events for the on observations
- n_off (integer of array like) – Number of events for the off observations
- alpha (float) – Scaling factor for the off observations, for wobble observations this is 1 / number of off regions