observational_extracted
combined_summaries(df)
Generate combined summaries of infection data using different sampling schemes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. Must contain columns: - 'effective_coi' (numeric, computed beforehand) - 'genome_ids' (list-like; if not, parse first with parse_list) - 'cotransmission' (Boolean) - Time frame columns (default: 'year' and 'month') |
required |
Returns:
| Type | Description |
|---|---|
|
pd.DataFrame: A combined summary DataFrame with different sampling schemes. |
Source code in fpg_observational_model/plotting_code/observational_extracted.py
parse_list(s)
Converts a string representation of a list into an actual Python list. If conversion fails, returns an empty list.
Source code in fpg_observational_model/plotting_code/observational_extracted.py
process_file(row, output_summary_dir, reassign_intervention_time=True)
Process a single file and write the summary output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
row
|
Series
|
A row from the file list DataFrame. |
required |
output_summary_dir
|
str
|
Folder where output files will be saved. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
The path to the written summary file. |
Source code in fpg_observational_model/plotting_code/observational_extracted.py
process_genetic_data(df)
Processes the DataFrame by
- Parsing the 'genome_ids' column and computing:
- true_coi: the total count of items in genome_ids.
- effective_coi: the count of unique items in genome_ids.
- Parsing the 'bite_ids' column and computing:
- cotransmission: a Boolean indicating if all items in bite_ids are unique.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame containing at least 'genome_ids' and 'bite_ids' columns as strings. |
required |
Returns:
| Type | Description |
|---|---|
|
pd.DataFrame: The modified DataFrame with additional computed columns. |
Source code in fpg_observational_model/plotting_code/observational_extracted.py
summarize_infections(df, groupby_cols=['year', 'month'], sample_n=None, sample_proportionally=True, sample_seasons=False, seed=input_seed)
Group and summarize infection data by a given time frame.
For each group (e.g., by year and month), computes: 1. Total rows, count and proportion of rows with effective_coi > 1. 2. Total and unique counts (and the proportion) of genome_ids (after flattening the lists from all rows). 3. Count and proportion for rows where cotransmission and superinfection is True.
Optionally, a random sample of rows can be taken before grouping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. Must contain columns: - 'effective_coi' (numeric, computed beforehand) - 'genome_ids' (list-like; if not, parse first with parse_list) - 'cotransmission' (Boolean) - Time frame columns (default: 'year' and 'month') |
required |
groupby_cols
|
list
|
List of column names to group by. Defaults to ['year', 'month']. |
['year', 'month']
|
sample_n
|
int or None
|
If provided, randomly sample n rows from the DataFrame before summarizing. |
None
|
seed
|
int
|
Random seed for sampling. |
input_seed
|
Source code in fpg_observational_model/plotting_code/observational_extracted.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |