chap_core.plotting package

Submodules

chap_core.plotting.backtest_plot module

class chap_core.plotting.backtest_plot.BackTestPlotBase[source]

Bases: ABC

Abstract base class for backtest plotting.

Subclasses must implement: - from_backtest: Class method to create plot instance from a BackTest object - plot: Method to generate and return the visualization - name: Class variable with the name of the plot type

abstractmethod classmethod from_backtest(backtest: BackTest)[source]

Create a plot instance from a BackTest object.

Parameters

backtestBackTest

The backtest object containing forecast and observation data

Returns

BackTestPlotBase

An instance of the concrete plot class

name: str = ''
abstractmethod plot()[source]

Generate and return the visualization.

Returns

Chart object (implementation-specific)

The visualization object (e.g., FacetChart for Altair-based plots)

class chap_core.plotting.backtest_plot.EvaluationBackTestPlot(forecast_df: DataFrame, observed_df: DataFrame)[source]

Bases: BackTestPlotBase

Backtest-plot that shows truth vs predictions over time.

classmethod from_backtest(backtest: BackTest) EvaluationBackTestPlot[source]

Create a plot instance from a BackTest object.

Parameters

backtestBackTest

The backtest object containing forecast and observation data

Returns

BackTestPlotBase

An instance of the concrete plot class

name: str = 'Evaluation Plot'
plot() FacetChart[source]

Generate and return the visualization.

Returns

Chart object (implementation-specific)

The visualization object (e.g., FacetChart for Altair-based plots)

chap_core.plotting.backtest_plot.clean_time(period)[source]

Convert period to ISO date format for Altair/vegafusion compatibility.

chap_core.plotting.backtest_plot.text_chart(text, line_length=80, font_size=12, align='left', pad_bottom=50)[source]
chap_core.plotting.backtest_plot.title_chart(text: str, width: int = 600, font_size: int = 24, pad: int = 10)[source]

Return an Altair chart that just displays a title.

chap_core.plotting.conftest module

chap_core.plotting.conftest.df() DataFrame[source]

chap_core.plotting.dataset_plot module

class chap_core.plotting.dataset_plot.DatasetPlot(df: DataFrame, geojson=None)[source]

Bases: ABC

abstractmethod data()[source]
classmethod from_dataset_model(dataset_model)[source]
classmethod from_pandas(df: DataFrame, geojson=None)[source]
abstractmethod plot() Chart[source]
plot_spec()[source]
class chap_core.plotting.dataset_plot.DiseaseCasesMap(df: DataFrame, geojson=None)[source]

Bases: DatasetPlot

data()[source]
plot()[source]
plot_variable: str = 'disease_cases'
class chap_core.plotting.dataset_plot.StandardizedFeaturePlot(df: DataFrame, geojson=None)[source]

Bases: DatasetPlot

This plot shows standardized(zero mean, unit variance) features over time for different locations. It includes a log1p transformation of the disease incidence rate (disease_cases/population) This shows how different features correlate over time and location.

data() DataFrame[source]
plot() HConcatChart[source]
chap_core.plotting.dataset_plot.temperature_transform(x)[source]

Transforming function f(x) that: - Is low (around 0) until 15 - Starts growing with highest growth around 25 - Plateaus at 30

Uses a sigmoid-like function with shifted center and scaling

chap_core.plotting.dataset_plot.test_standardized_feature_plot(df: DataFrame)[source]
chap_core.plotting.dataset_plot.test_temperature_transform()[source]

chap_core.plotting.evaluation_plot module

class chap_core.plotting.evaluation_plot.MetricByHorizonAndLocationMean(metric_data: FlatMetric, geojson: dict | None = None)[source]

Bases: MetricPlotV2

plot_from_df()[source]
visualization_info = VisualizationInfo(id='metric_by_horizon', display_name='Horizon Plot', description='Shows the aggregated metric by forecast horizon')
class chap_core.plotting.evaluation_plot.MetricByHorizonV2Mean(metric_data: FlatMetric, geojson: dict | None = None)[source]

Bases: MetricPlotV2

plot_from_df(title='Mean metric by horizon')[source]
visualization_info = VisualizationInfo(id='metric_by_horizon', display_name='Horizon Plot', description='Shows the aggregated metric by forecast horizon')
class chap_core.plotting.evaluation_plot.MetricByHorizonV2Sum(metric_data: FlatMetric, geojson: dict | None = None)[source]

Bases: MetricPlotV2

plot_from_df()[source]
visualization_info = VisualizationInfo(id='metric_by_horizon_sum', display_name='Horizon Plot (sum)', description='Sums metric across locations per forecast horizon')
class chap_core.plotting.evaluation_plot.MetricByTimePeriodAndLocationV2Mean(metric_data: FlatMetric, geojson: dict | None = None)[source]

Bases: MetricPlotV2

plot_from_df(title='Mean metric by location and time period') Chart[source]
visualization_info = VisualizationInfo(id='metric_by_time_period', display_name='Time Period Plot', description='Shows the aggregated metric by time period (per location)')
class chap_core.plotting.evaluation_plot.MetricByTimePeriodV2Mean(metric_data: FlatMetric, geojson: dict | None = None)[source]

Bases: MetricPlotV2

plot_from_df(title='Mean metric by time period')[source]
visualization_info = VisualizationInfo(id='metric_by_time_mean', display_name='Metric by time (mean)', description='Mean metric across locations and horizons per time period')
class chap_core.plotting.evaluation_plot.MetricByTimePeriodV2Sum(metric_data: FlatMetric, geojson: dict | None = None)[source]

Bases: MetricPlotV2

plot_from_df()[source]
visualization_info = VisualizationInfo(id='metric_by_time_sum', display_name='Horizon Plot (sum)', description='Sums metric across locations per forecast horizon')
class chap_core.plotting.evaluation_plot.MetricMapV2(metric_data: FlatMetric, geojson: dict | None = None)[source]

Bases: MetricPlotV2

plot_from_df(title='Metric Map by location') Chart[source]
visualization_info = VisualizationInfo(id='metric_map', display_name='Map', description='Shows a map of aggregated metrics per org unit')
class chap_core.plotting.evaluation_plot.MetricPlotV2(metric_data: FlatMetric, geojson: dict | None = None)[source]

Bases: ABC

Represents types of metrics plots, that always start from raw FlatMetric data. Differnet plots can process this data in the way they want to produce a plot

plot(title='Mean metric by horizon') Chart[source]
abstractmethod plot_from_df(title: str = '') Chart[source]
plot_spec() dict[source]
class chap_core.plotting.evaluation_plot.VisualizationInfo(*, id: str, displayName: str, description: str)[source]

Bases: DBModel

description: str
display_name: str
id: str
model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'registry': PydanticUndefined, 'validate_by_alias': True, 'validate_by_name': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

chap_core.plotting.evaluation_plot.make_plot_from_backtest_object(backtest: BackTest, plotting_class: MetricPlotV2, metric: MetricBase, geojson=None) Chart[source]

chap_core.plotting.prediction_plot module

Note: Some of this might be outdated, but plot_forecast_from_summaries is used in several places. is being used to create forecast plots.

chap_core.plotting.prediction_plot.add_prediction_lines(fig, prediction_df, transform, true_df)[source]
chap_core.plotting.prediction_plot.plot_forecast(quantiles: ndarray, true_data: HealthData, x_pred=None) Figure[source]
chap_core.plotting.prediction_plot.plot_forecast_from_summaries(summaries: ~bionumpy.bnpdataclass.bnpdataclass.SummaryStatistics | list[~bionumpy.bnpdataclass.bnpdataclass.SummaryStatistics], true_data: ~bionumpy.bnpdataclass.bnpdataclass.HealthData, transform=<function <lambda>>) Figure[source]
chap_core.plotting.prediction_plot.plot_forecasts_from_data_frame(prediction_df: ~pandas.core.frame.DataFrame | list[~pandas.core.frame.DataFrame], true_df, transform=<function <lambda>>) Figure[source]
chap_core.plotting.prediction_plot.prediction_plot(true_data: HealthData, predicition_sampler: IsSampler, climate_data: ClimateData, n_samples) Figure[source]

chap_core.plotting.season_plot module

class chap_core.plotting.season_plot.SeasonCorrelationBarPlot(*args, **kwargs)[source]

Bases: SeasonCorrelationPlot

data() DataFrame[source]
feature_name = 'mean_temperature'
plot() FacetChart[source]
class chap_core.plotting.season_plot.SeasonCorrelationPlot(*args, **kwargs)[source]

Bases: DatasetPlot

data() DataFrame[source]
plot()[source]
class chap_core.plotting.season_plot.SeasonPlot(df: DataFrame, geojson=None)[source]

Bases: DatasetPlot

data() DataFrame[source]
plot() FacetChart[source]
chap_core.plotting.season_plot.test_season_correlation_bar_plot(df: DataFrame)[source]
chap_core.plotting.season_plot.test_season_correlation_plot(df: DataFrame)[source]
chap_core.plotting.season_plot.test_season_plot(df: DataFrame)[source]

Module contents