Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add harmonisation #34

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
b1c4552
Initialise repo from copier
znichollscr Jan 9, 2025
9edfd88
Update URL
znichollscr Jan 9, 2025
13d365c
Add local package
znichollscr Jan 9, 2025
fd490d3
Add basic set up
znichollscr Jan 9, 2025
ae19730
Set up failing test of harmonisation
znichollscr Jan 9, 2025
cf30007
Update gitignore
znichollscr Jan 9, 2025
e2e5736
Add failing test files
znichollscr Jan 9, 2025
b799eed
Update files to use for testing
znichollscr Jan 10, 2025
600ff4c
Shuffle tests
znichollscr Jan 10, 2025
3739629
Set out skeleton
znichollscr Jan 10, 2025
cdb915a
WIP: harmonisation
znichollscr Jan 10, 2025
96e29fe
Pass first tests of harmonisation
znichollscr Jan 10, 2025
8b2f279
Add scaling calculation
znichollscr Jan 10, 2025
d294140
Fix up energy and industrial aggregation
znichollscr Jan 10, 2025
e20b089
Sort out dropping zero in harmonisation year
znichollscr Jan 10, 2025
96132ae
Fix more tests
znichollscr Jan 10, 2025
a88e57b
Fix more tests
znichollscr Jan 10, 2025
15b7be8
Less than 10 tests left
znichollscr Jan 10, 2025
ae6dbc2
Down to MESSAGE weirdness
znichollscr Jan 10, 2025
ce41b97
Finish off harmonisation tests
znichollscr Jan 10, 2025
87d7c9c
Add tests of multi-scenario harmonisation
znichollscr Jan 10, 2025
63fb51d
Get official list of IPs
znichollscr Jan 10, 2025
96d13a2
Start cleaning up
znichollscr Jan 10, 2025
810ad54
Next bit of clean up
znichollscr Jan 10, 2025
d3e7d51
Next bit of clean up
znichollscr Jan 10, 2025
8b86b09
Finish cleaning up pre-processing
znichollscr Jan 10, 2025
ff27b17
mypy
znichollscr Jan 10, 2025
d04c5e0
Parallelise harmonisation
znichollscr Jan 10, 2025
d63be28
Fix more tests
znichollscr Jan 10, 2025
d26374b
Remove pyam-iamc dependency
znichollscr Jan 10, 2025
0fea254
Almost there
znichollscr Jan 10, 2025
5b3b36c
Get tests passing
znichollscr Jan 10, 2025
aa29a56
Figure out weird tests
znichollscr Jan 10, 2025
2d8e6f5
Split out aneris helpers module
znichollscr Jan 10, 2025
94195ef
Add testing module
znichollscr Jan 10, 2025
a2a067f
Finish cleaning up
znichollscr Jan 10, 2025
e54113f
Add first go at harmonisation
znichollscr Jan 13, 2025
0bcf02e
Add scenario download
znichollscr Jan 13, 2025
5aeced9
Upgrade jupyter lab
znichollscr Jan 13, 2025
0665310
Remove line drop
znichollscr Jan 13, 2025
5c957a0
Update download script
znichollscr Jan 13, 2025
5bf4904
Clean up
znichollscr Jan 14, 2025
202d87c
Clean up
znichollscr Jan 14, 2025
2ef126a
Clean up
znichollscr Jan 14, 2025
e288cdc
Re-run notebook
znichollscr Jan 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
data/national/ceds/processed
data/national/gfed/processed
data/national/gfed-bb4cmip/processed
data/global-composite

# RCMIP data
data/global/rcmip/data_raw
Expand Down
2 changes: 2 additions & 0 deletions data/scenarios/data_raw/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ignore the download scenarios, they should be grabbed from the database
*__scenarios-scenariomip__*.csv
27 changes: 27 additions & 0 deletions data/scenarios/data_raw/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Scenario data can be downloaded from IIASA's resources here:
https://data.ece.iiasa.ac.at/ssp-submission.

Downloading the data can be done with the following commands.
(if you're not on a unix-based system,
create a virtual environment using whatever environment manager you like
then remove `venv/bin/` from all the commands below).

```sh
# Install pyam-iamc
python3 -m venv venv
venv/bin/pip install --upgrade pip wheel
venv/bin/pip install pyam-iamc tqdm
```

Login with ixmp4

```sh
# Note that this saves your login on your machine in plain text, be careful.
venv/bin/ixmp4 login <your-username>
```

Then, download the data

```sh
venv/bin/python download-database.py
```
31 changes: 31 additions & 0 deletions data/scenarios/data_raw/download-database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import datetime as dt
from pathlib import Path

import pyam
import tqdm

OUT_DIR = Path(__file__).parents[0]

time_id = dt.datetime.now().strftime("%Y%m%d-%H%M%S")

# Establish connection to the legacy pyam platform 'ssp-submission'
pyam.iiasa.Connection("ssp_submission")
conn_ssp = pyam.iiasa.Connection("ssp_submission")
props = conn_ssp.properties().reset_index()

# Retrieve the desired scenarios' emissions
# (download everything; loop over model-scenario combinations to not blow up RAM)
for model, scenario in tqdm.tqdm(
zip(props["model"], props["scenario"]), total=len(props["model"]), desc="Model-scenario combinations"
):
print(f"Grabbing {model=} {scenario=}")
df = pyam.read_iiasa("ssp_submission", model=model, scenario=scenario, variable="Emissions|*")
if df.empty:
print(f"No data for {model=} {scenario=}")
continue

# Write out the scenario data
output_filename = f"{time_id}__scenarios-scenariomip__{model}__{scenario}.csv".replace("/", "_").replace(" ", "-")
output_file = OUT_DIR / output_filename
df.to_csv(output_file)
print(f"Data for {model} {scenario} has been written to {output_file}")
18 changes: 18 additions & 0 deletions gcages/.copier-answers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
_commit: v0.10.1
_src_path: gl:znicholls/copier-core-python-repository
conda_release: false
email: [email protected]
include_cli: true
name: Zebedee Nicholls
notebook_based_docs: true
package_manager: uv
pandas_doctests: true
plot_dependencies: true
project_description_short: Workflows for assessing the global climate implications
of global emission scenarios, typically from IAMs.
project_name_human: Global Climate Assessment of Global Emission Scenarios
project_name_pip: gcages
project_name_python: gcages
project_url: https://github.com/openscm/gcages
track_lock_file: true
40 changes: 40 additions & 0 deletions gcages/.github/ISSUE_TEMPLATE/bug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
name: Bug report
about: Report a bug
title: ''
labels: bug
assignees: ''

---

## Describe the bug
<!--- A clear and concise description of what the bug is. -->

## Failing Test
<!---
Please put the code (ideally in the form of a unit test) which fails below.

e.g.

```python
def test_bug_12():
# Python code here which fails because of the bug
# This is best if other developers can simply copy and paste this test in
# order to run it
```
-->

## Expected behavior
<!--- A clear and concise description of what you expected to happen. -->

## Screenshots
<!--- If applicable, add screenshots to help explain your problem. -->

## System
<!--- Please complete the following information. -->

- OS: [e.g. Windows, Linux, macOS]
- Python version [e.g. Python 3.11]

## Additional context
<!--- Add any other context about the problem here. -->
21 changes: 21 additions & 0 deletions gcages/.github/ISSUE_TEMPLATE/default.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
name: Default
about: Report an issue or problem
title: ''
labels: triage
assignees: ''

---

## The problem
<!--- Useful to breakdown to "As a [persona], I [want to do], so that [reason] -->

## Definition of "done"
<!---
What are the things that must be true in order to close this issue

We find that describing these as dot points works well.
-->

## Additional context
<!--- Add any additional context can go here -->
32 changes: 32 additions & 0 deletions gcages/.github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
name: Feature Request
about: Request a feature or suggest an idea for this project
title: ''
labels: feature
assignees: ''

---

## The motivation

<!--- Useful to breakdown to "As a [persona], I [want to do], so that [reason] -->

## The proposed solution

<!---
If you'd like, please provide a description of the solution you would like to see

If you don't have any ideas for the solution, simply leave this blank
-->

## Alternatives

<!---
If you've considered any alternatives, please describe them here

If you don't have any alternatives, simply leave this blank
-->

## Additional context

<!--- Add any additional context can go here -->
29 changes: 29 additions & 0 deletions gcages/.github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: "Setup Python and uv"
description: "setup Python and uv"

inputs:
python-version:
description: "Python version to use"
required: true
uv-dependency-install-flags:
description: "Flags to pass to uv when running `uv install`"
required: true
run-uv-install:
description: "Should we run the uv install steps"
required: false
default: true

runs:
using: "composite"
steps:
- name: Setup uv
id: setup-uv
uses: astral-sh/setup-uv@v4
with:
version: "0.5.11"
python-version: ${{ inputs.python-version }}
- name: Install dependencies
shell: bash
if: ${{ (inputs.run-uv-install == 'true') }}
run: |
uv sync ${{ inputs.uv-dependency-install-flags }}
9 changes: 9 additions & 0 deletions gcages/.github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Description

## Checklist

Please confirm that this pull request has done the following:

- [ ] Tests added
- [ ] Documentation added (where applicable)
- [ ] Changelog item added to `changelog/`
3 changes: 3 additions & 0 deletions gcages/.github/release_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Announcements

* Announcement 1
91 changes: 91 additions & 0 deletions gcages/.github/workflows/bump.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Bump version
# For the time being, we still do this with pdm.
# Honestly, it doesn't really matter,
# but one day uv will have a bump command too and we can switch to that.
# Relevant issue in uv: https://github.com/astral-sh/uv/issues/6298

on:
workflow_dispatch:
inputs:
bump_rule:
type: choice
description: How to bump the project's version (see https://github.com/carstencodes/pdm-bump#usage)
options:
- no-pre-release
# no micro because we always sit on a pre-release in main,
# so we would always use no-pre-release instead of micro
# - micro
- minor
- major
- "pre-release --pre alpha"
- "pre-release --pre beta"
- "pre-release --pre release-candidate"
required: true

jobs:
bump_version:
name: "Bump version and create changelog"
if: "!startsWith(github.event.head_commit.message, 'bump:')"
strategy:
matrix:
os: [ "ubuntu-latest" ]
python-version: [ "3.9" ]
runs-on: "${{ matrix.os }}"
env:
CI_COMMIT_EMAIL: "[email protected]"
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: "${{ secrets.PERSONAL_ACCESS_TOKEN }}"

- name: Setup PDM
uses: pdm-project/[email protected]
with:
python-version: ${{ matrix.python-version }}

- name: Install pdm-bump
run: |
pdm self add pdm-bump

- uses: ./.github/actions/setup
with:
python-version: ${{ matrix.python-version }}
uv-dependency-install-flags: "--all-extras --group dev"

- name: Create bump and changelog
run: |
git config --global user.name "$GITHUB_ACTOR"
git config --global user.email "$CI_COMMIT_EMAIL"

BASE_VERSION=`sed -ne 's/^version = "\([0-9\.a]*\)"/\1/p' pyproject.toml`
echo "Bumping from version $BASE_VERSION"

# Bump
pdm bump ${{ github.event.inputs.bump_rule }}

NEW_VERSION=`sed -ne 's/^version = "\([0-9\.a]*\)"/\1/p' pyproject.toml`
echo "Bumping to version $NEW_VERSION"

# Build CHANGELOG
uv run towncrier build --yes --version v$NEW_VERSION

# Commit, tag and push
git commit -a -m "bump: version $BASE_VERSION -> $NEW_VERSION"
git tag v$NEW_VERSION
git push && git push --tags

# Bump to alpha (so that future commits do not have the same
# version as the tagged commit)
BASE_VERSION=`sed -ne 's/^version = "\([0-9\.a]*\)"/\1/p' pyproject.toml`

# Bump to pre-release of next version
pdm bump pre-release --pre alpha

NEW_VERSION=`sed -ne 's/^version = "\([0-9\.a]*\)"/\1/p' pyproject.toml`
echo "Bumping version $BASE_VERSION > $NEW_VERSION"

# Commit and push
git commit -a -m "bump(pre-release): version $BASE_VERSION > $NEW_VERSION"
git push
Loading