chap_core package¶
Subpackages¶
- chap_core.adaptors package
- chap_core.assessment package
- Subpackages
- chap_core.assessment.metrics package
- Submodules
- chap_core.assessment.metrics.above_truth module
- chap_core.assessment.metrics.base module
- chap_core.assessment.metrics.crps module
- chap_core.assessment.metrics.crps_norm module
- chap_core.assessment.metrics.example_metric module
- chap_core.assessment.metrics.mae module
- chap_core.assessment.metrics.peak_diff module
- chap_core.assessment.metrics.percentile_coverage module
- chap_core.assessment.metrics.rmse module
- chap_core.assessment.metrics.test_metrics module
- Module contents
- chap_core.assessment.metrics package
- Submodules
- chap_core.assessment.data_representation_transforming module
- chap_core.assessment.dataset_splitting module
- chap_core.assessment.evaluator module
- chap_core.assessment.evaluator_suites module
- chap_core.assessment.flat_representations module
- chap_core.assessment.forecast module
- chap_core.assessment.metric_table module
- chap_core.assessment.prediction_evaluator module
- chap_core.assessment.representations module
DiseaseObservationDiseaseTimeSeriesErrorErrorTimeSeriesForecastMultiLocationDiseaseTimeSeriesMultiLocationErrorTimeSeriesMultiLocationErrorTimeSeries.get_all_timeperiods()MultiLocationErrorTimeSeries.get_the_only_location()MultiLocationErrorTimeSeries.get_the_only_timeseries()MultiLocationErrorTimeSeries.locations()MultiLocationErrorTimeSeries.locationvalues_per_timepoint()MultiLocationErrorTimeSeries.num_locations()MultiLocationErrorTimeSeries.num_timeperiods()MultiLocationErrorTimeSeries.timeseries()MultiLocationErrorTimeSeries.timeseries_dictMultiLocationErrorTimeSeries.timeseries_length()
MultiLocationForecastSamples
- Module contents
- Subpackages
- chap_core.climate_data package
- chap_core.data package
- Subpackages
- Submodules
- chap_core.data.adaptors module
- chap_core.data.datasets module
- chap_core.data.open_dengue module
- Module contents
DataSetDataSet.add_fields()DataSet.aggregate_to_parent()DataSet.data()DataSet.df_from_pydantic_observations()DataSet.end_timestampDataSet.field_names()DataSet.filter_locations()DataSet.from_csv()DataSet.from_dict()DataSet.from_fields()DataSet.from_file()DataSet.from_pandas()DataSet.from_period_observations()DataSet.from_pickle()DataSet.get_location()DataSet.get_locations()DataSet.get_parent_dict()DataSet.interpolate()DataSet.items()DataSet.join_on_time()DataSet.keys()DataSet.locations()DataSet.merge()DataSet.model_dump()DataSet.period_rangeDataSet.plot()DataSet.plot_aggregate()DataSet.polygonsDataSet.remove_field()DataSet.resample()DataSet.restrict_time_period()DataSet.set_polygons()DataSet.start_timestampDataSet.to_csv()DataSet.to_pandas()DataSet.to_pickle()DataSet.to_report()DataSet.values()
PeriodObservation
- chap_core.database package
- Submodules
- chap_core.database.base_tables module
- chap_core.database.database module
SessionWrapperSessionWrapper.add_configured_model()SessionWrapper.add_dataset()SessionWrapper.add_dataset_from_csv()SessionWrapper.add_debug()SessionWrapper.add_evaluation_results()SessionWrapper.add_model_template()SessionWrapper.add_model_template_from_yaml_config()SessionWrapper.add_predictions()SessionWrapper.create_if_not_exists()SessionWrapper.get_backtest_with_truth()SessionWrapper.get_configured_model_by_name()SessionWrapper.get_configured_model_with_code()SessionWrapper.get_configured_models()SessionWrapper.get_dataset()SessionWrapper.get_dataset_by_name()SessionWrapper.get_model_template()SessionWrapper.list_all()
create_db_and_tables()
- chap_core.database.dataset_tables module
- chap_core.database.datasets_seed module
- chap_core.database.debug module
- chap_core.database.feature_tables module
- chap_core.database.model_spec_tables module
ModelSpecModelSpec.authorModelSpec.author_assessed_statusModelSpec.author_noteModelSpec.citation_infoModelSpec.configurationModelSpec.contact_emailModelSpec.covariatesModelSpec.descriptionModelSpec.display_nameModelSpec.idModelSpec.model_configModelSpec.nameModelSpec.organizationModelSpec.organization_logo_urlModelSpec.source_urlModelSpec.supported_period_typeModelSpec.targetModelSpec.target_name
ModelSpecBaseModelSpecReadget_available_models()get_available_models_from_config_dir()seed_with_session_wrapper()
- chap_core.database.model_template_seed module
- chap_core.database.model_templates_and_config_tables module
AuthorAssessedStatusConfiguredModelDBConfiguredModelDB.additional_continuous_covariatesConfiguredModelDB.archivedConfiguredModelDB.idConfiguredModelDB.model_configConfiguredModelDB.model_templateConfiguredModelDB.model_template_idConfiguredModelDB.nameConfiguredModelDB.user_option_valuesConfiguredModelDB.uses_chapkitConfiguredModelDB.validate_user_options()
ModelConfigurationModelTemplateDBModelTemplateDB.allow_free_additional_continuous_covariatesModelTemplateDB.authorModelTemplateDB.author_assessed_statusModelTemplateDB.author_noteModelTemplateDB.citation_infoModelTemplateDB.configured_modelsModelTemplateDB.contact_emailModelTemplateDB.descriptionModelTemplateDB.display_nameModelTemplateDB.hpo_search_spaceModelTemplateDB.idModelTemplateDB.model_configModelTemplateDB.nameModelTemplateDB.organizationModelTemplateDB.organization_logo_urlModelTemplateDB.required_covariatesModelTemplateDB.source_urlModelTemplateDB.supported_period_typeModelTemplateDB.targetModelTemplateDB.user_optionsModelTemplateDB.version
ModelTemplateInformationModelTemplateInformation.allow_free_additional_continuous_covariatesModelTemplateInformation.hpo_search_spaceModelTemplateInformation.model_configModelTemplateInformation.required_covariatesModelTemplateInformation.supported_period_typeModelTemplateInformation.targetModelTemplateInformation.user_options
ModelTemplateMetaDataModelTemplateMetaData.authorModelTemplateMetaData.author_assessed_statusModelTemplateMetaData.author_noteModelTemplateMetaData.citation_infoModelTemplateMetaData.contact_emailModelTemplateMetaData.descriptionModelTemplateMetaData.display_nameModelTemplateMetaData.model_configModelTemplateMetaData.organizationModelTemplateMetaData.organization_logo_url
- chap_core.database.tables module
BackTestBackTest.aggregate_metricsBackTest.configured_modelBackTest.createdBackTest.datasetBackTest.dataset_idBackTest.forecastsBackTest.idBackTest.metricsBackTest.model_configBackTest.model_db_idBackTest.model_idBackTest.model_template_versionBackTest.nameBackTest.org_unitsBackTest.split_periods
BackTestBaseBackTestForecastBackTestMetricBackTestReadConfiguredModelReadDataSetMetaForecastBaseForecastReadOldBackTestReadPredictionPredictionBasePredictionInfoPredictionReadPredictionSamplesEntry
- Module contents
- chap_core.external package
- Submodules
- chap_core.external.external_model module
- chap_core.external.github module
- chap_core.external.mlflow_wrappers module
- chap_core.external.model_configuration module
- chap_core.external.python_model module
- chap_core.external.r_description module
- chap_core.external.r_model module
- chap_core.external.r_models module
- chap_core.external.uv_wrapper module
- Module contents
- chap_core.fetch package
- chap_core.file_io package
- chap_core.geo_coding package
- chap_core.hpo package
- chap_core.models package
- Submodules
- chap_core.models.chapkit_rest_api_wrapper module
CHAPKitRestAPIWrapperCHAPKitRestAPIWrapper.close()CHAPKitRestAPIWrapper.create_config()CHAPKitRestAPIWrapper.delete_artifact()CHAPKitRestAPIWrapper.delete_config()CHAPKitRestAPIWrapper.delete_job()CHAPKitRestAPIWrapper.get_artifact()CHAPKitRestAPIWrapper.get_artifact_config()CHAPKitRestAPIWrapper.get_artifact_expand()CHAPKitRestAPIWrapper.get_artifact_tree_by_id()CHAPKitRestAPIWrapper.get_artifacts_for_config()CHAPKitRestAPIWrapper.get_config()CHAPKitRestAPIWrapper.get_config_artifacts()CHAPKitRestAPIWrapper.get_config_schema()CHAPKitRestAPIWrapper.get_job()CHAPKitRestAPIWrapper.get_jobs()CHAPKitRestAPIWrapper.health()CHAPKitRestAPIWrapper.info()CHAPKitRestAPIWrapper.link_artifact_to_config()CHAPKitRestAPIWrapper.list_configs()CHAPKitRestAPIWrapper.poll_job()CHAPKitRestAPIWrapper.predict()CHAPKitRestAPIWrapper.predict_and_wait()CHAPKitRestAPIWrapper.train()CHAPKitRestAPIWrapper.train_and_wait()CHAPKitRestAPIWrapper.unlink_artifact_from_config()CHAPKitRestAPIWrapper.update_config()CHAPKitRestAPIWrapper.wait_for_job()
- chap_core.models.configured_model module
- chap_core.models.external_chapkit_model module
- chap_core.models.external_model module
- chap_core.models.external_web_model module
- chap_core.models.local_configuration module
- chap_core.models.model_rest_api_wrapper module
- chap_core.models.model_template module
- chap_core.models.model_template_interface module
- chap_core.models.utils module
- Module contents
- chap_core.plotting package
- Submodules
- chap_core.plotting.backtest_plot module
- chap_core.plotting.conftest module
- chap_core.plotting.dataset_plot module
- chap_core.plotting.evaluation_plot module
- chap_core.plotting.prediction_plot module
- chap_core.plotting.season_plot module
- Module contents
- chap_core.predictor package
- Submodules
- chap_core.predictor.feature_spec module
- chap_core.predictor.model_registry module
- chap_core.predictor.naive_estimator module
- chap_core.predictor.naive_predictor module
- chap_core.predictor.poisson module
- chap_core.predictor.protocol module
- chap_core.predictor.published_models module
- Module contents
- chap_core.rest_api package
- Subpackages
- Submodules
- chap_core.rest_api.celery_tasks module
CeleryJobCeleryPoolJobDescriptionTrackedTaskTrackedTask.apply_async()TrackedTask.ignore_resultTrackedTask.on_failure()TrackedTask.on_success()TrackedTask.priorityTrackedTask.rate_limitTrackedTask.reject_on_worker_lostTrackedTask.request_stackTrackedTask.serializerTrackedTask.store_errors_even_if_ignoredTrackedTask.track_startedTrackedTask.typing
add_numbers()get_job_meta()read_environment_variables()
- chap_core.rest_api.data_models module
- chap_core.rest_api.db_worker_functions module
- chap_core.rest_api.worker_functions module
DataValueWorkerConfigdataset_from_request_v1()dataset_to_datalist()get_combined_dataset()get_health_dataset()get_target_id()get_target_name()harmonize_health_dataset()load_forecasts()predictions_to_datavalue()sample_dataset_to_prediction_response()samples_to_evaluation_response()train_on_json_data()v1_conversion()
- Module contents
- chap_core.runners package
- chap_core.simulation package
- chap_core.spatio_temporal_data package
- Submodules
- chap_core.spatio_temporal_data.converters module
- chap_core.spatio_temporal_data.multi_country_dataset module
- chap_core.spatio_temporal_data.temporal_dataclass module
DataSetDataSet.add_fields()DataSet.aggregate_to_parent()DataSet.data()DataSet.df_from_pydantic_observations()DataSet.end_timestampDataSet.field_names()DataSet.filter_locations()DataSet.from_csv()DataSet.from_dict()DataSet.from_fields()DataSet.from_file()DataSet.from_pandas()DataSet.from_period_observations()DataSet.from_pickle()DataSet.get_location()DataSet.get_locations()DataSet.get_parent_dict()DataSet.interpolate()DataSet.items()DataSet.join_on_time()DataSet.keys()DataSet.locations()DataSet.merge()DataSet.model_dump()DataSet.period_rangeDataSet.plot()DataSet.plot_aggregate()DataSet.polygonsDataSet.remove_field()DataSet.resample()DataSet.restrict_time_period()DataSet.set_polygons()DataSet.start_timestampDataSet.to_csv()DataSet.to_pandas()DataSet.to_pickle()DataSet.to_report()DataSet.values()
DataSetMetaDataPolygonTemporalDataclass
- Module contents
- chap_core.testing package
- chap_core.time_period package
- Submodules
- chap_core.time_period.date_util_wrapper module
DateUtilWrapperDayMonthPeriodRangePeriodRange.concatenate()PeriodRange.deltaPeriodRange.end_timestampPeriodRange.from_ids()PeriodRange.from_pandas()PeriodRange.from_period_list()PeriodRange.from_start_and_n_periods()PeriodRange.from_strings()PeriodRange.from_time_periods()PeriodRange.from_timestamps()PeriodRange.monthPeriodRange.searchsorted()PeriodRange.shapePeriodRange.start_timestampPeriodRange.to_period_index()PeriodRange.todict()PeriodRange.tolist()PeriodRange.topandas()PeriodRange.weekPeriodRange.year
TimeDeltaTimePeriodTimeStampWeekWeekNumberingYearclean_timestring()convert_time_period_string()parse()
- chap_core.time_period.multi_resolution module
- chap_core.time_period.period_assignment module
- chap_core.time_period.relationships module
- Module contents
DayMonthPeriodRangePeriodRange.concatenate()PeriodRange.deltaPeriodRange.end_timestampPeriodRange.from_ids()PeriodRange.from_pandas()PeriodRange.from_period_list()PeriodRange.from_start_and_n_periods()PeriodRange.from_strings()PeriodRange.from_time_periods()PeriodRange.from_timestamps()PeriodRange.monthPeriodRange.searchsorted()PeriodRange.shapePeriodRange.start_timestampPeriodRange.to_period_index()PeriodRange.todict()PeriodRange.tolist()PeriodRange.topandas()PeriodRange.weekPeriodRange.year
TimePeriodWeekYearget_period_range()
- chap_core.transformations package
- chap_core.worker package
Submodules¶
chap_core.alarms module¶
- class chap_core.alarms.OutbreakParameters(*, endemic_factor: float, probability_threshold: float)[source]¶
Bases:
BaseModel- endemic_factor: float¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- probability_threshold: float¶
- chap_core.alarms.outbreak_prediction(parameters: OutbreakParameters, case_samples: Iterable[float]) bool[source]¶
chap_core.api module¶
- class chap_core.api.PredictionData(area_polygons: chap_core.api.AreaPolygons = None, health_data: chap_core.spatio_temporal_data.temporal_dataclass.DataSet[bionumpy.bnpdataclass.bnpdataclass.HealthData] = None, climate_data: chap_core.spatio_temporal_data.temporal_dataclass.DataSet[bionumpy.bnpdataclass.bnpdataclass.ClimateData] = None, population_data: chap_core.spatio_temporal_data.temporal_dataclass.DataSet[bionumpy.bnpdataclass.bnpdataclass.HealthPopulationData] = None, disease_id: str | None = None, features: List[object] = None)[source]¶
Bases:
object- area_polygons: AreaPolygons = None¶
- disease_id: str | None = None¶
- features: List[object] = None¶
chap_core.api_types module¶
- class chap_core.api_types.BackTestParams(*, nPeriods: int, nSplits: int, stride: int)¶
Bases:
DBModel- 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].
- n_periods: int¶
- n_splits: int¶
- stride: int¶
- class chap_core.api_types.DataElement(*, pe: str, ou: str, value: float | None)¶
Bases:
BaseModel- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- ou: str¶
- pe: str¶
- value: float | None¶
- class chap_core.api_types.DataElementV2(*, period: str, orgUnit: str, value: float | None)¶
Bases:
BaseModel- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- orgUnit: str¶
- period: str¶
- value: float | None¶
- class chap_core.api_types.DataList(*, featureId: str, dhis2Id: str, data: Annotated[list[DataElement], MinLen(min_length=1)])¶
Bases:
BaseModel- data: list[DataElement]¶
- dhis2Id: str¶
- featureId: str¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class chap_core.api_types.DataListV2(*, featureId: str, dataElement: str, data: Annotated[list[DataElementV2], MinLen(min_length=1)])¶
Bases:
BaseModel- data: list[DataElementV2]¶
- dataElement: str¶
- featureId: str¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class chap_core.api_types.EvaluationEntry(*, orgUnit: str, period: str, quantile: float, value: float, splitPeriod: str)¶
Bases:
PredictionEntry- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- splitPeriod: str¶
- class chap_core.api_types.EvaluationResponse(*, actualCases: DataList, predictions: list[EvaluationEntry])¶
Bases:
BaseModel- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_dump(**kwargs)¶
Override to handle special types during serialization
- predictions: list[EvaluationEntry]¶
- class chap_core.api_types.FeatureCollectionModel(*, type: str = 'FeatureCollection', features: list[FeatureModel])¶
Bases:
FeatureCollectionModel- features: list[FeatureModel]¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class chap_core.api_types.FeatureModel(*, type: str = 'Feature', properties: dict[str, ~typing.Any] | None = <factory>, geometry: ~pydantic_geojson.point.PointModel | ~pydantic_geojson.multi_point.MultiPointModel | ~pydantic_geojson.line_string.LineStringModel | ~pydantic_geojson.multi_line_string.MultiLineStringModel | ~pydantic_geojson.polygon.PolygonModel | ~pydantic_geojson.multi_polygon.MultiPolygonModel, id: str | None = None)¶
Bases:
FeatureModel- id: str | None¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- properties: dict[str, Any] | None¶
- class chap_core.api_types.PeriodObservation(*, time_period: str)¶
Bases:
BaseModel- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- time_period: str¶
- class chap_core.api_types.PredictionEntry(*, orgUnit: str, period: str, quantile: float, value: float)¶
Bases:
BaseModel- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- orgUnit: str¶
- period: str¶
- quantile: float¶
- value: float¶
- class chap_core.api_types.PredictionRequest(*, orgUnitsGeoJson: FeatureCollectionModel, features: list[DataList], estimator_id: str = 'chap_ewars_monthly', n_periods: int = 3, include_data: bool = False)¶
Bases:
RequestV2- include_data: bool¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- n_periods: int¶
- class chap_core.api_types.RequestV1(*, orgUnitsGeoJson: FeatureCollectionModel, features: list[DataList])¶
Bases:
BaseModel- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- orgUnitsGeoJson: FeatureCollectionModel¶
- class chap_core.api_types.RequestV2(*, orgUnitsGeoJson: FeatureCollectionModel, features: list[DataList], estimator_id: str = 'chap_ewars_monthly')¶
Bases:
RequestV1- estimator_id: str¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
chap_core.cli module¶
Console script for chap_core.
- chap_core.cli.base_args(func, *args, **kwargs)[source]¶
Decorator that adds some base arguments to a command
- chap_core.cli.evaluate(model_name: Literal['MultiRegionPoissonModel', 'MultiRegionNaivePredictor'] | str, dataset_name: Literal['hydro_met_subset', 'hydromet_clean', 'hydromet_10', 'hydromet_5_filtered', 'laos_full_data', 'uganda_data', 'ISIMIP_dengue_harmonized'] | None = None, dataset_country: str | None = None, dataset_csv: Path | None = None, polygons_json: Path | None = None, polygons_id_field: str | None = 'id', prediction_length: int = 6, n_splits: int = 7, report_filename: str | None = 'target/report.pdf', ignore_environment: bool = False, debug: bool = False, log_file: str | None = None, run_directory_type: Literal['latest', 'timestamp', 'use_existing'] | None = 'timestamp', model_configuration_yaml: str | None = None, is_chapkit_model: bool = False)[source]¶
- chap_core.cli.evaluate_hpo(model_name: Literal['MultiRegionPoissonModel', 'MultiRegionNaivePredictor'] | str, dataset_name: Literal['hydro_met_subset', 'hydromet_clean', 'hydromet_10', 'hydromet_5_filtered', 'laos_full_data', 'uganda_data', 'ISIMIP_dengue_harmonized'] | None = None, dataset_country: str | None = None, dataset_csv: Path | None = None, polygons_json: Path | None = None, polygons_id_field: str | None = 'id', prediction_length: int = 3, n_splits: int = 7, report_filename: str | None = 'target/report.pdf', ignore_environment: bool = False, debug: bool = False, log_file: str | None = None, run_directory_type: Literal['latest', 'timestamp', 'use_existing'] | None = 'timestamp', model_configuration_yaml: str | None = None, metric: str | None = 'MSE', direction: Literal['maximize', 'minimize'] = 'minimize', evaluate_hpo: bool | None = True)[source]¶
Same as evaluate, but has three added arguments and a if check on argument evaluate_hpo.
- chap_core.cli.forecast(model_name: str, dataset_name: Literal['hydro_met_subset', 'hydromet_clean', 'hydromet_10', 'hydromet_5_filtered', 'laos_full_data', 'uganda_data', 'ISIMIP_dengue_harmonized'], n_months: int, model_path: str | None = None, out_path: str | None = PosixPath('.'))[source]¶
Forecast n_months ahead using the given model and dataset
- Parameters:
model_name: Name of the model to use, set to external to use an external model and specify the external model with model_path dataset_name: Name of the dataset to use, e.g. hydromet_5_filtered n_months: int: Number of months to forecast ahead model_path: Optional[str]: Path to the model if model_name is external. Can ge a github repo url starting with https://github.com and ending with .git or a path to a local directory. out_path: Optional[str]: Path to save the output file, default is the current directory
- chap_core.cli.main_function()[source]¶
This function should just be type hinted with common types, and it will run as a command line function Simple function<
>>> main()
- chap_core.cli.multi_forecast(model_name: str, dataset_name: Literal['hydro_met_subset', 'hydromet_clean', 'hydromet_10', 'hydromet_5_filtered', 'laos_full_data', 'uganda_data', 'ISIMIP_dengue_harmonized'], n_months: int, pre_train_months: int, out_path: Path = PosixPath('.'))[source]¶
- chap_core.cli.plot_dataset(data_filename: Path, plot_name: str = 'standardized_feature_plot')[source]¶
- chap_core.cli.sanity_check_model(model_url: str, use_local_environement: bool = False, dataset_path=None, model_config_path: str = None)[source]¶
Check that a model can be loaded, trained and used to make predictions
chap_core.climate_predictor module¶
- class chap_core.climate_predictor.FetcherNd(historical_data: DataSet[SimpleClimateData])[source]¶
Bases:
object- get_future_weather(period_range: PeriodRange) DataSet[SimpleClimateData][source]¶
- class chap_core.climate_predictor.FutureWeatherFetcher[source]¶
Bases:
object- get_future_weather(period_range: PeriodRange) DataSet[SimpleClimateData][source]¶
- class chap_core.climate_predictor.MonthlyClimatePredictor[source]¶
Bases:
object- predict(time_period: PeriodRange)[source]¶
- class chap_core.climate_predictor.QuickForecastFetcher(historical_data: DataSet[SimpleClimateData])[source]¶
Bases:
object- get_future_weather(period_range: PeriodRange) DataSet[SimpleClimateData][source]¶
- class chap_core.climate_predictor.SeasonalForecastFetcher(folder_path)[source]¶
Bases:
object- get_future_weather(period_range: PeriodRange) DataSet[SimpleClimateData][source]¶
- class chap_core.climate_predictor.WeeklyClimatePredictor[source]¶
Bases:
MonthlyClimatePredictor
chap_core.datatypes module¶
- class chap_core.datatypes.ClimateHealthTimeSeriesModel(*, time_period: str | Period, rainfall: float, mean_temperature: float, disease_cases: int)[source]¶
Bases:
BaseModel- disease_cases: int¶
- mean_temperature: float¶
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- rainfall: float¶
- time_period: str | Period¶
- class chap_core.datatypes.Location(latitude: float, longitude: float)[source]¶
Bases:
Shape- latitude: float¶
- longitude: float¶
chap_core.docker_helper_functions module¶
chap_core.exceptions module¶
chap_core.geojson module¶
chap_core.geometry module¶
- class chap_core.geometry.PFeatureCollectionModel(*, type: str = 'FeatureCollection', features: list[PFeatureModel])[source]¶
Bases:
FeatureCollectionModel- features: list[PFeatureModel]¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class chap_core.geometry.PFeatureModel(*, type: str = 'Feature', properties: dict, geometry: PointModel | MultiPointModel | LineStringModel | MultiLineStringModel | PolygonModel | MultiPolygonModel)[source]¶
Bases:
FeatureModel- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- properties: dict¶
- class chap_core.geometry.Polygons(polygons)[source]¶
Bases:
object- property bbox¶
- property data: FeatureCollectionModel¶
- filter_locations(locations: list[str])[source]¶
Filter the polygons to only include the specified locations
- chap_core.geometry.get_area_polygons(country: str, regions: list[str] = None, admin_level: int = 1) FeatureCollectionModel[source]¶
Get the polygons for the specified regions in the specified country (only ADMIN1 supported) Returns only the regions that are found in the data Name is put in the id field of the feature
Parameters¶
- countrystr
The country name
- regionslist[str], optional
Filtering which regions to get the polygons for based on region name
- admin_levelint
Which administrative level to get polygons for (0 for country, 1 for admin-1, etc)
Returns¶
- FeatureCollectionModel
The polygons for the specified regions
- chap_core.geometry.get_country_data(country, admin_level) PFeatureCollectionModel[source]¶
chap_core.geoutils module¶
Utility functions for working with geometries.
- chap_core.geoutils.buffer_feature(feature: FeatureModel, distance: float)[source]¶
Creates a buffer around a FeatureModel object. Features with point and line geometries will become polygons.
Parameters¶
- featureFeatureModel
A FeatureModel object representing a feature with a geometry.
- distancefloat
The distance to buffer around the geometry, given in the same coordinate system units as the feature geometry. For latitude-longitude geometries, a distance of 0.1 is approximately 10 km at the equator but increases towards the poles.
Returns¶
- FeatureModel
A FeatureModel object with the buffered geometry.
- chap_core.geoutils.buffer_point_features(collection: FeatureCollectionModel, distance: float)[source]¶
For a given FeatureCollection, creates a buffer around point-type FeatureModel objects. Features with polygon or line geometries remain unaltered.
Parameters¶
- collectionFeatureCollectionModel
A FeatureCollectionModel object representing a feature collection.
- distancefloat
The distance to buffer around the geometry, given in the same coordinate system units as the feature geometry. For latitude-longitude geometries, a distance of 0.1 is approximately 10 km at the equator but increases towards the poles.
Returns¶
- FeatureCollectionModel
A new FeatureCollectionModel object with any point geometries converted to polygon buffers.
- chap_core.geoutils.feature_bbox(feature: FeatureModel)[source]¶
Calculates the bounding box for a FeatureModel object.
Parameters¶
- featureFeatureModel
A FeatureModel object representing a feature with a geometry.
Returns¶
- tuple
A 4-tuple in the form of (xmin,ymin,xmax,ymax)
- chap_core.geoutils.inspect_feature_collection(collection)[source]¶
Inspect and return statistics of the contents of a FeatureModelCollection object.
Parameters¶
- collectionFeatureModelCollection
A FeatureModelCollection object representing a feature collection.
Returns¶
- dict
A dict object with basic count statistics of the different geometry types contained in the FeatureModelCollection.
- chap_core.geoutils.render(polygons: Polygons)[source]¶
Simple utility to render a Polygons object on a map for inspecting and debugging purposes.
Parameters¶
- polygonsPolygons
A Polygons object representing the set of polygons to be rendered.
Returns¶
- PIL.Image.Image
The rendered map image.
- chap_core.geoutils.simplify_topology(polygons: Polygons, threshold=None) Polygons[source]¶
Simplifies a Polygons object while preserving topology between adjacent polygons.
Parameters¶
- polygonsPolygons
A Polygons object representing the set of polygons to be simplified.
- thresholdfloat, optional
Coordinate distance threshold used to simplify/round coordinates. If None, the distance threshold will be automatically calculated relative to the bounding box of all polygons, specifically one-thousandth of the longest of the bounding box width or height. The threshold distance is specified in coordinate units. For latitude-longitude coordinates, the threshold should be specified in decimal degrees, where 0.01 decimal degrees is roughly 1 km at the equator but increases towards the poles. For more accurate thresholds, the Polygons object should be created using projected coordinates instead of latitude-longitude.
Returns¶
- Polygons
A simplified Polygons object with preserved topology.
chap_core.internal_state module¶
- class chap_core.internal_state.InternalState(control: chap_core.internal_state.Control | None, current_data: dict, model_path: str | None = None, current_job: chap_core.worker.interface.Job | None = None)[source]¶
Bases:
object- current_data: dict¶
- model_path: str | None = None¶
chap_core.log_config module¶
chap_core.model_spec module¶
- class chap_core.model_spec.EwarsParamSpec(*, n_weeks: Annotated[int, Gt(gt=0)], alpha: float)[source]¶
Bases:
ParameterSpec- alpha: float¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- n_weeks: Annotated[int, Gt(gt=0)]¶
- class chap_core.model_spec.ModelSpec(*, name: str, parameters: dict, features: list[Feature], period: PeriodType = PeriodType.any, description: str = 'No Description yet', author: str = 'Unknown Author', targets: str = 'disease_cases')[source]¶
Bases:
BaseModel- author: str¶
- description: str¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- name: str¶
- parameters: dict¶
- period: PeriodType¶
- targets: str¶
- class chap_core.model_spec.ParameterSpec[source]¶
Bases:
BaseModel- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
chap_core.pandas_adaptors module¶
chap_core.rbased_docker module¶
chap_core.training_control module¶
- class chap_core.training_control.PrintingTrainingControl[source]¶
Bases:
TrainingControl
chap_core.util module¶
- chap_core.util.nan_helper(y)[source]¶
Helper to handle indices and logical indices of NaNs.
- Input:
y, 1d numpy array with possible NaNs
- Output:
nans, logical indices of NaNs
index, a function, with signature indices= index(logical_indices), to convert logical indices of NaNs to ‘equivalent’ indices
- Example:
>>> # linear interpolation of NaNs >>> nans, x = nan_helper(y) >>> y[nans] = np.interp(x(nans), x(~nans), y[~nans])
chap_core.validators module¶
Module contents¶
Top-level package for chap-core.
- class chap_core.ModelTemplateInterface[source]¶
Bases:
ABC- get_default_model() ConfiguredModel[source]¶
- abstractmethod get_model(model_configuration: ModelConfiguration | None = None) ConfiguredModel[source]¶
- abstractmethod get_schema() ModelTemplateInformation[source]¶
- chap_core.get_temp_dir() Path[source]¶
Get the temporary directory for build and test artifacts.
Returns temporary directory path for storing build artifacts, test outputs, model files, and other temporary files. Creates the directory if it doesn’t exist.
Returns¶
- Path
Path to the temporary directory (default: ‘target/’)