emod_api.channelreports.utils module#

Helper functions, primarily for property reports, which are channel reports.

emod_api.channelreports.utils.property_report_to_csv(source_file: str | Path, csv_file: str | Path, channels: List[str] | None = None, groupby: List[str] | None = None, transpose: bool = False) None[source]#

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:
  • source_file – filename of property report

  • channels – list of channels to output, None results in writing _all_ channels to output

  • groupby – list of IPs into which to aggregate remaining IPs, None indicates no grouping, [] indicates _all_ aggregated

  • csv_file – filename of CSV formatted result

  • transpose – write channels as columns rather than rows

emod_api.channelreports.utils.read_json_file(filename: str | Path) Dict[source]#
emod_api.channelreports.utils.get_report_channels(json_data: Dict) Dict[source]#
emod_api.channelreports.utils.accumulate_channel_data(channels: List[str], verbose: bool, groupby: List[str], channel_data: Dict) Dict[str, ndarray][source]#

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:
  • channels – names of channels to plot

  • verbose – output some “debugging”/progress information if true

  • groupby – IP(s) under which to aggregate other IP:value pairs

  • channel_data – data for channels keyed on channel name

Returns:

tuple of dictionary of aggregated data, keyed on channel name, and of Numpy array of normalization values

emod_api.channelreports.utils.save_to_csv(trace_values: Dict[str, ndarray], filename: str | Path, transpose: bool = False) None[source]#

Save property report to CSV. Uses underlying ChannelReport.to_csv() function.

Parameters:
  • trace_values – full set of available channels, keyed on channel name

  • filename – destination file for CSV data

  • transpose – write channels as columns rather than rows

emod_api.channelreports.utils.plot_traces(trace_values: Dict[str, ndarray], norm_values: int | ndarray | None, overlay: bool, channels: List[str], title: str, legend: bool) Figure[source]#

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:
  • trace_values – channel data, keyed on channel name

  • norm_values – normalization data for channels

  • overlay – whether or not to overlay all variations of a given channel on one subplot

  • channels – selection of channel names to plot

  • title – plot title

  • legend – whether or not to include a legend on plots

Returns:

plt.Figure