gcages.testing#
Code to support our tests
This is here, rather than in our tests directory
because of the issues that come
when you turn your tests into a package using __init__.py files
(for details, see https://docs.pytest.org/en/7.1.x/explanation/goodpractices.html#choosing-an-import-mode).
Functions:
| Name | Description |
|---|---|
assert_frame_equal |
Assert two pd.DataFrame's are equal. |
get_ar6_all_emissions |
Get all emissions from AR6 for a given model-scenario |
get_ar6_harmonised_emissions |
Get all harmonised emissions from AR6 for a given model-scenario |
get_ar6_infilled_emissions |
Get all infilled emissions from AR6 for a given model-scenario |
get_ar6_metadata_outputs |
Get metadata from AR6 for a given model-scenario |
get_ar6_raw_emissions |
Get all raw emissions from AR6 for a given model-scenario |
get_ar6_temperature_outputs |
Get temperature outputs we've downloaded from AR6 for a given model-scenario |
guess_magicc_exe_path |
Guess the path to the MAGICC executable |
assert_frame_equal #
Assert two pd.DataFrame's are equal.
This is a very thin wrapper around pd.testing.assert_frame_equal that makes some use of pandas_indexing to give slightly nicer and clearer errors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res
|
DataFrame
|
Result |
required |
exp
|
DataFrame
|
Expected value |
required |
rtol
|
float
|
Relative tolerance |
1e-08
|
**kwargs
|
Any
|
Passed to pd.testing.assert_frame_equal |
{}
|
Raises:
| Type | Description |
|---|---|
AssertionError
|
The frames aren't equal |
Source code in src/gcages/testing.py
get_ar6_all_emissions
cached
#
get_ar6_all_emissions(
model: str,
scenario: str,
processed_ar6_output_data_dir: Path,
) -> DataFrame
Get all emissions from AR6 for a given model-scenario
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Model |
required |
scenario
|
str
|
Scenario |
required |
processed_ar6_output_data_dir
|
Path
|
Directory in which the AR6 was processed into individual model-scenario files (In the repo, see |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
All emissions from AR6 for |
Source code in src/gcages/testing.py
get_ar6_harmonised_emissions
cached
#
get_ar6_harmonised_emissions(
model: str,
scenario: str,
processed_ar6_output_data_dir: Path,
) -> DataFrame
Get all harmonised emissions from AR6 for a given model-scenario
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Model |
required |
scenario
|
str
|
Scenario |
required |
processed_ar6_output_data_dir
|
Path
|
Directory in which the AR6 was processed into individual model-scenario files (In the repo, see |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
All harmonised emissions from AR6 for |
Source code in src/gcages/testing.py
get_ar6_infilled_emissions
cached
#
get_ar6_infilled_emissions(
model: str,
scenario: str,
processed_ar6_output_data_dir: Path,
) -> DataFrame
Get all infilled emissions from AR6 for a given model-scenario
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Model |
required |
scenario
|
str
|
Scenario |
required |
processed_ar6_output_data_dir
|
Path
|
Directory in which the AR6 output was processed into model-scenario files (In the repo, see |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
All infilled emissions from AR6 for |
Source code in src/gcages/testing.py
get_ar6_metadata_outputs
cached
#
get_ar6_metadata_outputs(
model: str,
scenario: str,
ar6_output_data_dir: Path,
filename: str = "AR6_Scenarios_Database_metadata_indicators_v1.1_meta.csv",
) -> DataFrame
Get metadata from AR6 for a given model-scenario
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Model |
required |
scenario
|
str
|
Scenario |
required |
ar6_output_data_dir
|
Path
|
Directory in which the AR6 output was saved |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Metadata from AR6 for |
Source code in src/gcages/testing.py
get_ar6_raw_emissions
cached
#
get_ar6_raw_emissions(
model: str,
scenario: str,
processed_ar6_output_data_dir: Path,
) -> DataFrame
Get all raw emissions from AR6 for a given model-scenario
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Model |
required |
scenario
|
str
|
Scenario |
required |
processed_ar6_output_data_dir
|
Path
|
Directory in which the AR6 was processed into individual model-scenario files (In the repo, see |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
All raw emissions from AR6 for |
Source code in src/gcages/testing.py
get_ar6_temperature_outputs
cached
#
get_ar6_temperature_outputs(
model: str,
scenario: str,
processed_ar6_output_data_dir: Path,
dropna: bool = True,
) -> DataFrame
Get temperature outputs we've downloaded from AR6 for a given model-scenario
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Model |
required |
scenario
|
str
|
Scenario |
required |
processed_ar6_output_data_dir
|
Path
|
Directory in which the AR6 output was processed into model-scenario files (In the repo, see |
required |
dropna
|
bool
|
Drop time columns that only contain NaN |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
All temperature outputs we've downloaded from AR6 for |
Source code in src/gcages/testing.py
guess_magicc_exe_path #
guess_magicc_exe_path() -> Path
Guess the path to the MAGICC executable
Uses the MAGICC_EXECUTABLE_7 environment variable.
If that isn't set, it guesses.
Returns:
| Type | Description |
|---|---|
Path
|
Path to the MAGICC executable |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
The guessed path to the MAGICC executable does not exist |