Skip to content

Commit f56746c

Browse files
Merge branch 'master' into pyup-update-dask-0.15.4-to-0.16.0
2 parents 6cfa829 + 681ff2b commit f56746c

File tree

10 files changed

+73
-5
lines changed

10 files changed

+73
-5
lines changed

impactlab_tools/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from __future__ import absolute_import
66

77
__author__ = """Climate Impact Lab"""
8-
__version__ = '0.1.0'
8+
__version__ = '0.2.0'
99

1010
_module_imports = (
1111
)
4.21 MB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
12.3 MB
Binary file not shown.
191 KB
Binary file not shown.

impactlab_tools/utils/visualize.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import numpy as np
2+
3+
import matplotlib
4+
import matplotlib.pyplot as plt
5+
from mpl_toolkits.basemap import Basemap
6+
from matplotlib.patches import Polygon
7+
from matplotlib.collections import PatchCollection
8+
9+
import toolz
10+
11+
12+
def get_shape():
13+
14+
return 'assets/hierid_regions'
15+
16+
17+
@toolz.memoize
18+
def prep_polygons(
19+
shapepath=None,
20+
projection='cyl',
21+
**kwargs):
22+
23+
if shapepath is None:
24+
shapepath = get_shape()
25+
26+
m = Basemap(projection=projection, llcrnrlat=-90, urcrnrlat=90,\
27+
llcrnrlon=-180, urcrnrlon=180, resolution=None, **kwargs)
28+
m.readshapefile(shapepath, 'shapes', drawbounds=False)
29+
30+
poly = []
31+
32+
for ii in range(len(m.shapes)):
33+
poly.append(Polygon(m.shapes[ii], closed=False))
34+
35+
return m, poly
36+
37+
def plot_by_hierid(da, ax=None, clim=None, cmap='jet', **kwargs):
38+
39+
if ax is None:
40+
ax = plt.subplot(111)
41+
42+
if clim is None:
43+
clim = [da.min(), da.max()]
44+
45+
m, poly = prep_polygons()
46+
47+
hierids = np.array([m.shapes_info[i]['hierid'] for i in range(len(m.shapes))])
48+
hierids = hierids[np.in1d(hierids, da.hierid)]
49+
50+
color = da.sel(hierid=hierids).values
51+
52+
c = PatchCollection(poly, array=color, cmap=cmap, **kwargs)
53+
c.set_clim(clim) # set the range of colorbar here
54+
ax.add_collection(c)
55+
ax.set_xlim(-180, 180)
56+
ax.set_ylim(-90,90)
57+
ax.set_xticks(np.linspace(-180, 180, 7))
58+
ax.set_yticks(np.linspace(-90, 90, 7))
59+
ax.set_ylabel('Longitude')
60+
ax.set_xlabel('Latitude')
61+
plt.colorbar(c, ax=ax)
62+
63+
return ax

requirements_conda.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ xarray==0.9.6
55
h5py==2.7.1
66
numba==0.35.0
77
blaze==0.10.1
8-
scipy==0.19.1
8+
scipy==1.0.0
99
bottleneck==1.2.1
1010
dask==0.16.0
11+
basemap==1.0.7
12+
matplotlib==2.1.0
13+
14+

requirements_test.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Sphinx==1.6.5
22
sphinx-rtd-theme==0.2.5b1
33
pip==9.0.1
44
wheel==0.30.0
5-
flake8==3.4.1
5+
flake8==3.5.0
66
tox==2.9.1
77
coverage==4.4.1
88
pytest==3.2.3

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.1.0
2+
current_version = 0.2.0
33
commit = True
44
tag = True
55

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
setup(
4242
name='impactlab-tools',
43-
version='0.1.0',
43+
version='0.2.0',
4444
description="Python tools for Climate Impact Lab developers",
4545
long_description=readme,
4646
author="Climate Impact Lab",

0 commit comments

Comments
 (0)