ancient-map-tiler 0.1.1__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ancient-map-tiler
3
- Version: 0.1.1
3
+ Version: 0.2.0
4
4
  Summary: Provide tiles data for a web view of an ancient map
5
5
  Author: Noan Cloarec
6
6
  Author-email: noan.cloarec@gmail.com
@@ -8,6 +8,7 @@ Requires-Python: >=3.13
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: Programming Language :: Python :: 3.13
10
10
  Classifier: Programming Language :: Python :: 3.14
11
+ Requires-Dist: click (>=8)
11
12
  Requires-Dist: numpy (>=2)
12
13
  Requires-Dist: tqdm (>=4)
13
14
  Description-Content-Type: text/markdown
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ancient-map-tiler"
3
- version = "0.1.1"
3
+ version = "0.2.0"
4
4
  description = "Provide tiles data for a web view of an ancient map"
5
5
  authors = [
6
6
  { name = "Noan Cloarec", email = "noan.cloarec@gmail.com" }
@@ -9,7 +9,8 @@ readme = "README.md"
9
9
  requires-python = ">=3.13"
10
10
  dependencies = [
11
11
  "numpy (>=2)",
12
- "tqdm (>=4)"
12
+ "tqdm (>=4)",
13
+ "click (>=8)"
13
14
  ]
14
15
 
15
16
  [project.scripts]
@@ -1,8 +1,7 @@
1
- import argparse
2
- from argparse import Namespace
3
1
  from math import ceil, log
4
2
  from pathlib import Path
5
3
 
4
+ import click
6
5
  import numpy as np
7
6
  import numpy.typing as npt
8
7
  from PIL import Image
@@ -154,36 +153,37 @@ def get_tiles_for_all_zoom_levels(
154
153
  return res
155
154
 
156
155
 
157
- def parse_args() -> Namespace:
158
- parser = argparse.ArgumentParser(description="Create map tiles from a map source.")
159
- parser.add_argument(
160
- "map_source",
161
- help="Path or identifier of the map source to generate tiles from",
162
- )
163
- parser.add_argument(
164
- "--tile-size", "-t", help="Size of a tile. Default: 256", default=256, type=int
165
- )
166
- parser.add_argument(
167
- "--output-directory",
168
- "-o",
169
- help="Output directory where to store the tiles, must not exist",
170
- required=True,
171
- )
172
- parser.add_argument(
173
- "--image-format",
174
- "-f",
175
- help="Output image format. Default: .webp .Tested for .png and .webp",
176
- default=".webp",
177
- )
178
- return parser.parse_args()
179
-
180
-
181
- def main() -> None:
182
- args = parse_args()
183
- map_source: str = args.map_source
156
+ @click.command()
157
+ @click.argument(
158
+ "map-source",
159
+ type=click.Path(exists=True),
160
+ )
161
+ @click.option(
162
+ "-o",
163
+ "--output-directory",
164
+ type=click.Path(),
165
+ help="Output directory where to store the tiles, must not exist",
166
+ required=True,
167
+ )
168
+ @click.option(
169
+ "-t", "--tile-size", help="Size of a tile. Default: 256", type=int, default=256
170
+ )
171
+ @click.option(
172
+ "--image-format",
173
+ "-f",
174
+ help="Output image format. Default: .webp .Tested for .png and .webp",
175
+ default=".webp",
176
+ )
177
+ def main(
178
+ map_source: str, output_directory: str, tile_size: int, image_format: str
179
+ ) -> None:
180
+ """map-source: Path or identifier of the map source to generate tiles from"""
181
+ output_directory = Path(output_directory)
182
+ assert not output_directory.exists(), f"{output_directory} must not exist"
183
+ click.echo(f"Loading {map_source}...")
184
184
  map_image = np.asarray(Image.open(map_source), dtype="uint8")
185
- tiled_maps_by_zoom_level = get_tiles_for_all_zoom_levels(map_image, args.tile_size)
186
- Path.mkdir(args.output_directory)
185
+ tiled_maps_by_zoom_level = get_tiles_for_all_zoom_levels(map_image, tile_size)
186
+ Path.mkdir(output_directory)
187
187
  nb_images_to_save = sum(
188
188
  tiled_map.shape[0] * tiled_map.shape[1]
189
189
  for tiled_map in tiled_maps_by_zoom_level
@@ -192,7 +192,11 @@ def main() -> None:
192
192
  for zoom_level, tiled_map in enumerate(tiled_maps_by_zoom_level):
193
193
  save_to_directory(
194
194
  tiled_map,
195
- Path(args.output_directory) / str(zoom_level),
196
- image_format=args.image_format,
195
+ output_directory / str(zoom_level),
196
+ image_format=image_format,
197
197
  progress_bar=progress_bar,
198
198
  )
199
+
200
+
201
+ if __name__ == "__main__":
202
+ main()