utils
Helper functions, primarily for property reports, which are channel reports.
__get_trace_name(channel_title, key_value_pairs, groupby)
Return "canonical" trace name for a given channel, IP:value list, and groupby list.
Since we may be aggregating by IP values, trace name may not equal any particular channel name.
Example
title = "Infected" key_value_pairs = ["Age_Bin:Age_Bin_Property_From_0_To_20","QualityOfCare:High","QualityOfCare1:High","QualityOfCare2:High"]
groupby = None return "Infected:Age_Bin:Age_Bin_Property_From_0_To_20,QualityOfCare:High,QualityOfCare1:High,QualityOfCare2:High"
groupby = ["Age_Bin"] return = "Infected:Age_Bin:Age_Bin_Property_From_0_To_20"
groupby = ["Age_Bin", "QualityOfCare"] return = "Infected:Age_Bin:Age_Bin_Property_From_0_To_20,QualityOfCare:High"
groupby = [] return = "Infected"
Source code in emod_api/channelreports/utils.py
accumulate_channel_data(channels, verbose, groupby, channel_data)
Extract selected channel(s) from property report data.
Aggregate on groupby IP(s), if provided, otherwise on channel per unique IP:value pair (e.g., "QualityOfCare:High"), per main channel (e.g., "Infected").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channels
|
List[str]
|
names of channels to plot |
required |
verbose
|
bool
|
output some "debugging"/progress information if true |
required |
groupby
|
List[str]
|
IP(s) under which to aggregate other IP:value pairs |
required |
channel_data
|
Dict
|
data for channels keyed on channel name |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, ndarray]
|
tuple of dictionary of aggregated data, keyed on channel name, and of Numpy array of normalization values |
Source code in emod_api/channelreports/utils.py
plot_traces(trace_values, norm_values, overlay, channels, title, legend)
Plot trace data. One subplot per channel unless overlaying all variations of rolled-up IP(s) is requested.
A trace (like old-time pen and ink EKG) may represent the aggregation of several IP values so trace may not equal any particular channel data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trace_values
|
Dict[str, ndarray]
|
channel data, keyed on channel name |
required |
norm_values
|
Optional[Union[int, ndarray]]
|
normalization data for channels |
required |
overlay
|
bool
|
whether or not to overlay all variations of a given channel on one subplot |
required |
channels
|
List[str]
|
selection of channel names to plot |
required |
title
|
str
|
plot title |
required |
legend
|
bool
|
whether or not to include a legend on plots |
required |
Returns:
| Type | Description |
|---|---|
Figure
|
plt.Figure |
Source code in emod_api/channelreports/utils.py
property_report_to_csv(source_file, csv_file, channels=None, groupby=None, transpose=False)
Write a property report to a CSV formatted file.
Optionally selected a subset of available channels. Optionally "rolling-up" IP:value sub-channels into a "parent" IP.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_file
|
Union[str, Path]
|
filename of property report |
required |
channels
|
Optional[List[str]]
|
list of channels to output, None results in writing all channels to output |
None
|
groupby
|
Optional[List[str]]
|
list of IPs into which to aggregate remaining IPs, None indicates no grouping, [] indicates all aggregated |
None
|
csv_file
|
Union[str, Path]
|
filename of CSV formatted result |
required |
transpose
|
bool
|
write channels as columns rather than rows |
False
|
Source code in emod_api/channelreports/utils.py
save_to_csv(trace_values, filename, transpose=False)
Save property report to CSV. Uses underlying ChannelReport.to_csv() function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trace_values
|
Dict[str, ndarray]
|
full set of available channels, keyed on channel name |
required |
filename
|
Union[str, Path]
|
destination file for CSV data |
required |
transpose
|
bool
|
write channels as columns rather than rows |
False
|