Skip to content

Commit

Permalink
Multiplier and blur radius.
Browse files Browse the repository at this point in the history
  • Loading branch information
iwatkot committed Nov 18, 2024
1 parent 55f100f commit 2fb2b80
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion maps4fs/generator/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Config(Component):

def preprocess(self) -> None:
self._map_xml_path = self.game.map_xml_path(self.map_directory)
self.logger.debug(f"Map XML path: {self._map_xml_path}")
self.logger.debug("Map XML path: %s.", self._map_xml_path)

def process(self):
self._set_map_size()
Expand Down
27 changes: 26 additions & 1 deletion maps4fs/generator/dem.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from maps4fs.generator.component import Component

SRTM = "https://elevation-tiles-prod.s3.amazonaws.com/skadi/{latitude_band}/{tile_name}.hgt.gz"
DEFAULT_MULTIPLIER = 3
DEFAULT_BLUR_RADIUS = 21


# pylint: disable=R0903
Expand All @@ -36,6 +38,12 @@ def preprocess(self) -> None:
os.makedirs(self.hgt_dir, exist_ok=True)
os.makedirs(self.gz_dir, exist_ok=True)

self.multiplier = self.kwargs.get("multiplier", DEFAULT_MULTIPLIER)
self.blur_radius = self.kwargs.get("blur_radius", DEFAULT_BLUR_RADIUS)
self.logger.debug(
"DEM multiplier is %s, blur radius is %s.", self.multiplier, self.blur_radius
)

# pylint: disable=no-member
def process(self) -> None:
"""Reads SRTM file, crops it to map size, normalizes and blurs it,
Expand All @@ -44,7 +52,7 @@ def process(self) -> None:
self.coordinates, dist=self.distance
)
self.logger.debug(
f"Processing DEM. North: {north}, south: {south}, east: {east}, west: {west}."
"Processing DEM. North: %s, South: %s, East: %s, West: %s.", north, south, east, west
)

dem_output_size = self.distance * self.game.dem_multipliyer + 1
Expand Down Expand Up @@ -88,12 +96,29 @@ def process(self) -> None:
data, dem_output_resolution, interpolation=cv2.INTER_LINEAR
).astype("uint16")

self.logger.debug(
f"Maximum value in resampled data: {resampled_data.max()}, "
f"minimum value: {resampled_data.min()}."
)

resampled_data = resampled_data * self.multiplier # TODO: Add multiplier to config.
self.logger.debug(
f"DEM data multiplied by {self.multiplier}. Shape: {resampled_data.shape}, "
f"dtype: {resampled_data.dtype}. "
f"Min: {resampled_data.min()}, max: {resampled_data.max()}."
)

self.logger.debug(
f"DEM data was resampled. Shape: {resampled_data.shape}, "
f"dtype: {resampled_data.dtype}. "
f"Min: {resampled_data.min()}, max: {resampled_data.max()}."
)

resampled_data = cv2.GaussianBlur(resampled_data, (self.blur_radius, self.blur_radius), 0)
self.logger.debug( # TODO: Add blur radius to config.
f"Gaussion blur applied to DEM data with kernel size {self.blur_radius}. "
)

cv2.imwrite(self._dem_path, resampled_data)
self.logger.debug("DEM data was saved to %s.", self._dem_path)

Expand Down
8 changes: 4 additions & 4 deletions maps4fs/generator/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __init__( # pylint: disable=R0917
distance: int,
map_directory: str,
logger: Any = None,
**kwargs,
):
self.game = game
self.components: list[Component] = []
Expand All @@ -42,6 +43,8 @@ def __init__( # pylint: disable=R0917
self.logger = logger
self.logger.debug("Game was set to %s", game.code)

self.kwargs = kwargs

os.makedirs(self.map_directory, exist_ok=True)
self.logger.debug("Map directory created: %s", self.map_directory)

Expand All @@ -61,6 +64,7 @@ def generate(self) -> None:
self.distance,
self.map_directory,
self.logger,
**self.kwargs,
)
try:
component.process()
Expand All @@ -71,7 +75,6 @@ def generate(self) -> None:
e,
)
raise e
# setattr(self, game_component.__name__.lower(), component)
self.components.append(component)

pbar.update(1)
Expand All @@ -82,9 +85,6 @@ def previews(self) -> list[str]:
Returns:
list[str]: List of preview images.
"""
# texture_previews = self.texture.previews() # type: ignore # pylint: disable=no-member
# dem_previews = self.dem.previews() # type: ignore # pylint: disable=no-member
# return texture_previews + dem_previews
previews = []
for component in self.components:
previews.extend(component.previews())
Expand Down

0 comments on commit 2fb2b80

Please sign in to comment.