ghg_forcing_for_cmip.analysis#
Analysis pipeline for incorporating Earth observations into ground-based data.
Classes:
| Name | Description |
|---|---|
PredictionModel |
Prophet-based model for predicting future GHG concentrations. |
Functions:
| Name | Description |
|---|---|
evaluate_prediction_model |
Perform temporal cross-validation to assess forecast performance. |
extract_prophet_components |
Extract trend and seasonality components from Prophet models. |
fit_gb_from_eo |
Fit Bayesian regression model to predict ground-based values from EO. |
predict_gb |
Generate posterior predictions of the dependent variable. |
PredictionModel #
Prophet-based model for predicting future GHG concentrations.
Fits separate Prophet models for Southern, Tropical, and Northern regions based on latitude thresholds. The model configuration differs between CO2 and CH4 gases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gas
|
str
|
Greenhouse gas type, either "co2" or "ch4". |
required |
Methods:
| Name | Description |
|---|---|
__call__ |
Main prediction method that orchestrates preprocessing, fitting, and postprocessing. |
preprocess |
Prepare data and initialize Prophet models. |
fit_predict |
Fit models and generate forecasts for each region. |
postprocess |
Combine regional forecasts into a single DataFrame. |
Source code in src/ghg_forcing_for_cmip/analysis.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | |
__call__ #
__call__(
df_coverage: DataFrame,
future_time_range: tuple[int, int],
split_value: int,
n_datasets: int,
day: int = 15,
) -> DataFrame
Generate predictions for future time periods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_coverage
|
DataFrame
|
DataFrame with full spatial coverage of historical GHG data. |
required |
future_time_range
|
tuple[int, int]
|
Tuple of (start_year, end_year) for prediction period. |
required |
split_value
|
int
|
Latitude threshold for dividing regions. Southern region: lat < -split_value, Northern region: lat > split_value, Tropical region: -split_value <= lat <= split_value. |
required |
n_datasets
|
int
|
Number of posterior predictive datasets to generate future predictions for. |
required |
day
|
int
|
Day of month used for creating date variable. Default is 15. |
15
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with predicted GHG values in |
Source code in src/ghg_forcing_for_cmip/analysis.py
__init__ #
__init__(gas: str)
Initialize the PredictionModel with a gas type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gas
|
str
|
Greenhouse gas type, either "co2" or "ch4". |
required |
fit_predict #
fit_predict(
df_prophet: DataFrame,
df_future: DataFrame,
m_s: Any,
m_t: Any,
m_n: Any,
split_value: int,
) -> tuple[DataFrame, DataFrame, DataFrame]
Fit Prophet models and generate forecasts for each region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_prophet
|
DataFrame
|
Historical data prepared for Prophet (with 'ds' and 'y' columns). |
required |
df_future
|
DataFrame
|
Future data for predictions (with 'ds' column). |
required |
m_s
|
Any
|
Prophet model for Southern region. |
required |
m_t
|
Any
|
Prophet model for Tropical region. |
required |
m_n
|
Any
|
Prophet model for Northern region. |
required |
split_value
|
int
|
Latitude threshold for dividing regions. |
required |
Returns:
| Type | Description |
|---|---|
tuple[DataFrame, DataFrame, DataFrame]
|
Tuple containing forecast DataFrames for Southern, Northern, and Tropical regions. |
Source code in src/ghg_forcing_for_cmip/analysis.py
postprocess #
postprocess(
df_future: DataFrame,
forecast_s: DataFrame,
forecast_n: DataFrame,
forecast_t: DataFrame,
split_value: int,
) -> DataFrame
Combine regional forecasts into a single DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_future
|
DataFrame
|
Future data DataFrame with spatial coordinates. |
required |
forecast_s
|
DataFrame
|
Forecast DataFrame for Southern region. |
required |
forecast_n
|
DataFrame
|
Forecast DataFrame for Northern region. |
required |
forecast_t
|
DataFrame
|
Forecast DataFrame for Tropical region. |
required |
split_value
|
int
|
Latitude threshold used for region division. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Combined DataFrame with predicted values in |
Source code in src/ghg_forcing_for_cmip/analysis.py
preprocess #
preprocess(
df_coverage: DataFrame,
future_time_range: tuple[int, int],
day: int,
) -> tuple[DataFrame, DataFrame, Any, Any, Any]
Prepare data and initialize Prophet models for each region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_coverage
|
DataFrame
|
DataFrame with full spatial coverage of historical GHG data. |
required |
future_time_range
|
tuple[int, int]
|
Tuple of (start_year, end_year) for prediction period. |
required |
day
|
int
|
Day of month used for creating date variable. |
required |
Returns:
| Type | Description |
|---|---|
tuple[DataFrame, DataFrame, Prophet, Prophet, Prophet]
|
Tuple containing: - DataFrame prepared for Prophet (with 'ds' and 'y' columns) - Future DataFrame for predictions - Prophet model for Southern region - Prophet model for Tropical region - Prophet model for Northern region |
Source code in src/ghg_forcing_for_cmip/analysis.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | |
evaluate_prediction_model #
evaluate_prediction_model(
model: Any,
df_full: DataFrame,
cutoffs: list[int],
split_value: int,
future_years: int = 1,
) -> DataFrame
Perform temporal cross-validation to assess forecast performance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
PredictionModel
|
Instance of the prediction model class. |
required |
df_full
|
DataFrame
|
Complete historical dataset containing 'year', 'value_gb', etc. |
required |
cutoffs
|
list[int]
|
List of years to use as split points for training/testing. |
required |
split_value
|
int
|
Latitude threshold for regional division in the model. |
required |
future_years
|
int
|
Duration of the forecast horizon to evaluate (default: 1 year). |
1
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Table of RMSE and MAE metrics for each cutoff year. |
Source code in src/ghg_forcing_for_cmip/analysis.py
extract_prophet_components #
extract_prophet_components(
model: PredictionModel,
df_coverage: DataFrame,
future_time_range: tuple[int, int],
split_value: int,
day: int = 15,
) -> dict[str, DataFrame]
Extract trend and seasonality components from Prophet models.
Fits Prophet models and extracts the trend and yearly seasonality components for visualization purposes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
PredictionModel
|
Instance of PredictionModel. |
required |
df_coverage
|
DataFrame
|
Historical data for fitting the models. |
required |
future_time_range
|
tuple[int, int]
|
Tuple of (start_year, end_year) for the prediction period. |
required |
split_value
|
int
|
Latitude threshold for dividing regions. |
required |
day
|
int
|
Day of month used for creating date variable. |
15
|
Returns:
| Type | Description |
|---|---|
dict[str, DataFrame]
|
Dictionary with keys 'southern', 'tropical', 'northern', each containing a DataFrame with columns 'ds', 'trend', 'yearly'. |
Source code in src/ghg_forcing_for_cmip/analysis.py
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 | |
fit_gb_from_eo #
fit_gb_from_eo(
formula: str,
df: DataFrame,
seed: int,
categorical: list[str],
draws: int = 1000,
chains: int = 4,
cores: Optional[int] = None,
target_accept: float = 0.95,
) -> Any
Fit Bayesian regression model to predict ground-based values from EO.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
formula
|
str
|
Statistical model formulation. |
required |
df
|
DataFrame
|
Data used for fitting. |
required |
seed
|
int
|
Random seed for reproducibility. |
required |
categorical
|
list[str]
|
Variables in |
required |
draws
|
int
|
Posterior draws for MCMC sampling. |
1000
|
chains
|
int
|
Number of MCMC chains. |
4
|
cores
|
Optional[int]
|
CPU cores used for sampling. If |
None
|
target_accept
|
float
|
Target acceptance rate for NUTS sampler. |
0.95
|
Returns:
| Type | Description |
|---|---|
Any
|
Tuple of the fitted model and inference data. |
Source code in src/ghg_forcing_for_cmip/analysis.py
predict_gb #
predict_gb(
idata: Any,
model: Any,
in_sample_predictions: bool,
test_data: Optional[DataFrame] = None,
n_datasets: Optional[int] = None,
seed: Optional[int] = None,
dv_name: str = "value_gb",
) -> Any
Generate posterior predictions of the dependent variable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idata
|
Any
|
Inference data object from MCMC sampling. |
required |
model
|
Any
|
Fitted Bayesian model. |
required |
in_sample_predictions
|
bool
|
Whether to predict on training data. If |
required |
test_data
|
Optional[DataFrame]
|
New data for out-of-sample predictions. Required if
|
None
|
n_datasets
|
Optional[int]
|
Number of posterior predictive datasets to generate for
out-of-sample predictions. Required if |
None
|
seed
|
Optional[int]
|
Random seed for reproducibility. Required if
|
None
|
dv_name
|
str
|
Dependent variable name in the model. |
'value_gb'
|
Returns:
| Type | Description |
|---|---|
Any
|
predicted values. |
Source code in src/ghg_forcing_for_cmip/analysis.py
81 82 83 84 85 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 | |