Skip to content

Commit cd028f3

Browse files
author
Mike Hearne
authored
Merge pull request #152 from emthompson-usgs/cleanup
Code cleanup of basemapcity module
2 parents d17b65a + f5291af commit cd028f3

1 file changed

Lines changed: 73 additions & 58 deletions

File tree

mapio/basemapcity.py

Lines changed: 73 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,24 @@ def limitByMapCollision(
3838
resolution='l',area_thresh=1000.,projection='lcc',\
3939
lat_1=50.,lon_0=-107.,ax=ax)
4040
#######################################
41-
:param fontsize:
42-
Desired font size for city labels.
43-
:param fontname:
44-
Desired font name for city labels.
45-
:param basemap:
46-
Basemap object.
47-
:raises DataSetException:
48-
When font name is not one of the supported Matplotlib font names OR
49-
when (if placement column exists) placement columns contain any values
50-
not in E,W,N,S,SE,SW,NE,N OR
51-
when cities have not been projected (project() has not been called.)
52-
:returns:
53-
New Cities instance where smaller colliding cities have been removed.
41+
42+
Args:
43+
fontsize (float):
44+
Desired font size for city labels.
45+
fontname (str):
46+
Desired font name for city labels.
47+
basemap (Basemap):
48+
Basemap object.
49+
50+
Raises:
51+
DataSetException:
52+
When font name is not one of the supported Matplotlib font names OR
53+
when (if placement column exists) placement columns contain any values
54+
not in E,W,N,S,SE,SW,NE,N OR
55+
when cities have not been projected (project() has not been called.)
56+
57+
Returns:
58+
New Cities instance where smaller colliding cities have been removed.
5459
"""
5560
if basemap.ax is None:
5661
raise DataSetException(
@@ -108,24 +113,25 @@ def limitByMapCollision(
108113
newdf["left"] = lefts[ikeep]
109114
newdf["right"] = rights[ikeep]
110115
except Exception as e:
111-
print(e)
116+
raise e
112117
return type(self)(newdf)
113118

114119
def renderToMap(
115120
self, ax, fontname="Bitstream Vera Sans", fontsize=10.0, zorder=10, shadow=False
116121
):
117122
"""Render cities on Basemap axes.
118123
119-
:param ax:
120-
Matplotlib Axes instance.
121-
:param fontname:
122-
String name of font.
123-
:param fontsize:
124-
Font size in points.
125-
:param zorder:
126-
Matplotlib plotting order - higher zorder is on top.
127-
:param shadow:
128-
Boolean indicating whether "drop-shadow" effect should be used.
124+
Args:
125+
ax (Axis):
126+
Matplotlib Axes instance.
127+
fontname (str):
128+
Name of font.
129+
fontsize (float):
130+
Font size in points.
131+
zorder (float):
132+
Matplotlib plotting order - higher zorder is on top.
133+
shadow (bool):
134+
Boolean indicating whether "drop-shadow" effect should be used.
129135
"""
130136
if "x" not in self._dataframe.columns and "y" not in self._dataframe.columns:
131137
raise DataSetException("Cities object has not had project() called yet.")
@@ -135,20 +141,24 @@ def renderToMap(
135141
self._display_to_data_transform = ax.transData.inverted()
136142

137143
for index, row in self._dataframe.iterrows():
144+
self._renderRow(row, ax, fontname, fontsize, shadow=shadow, zorder=zorder)
138145
ax.plot(row["x"], row["y"], "k.")
139146

140147
def _getCityBoundingBoxes(self, df, fontname, fontsize, ax):
141148
"""Get the axes coordinate system bounding boxes for each city.
142-
:param df:
143-
DataFrame containing information about cities.
144-
:param fontname:
145-
fontname ('Arial','Helvetica', etc.)
146-
:param fontsize:
147-
Font size in points.
148-
:param ax:
149-
Axes object.
150-
:returns:
151-
Numpy arrays of top,bottom,left and right edges of city bounding boxes.
149+
150+
Args:
151+
df (DataFrame):
152+
DataFrame containing information about cities.
153+
fontname (str):
154+
fontname ('Arial','Helvetica', etc.)
155+
fontsize (float):
156+
Font size in points.
157+
ax (Axis):
158+
Axes object.
159+
160+
Returns:
161+
Numpy arrays of top,bottom,left and right edges of city bounding boxes.
152162
"""
153163
fig = ax.get_figure()
154164
fwidth, fheight = fig.get_figwidth(), fig.get_figheight()
@@ -192,20 +202,23 @@ def _getCityBoundingBoxes(self, df, fontname, fontsize, ax):
192202

193203
def _renderRow(self, row, ax, fontname, fontsize, zorder=10, shadow=False):
194204
"""Internal method to consistently render city names.
195-
:param row:
196-
pandas dataframe row.
197-
:param ax:
198-
Matplotlib Axes instance.
199-
:param fontname:
200-
String name of desired font.
201-
:param fontsize:
202-
Font size in points.
203-
:param zorder:
204-
Matplotlib plotting order - higher zorder is on top.
205-
:param shadow:
206-
Boolean indicating whether "drop-shadow" effect should be used.
207-
:returns:
208-
Matplotlib Text instance.
205+
206+
Args:
207+
row (pandas.core.series.Series):
208+
pandas dataframe row.
209+
ax (matplotlib.axes._subplots.AxesSubplot):
210+
Matplotlib Axes instance.
211+
fontname (str):
212+
String name of desired font.
213+
fontsize (float):
214+
Font size in points.
215+
zorder (float):
216+
Matplotlib plotting order - higher zorder is on top.
217+
shadow (bool):
218+
Boolean indicating whether "drop-shadow" effect should be used.
219+
220+
Returns:
221+
Matplotlib Text instance.
209222
"""
210223
ha = "left"
211224
va = "center"
@@ -266,16 +279,18 @@ def _renderRow(self, row, ax, fontname, fontsize, zorder=10, shadow=False):
266279

267280
def _getCityEdges(self, row, ax, fig, fontname, fontsize):
268281
"""Return the edges of a city label on a given map axes.
269-
:param row:
270-
Row of a dataframe containing city information.
271-
:param ax:
272-
Axes instance.
273-
:param fig:
274-
Figure instance.
275-
:param fontname:
276-
Matplotlib compatible font name.
277-
:param fontsize:
278-
Font size in points.
282+
283+
Args:
284+
row (pandas.core.series.Series):
285+
Row of a dataframe containing city information.
286+
ax (matplotlib.axes._subplots.AxesSubplot):
287+
Axes instance.
288+
fig (matplotlib.figure.Figure):
289+
Figure instance.
290+
fontname (str):
291+
Matplotlib compatible font name.
292+
fontsize (float):
293+
Font size in points.
279294
"""
280295
th = self._renderRow(row, ax, fontname, fontsize)
281296
bbox = th.get_window_extent(fig.canvas.renderer)

0 commit comments

Comments
 (0)