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 license #6

Merged
merged 14 commits into from
Jun 4, 2021
83 changes: 83 additions & 0 deletions .github/workflows/ci-cd-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: MESMER-OpenSCM Runner CI-CD
on:
push:
branches:
- main
tags:
- 'v*'
pull_request:

jobs:
linting-and-docs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["ubuntu-latest"]
python-version: [3.8]

steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Cache conda
uses: actions/cache@v2
with:
path: ~/conda_pkgs_dir
key:
${{ runner.os }}-conda-py${{ matrix.python-version }}-${{
hashFiles('environment.yml') }}
- name: Setup conda
uses: conda-incubator/setup-miniconda@v2.0.1
with:
channels: conda-forge
channel-priority: strict
activate-environment: mesmer-openscmrunner-tests
auto-update-conda: false
python-version: ${{ matrix.python-version }}
- name: Conda info
shell: bash -l {0}
run: conda info
- name: Run format and linting tests
shell: bash -l {0}
# TODO: use make -B conda-environment when mesmer is available
run: |
which python
conda install black flake8 isort
black --exclude _version.py --check src tests setup.py
flake8 src tests setup.py
isort --check-only --quiet src tests setup.py

build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["ubuntu-latest"]
python-version: [3.8]

steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Cache conda
uses: actions/cache@v2
with:
path: ~/conda_pkgs_dir
key:
${{ runner.os }}-conda-py${{ matrix.python-version }}-${{
hashFiles('environment.yml') }}
- name: Setup conda
uses: conda-incubator/setup-miniconda@v2.0.1
with:
channels: conda-forge
channel-priority: strict
activate-environment: mesmer-openscmrunner-tests
auto-update-conda: false
python-version: ${{ matrix.python-version }}
- name: Conda info
shell: bash -l {0}
run: conda info
- name: Run tests
shell: bash -l {0}
# TDOO: use make -B test
run: |
which python
conda install pytest
pytest tests/test_source_file_headers.py
10 changes: 10 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
External contributors
=====================

- Zebedee Nicholls (MESMER-OpenSCM Runner lead developer)

ETH Zurich team
===============

- Lea Beusch (MESMER developer)
- Mathias Hauser (MESMER long-term maintainer)
621 changes: 621 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

27 changes: 26 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
MESMER-OpenSCM Runner
=====================

Coupling between MESMER and `OpenSCM-Runner <https://github.com/openscm/openscm-runner>`_.
Coupling between `MESMER <https://github.com/MESMER-group/mesmer>`_ and `OpenSCM-Runner <https://github.com/openscm/openscm-runner>`_.

.. sec-begin-license

License
-------

Copyright (c) 2021 MESMER-OpenSCM Runner contributors, listed in AUTHORS, and ETH Zurich.

MESMER-OpenSCM Runner is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License (see `LICENSE <https://github.com/openscm/scmdata/blob/master/LICENSE>`_), or
(at your option) any later version.

MESMER-OpenSCM Runner is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.

The full list of code contributors can be found in AUTHORS or at
[github.com/znicholls/mesmer-openscmrunner/graphs/contributors](https://github.com/znicholls/mesmer-openscmrunner/graphs/contributors).

.. sec-end-license
10 changes: 6 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@
AUTHORS = [
("Zeb Nicholls", "zebedee.nicholls@climate-energy-college.org"),
("Lea Beusch", "lea.beusch@env.ethz.ch"),
("Mathias Hauser", "mathias.hauser@env.ethz.ch"),
]
URL = "https://github.com/znicholls/mesmer-openscmrunner"
PROJECT_URLS = {
"Bug Reports": "https://github.com/znicholls/mesmer-openscmrunner/issues",
# "Documentation": "https://mesmer-openscmruner.readthedocs.io/en/latest",
"Source": "https://github.com/znicholls/mesmer-openscmrunner",
}
LICENSE = None # "3-Clause BSD License"
LICENSE = "GPLv3+" # I think this is the right short-hand...
CLASSIFIERS = [
"Development Status :: 4 - Beta",
# "License :: OSI Approved :: BSD License",
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.7",
Expand All @@ -41,8 +42,9 @@
REQUIREMENTS = [
# "mesmer", # once released
"openscm-runner>=0.6",
"scmdata>=0.9,<0.10", #whilst running notebooks with rcmip phase 2 output
]
"scmdata>=0.9,<0.10", # whilst running notebooks with rcmip phase 2 output
"xarray==0.17.0", # whilst running notebooks with rcmip phase 2 output
]
REQUIREMENTS_TESTS = [
"codecov",
"nbval",
Expand Down
3 changes: 3 additions & 0 deletions src/mesmer_openscmrunner/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# MESMER-OpenSCM Runner, land-climate dynamics group, S.I. Seneviratne
# Copyright (c) 2021 MESMER-OpenSCM Runner contributors, listed in AUTHORS, and ETH Zurich.
# Licensed under the GNU General Public License v3.0 or later; see LICENSE or https://www.gnu.org/licenses/
1 change: 0 additions & 1 deletion src/mesmer_openscmrunner/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# This file helps to compute a version number in source trees obtained from
# git-archive tarball (such as those provided by githubs download-from-tag
# feature). Distribution tarballs (built by setup.py sdist) and build
Expand Down
25 changes: 14 additions & 11 deletions src/mesmer_openscmrunner/draw_realisations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# MESMER-OpenSCM Runner, land-climate dynamics group, S.I. Seneviratne
# Copyright (c) 2021 MESMER-OpenSCM Runner contributors, listed in AUTHORS, and ETH Zurich.
# Licensed under the GNU General Public License v3.0 or later; see LICENSE or https://www.gnu.org/licenses/

import joblib
import mesmer.create_emulations
import xarray as xr
Expand Down Expand Up @@ -47,9 +51,6 @@ def _draw_realisations_from_mesmer_file_and_openscm_output(
``openscm_hfds`` contains variables other than ``"Heat Uptake|Ocean"``
"""
mesmer_bundle = joblib.load(mesmer_bundle_file)
import pdb
pdb.set_trace()
time_mesmer = mesmer_bundle["time"]

gsat_scenarios = set(openscm_gsat.get_unique_meta("scenario"))
hfds_scenarios = set(openscm_hfds.get_unique_meta("scenario"))
Expand All @@ -76,8 +77,12 @@ def _draw_realisations_from_mesmer_file_and_openscm_output(
scen_tas = _filter_and_assert_1d(scen_gsat.filter(year=hard_coded_scen_years))

openscm_hfds_for_mesmer_scen = openscm_hfds_for_mesmer.filter(scenario=scenario)
hist_hfds = _filter_and_assert_1d(openscm_hfds_for_mesmer_scen.filter(year=hard_coded_hist_years))
scen_hfds = _filter_and_assert_1d(openscm_hfds_for_mesmer_scen.filter(year=hard_coded_scen_years))
hist_hfds = _filter_and_assert_1d(
openscm_hfds_for_mesmer_scen.filter(year=hard_coded_hist_years)
)
scen_hfds = _filter_and_assert_1d(
openscm_hfds_for_mesmer_scen.filter(year=hard_coded_scen_years)
)

# TODO: remove hard-coding and actually map up with what MESMER expects
preds_lt_scenario = {}
Expand All @@ -104,15 +109,13 @@ def _draw_realisations_from_mesmer_file_and_openscm_output(
land_fractions=mesmer_bundle["land_fractions"],
time={
"hist": scen_gsat.filter(year=hard_coded_hist_years)["year"].values,
scenario: scen_gsat.filter(year=hard_coded_scen_years)["year"].values
scenario: scen_gsat.filter(year=hard_coded_scen_years)["year"].values,
},
)

result_scenario = (
result_scenario
.squeeze(dim="scenario", drop=True)
.expand_dims({"scenario": [scenario]})
)
result_scenario = result_scenario.squeeze(
dim="scenario", drop=True
).expand_dims({"scenario": [scenario]})
out.append(result_scenario)

out = xr.merge(out)
Expand Down
26 changes: 25 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
# MESMER-OpenSCM Runner, land-climate dynamics group, S.I. Seneviratne
# Copyright (c) 2021 MESMER-OpenSCM Runner contributors, listed in AUTHORS, and ETH Zurich.
# Licensed under the GNU General Public License v3.0 or later; see LICENSE or https://www.gnu.org/licenses/

import os.path

import pytest

TEST_DATA_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "test-data")
REPO_ROOT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
TEST_DATA_DIR = os.path.join(REPO_ROOT_DIR, "tests", "test-data")


@pytest.fixture
def test_data_dir():
return TEST_DATA_DIR


@pytest.fixture
def repo_root_dir():
return REPO_ROOT_DIR


def pytest_addoption(parser):
parser.addoption(
"--update-copyright-notices",
action="store_true",
default=False,
help="Overwrite expected values",
)


@pytest.fixture
def update_copyright_notices(request):
return request.config.getoption("--update-copyright-notices")
16 changes: 13 additions & 3 deletions tests/integration/test_create_realisations.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# MESMER-OpenSCM Runner, land-climate dynamics group, S.I. Seneviratne
# Copyright (c) 2021 MESMER-OpenSCM Runner contributors, listed in AUTHORS, and ETH Zurich.
# Licensed under the GNU General Public License v3.0 or later; see LICENSE or https://www.gnu.org/licenses/

import os.path

import scmdata
Expand Down Expand Up @@ -54,7 +58,9 @@ def test_create_realisations_from_pre_run_data(test_data_dir):
assert set(result.data_vars) == {"tas"}
assert set(result.dims) == {"realisation", "scenario", "z", "year"}

assert set(result["scenario"].values) == set(openscm_gsat.get_unique_meta("scenario"))
assert set(result["scenario"].values) == set(
openscm_gsat.get_unique_meta("scenario")
)

# make sure we can get onto a lat lon grid from what is saved
result_reshaped = result.set_index(z=("lat", "lon")).unstack("z")
Expand All @@ -67,7 +73,9 @@ def test_create_realisations_from_pre_run_data(test_data_dir):
}


def test_create_realisations_from_pre_run_data_with_unrecognised_scenario_name(test_data_dir):
def test_create_realisations_from_pre_run_data_with_unrecognised_scenario_name(
test_data_dir,
):
mesmer_bundle_file = os.path.join(
test_data_dir, "mesmer-bundles", "test-generic-mesmer-bundle.pkl"
)
Expand Down Expand Up @@ -112,7 +120,9 @@ def test_create_realisations_from_pre_run_data_with_unrecognised_scenario_name(t
assert set(result.data_vars) == {"tas"}
assert set(result.dims) == {"realisation", "scenario", "z", "year"}

assert set(result["scenario"].values) == set(openscm_gsat.get_unique_meta("scenario"))
assert set(result["scenario"].values) == set(
openscm_gsat.get_unique_meta("scenario")
)

# make sure we can get onto a lat lon grid from what is saved
result_reshaped = result.set_index(z=("lat", "lon")).unstack("z")
Expand Down
50 changes: 50 additions & 0 deletions tests/test_source_file_headers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# MESMER-OpenSCM Runner, land-climate dynamics group, S.I. Seneviratne
# Copyright (c) 2021 MESMER-OpenSCM Runner contributors, listed in AUTHORS, and ETH Zurich.
# Licensed under the GNU General Public License v3.0 or later; see LICENSE or https://www.gnu.org/licenses/
import datetime
import glob
import os.path

import pytest

LICENSE_TEMPLATE = """# MESMER-OpenSCM Runner, land-climate dynamics group, S.I. Seneviratne
# Copyright (c) 2021{} MESMER-OpenSCM Runner contributors, listed in AUTHORS, and ETH Zurich.
# Licensed under the GNU General Public License v3.0 or later; see LICENSE or https://www.gnu.org/licenses/"""


EXCLUDE = ["_version.py"]


def test_source_code_headers(repo_root_dir, update_copyright_notices, n_lines=None):
n_lines = len(LICENSE_TEMPLATE.split("\n")) if n_lines is None else n_lines

files_to_check = glob.glob(
os.path.join(repo_root_dir, "tests", "**", "*.py"), recursive=True
) + glob.glob(os.path.join(repo_root_dir, "src", "**", "*.py"), recursive=True)

files_to_check = [f for f in files_to_check if os.path.basename(f) not in EXCLUDE]

now = datetime.datetime.now()
current_year = now.year
if current_year == 2021:
license_template = LICENSE_TEMPLATE.format("")
else:
license_template = LICENSE_TEMPLATE.format("-{}".format(current_year))

for f in files_to_check:
with open(f) as fh:
contents = fh.read()

if not contents.startswith(license_template):
if update_copyright_notices:
contents = "\n".join(contents.split("\n")[n_lines:])
contents = "{}\n\n{}".format(license_template, contents)
with open(f, "w") as fh:
fh.write(contents)
else:
raise ValueError(
"Update headers in source files (failing file: {})".format(f)
)

if update_copyright_notices:
pytest.skip("Updated copyright notices")