Skip to content

Commit 4ab7d7f

Browse files
committed
Update maps.py
1 parent 3267847 commit 4ab7d7f

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/maps.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212

1313
# Credit - Bahar
14+
# Modifications - Muktadir
1415
class MapReader:
1516
def __init__(self, filename, mapName):
1617
self.mapName = mapName
@@ -19,6 +20,13 @@ def __init__(self, filename, mapName):
1920
self.size = (int(data[0]), int(data[1]))
2021
self.data = [[int(data[i * self.size[1] + j + 2]) for j in range(self.size[1])] for i in range(self.size[0])]
2122
logging.info(f"Your map is {self.size[0]}x{self.size[1]}")
23+
24+
25+
def standardize(self, converter):
26+
logging.info(f"Normalizing the data in [-1, 1] using {converter.__class__.__name__}")
27+
#TODO Ishaan
28+
# (self.converter.get_char(mapReader.data[i + x][j + y]) / (len(self.converter.char_groups) - 1)) * -2 + 1
29+
pass
2230

2331
# Converter object that can return character for OpenStreetMap layer group
2432
# Credit - Bahar
@@ -38,7 +46,7 @@ def get_char(self, layer):
3846

3947
# New Cell
4048
# Credit - Bahar
41-
# Modifications - Ishaan
49+
# Modifications - Ishaan, Muktadir
4250

4351
class MapsDataset(Dataset):
4452
def __init__(self, window_size, step_size, sample_group_size, converter, outputDir="../data/output"):
@@ -53,6 +61,8 @@ def __init__(self, window_size, step_size, sample_group_size, converter, outputD
5361

5462
os.makedirs(self.outputDir, exist_ok=True)
5563

64+
65+
5666

5767
def __len__(self):
5868
return len(self.samples)
@@ -80,6 +90,9 @@ def generate_patches(self, mapReader, image_groups=3, outDirectory=None):
8090
mapReader (MapReader): reader for a single big map!
8191
image_groups (int, optional): _description_. Defaults to 3.
8292
"""
93+
94+
mapReader.standardize(converter=self.converter)
95+
8396
if outDirectory is None:
8497
outDirectory = os.path.join(self.outputDir, mapReader.mapName, f"{self.window_size[0]}x{self.window_size[1]}", f"{self.step_size}x{self.step_size}")
8598
os.makedirs(outDirectory, exist_ok=True)
@@ -105,9 +118,16 @@ def generate_patches(self, mapReader, image_groups=3, outDirectory=None):
105118
def extractSample(self, mapReader, topLeft):
106119
i = topLeft[0]
107120
j = topLeft[1]
121+
# sample = [
122+
# [
123+
# (self.converter.get_char(mapReader.data[i + x][j + y]) / (len(self.converter.char_groups) - 1)) * -2 + 1 # TODO this conversion should be done once in the original data instead of patches.
124+
# for y in range(self.window_size[1])
125+
# ]
126+
# for x in range(self.window_size[0])
127+
# ]
108128
sample = [
109129
[
110-
(self.converter.get_char(mapReader.data[i + x][j + y]) / (len(self.converter.char_groups) - 1)) * -2 + 1 # TODO this conversion should be done once in the original data instead of patches.
130+
mapReader.data[i + x][j + y]
111131
for y in range(self.window_size[1])
112132
]
113133
for x in range(self.window_size[0])

0 commit comments

Comments
 (0)