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

Ar6 colors #213

Merged
merged 28 commits into from
Apr 15, 2019
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
eb11b44
update test code to use newer freetype
gidden Apr 4, 2019
5954786
add ability to declare in run control AR6 colors
gidden Apr 4, 2019
f4974ba
appease stickler
gidden Apr 5, 2019
0277e98
update ci for new matplotlib
gidden Apr 9, 2019
588155a
get a list of files in env
gidden Apr 9, 2019
c0cfab6
update deps, only region issue now
gidden Apr 9, 2019
67e35f6
now should pass on linux
gidden Apr 9, 2019
28b30d5
update envs again
gidden Apr 9, 2019
cc4e2ef
libiconv goes back in..
gidden Apr 9, 2019
60a7a63
remove python2 from travis, add py36, py35
gidden Apr 9, 2019
3c59baa
try make in windows
gidden Apr 9, 2019
b132f39
update conda on appveyor
gidden Apr 9, 2019
475ea86
try again
gidden Apr 9, 2019
d65a479
better join in travis
gidden Apr 9, 2019
601fb97
explicit conda in appveyor
gidden Apr 9, 2019
4d48ab6
try just blanket conda forge installs
gidden Apr 9, 2019
d8b4684
remove py35 as it is automagically getting bumped to 37 via conda, pr…
gidden Apr 9, 2019
c530a47
try py37 in appveyor
gidden Apr 9, 2019
2424779
update assertion
gidden Apr 9, 2019
71852c8
Add RCP colours and tweak Makefile (#6)
znicholls Apr 10, 2019
307cc42
rename ssp3 lowntcf, fix long comment
gidden Apr 10, 2019
801a245
update figure test
gidden Apr 10, 2019
2d2ccf8
revert makefile changes
gidden Apr 10, 2019
41408c8
Update make setup for CI (#7)
znicholls Apr 10, 2019
b2e726d
added tutorial notebook
gidden Apr 11, 2019
44599c9
added to release notes
gidden Apr 11, 2019
4196e33
simplify tutorial
gidden Apr 11, 2019
39df3c1
add the tutorial to the list
gidden Apr 11, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 12 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ language: sh
matrix:
include:
- os: linux
env: PYENV=py37
env: PYENV=py36
- os: linux
env: PYENV=py27
- os: osx
env: PYENV=py37
- os: osx
env: PYENV=py27
env: PYENV=py36
- os: osx
env: PYENV=py37
# Observed on 10-Feb-19, choclatey builds for miniconda3 break
# see: https://github.com/conda/conda/issues/6064
# It is not clear how/when this can be fixed, so turn this back off for now
Expand All @@ -21,17 +21,21 @@ matrix:

before_install:
- source ./ci/env.sh
- bash ./ci/travis-install.sh
- bash ./ci/travis-install-miniconda.sh
- conda create -n testing python=$PYVERSION --yes
- source activate testing
- make virtual-environment
- make -B virtual-environment

install:
- make install

script:
- python -c "import os, sys; assert os.environ['PYVERSION'] == sys.version[0]"
- conda list
- python -c "import os; print(os.environ['PYVERSION'])"
- python -c "import sys; print(sys.version)"
- python -c "import os, sys; assert os.environ['PYVERSION'] == '.'.join([sys.version[0], sys.version[2]])"
- make test
# silly problems are there for building docs in windows and py2 (tries to look for py3 jupyter kernel)
# only test docs once to make sure everything works on most recent python
- cd doc
- if [[ "${PYENV}" == "py37" && "${TRAVIS_OS_NAME}" != 'windows' ]]; then make html; fi
- cd ..
Expand Down
19 changes: 9 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
.DEFAULT_GOAL := help

CI_DIR=./ci
CI_ENVIRONMENT_CONDA_DEFAULT_FILE=$(CI_DIR)/environment-conda-default.txt
CI_ENVIRONMENT_CONDA_FORGE_FILE=$(CI_DIR)/environment-conda-forge.txt


ifndef CONDA_PREFIX
$(error Conda not active, please install conda and then activate it using \`conda activate\`))
Expand All @@ -10,7 +14,6 @@ endif
VENV_DIR=$(CONDA_PREFIX)
endif


define PRINT_HELP_PYSCRIPT
import re, sys

Expand Down Expand Up @@ -80,19 +83,15 @@ docs: $(VENV_DIR) ## make the docs

.PHONY: virtual-environment
virtual-environment: $(VENV_DIR) ## make virtual environment for development

$(VENV_DIR): $(CI_ENVIRONMENT_CONDA_DEFAULT_FILE) $(CI_ENVIRONMENT_CONDA_FORGE_FILE)
# TODO: unify with ci install instructions somehow
$(CONDA_EXE) install --yes $(shell cat ci/environment-conda-default.txt | tr '\n' ' ')
$(CONDA_EXE) install --yes -c conda-forge $(shell cat ci/environment-conda-forge.txt | tr '\n' ' ')
# do matplotlib version fiddling for making plots
$(CONDA_EXE) uninstall --yes --force matplotlib
$(CONDA_EXE) install --yes $(shell cat $(CI_ENVIRONMENT_CONDA_DEFAULT_FILE) | tr '\n' ' ')
$(CONDA_EXE) install --yes -c conda-forge $(shell cat $(CI_ENVIRONMENT_CONDA_FORGE_FILE) | tr '\n' ' ')
# Install development setup
$(VENV_DIR)/bin/pip install -e .[tests,deploy]
# do matplotlib version fiddling for making plots (part 2)
$(VENV_DIR)/bin/pip uninstall -y matplotlib
$(VENV_DIR)/bin/pip install matplotlib==2.1.2
touch $(VENV_DIR)
# install docs requirements
cd doc; pip install -r requirements.txt
cd doc; $(VENV_DIR)/bin/pip install -r requirements.txt

.PHONY: release-on-conda
release-on-conda: ## release pyam on conda
Expand Down
19 changes: 12 additions & 7 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

environment:
matrix:
- PYTHON_VERSION: "2.7"
MINICONDA: "C:\\Miniconda-x64"
PYTHON_ARCH: "64"
- PYTHON_VERSION: "3.6"
MINICONDA: "C:\\Miniconda36-x64"
PYTHON_ARCH: "64"
- PYTHON_VERSION: "3.7"
MINICONDA: "C:\\Miniconda37-x64"
PYTHON_ARCH: "64"

init:
- "ECHO %PYTHON_VERSION% %MINICONDA%"
Expand All @@ -20,14 +20,19 @@ install:
- set "CONDA_ROOT=C:\Miniconda%BASE_PYTHON_VERSION%%ARCH_LABEL%"
- set "PATH=%CONDA_ROOT%;%CONDA_ROOT%\Scripts;%CONDA_ROOT%\Library\bin;%PATH%"

# Dependencies and package install
- conda install --yes geopandas cartopy
- if "%PYTHON_VERSION%" == "2.7" pip install functools32
# create conda environment
- conda update --yes conda
- conda create -n testing python="%PYTHON_VERSION%" --yes
- conda --version
- activate testing
- conda install -y numpy pandas pyyaml xlrd xlsxwriter matplotlib==3.0.3 seaborn==0.9.0 six requests jupyter nbconvert
- conda install -y -c conda-forge libiconv gdal fiona geopandas cartopy

build: false

test_script:
- pip install -e .[tests]
- conda list
- pip install -e .[tests,deploy]
- pytest -v --mpl tests --mpl-results-path=test-artifacts

artifacts:
Expand Down
17 changes: 11 additions & 6 deletions ci/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,23 @@ case "${TRAVIS_OS_NAME}" in
esac

case "${PYENV}" in
py27)
export PYVERSION=2
export CHOCOPATH='miniconda2'
export CHOCONAME='miniconda'
py35)
export PYVERSION=3.5
export CHOCOPATH='miniconda3'
export CHOCONAME='miniconda3'
;;
py36)
export PYVERSION=3.6
export CHOCOPATH='miniconda3'
export CHOCONAME='miniconda3'
;;
py37)
export PYVERSION=3
export PYVERSION=3.7
export CHOCOPATH='miniconda3'
export CHOCONAME='miniconda3'
;;
esac
export URL="https://repo.anaconda.com/miniconda/Miniconda$PYVERSION-latest-$OSNAME-x86_64.$EXT"
export URL="https://repo.anaconda.com/miniconda/Miniconda3-latest-$OSNAME-x86_64.$EXT"

if [[ "$TRAVIS_OS_NAME" != 'windows' ]]; then
export PATH=$HOME/miniconda/bin:$PATH
Expand Down
8 changes: 4 additions & 4 deletions ci/environment-conda-default.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
numpy==1.14.0
pandas==0.22.0
numpy
pandas
pyyaml
xlrd
xlsxwriter
matplotlib==2.1.2
seaborn==0.8.1
matplotlib==3.0.3
seaborn==0.9.0
six
requests
jupyter
Expand Down
1 change: 1 addition & 0 deletions ci/environment-conda-forge.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
libiconv
gdal
fiona
geopandas
Expand Down
2 changes: 0 additions & 2 deletions ci/travis-install.sh → ci/travis-install-miniconda.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,3 @@ fi
# update conda
conda update --yes conda

# create named env
conda create -n testing python=$PYVERSION --yes
1 change: 1 addition & 0 deletions doc/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ cloud_sptheme
nbformat
ipython
jupyter
jupyter_contrib_nbextensions
pillow
38 changes: 38 additions & 0 deletions pyam/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,28 @@
'bottom': dict(loc='upper center', bbox_to_anchor=(0.5, -0.2), ncol=3),
}

PYAM_COLORS = {
znicholls marked this conversation as resolved.
Show resolved Hide resolved
'AR6-SSP1-1.9': "#00AAD0",
'AR6-SSP1-2.6': "#003466",
'AR6-SSP2-4.5': "#EF550F",
'AR6-SSP3-7.0': "#E00000",
'AR6-SSP3-LowNTCF': "#E00000",
'AR6-SSP4-3.4': "#FFA900",
'AR6-SSP4-6.0': "#C47900",
'AR6-SSP5-3.4-OS': "#7F006E",
'AR6-SSP5-8.5': "#990002",
znicholls marked this conversation as resolved.
Show resolved Hide resolved
'AR6-RCP-2.6': "#003466",
'AR6-RCP-4.5': "#5492CD",
'AR6-RCP-6.0': "#C47900",
'AR6-RCP-8.5': "#990002",
# AR5 colours from
# https://tdaviesbarnard.co.uk/1202/ipcc-official-colors-rcp/
'AR5-RCP-2.6': "#0000FF",
'AR5-RCP-4.5': "#79BCFF",
'AR5-RCP-6.0': "#FF822D",
'AR5-RCP-8.5': "#FF0000",
}


def reset_default_props(**kwargs):
"""Reset properties to initial cycle point"""
Expand Down Expand Up @@ -110,6 +132,22 @@ def assign_style_props(df, color=None, marker=None, linestyle=None,
props_for_kind[val] = next(defaults[kind])
props[kind] = props_for_kind

# update for special properties only if they exist in props
if 'color' in props:
d = props['color']
values = list(d.values())
# find if any colors in our properties corresponds with special colors
# we know about
overlap_idx = np.in1d(values, list(PYAM_COLORS.keys()))
if overlap_idx.any(): # some exist in our special set
keys = np.array(list(d.keys()))[overlap_idx]
values = np.array(values)[overlap_idx]
# translate each from pyam name, like AR6-SSP2-45 to proper color
# designation
for k, v in zip(keys, values):
d[k] = PYAM_COLORS[v]
# replace props with updated dict without special colors
props['color'] = d
return props


Expand Down
Binary file modified tests/expected_figs/test_add_panel_label.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/expected_figs/test_bar_plot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/expected_figs/test_bar_plot_h.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/expected_figs/test_bar_plot_rc.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/expected_figs/test_bar_plot_stacked.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/expected_figs/test_bar_plot_stacked_net_line.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/expected_figs/test_bar_plot_title.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/expected_figs/test_line_PYAM_COLORS.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/expected_figs/test_line_color.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/expected_figs/test_line_color_fill_between.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/expected_figs/test_line_color_final_ranges.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/expected_figs/test_line_filter_title.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/expected_figs/test_line_linestyle_legend.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/expected_figs/test_line_marker_legend.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/expected_figs/test_line_no_legend.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/expected_figs/test_line_plot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/expected_figs/test_line_plot_1_var.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/expected_figs/test_line_plot_2_vars.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/expected_figs/test_line_plot_bottom_legend.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/expected_figs/test_line_plot_dict_legend.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/expected_figs/test_line_rm_legend_label.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/expected_figs/test_line_single_color.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/expected_figs/test_line_update_rc.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/expected_figs/test_pie_plot_labels.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/expected_figs/test_pie_plot_legend.png
Binary file modified tests/expected_figs/test_pie_plot_other.png
Binary file modified tests/expected_figs/test_region.png
Binary file modified tests/expected_figs/test_region_cbar.png
Binary file modified tests/expected_figs/test_region_cbar_args.png
Binary file modified tests/expected_figs/test_region_cmap.png
Binary file modified tests/expected_figs/test_region_crs.png
Binary file modified tests/expected_figs/test_region_map_regions.png
Binary file modified tests/expected_figs/test_region_map_regions_legend.png
Binary file modified tests/expected_figs/test_region_vmin_vmax.png
Binary file modified tests/expected_figs/test_scatter.png
Binary file modified tests/expected_figs/test_scatter_meta.png
Binary file modified tests/expected_figs/test_scatter_variables_with_meta_color.png
Binary file modified tests/expected_figs/test_scatter_with_lines.png
Binary file modified tests/expected_figs/test_stack_plot.png
Binary file modified tests/expected_figs/test_stack_plot_other.png
36 changes: 32 additions & 4 deletions tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
import os
import copy
import numpy as np
import pandas as pd
import pyam

import warnings

# on CI, freetype version 2.6.1 works, but 2.8.0 does not
# if we want to move to 2.8.0, then we will need to regenerate images
FREETYPE_VERSION = matplotlib.ft2font.__freetype_version__
if int(FREETYPE_VERSION.replace('.', '')) > 261:
pytest.skip('Freetype version > 2.6.1: {}'.format(FREETYPE_VERSION),
allow_module_level=True)
if int(FREETYPE_VERSION.replace('.', '')) < 291:
msg = 'Freetype version < 2.9.1: {}'.format(FREETYPE_VERSION)
warnings.warn('test_plotting.py is being skipped due to a '
'Freetype Version mismatch: {}'.format(msg))
pytest.skip(msg, allow_module_level=True)

try:
import cartopy
Expand Down Expand Up @@ -82,6 +85,31 @@ def test_line_color(plot_df):
return fig


@pytest.mark.mpl_image_compare(**MPL_KWARGS)
gidden marked this conversation as resolved.
Show resolved Hide resolved
def test_line_PYAM_COLORS(plot_df):
# add a family of lines for each color in plotting.PYAM_COLORS separated by
# a small offset
update = {'color': {'model': {}}}
_df = plot_df.filter(
model='test_model',
variable='Primary Energy',
scenario='test_scenario1',
).data.copy()
dfs = []
for i, color in enumerate(plotting.PYAM_COLORS):
df = _df.copy()
model = color
df['model'] = model
df['value'] += i
update['color']['model'][model] = color
dfs.append(df)
df = pyam.IamDataFrame(pd.concat(dfs))
fig, ax = plt.subplots(figsize=(8, 8))
with update_run_control(update):
df.line_plot(ax=ax, color='model', legend=True)
return fig


@pytest.mark.mpl_image_compare(**MPL_KWARGS)
def test_line_color_fill_between(plot_df):
fig, ax = plt.subplots(figsize=(8, 8))
Expand Down