Skip to content

Commit b94e135

Browse files
committed
code clean up2
1 parent 4676cc5 commit b94e135

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Localization/histogram_filter/histogram_filter.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
1212
"""
1313

14+
import copy
1415
import math
15-
import numpy as np
16+
1617
import matplotlib.pyplot as plt
17-
import copy
18-
from scipy.stats import norm
18+
import numpy as np
1919
from scipy.ndimage import gaussian_filter
20+
from scipy.stats import norm
2021

2122
# Parameters
2223
EXTEND_AREA = 10.0 # [m] grid map extention length
@@ -41,7 +42,7 @@
4142
show_animation = True
4243

4344

44-
class grid_map():
45+
class GridMap:
4546

4647
def __init__(self):
4748
self.data = None
@@ -117,7 +118,7 @@ def motion_model(x, u):
117118

118119
def draw_heatmap(data, mx, my):
119120
maxp = max([max(igmap) for igmap in data])
120-
plt.pcolor(mx, my, data, vmax=maxp, cmap=plt.cm.Blues)
121+
plt.pcolor(mx, my, data, vmax=maxp, cmap=plt.cm.get_cmap("Blues"))
121122
plt.axis("equal")
122123

123124

@@ -157,8 +158,7 @@ def normalize_probability(gmap):
157158

158159

159160
def init_gmap(xyreso, minx, miny, maxx, maxy):
160-
161-
gmap = grid_map()
161+
gmap = GridMap()
162162

163163
gmap.xyreso = xyreso
164164
gmap.minx = minx
@@ -168,7 +168,7 @@ def init_gmap(xyreso, minx, miny, maxx, maxy):
168168
gmap.xw = int(round((gmap.maxx - gmap.minx) / gmap.xyreso))
169169
gmap.yw = int(round((gmap.maxy - gmap.miny) / gmap.xyreso))
170170

171-
gmap.data = [[1.0 for i in range(gmap.yw)] for i in range(gmap.xw)]
171+
gmap.data = [[1.0 for _ in range(gmap.yw)] for _ in range(gmap.xw)]
172172
gmap = normalize_probability(gmap)
173173

174174
return gmap
@@ -183,7 +183,7 @@ def map_shift(gmap, xshift, yshift):
183183
nix = ix + xshift
184184
niy = iy + yshift
185185

186-
if nix >= 0 and nix < gmap.xw and niy >= 0 and niy < gmap.yw:
186+
if 0 <= nix < gmap.xw and 0 <= niy < gmap.yw:
187187
gmap.data[ix + xshift][iy + yshift] = tgmap[ix][iy]
188188

189189
return gmap

0 commit comments

Comments
 (0)