Skip to content

Commit

Permalink
Merge f59177b into 5c660fa
Browse files Browse the repository at this point in the history
  • Loading branch information
sadielbartholomew committed Nov 24, 2018
2 parents 5c660fa + f59177b commit 180b9c0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
5 changes: 4 additions & 1 deletion docs/installing-oggm.rst
Expand Up @@ -73,6 +73,8 @@ Optional:
- progressbar2 (displays the download progress)
- bottleneck (speeds up xarray operations)
- dask (works nicely with xarray)
- `python-colorspace <https://github.com/retostauffer/python-colorspace>`_
(applies HCL-based color palettes to some graphics)


.. _conda-install:
Expand Down Expand Up @@ -328,9 +330,10 @@ Now install further dependencies::

$ pip install pyproj rasterio Pillow geopandas netcdf4 scikit-image configobj joblib xarray boto3 progressbar2 pytest motionless dask bottleneck

Finally, install the salem library::
Finally, install the salem and python-colorspace libraries::

$ pip install git+https://github.com/fmaussion/salem.git
$ pip install git+https://github.com/retostauffer/python-colorspace.git

OGGM and tests
~~~~~~~~~~~~~~
Expand Down
5 changes: 5 additions & 0 deletions docs/whats-new.rst
Expand Up @@ -13,6 +13,8 @@ New contributors to the project:
cross-validation tools and an associated website.
- **Philipp Gregor** (Master student, University of Innsbruck), added options
to switch on lateral bed stress in the flowline ice dynamics
- **Sadie Bartholomew** (Software Engineer, UK Met Office), added ability to
replace colormaps in graphics with HCL-based colors using python-colorspace.

Breaking changes
~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -151,6 +153,9 @@ Enhancements
- New ``process_dummy_cru_file`` taks to run OGGM with randomized CRU data
(:pull:`603`).
By `Fabien Maussion <https://github.com/fmaussion>`_.
- Colormaps in some graphics are replaced with Hue-Chroma-Luminance (HCL) based
improvements when python-colorspace is (optionally) installed (:pull:`587`).
By `Sadie Bartholomew <https://github.com/sadielbartholomew>`_.


Bug fixes
Expand Down
34 changes: 25 additions & 9 deletions oggm/graphics.py
Expand Up @@ -13,12 +13,30 @@
import shapely.geometry as shpg
from matplotlib import cm as colormap

try:
# optional python-colorspace dependency for better (HCL-based) colormaps
from colorspace import sequential_hcl
USE_HCL_CMAP = True
except ImportError:
USE_HCL_CMAP = False

from oggm.core.flowline import FileModel
from oggm import cfg, utils

# Module logger
log = logging.getLogger(__name__)

# Set global colormaps
ALTITUDE_CMAP = colormap.terrain
if USE_HCL_CMAP:
CMAP_DIVS = 100 # number of discrete colours from continuous colormaps
THICKNESS_CMAP = sequential_hcl("Blue-Yellow", rev=True).cmap(CMAP_DIVS)
SECTION_THICKNESS_CMAP = THICKNESS_CMAP
GLACIER_THICKNESS_CMAP = THICKNESS_CMAP
else:
SECTION_THICKNESS_CMAP = plt.cm.get_cmap('YlOrRd')
GLACIER_THICKNESS_CMAP = plt.get_cmap('viridis')


def truncate_colormap(cmap, minval=0.0, maxval=1.0, n=256):
"""Remove extreme colors from a colormap."""
Expand Down Expand Up @@ -216,7 +234,7 @@ def plot_domain(gdirs, ax=None, smap=None):
except ValueError:
pass

cm = truncate_colormap(colormap.terrain, minval=0.25, maxval=1.0, n=256)
cm = truncate_colormap(ALTITUDE_CMAP, minval=0.25, maxval=1.0, n=256)
smap.set_cmap(cm)
smap.set_plot_params(nlevels=256)

Expand Down Expand Up @@ -256,7 +274,7 @@ def plot_centerlines(gdirs, ax=None, smap=None, use_flowlines=False,
with utils.ncDataset(gdir.get_filepath('gridded_data')) as nc:
topo = nc.variables['topo'][:]

cm = truncate_colormap(colormap.terrain, minval=0.25, maxval=1.0, n=256)
cm = truncate_colormap(ALTITUDE_CMAP, minval=0.25, maxval=1.0, n=256)
smap.set_cmap(cm)
smap.set_plot_params(nlevels=256)
smap.set_data(topo)
Expand Down Expand Up @@ -464,9 +482,8 @@ def plot_inversion(gdirs, ax=None, smap=None, linewidth=3, vmax=None):
toplot_crs.append(crs)
vol.extend(c['volume'])

cm = plt.cm.get_cmap('YlOrRd')
dl = salem.DataLevels(cmap=cm, nlevels=256, data=toplot_th,
vmin=0, vmax=vmax)
dl = salem.DataLevels(cmap=SECTION_THICKNESS_CMAP, nlevels=256,
data=toplot_th, vmin=0, vmax=vmax)
colors = dl.to_rgb()
for l, c, crs in zip(toplot_lines, colors, toplot_crs):
smap.set_geometry(l, crs=crs, color=c,
Expand Down Expand Up @@ -516,7 +533,7 @@ def plot_distributed_thickness(gdirs, ax=None, smap=None, varname_suffix=''):
for l in poly_pix.interiors:
smap.set_geometry(l, crs=crs, color='black', linewidth=0.5)

smap.set_cmap(plt.get_cmap('viridis'))
smap.set_cmap(GLACIER_THICKNESS_CMAP)
smap.set_plot_params(nlevels=256)
smap.set_data(thick)

Expand Down Expand Up @@ -577,9 +594,8 @@ def plot_modeloutput_map(gdirs, ax=None, smap=None, model=None,
toplot_lines.append(line)
toplot_crs.append(crs)

cm = plt.cm.get_cmap('YlOrRd')
dl = salem.DataLevels(cmap=cm, nlevels=256, data=toplot_th,
vmin=0, vmax=vmax)
dl = salem.DataLevels(cmap=SECTION_THICKNESS_CMAP, nlevels=256,
data=toplot_th, vmin=0, vmax=vmax)
colors = dl.to_rgb()
for l, c, crs in zip(toplot_lines, colors, toplot_crs):
smap.set_geometry(l, crs=crs, color=c,
Expand Down

0 comments on commit 180b9c0

Please sign in to comment.