pixel-map 0.1.1__tar.gz → 0.1.2__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.
- {pixel_map-0.1.1 → pixel_map-0.1.2}/PKG-INFO +5 -7
- pixel_map-0.1.2/pixel_map/__init__.py +4 -0
- pixel_map-0.1.2/pixel_map/__main__.py +170 -0
- pixel_map-0.1.2/pixel_map/example_files/london_buildings.parquet +0 -0
- pixel_map-0.1.2/pixel_map/example_files/london_park.parquet +0 -0
- pixel_map-0.1.2/pixel_map/example_files/london_water.parquet +0 -0
- pixel_map-0.1.2/pixel_map/example_files/monaco_buildings.parquet +0 -0
- {pixel_map-0.1.1 → pixel_map-0.1.2}/pixel_map/plotter.py +81 -52
- pixel_map-0.1.2/pixel_map/renderers.py +129 -0
- {pixel_map-0.1.1 → pixel_map-0.1.2}/pyproject.toml +10 -8
- pixel_map-0.1.1/pixel_map/__init__.py +0 -2
- pixel_map-0.1.1/pixel_map/__main__.py +0 -102
- {pixel_map-0.1.1 → pixel_map-0.1.2}/LICENSE +0 -0
- {pixel_map-0.1.1 → pixel_map-0.1.2}/README.md +0 -0
- {pixel_map-0.1.1 → pixel_map-0.1.2}/tests/__init__.py +0 -0
- {pixel_map-0.1.1 → pixel_map-0.1.2}/tests/test_bbox.py +0 -0
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pixel-map
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: A Python CLI tool for plotting geo files in the terminal
|
|
5
5
|
Author-Email: Kamil Raczycki <kraczycki@kraina.ai>
|
|
6
6
|
License: MIT
|
|
7
7
|
Requires-Python: >=3.9
|
|
8
8
|
Requires-Dist: rich>=12.0.0
|
|
9
9
|
Requires-Dist: typer[all]>=0.9.0
|
|
10
|
-
Requires-Dist: img2unicode[n2]>=0.1a11; sys_platform != "win32"
|
|
11
|
-
Requires-Dist: img2unicode>=0.1a11; sys_platform == "win32"
|
|
10
|
+
Requires-Dist: img2unicode[n2]>=0.1a11; sys_platform != "win32" and sys_platform != "darwin"
|
|
11
|
+
Requires-Dist: img2unicode>=0.1a11; sys_platform == "win32" or sys_platform == "darwin"
|
|
12
12
|
Requires-Dist: geopandas>=0.6
|
|
13
13
|
Requires-Dist: numpy>=1.26.0
|
|
14
|
-
Requires-Dist:
|
|
15
|
-
Requires-Dist:
|
|
16
|
-
Requires-Dist: matplotlib
|
|
17
|
-
Requires-Dist: pillow
|
|
14
|
+
Requires-Dist: contextily>=1
|
|
15
|
+
Requires-Dist: matplotlib>=3.2.0
|
|
18
16
|
Requires-Dist: pyarrow>=16.0.0
|
|
19
17
|
Description-Content-Type: text/markdown
|
|
20
18
|
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"""Main CLI module."""
|
|
2
|
+
|
|
3
|
+
from contextlib import suppress
|
|
4
|
+
from typing import Annotated, Optional, cast
|
|
5
|
+
|
|
6
|
+
import click
|
|
7
|
+
import typer
|
|
8
|
+
|
|
9
|
+
from pixel_map import __app_name__, __version__
|
|
10
|
+
from pixel_map.renderers import AVAILABLE_RENDERERS
|
|
11
|
+
|
|
12
|
+
renderer_help_string = ", ".join(
|
|
13
|
+
f"[bold dark_orange]{renderer}[/bold dark_orange]"
|
|
14
|
+
for renderer in sorted(AVAILABLE_RENDERERS.keys())
|
|
15
|
+
)
|
|
16
|
+
VALID_EXAMPLE_FILES = ["london_buildings", "london_park", "london_water", "monaco_buildings"]
|
|
17
|
+
example_files_help_string = ", ".join(
|
|
18
|
+
f"[bold dark_orange]{example}[/bold dark_orange]" for example in sorted(VALID_EXAMPLE_FILES)
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
app = typer.Typer(context_settings={"help_option_names": ["-h", "--help"]}, rich_markup_mode="rich")
|
|
22
|
+
|
|
23
|
+
# TODO:
|
|
24
|
+
# - add option to select colours (pass list - must match number of files)
|
|
25
|
+
# - add option to select colours per type (polygon, linestring, point)
|
|
26
|
+
# (pass list(s) - must match number of files)
|
|
27
|
+
# - define default colour schemes with option to select
|
|
28
|
+
# --light (positron + blue)
|
|
29
|
+
# or --dark (darkmatter + orange?) [default]
|
|
30
|
+
# or --street (voyager + ???)
|
|
31
|
+
# - add option to select tileset (or no tileset) by name
|
|
32
|
+
# - add option to pass map height and width
|
|
33
|
+
# - add option to remove the panel (border)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _version_callback(value: bool) -> None:
|
|
37
|
+
if value:
|
|
38
|
+
typer.echo(f"{__app_name__} {__version__}")
|
|
39
|
+
raise typer.Exit()
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class BboxGeometryParser(click.ParamType): # type: ignore
|
|
43
|
+
"""Parser for bounding boxes."""
|
|
44
|
+
|
|
45
|
+
name = "BBOX"
|
|
46
|
+
|
|
47
|
+
def convert(self, value, param=None, ctx=None): # type: ignore
|
|
48
|
+
"""Convert parameter value."""
|
|
49
|
+
with suppress(ValueError): # ValueError raised when passing non-numbers to float()
|
|
50
|
+
bbox_values = tuple(float(x.strip()) for x in value.split(","))
|
|
51
|
+
if len(bbox_values) == 4:
|
|
52
|
+
return bbox_values
|
|
53
|
+
|
|
54
|
+
raise typer.BadParameter(
|
|
55
|
+
"Cannot parse provided bounding box."
|
|
56
|
+
" Valid value must contain 4 floating point numbers"
|
|
57
|
+
" separated by commas."
|
|
58
|
+
) from None
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@app.command() # type: ignore
|
|
62
|
+
def plot(
|
|
63
|
+
files: Annotated[
|
|
64
|
+
list[str],
|
|
65
|
+
typer.Argument(
|
|
66
|
+
help="List of files to display. Those could be any that can be opened by GeoPandas.",
|
|
67
|
+
show_default=False,
|
|
68
|
+
),
|
|
69
|
+
],
|
|
70
|
+
bbox: Annotated[
|
|
71
|
+
Optional[str],
|
|
72
|
+
typer.Option(
|
|
73
|
+
help=(
|
|
74
|
+
"Clip the map to a given [bold dark_orange]bounding box[/bold dark_orange]."
|
|
75
|
+
" Expects 4 floating point numbers separated by commas."
|
|
76
|
+
),
|
|
77
|
+
click_type=BboxGeometryParser(),
|
|
78
|
+
show_default=False,
|
|
79
|
+
),
|
|
80
|
+
] = None,
|
|
81
|
+
renderer: Annotated[
|
|
82
|
+
str,
|
|
83
|
+
typer.Option(
|
|
84
|
+
"--renderer",
|
|
85
|
+
"-r",
|
|
86
|
+
help=(
|
|
87
|
+
"Renderer used for generating terminal output."
|
|
88
|
+
f" Possible values: {renderer_help_string}."
|
|
89
|
+
),
|
|
90
|
+
case_sensitive=False,
|
|
91
|
+
show_default="block",
|
|
92
|
+
is_eager=True,
|
|
93
|
+
),
|
|
94
|
+
] = "block",
|
|
95
|
+
no_border: Annotated[
|
|
96
|
+
bool,
|
|
97
|
+
typer.Option(
|
|
98
|
+
"--no-border/",
|
|
99
|
+
"--fullscreen/",
|
|
100
|
+
help=("Removes the border around the map."),
|
|
101
|
+
show_default=False,
|
|
102
|
+
),
|
|
103
|
+
] = False,
|
|
104
|
+
example_files: Annotated[
|
|
105
|
+
bool,
|
|
106
|
+
typer.Option(
|
|
107
|
+
"--example/",
|
|
108
|
+
"--example-files/",
|
|
109
|
+
help=(
|
|
110
|
+
"Can be used to load one of example files based on name."
|
|
111
|
+
f" Possible values: {example_files_help_string}."
|
|
112
|
+
),
|
|
113
|
+
show_default=False,
|
|
114
|
+
),
|
|
115
|
+
] = False,
|
|
116
|
+
version: Annotated[
|
|
117
|
+
Optional[bool],
|
|
118
|
+
typer.Option(
|
|
119
|
+
"--version",
|
|
120
|
+
"-v",
|
|
121
|
+
help="Show the application's version and exit.",
|
|
122
|
+
callback=_version_callback,
|
|
123
|
+
is_eager=True,
|
|
124
|
+
),
|
|
125
|
+
] = None,
|
|
126
|
+
) -> None:
|
|
127
|
+
"""
|
|
128
|
+
Plot the geo data into a terminal.
|
|
129
|
+
|
|
130
|
+
Generates a Matplotlib canvas that is rendered to an image and later transformed into a list of
|
|
131
|
+
unicode characters.
|
|
132
|
+
"""
|
|
133
|
+
import warnings
|
|
134
|
+
|
|
135
|
+
from pixel_map.plotter import plot_geo_data
|
|
136
|
+
|
|
137
|
+
if renderer not in AVAILABLE_RENDERERS:
|
|
138
|
+
raise typer.BadParameter(f"Provided renderer {renderer} doesn't exist.") from None
|
|
139
|
+
|
|
140
|
+
if example_files:
|
|
141
|
+
from pathlib import Path
|
|
142
|
+
|
|
143
|
+
loaded_example_files = []
|
|
144
|
+
for file_name in files:
|
|
145
|
+
if file_name not in VALID_EXAMPLE_FILES:
|
|
146
|
+
raise typer.BadParameter(
|
|
147
|
+
f"Provided file {file_name} doesn't exist in examples."
|
|
148
|
+
) from None
|
|
149
|
+
loaded_example_files.append(
|
|
150
|
+
(Path(__file__).parent / "example_files" / f"{file_name}.parquet").as_posix()
|
|
151
|
+
)
|
|
152
|
+
files = loaded_example_files
|
|
153
|
+
|
|
154
|
+
with warnings.catch_warnings():
|
|
155
|
+
warnings.filterwarnings("ignore")
|
|
156
|
+
plot_geo_data(
|
|
157
|
+
files,
|
|
158
|
+
renderer=renderer,
|
|
159
|
+
bbox=cast(Optional[tuple[float, float, float, float]], bbox),
|
|
160
|
+
no_border=no_border,
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def main() -> None:
|
|
165
|
+
"""Run the CLI."""
|
|
166
|
+
app(prog_name=__app_name__) # pragma: no cover
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
if __name__ == "__main__":
|
|
170
|
+
app(prog_name=__app_name__) # pragma: no cover
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -10,7 +10,6 @@ from typing import Any, Optional
|
|
|
10
10
|
|
|
11
11
|
import contextily as cx
|
|
12
12
|
import geopandas as gpd
|
|
13
|
-
import img2unicode
|
|
14
13
|
import numpy as np
|
|
15
14
|
from matplotlib import pyplot as plt
|
|
16
15
|
from matplotlib.axes import Axes
|
|
@@ -18,33 +17,48 @@ from pyproj import Transformer
|
|
|
18
17
|
from pyproj.enums import TransformDirection
|
|
19
18
|
from rich import get_console
|
|
20
19
|
from rich.box import HEAVY
|
|
20
|
+
from rich.color import Color
|
|
21
21
|
from rich.panel import Panel
|
|
22
22
|
from rich.progress import Progress, SpinnerColumn, TextColumn
|
|
23
|
+
from rich.style import Style
|
|
24
|
+
from rich.text import Text
|
|
25
|
+
|
|
26
|
+
from pixel_map.renderers import AVAILABLE_RENDERERS
|
|
23
27
|
|
|
24
28
|
TRANSFORMER = Transformer.from_crs("EPSG:4326", "EPSG:3857", always_xy=True)
|
|
25
29
|
|
|
30
|
+
# TODO:
|
|
31
|
+
# - change geopandas loading to get multiple dfs instead of one
|
|
32
|
+
# - add option to load contextily from string or name
|
|
26
33
|
|
|
27
34
|
def plot_geo_data(
|
|
28
|
-
files: list[str],
|
|
35
|
+
files: list[str],
|
|
36
|
+
renderer: str,
|
|
37
|
+
bbox: Optional[tuple[float, float, float, float]] = None,
|
|
38
|
+
no_border: bool = False,
|
|
29
39
|
) -> None:
|
|
30
40
|
"""
|
|
31
|
-
Plot
|
|
41
|
+
Plot the geo data into a terminal.
|
|
32
42
|
|
|
33
43
|
Generates a Matplotlib canvas that is rendered to an image and later transformed into a list of
|
|
34
44
|
unicode characters.
|
|
35
45
|
|
|
36
46
|
Args:
|
|
37
47
|
files (list[str]): List of files to plot.
|
|
48
|
+
renderer (str): A name for the renderer used to generate terminal output.
|
|
49
|
+
Defaults to "block".
|
|
38
50
|
bbox (Optional[tuple[float, float, float, float]], optional): Bounding box used to clip the
|
|
39
51
|
geo data. Defaults to None.
|
|
52
|
+
no_border (Optional[bool], optional): Removes the border around the map. Defaults to False.
|
|
40
53
|
"""
|
|
41
54
|
console = get_console()
|
|
42
55
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
56
|
+
if no_border:
|
|
57
|
+
terminal_width = console.width
|
|
58
|
+
terminal_height = console.height - 1
|
|
59
|
+
else:
|
|
60
|
+
terminal_width = console.width - 2
|
|
61
|
+
terminal_height = console.height - 3 # 2 for panel and 1 for new line
|
|
48
62
|
|
|
49
63
|
map_width = terminal_width
|
|
50
64
|
map_height = terminal_height * 2
|
|
@@ -124,49 +138,31 @@ def plot_geo_data(
|
|
|
124
138
|
console=console,
|
|
125
139
|
) as progress:
|
|
126
140
|
progress.add_task("Rendering geo data", total=None)
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
# img2unicode.ExactGenericDualOptimizer("block"),
|
|
130
|
-
# img2unicode.FastQuadDualOptimizer(),
|
|
131
|
-
img2unicode.FastGenericDualOptimizer("block"),
|
|
132
|
-
# img2unicode.ExactGammaOptimizer("no_block"),
|
|
133
|
-
max_h=terminal_height,
|
|
134
|
-
max_w=terminal_width,
|
|
135
|
-
allow_upscale=True,
|
|
141
|
+
renderer_object = AVAILABLE_RENDERERS[renderer](
|
|
142
|
+
terminal_width=terminal_width, terminal_height=terminal_height
|
|
136
143
|
)
|
|
137
|
-
characters, foreground_colors, background_colors =
|
|
138
|
-
# braille_renderer = img2unicode.GammaRenderer(
|
|
139
|
-
# img2unicode.BestGammaOptimizer(True, "braille"),
|
|
140
|
-
# max_h=terminal_height,
|
|
141
|
-
# max_w=terminal_width,
|
|
142
|
-
# allow_upscale=True,
|
|
143
|
-
# )
|
|
144
|
-
# characters, foreground_colors, background_colors = braille_renderer.render_numpy(image)
|
|
144
|
+
characters, foreground_colors, background_colors = renderer_object.render_numpy(image)
|
|
145
145
|
full_rich_string = _construct_full_rich_string(
|
|
146
146
|
characters, foreground_colors, background_colors
|
|
147
147
|
)
|
|
148
|
-
|
|
149
|
-
# # my_console.print("[bold blue]Starting work!")
|
|
148
|
+
|
|
150
149
|
map_minx, map_miny = TRANSFORMER.transform(left, bottom, direction=TransformDirection.INVERSE)
|
|
151
150
|
map_maxx, map_maxy = TRANSFORMER.transform(right, top, direction=TransformDirection.INVERSE)
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
title =
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
box=HEAVY,
|
|
151
|
+
|
|
152
|
+
if no_border:
|
|
153
|
+
console.print(full_rich_string)
|
|
154
|
+
else:
|
|
155
|
+
title = _generate_panel_title(files, terminal_width)
|
|
156
|
+
|
|
157
|
+
console.print(
|
|
158
|
+
Panel.fit(
|
|
159
|
+
full_rich_string,
|
|
160
|
+
padding=0,
|
|
161
|
+
title=title,
|
|
162
|
+
subtitle=f"BBOX: {map_minx:.5f},{map_miny:.5f},{map_maxx:.5f},{map_maxy:.5f}",
|
|
163
|
+
box=HEAVY,
|
|
164
|
+
)
|
|
167
165
|
)
|
|
168
|
-
)
|
|
169
|
-
# console.print(full_rich_string)
|
|
170
166
|
|
|
171
167
|
|
|
172
168
|
def _load_geo_data(
|
|
@@ -246,17 +242,50 @@ def _expand_axes_limit_to_match_ratio(ax: Axes, ratio: float) -> tuple[float, fl
|
|
|
246
242
|
|
|
247
243
|
def _construct_full_rich_string(
|
|
248
244
|
characters: Any, foreground_colors: Any, background_colors: Any
|
|
249
|
-
) ->
|
|
250
|
-
|
|
245
|
+
) -> Text:
|
|
246
|
+
has_fg_color = foreground_colors is not None
|
|
247
|
+
has_bg_color = background_colors is not None
|
|
248
|
+
result = Text()
|
|
251
249
|
for y in range(characters.shape[0]):
|
|
252
250
|
for x in range(characters.shape[1]):
|
|
253
251
|
idx = y, x
|
|
254
252
|
res = characters[idx]
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
253
|
+
result.append(
|
|
254
|
+
chr(res),
|
|
255
|
+
style=Style(
|
|
256
|
+
color=(Color.from_rgb(*foreground_colors[idx]) if has_fg_color else None),
|
|
257
|
+
bgcolor=(Color.from_rgb(*background_colors[idx]) if has_bg_color else None),
|
|
258
|
+
),
|
|
260
259
|
)
|
|
261
|
-
result
|
|
260
|
+
result.append("\n")
|
|
262
261
|
return result[:-1]
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def _generate_panel_title(files: list[str], terminal_width: int) -> str:
|
|
265
|
+
file_paths = [Path(f).name for f in files]
|
|
266
|
+
|
|
267
|
+
if len(file_paths) == 1:
|
|
268
|
+
title = "1 file"
|
|
269
|
+
else:
|
|
270
|
+
title = f"{len(file_paths)} files"
|
|
271
|
+
|
|
272
|
+
file_names_in_title = []
|
|
273
|
+
file_names_left = file_paths
|
|
274
|
+
while file_names_left:
|
|
275
|
+
current_file_name = file_names_left.pop(0)
|
|
276
|
+
file_names_in_title.append(current_file_name)
|
|
277
|
+
titles_joined = ", ".join(file_names_in_title)
|
|
278
|
+
titles_left = len(file_names_left)
|
|
279
|
+
if titles_left == 0:
|
|
280
|
+
new_title = titles_joined
|
|
281
|
+
elif titles_left == 1:
|
|
282
|
+
new_title = f"{titles_joined} + 1 other file"
|
|
283
|
+
else:
|
|
284
|
+
new_title = f"{titles_joined} + {titles_left} other files"
|
|
285
|
+
|
|
286
|
+
if len(new_title) > (terminal_width - 4):
|
|
287
|
+
break
|
|
288
|
+
|
|
289
|
+
title = new_title
|
|
290
|
+
|
|
291
|
+
return title
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Wrappers around img2unicode.Renderers.
|
|
3
|
+
|
|
4
|
+
Look https://github.com/matrach/img2unicode/tree/master/examples for more information
|
|
5
|
+
about renderers.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from typing import TYPE_CHECKING
|
|
9
|
+
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from img2unicode import Renderer
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def get_fast_block_renderer(terminal_width: int, terminal_height: int) -> "Renderer":
|
|
15
|
+
"""Fast block renderer."""
|
|
16
|
+
import img2unicode
|
|
17
|
+
|
|
18
|
+
return img2unicode.Renderer(
|
|
19
|
+
img2unicode.FastGenericDualOptimizer("block"),
|
|
20
|
+
max_h=terminal_height,
|
|
21
|
+
max_w=terminal_width,
|
|
22
|
+
allow_upscale=True,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def get_fast_all_renderer(terminal_width: int, terminal_height: int) -> "Renderer":
|
|
27
|
+
"""Fast all renderer."""
|
|
28
|
+
import img2unicode
|
|
29
|
+
|
|
30
|
+
return img2unicode.Renderer(
|
|
31
|
+
img2unicode.FastGenericDualOptimizer(),
|
|
32
|
+
max_h=terminal_height,
|
|
33
|
+
max_w=terminal_width,
|
|
34
|
+
allow_upscale=True,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def get_fast_ascii_renderer(terminal_width: int, terminal_height: int) -> "Renderer":
|
|
39
|
+
"""Fast all renderer."""
|
|
40
|
+
import img2unicode
|
|
41
|
+
|
|
42
|
+
return img2unicode.Renderer(
|
|
43
|
+
img2unicode.FastGenericDualOptimizer("ascii"),
|
|
44
|
+
max_h=terminal_height,
|
|
45
|
+
max_w=terminal_width,
|
|
46
|
+
allow_upscale=True,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def get_space_renderer(terminal_width: int, terminal_height: int) -> "Renderer":
|
|
51
|
+
"""Space renderer."""
|
|
52
|
+
import img2unicode
|
|
53
|
+
|
|
54
|
+
return img2unicode.Renderer(
|
|
55
|
+
img2unicode.SpaceDualOptimizer(),
|
|
56
|
+
max_h=terminal_height,
|
|
57
|
+
max_w=terminal_width,
|
|
58
|
+
allow_upscale=True,
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def get_half_renderer(terminal_width: int, terminal_height: int) -> "Renderer":
|
|
63
|
+
"""Half renderer."""
|
|
64
|
+
import img2unicode
|
|
65
|
+
|
|
66
|
+
return img2unicode.Renderer(
|
|
67
|
+
img2unicode.HalfBlockDualOptimizer(),
|
|
68
|
+
max_h=terminal_height,
|
|
69
|
+
max_w=terminal_width,
|
|
70
|
+
allow_upscale=True,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def get_quad_renderer(terminal_width: int, terminal_height: int) -> "Renderer":
|
|
75
|
+
"""Quad renderer."""
|
|
76
|
+
import img2unicode
|
|
77
|
+
|
|
78
|
+
return img2unicode.Renderer(
|
|
79
|
+
img2unicode.FastQuadDualOptimizer(),
|
|
80
|
+
max_h=terminal_height,
|
|
81
|
+
max_w=terminal_width,
|
|
82
|
+
allow_upscale=True,
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def get_braille_renderer(terminal_width: int, terminal_height: int) -> "Renderer":
|
|
87
|
+
"""Braille renderer."""
|
|
88
|
+
import img2unicode
|
|
89
|
+
|
|
90
|
+
return img2unicode.GammaRenderer(
|
|
91
|
+
img2unicode.BestGammaOptimizer(use_color=True, charmask="braille"),
|
|
92
|
+
max_h=terminal_height,
|
|
93
|
+
max_w=terminal_width,
|
|
94
|
+
allow_upscale=True,
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
def get_ascii_bw_renderer(terminal_width: int, terminal_height: int) -> "Renderer":
|
|
98
|
+
"""ASCII black-white renderer."""
|
|
99
|
+
import img2unicode
|
|
100
|
+
|
|
101
|
+
return img2unicode.GammaRenderer(
|
|
102
|
+
img2unicode.BestGammaOptimizer(use_color=False, charmask="ascii"),
|
|
103
|
+
max_h=terminal_height,
|
|
104
|
+
max_w=terminal_width,
|
|
105
|
+
allow_upscale=True,
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
def get_braille_bw_renderer(terminal_width: int, terminal_height: int) -> "Renderer":
|
|
109
|
+
"""Braille renderer."""
|
|
110
|
+
import img2unicode
|
|
111
|
+
|
|
112
|
+
return img2unicode.GammaRenderer(
|
|
113
|
+
img2unicode.BestGammaOptimizer(use_color=False, charmask="braille"),
|
|
114
|
+
max_h=terminal_height,
|
|
115
|
+
max_w=terminal_width,
|
|
116
|
+
allow_upscale=True,
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
AVAILABLE_RENDERERS = {
|
|
120
|
+
"block": get_fast_block_renderer,
|
|
121
|
+
"all": get_fast_all_renderer,
|
|
122
|
+
"ascii": get_fast_ascii_renderer,
|
|
123
|
+
"space": get_space_renderer,
|
|
124
|
+
"half": get_half_renderer,
|
|
125
|
+
"quad": get_quad_renderer,
|
|
126
|
+
"braille": get_braille_renderer,
|
|
127
|
+
"braille-bw": get_braille_bw_renderer,
|
|
128
|
+
"ascii-bw": get_ascii_bw_renderer,
|
|
129
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "pixel-map"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.2"
|
|
4
4
|
description = "A Python CLI tool for plotting geo files in the terminal"
|
|
5
5
|
authors = [
|
|
6
6
|
{ name = "Kamil Raczycki", email = "kraczycki@kraina.ai" },
|
|
@@ -8,14 +8,12 @@ authors = [
|
|
|
8
8
|
dependencies = [
|
|
9
9
|
"rich>=12.0.0",
|
|
10
10
|
"typer[all]>=0.9.0",
|
|
11
|
-
"img2unicode[n2]>=0.1a11; sys_platform != 'win32'",
|
|
12
|
-
"img2unicode>=0.1a11; sys_platform == 'win32'",
|
|
11
|
+
"img2unicode[n2]>=0.1a11; sys_platform != 'win32' and sys_platform != 'darwin'",
|
|
12
|
+
"img2unicode>=0.1a11; sys_platform == 'win32' or sys_platform == 'darwin'",
|
|
13
13
|
"geopandas>=0.6",
|
|
14
14
|
"numpy>=1.26.0",
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"matplotlib",
|
|
18
|
-
"pillow",
|
|
15
|
+
"contextily>=1",
|
|
16
|
+
"matplotlib>=3.2.0",
|
|
19
17
|
"pyarrow>=16.0.0",
|
|
20
18
|
]
|
|
21
19
|
requires-python = ">=3.9"
|
|
@@ -56,6 +54,10 @@ test = [
|
|
|
56
54
|
"pytest-check>=2.3.1",
|
|
57
55
|
"pytest-parametrization>=2022.2.1",
|
|
58
56
|
]
|
|
57
|
+
license = [
|
|
58
|
+
"licensecheck",
|
|
59
|
+
"pipdeptree",
|
|
60
|
+
]
|
|
59
61
|
|
|
60
62
|
[tool.pdm.scripts]
|
|
61
63
|
post_install = "pre-commit install"
|
|
@@ -127,7 +129,7 @@ close-quotes-on-newline = true
|
|
|
127
129
|
wrap-one-line = true
|
|
128
130
|
|
|
129
131
|
[tool.bumpver]
|
|
130
|
-
current_version = "0.1.
|
|
132
|
+
current_version = "0.1.2"
|
|
131
133
|
version_pattern = "MAJOR.MINOR.PATCH[PYTAGNUM]"
|
|
132
134
|
commit_message = "chore(CI/CD): bump version {old_version} -> {new_version}"
|
|
133
135
|
commit = true
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"""Main CLI module."""
|
|
2
|
-
|
|
3
|
-
from typing import Annotated, Optional, cast
|
|
4
|
-
|
|
5
|
-
import click
|
|
6
|
-
import typer
|
|
7
|
-
|
|
8
|
-
from pixel_map import __app_name__, __version__
|
|
9
|
-
|
|
10
|
-
app = typer.Typer(
|
|
11
|
-
context_settings={"help_option_names": ["-h", "--help"]}, rich_markup_mode="rich"
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
# TODO:
|
|
15
|
-
# - add option to select colours (pass list - must match number of files)
|
|
16
|
-
# - add option to select colours per type (polygon, linestring, point)
|
|
17
|
-
# (pass list(s) - must match number of files)
|
|
18
|
-
# - define default colour schemes with option to select
|
|
19
|
-
# --light (positron + blue)
|
|
20
|
-
# or --dark (darkmatter + orange?) [default]
|
|
21
|
-
# or --street (voyager + ???)
|
|
22
|
-
# - add option to select tileset (or no tileset) by name
|
|
23
|
-
# - add option to pass map height and width
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
def _version_callback(value: bool) -> None:
|
|
27
|
-
if value:
|
|
28
|
-
typer.echo(f"{__app_name__} {__version__}")
|
|
29
|
-
raise typer.Exit()
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
class BboxGeometryParser(click.ParamType): # type: ignore
|
|
33
|
-
"""Parser for bounding boxes."""
|
|
34
|
-
|
|
35
|
-
name = "BBOX"
|
|
36
|
-
|
|
37
|
-
def convert(self, value, param=None, ctx=None): # type: ignore
|
|
38
|
-
"""Convert parameter value."""
|
|
39
|
-
try:
|
|
40
|
-
bbox_values = tuple(float(x.strip()) for x in value.split(","))
|
|
41
|
-
if len(bbox_values) == 4:
|
|
42
|
-
return bbox_values
|
|
43
|
-
except ValueError: # ValueError raised when passing non-numbers to float()
|
|
44
|
-
pass
|
|
45
|
-
|
|
46
|
-
raise typer.BadParameter(
|
|
47
|
-
"Cannot parse provided bounding box."
|
|
48
|
-
" Valid value must contain 4 floating point numbers"
|
|
49
|
-
" separated by commas."
|
|
50
|
-
) from None
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
@app.command() # type: ignore
|
|
54
|
-
def plot(
|
|
55
|
-
files: Annotated[
|
|
56
|
-
list[str],
|
|
57
|
-
typer.Argument(
|
|
58
|
-
help="List of files to display. Those could be any that can be opened by GeoPandas.",
|
|
59
|
-
show_default=False,
|
|
60
|
-
),
|
|
61
|
-
],
|
|
62
|
-
bbox: Annotated[
|
|
63
|
-
Optional[str],
|
|
64
|
-
typer.Option(
|
|
65
|
-
help=(
|
|
66
|
-
"Clip the map to a given [bold dark_orange]bounding box[/bold dark_orange]."
|
|
67
|
-
" Expects 4 floating point numbers separated by commas."
|
|
68
|
-
),
|
|
69
|
-
click_type=BboxGeometryParser(),
|
|
70
|
-
show_default=False,
|
|
71
|
-
),
|
|
72
|
-
] = None,
|
|
73
|
-
version: Annotated[
|
|
74
|
-
Optional[bool],
|
|
75
|
-
typer.Option(
|
|
76
|
-
"--version",
|
|
77
|
-
"-v",
|
|
78
|
-
help="Show the application's version and exit.",
|
|
79
|
-
callback=_version_callback,
|
|
80
|
-
is_eager=True,
|
|
81
|
-
),
|
|
82
|
-
] = None,
|
|
83
|
-
) -> None:
|
|
84
|
-
"""Plot the geodata in the terminal."""
|
|
85
|
-
import warnings
|
|
86
|
-
|
|
87
|
-
from pixel_map.plotter import plot_geo_data
|
|
88
|
-
|
|
89
|
-
with warnings.catch_warnings():
|
|
90
|
-
warnings.filterwarnings("ignore")
|
|
91
|
-
plot_geo_data(
|
|
92
|
-
files, bbox=cast(Optional[tuple[float, float, float, float]], bbox)
|
|
93
|
-
)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
def main() -> None:
|
|
97
|
-
"""Run the CLI."""
|
|
98
|
-
app(prog_name=__app_name__) # pragma: no cover
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if __name__ == "__main__":
|
|
102
|
-
app(prog_name=__app_name__) # pragma: no cover
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|