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 test data for gcages #41

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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.
162 changes: 162 additions & 0 deletions gcages/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# Raw scenario database file
tests/test-data/AR6_Scenarios_Database_World_ALL_CLIMATE_v1.1.csv

# Notebooks
*.ipynb

# Auto-generated docs and helper files
docs/api/*
!docs/api/.gitkeep
docs/cli/*
!docs/cli/.gitkeep

# pdm stuff
.pdm-python

# Databases
*.db

# Jupyter cache
.jupyter_cache

# IDE stuff
.idea/

# Ruff cache
.ruff_cache

# Licence check
licence-check.txt

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# Mac stuff
*.DS_Store
52 changes: 52 additions & 0 deletions gcages/scripts/changelog-to-release-template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""
Extract the changes from the latest version in our CHANGELOG

These can then be used in our release template.
"""

from __future__ import annotations

from pathlib import Path

import typer


def main() -> None:
"""
Extract the latest version changes from our CHANGELOG

They are printed to stdout
"""
CHANGELOG = Path("docs") / "changelog.md"

with open(CHANGELOG) as fh:
changelog_raw = fh.read()

check_for_next_version = False
grab_notes = False
latest_version_notes: list[str] = []
for line in changelog_raw.splitlines():
if not check_for_next_version:
if line == "<!-- towncrier release notes start -->":
check_for_next_version = True

continue

if not grab_notes:
if line.startswith("## Global Climate Assessment of Global Emission Scenarios"):
grab_notes = True

continue

# We are grabbing notes now
# If we've reached the next version's notes, break
if line.startswith("## Global Climate Assessment of Global Emission Scenarios"):
break

latest_version_notes.append(line)

print("\n".join(latest_version_notes))


if __name__ == "__main__":
typer.run(main)
39 changes: 39 additions & 0 deletions gcages/scripts/convert_ar6_res_to_test_csvs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
Convert the test file from xls to csvs we can use in the repo
"""

from pathlib import Path

import pandas as pd
import pandas_indexing as pix
import tqdm

TEST_DATA_DIR = Path(__file__).parents[1] / "tests" / "test-data"
# This file is available from the scenario explorer.
# It's nearly 1GB, which is why we don't include it here.
# It's md5sum is:
# 4b8aea8270566584db9d893ff7b4562e tests/test-data/AR6_Scenarios_Database_World_ALL_CLIMATE_v1.1.csv
# (Generated with `md5sum tests/test-data/AR6_Scenarios_Database_World_ALL_CLIMATE_v1.1.csv`)

raw = pd.read_csv(TEST_DATA_DIR / "AR6_Scenarios_Database_World_ALL_CLIMATE_v1.1.csv").set_index(
["Model", "Scenario", "Variable", "Unit", "Region"]
)

emissions = raw[pix.ismatch(Variable="**Emissions**")]
temperature_magicc = raw[pix.ismatch(Variable="**|Surface Temperature**MAGICC**")]

temperature_magicc.index.to_frame()[["Model", "Scenario"]].drop_duplicates().to_csv(
TEST_DATA_DIR / "ar6_scenarios_raw_model_scenario_combinations.csv", index=False
)

for (model, scenario), msdf in tqdm.tqdm(temperature_magicc.groupby(["Model", "Scenario"])):
filename = f"ar6_scenarios__{model}__{scenario}__temperatures.csv"
filename = filename.replace("/", "_").replace(" ", "_")
out_file = TEST_DATA_DIR / filename

msdf.to_csv(out_file)

filename_emissions = f"ar6_scenarios__{model}__{scenario}__emissions.csv"
filename_emissions = filename_emissions.replace("/", "_").replace(" ", "_")
out_file_emissions = TEST_DATA_DIR / filename_emissions
emissions[pix.ismatch(Model=model) & pix.ismatch(Scenario=scenario)].to_csv(out_file_emissions)
29 changes: 29 additions & 0 deletions gcages/scripts/test-install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
Test that all of our modules can be imported

Also test that associated constants are set correctly

Thanks https://stackoverflow.com/a/25562415/10473080
"""

import importlib
import pkgutil

import gcages


def import_submodules(package_name: str) -> None:
"""
Test import of submodules
"""
package = importlib.import_module(package_name)

for _, name, is_pkg in pkgutil.walk_packages(package.__path__):
full_name = package.__name__ + "." + name
importlib.import_module(full_name)
if is_pkg:
import_submodules(full_name)


import_submodules("gcages")
print(gcages.__version__)
Empty file added gcages/tests/test-data/.gitkeep
Empty file.
Loading