Skip to content

Commit 7482f94

Browse files
committed
renames and relocation
1 parent 5f229aa commit 7482f94

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

climada/util/plot.py

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def geo_bin_from_array(array_sub, geo_coord, var_name, title, pop_name=True,\
5656
ValueError
5757
"""
5858
# Generate array of values used in each subplot
59-
num_im, list_arr = get_collection_arrays(array_sub)
59+
num_im, list_arr = _get_collection_arrays(array_sub)
6060
list_tit = to_list(num_im, title, 'title')
6161
list_name = to_list(num_im, var_name, 'var_name')
6262
list_coord = to_list(num_im, geo_coord, 'geo_coord')
@@ -73,7 +73,7 @@ def geo_bin_from_array(array_sub, geo_coord, var_name, title, pop_name=True,\
7373
(coord.shape[0], array_im.size))
7474

7575
# Binned image with coastlines
76-
extent = get_borders(coord)
76+
extent = _get_borders(coord)
7777
extent = ([extent[0] - buffer_deg, extent[1] + buffer_deg, extent[2] -\
7878
buffer_deg, extent[3] + buffer_deg])
7979
axis.set_extent((extent))
@@ -121,7 +121,7 @@ def geo_im_from_array(array_sub, geo_coord, var_name, title, **kwargs):
121121
ValueError
122122
"""
123123
# Generate array of values used in each subplot
124-
num_im, list_arr = get_collection_arrays(array_sub)
124+
num_im, list_arr = _get_collection_arrays(array_sub)
125125
list_tit = to_list(num_im, title, 'title')
126126
list_name = to_list(num_im, var_name, 'var_name')
127127
list_coord = to_list(num_im, geo_coord, 'geo_coord')
@@ -139,7 +139,7 @@ def geo_im_from_array(array_sub, geo_coord, var_name, title, **kwargs):
139139
raise ValueError("Size mismatch in input array: %s != %s." % \
140140
(coord.shape[0], array_im.size))
141141
# Create regular grid where to interpolate the array
142-
extent = get_borders(coord)
142+
extent = _get_borders(coord)
143143
grid_x, grid_y = np.mgrid[
144144
extent[0] : extent[1] : complex(0, RESOLUTION),
145145
extent[2] : extent[3] : complex(0, RESOLUTION)]
@@ -160,12 +160,12 @@ def geo_im_from_array(array_sub, geo_coord, var_name, title, **kwargs):
160160

161161
return fig, axis_sub
162162

163-
class Graph2D(object):
163+
class Graph2D():
164164
"""2D graph object. Handles various subplots and curves."""
165165
def __init__(self, title='', num_subplots=1, num_row=None, num_col=None):
166166

167167
if (num_row is None) or (num_col is None):
168-
self.num_row, self.num_col = get_row_col_size(num_subplots)
168+
self.num_row, self.num_col = _get_row_col_size(num_subplots)
169169
else:
170170
self.num_row = num_row
171171
self.num_col = num_col
@@ -251,30 +251,6 @@ def get_elems(self):
251251
"""
252252
return self.fig, self.axs
253253

254-
def get_collection_arrays(array_sub):
255-
""" Get number of array rows and generate list of array if only one row
256-
257-
Parameters:
258-
array_sub (np.array(1d or 2d) or list(np.array)): Each array (in a row
259-
or in the list) are values at each point in corresponding
260-
261-
Returns:
262-
num_im (int), list_arr (2d np.ndarray or list(1d np.array))
263-
"""
264-
num_im = 1
265-
if not isinstance(array_sub, list):
266-
if len(array_sub.shape) == 1 or array_sub.shape[1] == 1:
267-
list_arr = list()
268-
list_arr.append(array_sub)
269-
else:
270-
list_arr = array_sub
271-
num_im = array_sub.shape[0]
272-
else:
273-
num_im = len(array_sub)
274-
list_arr = array_sub
275-
276-
return num_im, list_arr
277-
278254
def make_map(num_sub=1, projection=ccrs.PlateCarree()):
279255
"""Create map figure with cartopy.
280256
@@ -286,7 +262,7 @@ def make_map(num_sub=1, projection=ccrs.PlateCarree()):
286262
Returns:
287263
matplotlib.figure.Figure, np.array(cartopy.mpl.geoaxes.GeoAxesSubplot)
288264
"""
289-
num_row, num_col = get_row_col_size(num_sub)
265+
num_row, num_col = _get_row_col_size(num_sub)
290266
fig, axis_sub = plt.subplots(num_row, num_col, figsize=(9, 13), \
291267
subplot_kw=dict(projection=projection), squeeze=False)
292268

@@ -337,8 +313,8 @@ def add_populated_places(axis, extent, projection=ccrs.PlateCarree()):
337313

338314
shp = shapereader.Reader(shp_file)
339315
for rec, point in zip(shp.records(), shp.geometries()):
340-
if (point.x <= extent[1]) and (point.x > extent[0]):
341-
if (point.y <= extent[3]) and (point.y > extent[2]):
316+
if extent[0] < point.x <= extent[1]:
317+
if extent[2] < point.y <= extent[3]:
342318
axis.plot(point.x, point.y, 'ko', markersize=7, \
343319
transform=projection)
344320
axis.text(point.x, point.y, rec.attributes['name'], \
@@ -362,13 +338,37 @@ def add_cntry_names(axis, extent, projection=ccrs.PlateCarree()):
362338
for rec, point in zip(shp.records(), shp.geometries()):
363339
point_x = point.centroid.xy[0][0]
364340
point_y = point.centroid.xy[1][0]
365-
if (point_x <= extent[1]) and (point_x > extent[0]):
366-
if (point_y <= extent[3]) and (point_y > extent[2]):
341+
if extent[0] < point_x <= extent[1]:
342+
if extent[2] < point_y <= extent[3]:
367343
axis.text(point_x, point_y, rec.attributes['NAME'], \
368344
horizontalalignment='center', verticalalignment='center', \
369345
transform=projection, fontsize=14)
370346

371-
def get_row_col_size(num_sub):
347+
def _get_collection_arrays(array_sub):
348+
""" Get number of array rows and generate list of array if only one row
349+
350+
Parameters:
351+
array_sub (np.array(1d or 2d) or list(np.array)): Each array (in a row
352+
or in the list) are values at each point in corresponding
353+
354+
Returns:
355+
num_im (int), list_arr (2d np.ndarray or list(1d np.array))
356+
"""
357+
num_im = 1
358+
if not isinstance(array_sub, list):
359+
if len(array_sub.shape) == 1 or array_sub.shape[1] == 1:
360+
list_arr = list()
361+
list_arr.append(array_sub)
362+
else:
363+
list_arr = array_sub
364+
num_im = array_sub.shape[0]
365+
else:
366+
num_im = len(array_sub)
367+
list_arr = array_sub
368+
369+
return num_im, list_arr
370+
371+
def _get_row_col_size(num_sub):
372372
"""Compute number of rows and columns of subplots in figure.
373373
374374
Parameters:
@@ -389,7 +389,7 @@ def get_row_col_size(num_sub):
389389
num_row = int(num_sub/2) + num_sub % 2
390390
return num_row, num_col
391391

392-
def get_borders(geo_coord):
392+
def _get_borders(geo_coord):
393393
"""Get min and max longitude and min and max latitude (in this order).
394394
395395
Parameters:

0 commit comments

Comments
 (0)