pixel-map 0.3.0__tar.gz → 0.4.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.1
2
2
  Name: pixel-map
3
- Version: 0.3.0
3
+ Version: 0.4.0
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
@@ -10,7 +10,6 @@ Classifier: Topic :: Scientific/Engineering :: GIS
10
10
  Classifier: Intended Audience :: Science/Research
11
11
  Classifier: Intended Audience :: Developers
12
12
  Classifier: Programming Language :: Python :: 3
13
- Classifier: Programming Language :: Python :: 3.10
14
13
  Classifier: Programming Language :: Python :: 3.11
15
14
  Classifier: Programming Language :: Python :: 3.12
16
15
  Classifier: Programming Language :: Python :: 3.13
@@ -19,13 +18,14 @@ Classifier: Operating System :: MacOS
19
18
  Classifier: Operating System :: Microsoft :: Windows
20
19
  Project-URL: Homepage, https://github.com/RaczeQ/pixel-map
21
20
  Project-URL: Repository, https://github.com/RaczeQ/pixel-map
21
+ Project-URL: Documentation, https://raczeq.github.io/pixel-map/
22
22
  Project-URL: Changelog, https://github.com/RaczeQ/pixel-map/blob/main/CHANGELOG.md
23
- Requires-Python: >=3.10
23
+ Requires-Python: >=3.11
24
24
  Requires-Dist: rich>=12.0.0
25
- Requires-Dist: typer[all]>=0.9.0
26
- Requires-Dist: geopandas>=0.8
25
+ Requires-Dist: typer[all]>=0.16.0
26
+ Requires-Dist: geopandas>=0.14
27
27
  Requires-Dist: numpy>=1.26.0
28
- Requires-Dist: contextily>=1
28
+ Requires-Dist: basemaplibre>=0.1.1
29
29
  Requires-Dist: matplotlib>=3.2.0
30
30
  Requires-Dist: pyarrow>=16.0.0
31
31
  Requires-Dist: pillow>=10.1.0
@@ -42,25 +42,17 @@ Python CLI tool for plotting geo data in the terminal
42
42
  <p align="center">
43
43
  <img alt="GitHub" src="https://img.shields.io/github/license/raczeq/pixel-map?logo=mit&logoColor=%23fff">
44
44
  <img src="https://img.shields.io/github/checks-status/raczeq/pixel-map/main?logo=GitHubActions&logoColor=%23fff" alt="Checks">
45
- <a href="https://github.com/raczeq/pixel-map/actions/workflows/ci-prod.yml" target="_blank">
46
- <img alt="GitHub Workflow Status - PROD" src="https://img.shields.io/github/actions/workflow/status/raczeq/pixel-map/ci-prod.yml?label=build-prod&logo=GitHubActions&logoColor=%23fff">
47
- </a>
48
- <a href="https://results.pre-commit.ci/latest/github/raczeq/pixel-map/main" target="_blank">
49
- <img src="https://results.pre-commit.ci/badge/github/raczeq/pixel-map/main.svg" alt="pre-commit.ci status">
50
- </a>
45
+ <a href="https://github.com/raczeq/pixel-map/actions/workflows/ci-prod.yml" target="_blank"><img alt="GitHub Workflow Status - PROD" src="https://img.shields.io/github/actions/workflow/status/raczeq/pixel-map/ci-prod.yml?label=build-prod&logo=GitHubActions&logoColor=%23fff"></a>
46
+ <a href="https://results.pre-commit.ci/latest/github/raczeq/pixel-map/main" target="_blank"><img src="https://results.pre-commit.ci/badge/github/raczeq/pixel-map/main.svg" alt="pre-commit.ci status"></a>
51
47
  <a href="https://www.codefactor.io/repository/github/raczeq/pixel-map"><img alt="CodeFactor Grade" src="https://img.shields.io/codefactor/grade/github/raczeq/pixel-map?logo=codefactor&logoColor=%23fff"></a>
52
48
  <a href="https://app.codecov.io/gh/raczeq/pixel-map/tree/main"><img alt="Codecov" src="https://img.shields.io/codecov/c/github/raczeq/pixel-map?logo=codecov&token=PRS4E02ZX0&logoColor=%23fff"></a>
53
- <a href="https://pypi.org/project/pixel-map" target="_blank">
54
- <img src="https://img.shields.io/pypi/v/pixel-map?color=%2334D058&label=pypi%20package&logo=pypi&logoColor=%23fff" alt="Package version">
55
- </a>
56
- <a href="https://pypi.org/project/pixel-map" target="_blank">
57
- <img src="https://img.shields.io/pypi/pyversions/pixel-map.svg?color=%2334D058&logo=python&logoColor=%23fff" alt="Supported Python versions">
58
- </a>
59
- <a href="https://pypi.org/project/pixel-map" target="_blank">
60
- <img alt="PyPI - Downloads" src="https://img.shields.io/pypi/dm/pixel-map">
61
- </a>
49
+ <a href="https://pypi.org/project/pixel-map" target="_blank"><img src="https://img.shields.io/pypi/v/pixel-map?color=%2334D058&label=pypi%20package&logo=pypi&logoColor=%23fff" alt="Package version"></a>
50
+ <a href="https://pypi.org/project/pixel-map" target="_blank"><img src="https://img.shields.io/pypi/pyversions/pixel-map.svg?color=%2334D058&logo=python&logoColor=%23fff" alt="Supported Python versions"></a>
51
+ <a href="https://pypi.org/project/pixel-map" target="_blank"><img alt="PyPI - Downloads" src="https://img.shields.io/pypi/dm/pixel-map"></a>
62
52
  </p>
63
53
 
54
+ [Documentation](https://raczeq.github.io/pixel-map/) · [Examples](https://raczeq.github.io/pixel-map/examples/) · [Basemaps](https://raczeq.github.io/pixel-map/basemaps/) · [Renderers](https://raczeq.github.io/pixel-map/renderers/)
55
+
64
56
  ## Installation
65
57
 
66
58
  PyPI:
@@ -93,38 +85,42 @@ See more examples below ⬇️
93
85
  <summary>CLI Help output (<code>pixel-map -h</code>)</summary>
94
86
 
95
87
  ```console
96
- Usage: pixel-map [OPTIONS] FILES...
88
+ Usage: pixel-map [OPTIONS] {files}...
97
89
 
98
90
  Plot the geo data into a terminal.
91
+
99
92
  Generates a Matplotlib canvas that is rendered to an image and later transformed into a list of
100
93
  unicode characters.
101
94
 
102
- ╭─ Arguments ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
103
- │ * files FILES... List of files to display. Those could be any that can be opened by GeoPandas. [required] │
104
- ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
105
- ╭─ Options ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
106
- │ --bbox -b BBOX Clip the map to a given bounding box. Expects 4 floating point numbers separated by commas. │
107
- │ --renderer -r TEXT Renderer used for generating terminal output. Possible values: all, ascii, ascii-bw, block, braille, braille-bw, half, quad, │
108
- │ space. │
109
- │ [default: (block)] │
110
- │ --dark --light Uses the predefined dark or light style. Can be overriden with user defined style. [default: dark] │
111
- │ --color -c COLOR Pass color or list of colours per each geo file. │
112
- │ --alpha,--opacity -a FLOAT Pass opacity or list of opacities per each geo file. │
113
- │ --basemap,--tileset -t TILES Set the basemap provider. Can be any value parsed by xyzservices library. Defaults to CartoDB.DarkMatterNoLabels if --dark │
114
- │ or CartoDB.PositronNoLabels if --light. │
115
- │ --no-border,--fullscreen -f Removes the border around the map. │
116
- │ --no-background,--no-bg Removes the background of the map and plots only geo data. │
117
- │ --background-color,--bg-color COLOR Set the background color. Can be used together with --no-background. │
118
- │ --width INT Override the current console width. │
119
- │ --height INT Override the current console height. │
120
- │ --dpi INT DPI used to get better quality matplotlib plot before rendering to terminal. [default: 10] │
121
- │ --example,--example-files Can be used to load one of example files based on name. Possible values: london_buildings, london_park, london_water, │
122
- │ monaco_buildings. │
123
- │ --version -v Show the application's version and exit. │
124
- │ --install-completion Install completion for the current shell. │
125
- │ --show-completion Show completion for the current shell, to copy it or customize the installation. │
126
- │ --help -h Show this message and exit. │
127
- ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
95
+ ╭─ Arguments ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
96
+ │ * files <str> List of files to display. Those could be any that can be opened by GeoPandas. [required] │
97
+ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
98
+ ╭─ Options ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
99
+ │ --bbox -b BBOX Clip the map to a given bounding box. Expects 4 floating point numbers separated by commas. │
100
+ │ --renderer -r <str> Renderer used for generating terminal output. Possible values: all, ascii, ascii-bw, block, braille, braille-bw, half, │
101
+ │ quad, space. │
102
+ │ [default: (block)] │
103
+ │ --dark --light Uses the predefined dark or light style. Can be overriden with user defined style. [default: dark] │
104
+ │ --color -c COLOR Pass color or list of colours per each geo file. │
105
+ │ --alpha,--opacity -a FLOAT Pass opacity or list of opacities per each geo file. │
106
+ │ --basemap,--tileset -t TILES Set the basemap. Can be a name of a basemaplibre style, or a URL or a path of a MapLibre style JSON. Raster tiles (like │
107
+ │ names of xyzservices) need contextily to be installed. Defaults to OpenFreeMap.Dark if --dark or OpenFreeMap.Positron if │
108
+ │ --light. │
109
+ │ --no-border,--fullscreen -f Removes the border around the map. │
110
+ │ --no-background,--no-bg Removes the background of the map and plots only geo data. │
111
+ │ --background-color,--bg-color COLOR Set the background color. Can be used together with --no-background. │
112
+ │ --width INT Override the current console width. │
113
+ │ --height INT Override the current console height. │
114
+ │ --dpi INT DPI used to rasterise the matplotlib plot. Setting this to 8 (matching the renderer's subpixel width) skips the PIL resize │
115
+ │ for a faster path; higher values improve anti-aliasing quality. │
116
+ │ [default: 8] │
117
+ │ --example,--example-files Can be used to load one of example files based on name. Possible values: london_buildings, london_park, london_water, │
118
+ │ monaco_buildings. │
119
+ │ --version -v Show the application's version and exit. │
120
+ │ --install-completion Install completion for the current shell. │
121
+ │ --show-completion Show completion for the current shell, to copy it or customize the installation. │
122
+ │ --help -h Show this message and exit. │
123
+ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
128
124
  ```
129
125
  </details>
130
126
 
@@ -162,7 +158,7 @@ $ pixel-map --example london_buildings london_water london_park -c C1,C0,C2
162
158
  #### Different basemap and changed opacity (alpha)
163
159
 
164
160
  ```sh
165
- $ pixel-map --example london_water -c C0 -a 0.6 -t Esri.WorldImagery
161
+ $ pixel-map --example london_water -c C0 -a 0.6 -t VersaTiles.Satellite
166
162
  ```
167
163
  <p align="center">
168
164
  <img src="https://raw.githubusercontent.com/RaczeQ/pixel-map/main/images/london_satellite.jpg"><br/>
@@ -170,7 +166,7 @@ $ pixel-map --example london_water -c C0 -a 0.6 -t Esri.WorldImagery
170
166
 
171
167
  #### No background and different renderer
172
168
 
173
- You can explore multiple available renderers. Full list available in the `pixel-map` CLI help.
169
+ You can explore [multiple available renderers](https://raczeq.github.io/pixel-map/renderers/).
174
170
 
175
171
  ```sh
176
172
  $ pixel-map --example london_buildings --no-bg -r ascii-bw
@@ -191,7 +187,7 @@ $ pixel-map --example london_buildings --no-bg -r ascii-bw
191
187
 
192
188
  - `matplotlib (>=3.2.0)`: For generating the plot with styling and cropping
193
189
 
194
- - `contextily (>=1)`: For adding basemap to the plot
190
+ - `basemaplibre (>=0.1.1)`: For adding basemap to the plot (raster tiles need `contextily`, which is not installed by default)
195
191
 
196
192
  - `numpy (>=1.26.0)`: For transforming matplotlib array into an image
197
193
 
@@ -203,7 +199,7 @@ $ pixel-map --example london_buildings --no-bg -r ascii-bw
203
199
  2. `Matplotlib` figure is created with the size of the terminal (`pixel-map` expects a default monospace font with the ratio of 8 to 16 pixels. Figure canvas takes terminal height and multiplies it by two).
204
200
  3. GeoSerieses are plotted to the canvas.
205
201
  4. Plot bounding box is expanded to the canvas ratio (based on terminal size).
206
- 5. Basemap is loaded with `contextily`.
202
+ 5. Basemap is drawn with `basemaplibre` from a MapLibre style, without labels.
207
203
  6. Canvas is copied to the image as an `NumPy` array.
208
204
  7. Image is downsampled and converted to a grid of Unicode characters with
209
205
  foreground/background colours using the native dual-colour engine in
@@ -9,25 +9,17 @@ Python CLI tool for plotting geo data in the terminal
9
9
  <p align="center">
10
10
  <img alt="GitHub" src="https://img.shields.io/github/license/raczeq/pixel-map?logo=mit&logoColor=%23fff">
11
11
  <img src="https://img.shields.io/github/checks-status/raczeq/pixel-map/main?logo=GitHubActions&logoColor=%23fff" alt="Checks">
12
- <a href="https://github.com/raczeq/pixel-map/actions/workflows/ci-prod.yml" target="_blank">
13
- <img alt="GitHub Workflow Status - PROD" src="https://img.shields.io/github/actions/workflow/status/raczeq/pixel-map/ci-prod.yml?label=build-prod&logo=GitHubActions&logoColor=%23fff">
14
- </a>
15
- <a href="https://results.pre-commit.ci/latest/github/raczeq/pixel-map/main" target="_blank">
16
- <img src="https://results.pre-commit.ci/badge/github/raczeq/pixel-map/main.svg" alt="pre-commit.ci status">
17
- </a>
12
+ <a href="https://github.com/raczeq/pixel-map/actions/workflows/ci-prod.yml" target="_blank"><img alt="GitHub Workflow Status - PROD" src="https://img.shields.io/github/actions/workflow/status/raczeq/pixel-map/ci-prod.yml?label=build-prod&logo=GitHubActions&logoColor=%23fff"></a>
13
+ <a href="https://results.pre-commit.ci/latest/github/raczeq/pixel-map/main" target="_blank"><img src="https://results.pre-commit.ci/badge/github/raczeq/pixel-map/main.svg" alt="pre-commit.ci status"></a>
18
14
  <a href="https://www.codefactor.io/repository/github/raczeq/pixel-map"><img alt="CodeFactor Grade" src="https://img.shields.io/codefactor/grade/github/raczeq/pixel-map?logo=codefactor&logoColor=%23fff"></a>
19
15
  <a href="https://app.codecov.io/gh/raczeq/pixel-map/tree/main"><img alt="Codecov" src="https://img.shields.io/codecov/c/github/raczeq/pixel-map?logo=codecov&token=PRS4E02ZX0&logoColor=%23fff"></a>
20
- <a href="https://pypi.org/project/pixel-map" target="_blank">
21
- <img src="https://img.shields.io/pypi/v/pixel-map?color=%2334D058&label=pypi%20package&logo=pypi&logoColor=%23fff" alt="Package version">
22
- </a>
23
- <a href="https://pypi.org/project/pixel-map" target="_blank">
24
- <img src="https://img.shields.io/pypi/pyversions/pixel-map.svg?color=%2334D058&logo=python&logoColor=%23fff" alt="Supported Python versions">
25
- </a>
26
- <a href="https://pypi.org/project/pixel-map" target="_blank">
27
- <img alt="PyPI - Downloads" src="https://img.shields.io/pypi/dm/pixel-map">
28
- </a>
16
+ <a href="https://pypi.org/project/pixel-map" target="_blank"><img src="https://img.shields.io/pypi/v/pixel-map?color=%2334D058&label=pypi%20package&logo=pypi&logoColor=%23fff" alt="Package version"></a>
17
+ <a href="https://pypi.org/project/pixel-map" target="_blank"><img src="https://img.shields.io/pypi/pyversions/pixel-map.svg?color=%2334D058&logo=python&logoColor=%23fff" alt="Supported Python versions"></a>
18
+ <a href="https://pypi.org/project/pixel-map" target="_blank"><img alt="PyPI - Downloads" src="https://img.shields.io/pypi/dm/pixel-map"></a>
29
19
  </p>
30
20
 
21
+ [Documentation](https://raczeq.github.io/pixel-map/) · [Examples](https://raczeq.github.io/pixel-map/examples/) · [Basemaps](https://raczeq.github.io/pixel-map/basemaps/) · [Renderers](https://raczeq.github.io/pixel-map/renderers/)
22
+
31
23
  ## Installation
32
24
 
33
25
  PyPI:
@@ -60,38 +52,42 @@ See more examples below ⬇️
60
52
  <summary>CLI Help output (<code>pixel-map -h</code>)</summary>
61
53
 
62
54
  ```console
63
- Usage: pixel-map [OPTIONS] FILES...
55
+ Usage: pixel-map [OPTIONS] {files}...
64
56
 
65
57
  Plot the geo data into a terminal.
58
+
66
59
  Generates a Matplotlib canvas that is rendered to an image and later transformed into a list of
67
60
  unicode characters.
68
61
 
69
- ╭─ Arguments ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
70
- │ * files FILES... List of files to display. Those could be any that can be opened by GeoPandas. [required] │
71
- ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
72
- ╭─ Options ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
73
- │ --bbox -b BBOX Clip the map to a given bounding box. Expects 4 floating point numbers separated by commas. │
74
- │ --renderer -r TEXT Renderer used for generating terminal output. Possible values: all, ascii, ascii-bw, block, braille, braille-bw, half, quad, │
75
- │ space. │
76
- │ [default: (block)] │
77
- │ --dark --light Uses the predefined dark or light style. Can be overriden with user defined style. [default: dark] │
78
- │ --color -c COLOR Pass color or list of colours per each geo file. │
79
- │ --alpha,--opacity -a FLOAT Pass opacity or list of opacities per each geo file. │
80
- │ --basemap,--tileset -t TILES Set the basemap provider. Can be any value parsed by xyzservices library. Defaults to CartoDB.DarkMatterNoLabels if --dark │
81
- │ or CartoDB.PositronNoLabels if --light. │
82
- │ --no-border,--fullscreen -f Removes the border around the map. │
83
- │ --no-background,--no-bg Removes the background of the map and plots only geo data. │
84
- │ --background-color,--bg-color COLOR Set the background color. Can be used together with --no-background. │
85
- │ --width INT Override the current console width. │
86
- │ --height INT Override the current console height. │
87
- │ --dpi INT DPI used to get better quality matplotlib plot before rendering to terminal. [default: 10] │
88
- │ --example,--example-files Can be used to load one of example files based on name. Possible values: london_buildings, london_park, london_water, │
89
- │ monaco_buildings. │
90
- │ --version -v Show the application's version and exit. │
91
- │ --install-completion Install completion for the current shell. │
92
- │ --show-completion Show completion for the current shell, to copy it or customize the installation. │
93
- │ --help -h Show this message and exit. │
94
- ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
62
+ ╭─ Arguments ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
63
+ │ * files <str> List of files to display. Those could be any that can be opened by GeoPandas. [required] │
64
+ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
65
+ ╭─ Options ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
66
+ │ --bbox -b BBOX Clip the map to a given bounding box. Expects 4 floating point numbers separated by commas. │
67
+ │ --renderer -r <str> Renderer used for generating terminal output. Possible values: all, ascii, ascii-bw, block, braille, braille-bw, half, │
68
+ │ quad, space. │
69
+ │ [default: (block)] │
70
+ │ --dark --light Uses the predefined dark or light style. Can be overriden with user defined style. [default: dark] │
71
+ │ --color -c COLOR Pass color or list of colours per each geo file. │
72
+ │ --alpha,--opacity -a FLOAT Pass opacity or list of opacities per each geo file. │
73
+ │ --basemap,--tileset -t TILES Set the basemap. Can be a name of a basemaplibre style, or a URL or a path of a MapLibre style JSON. Raster tiles (like │
74
+ │ names of xyzservices) need contextily to be installed. Defaults to OpenFreeMap.Dark if --dark or OpenFreeMap.Positron if │
75
+ │ --light. │
76
+ │ --no-border,--fullscreen -f Removes the border around the map. │
77
+ │ --no-background,--no-bg Removes the background of the map and plots only geo data. │
78
+ │ --background-color,--bg-color COLOR Set the background color. Can be used together with --no-background. │
79
+ │ --width INT Override the current console width. │
80
+ │ --height INT Override the current console height. │
81
+ │ --dpi INT DPI used to rasterise the matplotlib plot. Setting this to 8 (matching the renderer's subpixel width) skips the PIL resize │
82
+ │ for a faster path; higher values improve anti-aliasing quality. │
83
+ │ [default: 8] │
84
+ │ --example,--example-files Can be used to load one of example files based on name. Possible values: london_buildings, london_park, london_water, │
85
+ │ monaco_buildings. │
86
+ │ --version -v Show the application's version and exit. │
87
+ │ --install-completion Install completion for the current shell. │
88
+ │ --show-completion Show completion for the current shell, to copy it or customize the installation. │
89
+ │ --help -h Show this message and exit. │
90
+ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
95
91
  ```
96
92
  </details>
97
93
 
@@ -129,7 +125,7 @@ $ pixel-map --example london_buildings london_water london_park -c C1,C0,C2
129
125
  #### Different basemap and changed opacity (alpha)
130
126
 
131
127
  ```sh
132
- $ pixel-map --example london_water -c C0 -a 0.6 -t Esri.WorldImagery
128
+ $ pixel-map --example london_water -c C0 -a 0.6 -t VersaTiles.Satellite
133
129
  ```
134
130
  <p align="center">
135
131
  <img src="https://raw.githubusercontent.com/RaczeQ/pixel-map/main/images/london_satellite.jpg"><br/>
@@ -137,7 +133,7 @@ $ pixel-map --example london_water -c C0 -a 0.6 -t Esri.WorldImagery
137
133
 
138
134
  #### No background and different renderer
139
135
 
140
- You can explore multiple available renderers. Full list available in the `pixel-map` CLI help.
136
+ You can explore [multiple available renderers](https://raczeq.github.io/pixel-map/renderers/).
141
137
 
142
138
  ```sh
143
139
  $ pixel-map --example london_buildings --no-bg -r ascii-bw
@@ -158,7 +154,7 @@ $ pixel-map --example london_buildings --no-bg -r ascii-bw
158
154
 
159
155
  - `matplotlib (>=3.2.0)`: For generating the plot with styling and cropping
160
156
 
161
- - `contextily (>=1)`: For adding basemap to the plot
157
+ - `basemaplibre (>=0.1.1)`: For adding basemap to the plot (raster tiles need `contextily`, which is not installed by default)
162
158
 
163
159
  - `numpy (>=1.26.0)`: For transforming matplotlib array into an image
164
160
 
@@ -170,7 +166,7 @@ $ pixel-map --example london_buildings --no-bg -r ascii-bw
170
166
  2. `Matplotlib` figure is created with the size of the terminal (`pixel-map` expects a default monospace font with the ratio of 8 to 16 pixels. Figure canvas takes terminal height and multiplies it by two).
171
167
  3. GeoSerieses are plotted to the canvas.
172
168
  4. Plot bounding box is expanded to the canvas ratio (based on terminal size).
173
- 5. Basemap is loaded with `contextily`.
169
+ 5. Basemap is drawn with `basemaplibre` from a MapLibre style, without labels.
174
170
  6. Canvas is copied to the image as an `NumPy` array.
175
171
  7. Image is downsampled and converted to a grid of Unicode characters with
176
172
  foreground/background colours using the native dual-colour engine in
@@ -1,4 +1,4 @@
1
1
  """Pixel-map library."""
2
2
 
3
3
  __app_name__ = "pixel-map"
4
- __version__ = "0.3.0"
4
+ __version__ = "0.4.0"
@@ -3,7 +3,6 @@
3
3
  from contextlib import suppress
4
4
  from typing import Annotated, cast
5
5
 
6
- import click
7
6
  import typer
8
7
 
9
8
  from pixel_map import __app_name__, __version__
@@ -30,53 +29,32 @@ def _version_callback(value: bool) -> None:
30
29
  raise typer.Exit()
31
30
 
32
31
 
33
- class BboxParser(click.ParamType): # type: ignore
34
- """Parser for bounding boxes."""
32
+ def _parse_bbox(value: str) -> tuple[float, ...]:
33
+ with suppress(ValueError): # ValueError raised when passing non-numbers to float()
34
+ bbox_values = tuple(float(x.strip()) for x in value.split(","))
35
+ if len(bbox_values) == 4:
36
+ return bbox_values
35
37
 
36
- name = "BBOX"
38
+ raise typer.BadParameter(
39
+ "Cannot parse provided bounding box."
40
+ " Valid value must contain 4 floating point numbers"
41
+ " separated by commas."
42
+ ) from None
37
43
 
38
- def convert(self, value, param=None, ctx=None): # type: ignore
39
- """Convert parameter value."""
40
- with suppress(ValueError): # ValueError raised when passing non-numbers to float()
41
- bbox_values = tuple(float(x.strip()) for x in value.split(","))
42
- if len(bbox_values) == 4:
43
- return bbox_values
44
44
 
45
- raise typer.BadParameter(
46
- "Cannot parse provided bounding box."
47
- " Valid value must contain 4 floating point numbers"
48
- " separated by commas."
49
- ) from None
50
-
51
-
52
- class ColorParser(click.ParamType): # type: ignore
53
- """Parser for colours."""
54
-
55
- name = "COLOR"
56
-
57
- def convert(self, value, param=None, ctx=None): # type: ignore
58
- """Convert parameter value."""
59
- with suppress(ValueError): # ValueError raised when passing non-numbers to float()
60
- colors = [x.strip() for x in value.split(",")]
61
- return colors
45
+ def _parse_colors(value: str) -> list[str]:
46
+ return [x.strip() for x in value.split(",")]
62
47
 
63
48
 
64
- class AlphaParser(click.ParamType): # type: ignore
65
- """Parser for bounding boxes."""
49
+ def _parse_alphas(value: str) -> list[float]:
50
+ with suppress(ValueError): # ValueError raised when passing non-numbers to float()
51
+ return [float(x.strip()) for x in value.split(",")]
66
52
 
67
- name = "FLOAT"
68
-
69
- def convert(self, value, param=None, ctx=None): # type: ignore
70
- """Convert parameter value."""
71
- with suppress(ValueError): # ValueError raised when passing non-numbers to float()
72
- alpha_values = [float(x.strip()) for x in value.split(",")]
73
- return alpha_values
74
-
75
- raise typer.BadParameter(
76
- "Cannot parse provided alpha values."
77
- " Valid value must contain floating point numbers"
78
- " separated by commas."
79
- ) from None
53
+ raise typer.BadParameter(
54
+ "Cannot parse provided alpha values."
55
+ " Valid value must contain floating point numbers"
56
+ " separated by commas."
57
+ ) from None
80
58
 
81
59
 
82
60
  @app.command() # type: ignore
@@ -97,7 +75,8 @@ def plot(
97
75
  "Clip the map to a given [bold dark_orange]bounding box[/bold dark_orange]."
98
76
  " Expects 4 floating point numbers separated by commas."
99
77
  ),
100
- click_type=BboxParser(),
78
+ parser=_parse_bbox,
79
+ metavar="BBOX",
101
80
  show_default=False,
102
81
  ),
103
82
  ] = None,
@@ -131,7 +110,8 @@ def plot(
131
110
  "--color",
132
111
  "-c",
133
112
  help=("Pass color or list of colours per each geo file."),
134
- click_type=ColorParser(),
113
+ parser=_parse_colors,
114
+ metavar="COLOR",
135
115
  show_default=False,
136
116
  ),
137
117
  ] = None,
@@ -142,7 +122,8 @@ def plot(
142
122
  "--opacity",
143
123
  "-a",
144
124
  help=("Pass opacity or list of opacities per each geo file."),
145
- click_type=AlphaParser(),
125
+ parser=_parse_alphas,
126
+ metavar="FLOAT",
146
127
  show_default=False,
147
128
  ),
148
129
  ] = None,
@@ -154,9 +135,11 @@ def plot(
154
135
  "-t",
155
136
  metavar="TILES",
156
137
  help=(
157
- "Set the basemap provider. Can be any value parsed by xyzservices library."
158
- " Defaults to [bold dark_orange]ESRI World_Dark_Gray_Base[/bold dark_orange]"
159
- " if --dark or [bold dark_orange]ESRI World_Light_Gray_Base[/bold dark_orange]"
138
+ "Set the basemap. Can be a name of a basemaplibre style, or a URL or a path of"
139
+ " a MapLibre style JSON. Raster tiles (like names of xyzservices) need contextily"
140
+ " to be installed."
141
+ " Defaults to [bold dark_orange]OpenFreeMap.Dark[/bold dark_orange]"
142
+ " if --dark or [bold dark_orange]OpenFreeMap.Positron[/bold dark_orange]"
160
143
  " if --light."
161
144
  ),
162
145
  show_default=False,
@@ -252,6 +235,7 @@ def plot(
252
235
  import warnings
253
236
 
254
237
  from pixel_map.plotter import (
238
+ BasemapError,
255
239
  get_predefined_dark_style,
256
240
  get_predefined_light_style,
257
241
  plot_geo_data,
@@ -307,19 +291,22 @@ def plot(
307
291
 
308
292
  with warnings.catch_warnings():
309
293
  warnings.filterwarnings("ignore")
310
- plot_geo_data(
311
- files,
312
- renderer=renderer,
313
- bbox=cast("tuple[float, float, float, float] | None", bbox),
314
- color=parsed_colors,
315
- alpha=parsed_alphas,
316
- basemap_provider=basemap_provider,
317
- background_color=background_color or "black",
318
- no_border=no_border,
319
- console_width=console_width,
320
- console_height=console_height,
321
- plotting_dpi=plotting_dpi,
322
- )
294
+ try:
295
+ plot_geo_data(
296
+ files,
297
+ renderer=renderer,
298
+ bbox=cast("tuple[float, float, float, float] | None", bbox),
299
+ color=parsed_colors,
300
+ alpha=parsed_alphas,
301
+ basemap_provider=basemap_provider,
302
+ background_color=background_color or "black",
303
+ no_border=no_border,
304
+ console_width=console_width,
305
+ console_height=console_height,
306
+ plotting_dpi=plotting_dpi,
307
+ )
308
+ except BasemapError as ex:
309
+ raise typer.BadParameter(str(ex)) from None
323
310
 
324
311
 
325
312
  def main() -> None:
@@ -5,12 +5,14 @@ Generates a Matplotlib canvas that is rendered to an image and later transformed
5
5
  unicode characters.
6
6
  """
7
7
 
8
+ import math
8
9
  import os
9
10
  from pathlib import Path
10
11
  from typing import Any
11
12
 
12
- import contextily as cx
13
+ import basemaplibre as bml
13
14
  import geopandas as gpd
15
+ import httpx
14
16
  import numpy as np
15
17
  from matplotlib import pyplot as plt
16
18
  from matplotlib.axes import Axes
@@ -26,11 +28,20 @@ from rich.style import Style
26
28
  from rich.text import Text
27
29
 
28
30
  from pixel_map.renderers import AVAILABLE_RENDERERS
31
+ from pixel_map.terminal_renderers import SUB_W
29
32
 
30
33
  TRANSFORMER = Transformer.from_crs("EPSG:4326", "EPSG:3857", always_xy=True)
31
34
 
32
35
  EPSG_3857_BOUNDS = (-20037508.34, -20048966.1, 20037508.34, 20048966.1)
33
36
 
37
+ # Scale of the basemap: a map in a terminal of 120 columns shows as much as one 240 pixels wide on
38
+ # a web page, so that only the main roads, rivers and borders are left.
39
+ CSS_PIXELS_PER_COLUMN = 2
40
+
41
+
42
+ class BasemapError(ValueError):
43
+ """Basemap that cannot be drawn."""
44
+
34
45
 
35
46
  def plot_geo_data(
36
47
  files: list[str],
@@ -61,8 +72,9 @@ def plot_geo_data(
61
72
  If a list, must be the same length as a number of files. Defaults to "C0".
62
73
  alpha (Union[str, list[float]], optional): Opacity or list of opacities used to plot
63
74
  geo data. If a list, must be the same length as a number of files. Defaults to 1.
64
- basemap_provider (str, optional): A basemap used to plot under the geo data.
65
- Defaults to None.
75
+ basemap_provider (str, optional): A basemap used to plot under the geo data: a name of
76
+ `basemaplibre.STYLES`, a URL or a path of a MapLibre style JSON, or anything that
77
+ contextily draws, if it's installed. Defaults to None.
66
78
  background_color (str, optional): Background color. Used then basemap_provider is None.
67
79
  Defaults to None.
68
80
  no_border (bool, optional): Removes the border around the map. Defaults to False.
@@ -71,7 +83,7 @@ def plot_geo_data(
71
83
  console_height (int, optional): Console height. Can be used to set arbitrary value.
72
84
  Defaults to None.
73
85
  plotting_dpi (int, optional): Quality of matplotlib figure. It's used to multiply terminal
74
- size by some value to get better quality plot. Defaults to 10.
86
+ size by some value to get better quality plot. Defaults to 8.
75
87
  """
76
88
  force_terminal = os.getenv("FORCE_TERMINAL_MODE", "false").lower() == "true"
77
89
  if force_terminal:
@@ -136,24 +148,11 @@ def plot_geo_data(
136
148
 
137
149
  left, bottom, right, top = _expand_axes_limit_to_match_ratio(ax, ratio=map_ratio)
138
150
 
151
+ ax.set_position((0, 0, 1, 1))
152
+
139
153
  if basemap_provider:
140
- try:
141
- cx.add_basemap(
142
- ax,
143
- source=basemap_provider,
144
- crs=3857,
145
- attribution=False,
146
- )
147
- except ValueError:
148
- cx.add_basemap(
149
- ax,
150
- source=basemap_provider,
151
- crs=3857,
152
- attribution=False,
153
- zoom=0,
154
- )
154
+ _add_basemap(ax, basemap_provider)
155
155
 
156
- ax.set_position((0, 0, 1, 1))
157
156
  canvas.draw()
158
157
 
159
158
  # buffer_rgba() replaces the deprecated (and removed in matplotlib 3.10)
@@ -205,19 +204,42 @@ def plot_geo_data(
205
204
  )
206
205
 
207
206
 
208
- ESRI_URL = "https://server.arcgisonline.com/ArcGIS/rest/services/Canvas/{variant}/MapServer/tile/"
209
-
210
-
211
207
  def get_predefined_dark_style() -> tuple[str, str]:
212
208
  """Get default background and color for dark style."""
213
- url = ESRI_URL.format(variant="World_Dark_Gray_Base") + "{z}/{y}/{x}"
214
- return url, "C1"
209
+ return "OpenFreeMap.Dark", "C1"
215
210
 
216
211
 
217
212
  def get_predefined_light_style() -> tuple[str, str]:
218
213
  """Get default background and color for light style."""
219
- url = ESRI_URL.format(variant="World_Light_Gray_Base") + "{z}/{y}/{x}"
220
- return url, "C0"
214
+ return "OpenFreeMap.Positron", "C0"
215
+
216
+
217
+ def _add_basemap(ax: Axes, source: str) -> None:
218
+ """Draw a basemap without labels, which would not be readable in a terminal."""
219
+ try:
220
+ try:
221
+ bml.add_basemap(
222
+ ax,
223
+ source=source,
224
+ crs=3857,
225
+ attribution=False,
226
+ labels=False,
227
+ # A column of the terminal is an inch of the figure, in which matplotlib draws
228
+ # 96 CSS pixels of the style by default.
229
+ zoom_adjust=math.log2(CSS_PIXELS_PER_COLUMN / 96),
230
+ pixel_ratio=SUB_W / CSS_PIXELS_PER_COLUMN,
231
+ )
232
+ except TypeError:
233
+ # Not a MapLibre style, so there are no labels to drop: raster tiles and files are drawn
234
+ # by contextily, if it's installed.
235
+ bml.add_basemap(ax, source=source, crs=3857, attribution=False)
236
+ except ImportError as ex:
237
+ raise BasemapError(
238
+ f"Basemap {source!r} is not a MapLibre style."
239
+ " Raster tiles need contextily: pip install contextily"
240
+ ) from ex
241
+ except (ValueError, OSError, httpx.HTTPError) as ex:
242
+ raise BasemapError(f"Basemap {source!r} cannot be drawn: {ex}") from ex
221
243
 
222
244
 
223
245
  def _load_geo_data(
@@ -230,16 +230,16 @@ def _braille_template(codepoint: int) -> np.ndarray:
230
230
  """
231
231
  bits = codepoint - 0x2800
232
232
  t = np.zeros((SUB_H, SUB_W), dtype=bool)
233
- # Unicode dot numbering: dots 1-4 are the left column (top->bottom),
234
- # dots 5-8 are the right column.
233
+ # Unicode dot numbering: dots 1-3 are the left column (top->bottom), dots 4-6 the right one,
234
+ # dots 7 and 8 the row added below them.
235
235
  positions = [
236
236
  (0, 0), # dot 1
237
237
  (1, 0), # dot 2
238
238
  (2, 0), # dot 3
239
- (3, 0), # dot 4
240
- (0, 1), # dot 5
241
- (1, 1), # dot 6
242
- (2, 1), # dot 7
239
+ (0, 1), # dot 4
240
+ (1, 1), # dot 5
241
+ (2, 1), # dot 6
242
+ (3, 0), # dot 7
243
243
  (3, 1), # dot 8
244
244
  ]
245
245
  for bit, (rg, cg) in enumerate(positions):
@@ -1,21 +1,21 @@
1
1
  [project]
2
2
  name = "pixel-map"
3
- version = "0.3.0"
3
+ version = "0.4.0"
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" },
7
7
  ]
8
8
  dependencies = [
9
9
  "rich>=12.0.0",
10
- "typer[all]>=0.9.0",
11
- "geopandas>=0.8",
10
+ "typer[all]>=0.16.0",
11
+ "geopandas>=0.14",
12
12
  "numpy>=1.26.0",
13
- "contextily>=1",
13
+ "basemaplibre>=0.1.1",
14
14
  "matplotlib>=3.2.0",
15
15
  "pyarrow>=16.0.0",
16
16
  "pillow>=10.1.0",
17
17
  ]
18
- requires-python = ">=3.10"
18
+ requires-python = ">=3.11"
19
19
  readme = "README.md"
20
20
  classifiers = [
21
21
  "Development Status :: 3 - Alpha",
@@ -24,7 +24,6 @@ classifiers = [
24
24
  "Intended Audience :: Science/Research",
25
25
  "Intended Audience :: Developers",
26
26
  "Programming Language :: Python :: 3",
27
- "Programming Language :: Python :: 3.10",
28
27
  "Programming Language :: Python :: 3.11",
29
28
  "Programming Language :: Python :: 3.12",
30
29
  "Programming Language :: Python :: 3.13",
@@ -39,6 +38,7 @@ text = "MIT"
39
38
  [project.urls]
40
39
  Homepage = "https://github.com/RaczeQ/pixel-map"
41
40
  Repository = "https://github.com/RaczeQ/pixel-map"
41
+ Documentation = "https://raczeq.github.io/pixel-map/"
42
42
  Changelog = "https://github.com/RaczeQ/pixel-map/blob/main/CHANGELOG.md"
43
43
 
44
44
  [project.scripts]
@@ -77,6 +77,11 @@ license = [
77
77
  "licensecheck",
78
78
  "pipdeptree",
79
79
  ]
80
+ docs = [
81
+ "zensical>=0.1.3",
82
+ "mkdocstrings-python>=2.0.11",
83
+ "contextily>=1.6.2",
84
+ ]
80
85
 
81
86
  [tool.pdm.scripts]
82
87
  post_install = "pre-commit install"
@@ -84,7 +89,6 @@ post_install = "pre-commit install"
84
89
  [tool.black]
85
90
  line-length = 100
86
91
  target-version = [
87
- "py310",
88
92
  "py311",
89
93
  "py312",
90
94
  "py313",
@@ -93,7 +97,7 @@ preview = true
93
97
 
94
98
  [tool.ruff]
95
99
  line-length = 100
96
- target-version = "py310"
100
+ target-version = "py311"
97
101
  extend-exclude = [
98
102
  "old",
99
103
  ]
@@ -151,7 +155,7 @@ close-quotes-on-newline = true
151
155
  wrap-one-line = true
152
156
 
153
157
  [tool.bumpver]
154
- current_version = "0.3.0"
158
+ current_version = "0.4.0"
155
159
  version_pattern = "MAJOR.MINOR.PATCH[PYTAGNUM]"
156
160
  commit_message = "chore(CI/CD): bump version {old_version} -> {new_version}"
157
161
  commit = true
@@ -0,0 +1,163 @@
1
+ """Tests for basemaps."""
2
+
3
+ import json
4
+ import sys
5
+ from pathlib import Path
6
+ from types import SimpleNamespace
7
+ from typing import Any
8
+
9
+ import httpx
10
+ import pytest
11
+ from matplotlib import pyplot as plt
12
+ from ml2drender import Renderer
13
+ from pytest_mock import MockerFixture
14
+ from rich.text import Text
15
+ from typer.testing import CliRunner
16
+
17
+ from pixel_map.__main__ import app
18
+ from pixel_map.plotter import _add_basemap
19
+
20
+ runner = CliRunner()
21
+
22
+ LABEL = {"type": "Feature", "properties": {}, "geometry": {"type": "Point", "coordinates": [0, 0]}}
23
+
24
+
25
+ @pytest.fixture # type: ignore
26
+ def style(tmp_path: Path) -> str:
27
+ """Red style with a label, whose glyphs cannot be loaded."""
28
+ path = tmp_path / "style.json"
29
+ layers = [
30
+ {"id": "red", "type": "background", "paint": {"background-color": "#ff0000"}},
31
+ {"id": "label", "type": "symbol", "source": "label", "layout": {"text-field": "label"}},
32
+ ]
33
+ document = {
34
+ "version": 8,
35
+ "glyphs": (tmp_path / "{fontstack}" / "{range}.pbf").as_uri(),
36
+ "sources": {"label": {"type": "geojson", "data": LABEL}},
37
+ "layers": layers,
38
+ }
39
+ path.write_text(json.dumps(document))
40
+ return path.as_posix()
41
+
42
+
43
+ @pytest.mark.parametrize("dpi", [1, 8, 100]) # type: ignore
44
+ def test_resolution(style: str, dpi: int) -> None:
45
+ """Test if basemap has the resolution of the renderers, without labels, whatever the dpi."""
46
+ figure, ax = plt.subplots(figsize=(20, 10), dpi=dpi)
47
+ ax.set_position((0, 0, 1, 1))
48
+ ax.axis((-2000, 2000, -1000, 1000))
49
+
50
+ _add_basemap(ax, style)
51
+
52
+ image = ax.images[0].get_array()
53
+ assert image.shape[:2] == (80, 160)
54
+ assert (image[..., :3] == [255, 0, 0]).all()
55
+ plt.close(figure)
56
+
57
+
58
+ def test_rendered_once(style: str, mocker: MockerFixture) -> None:
59
+ """Test if basemap isn't rendered again when the canvas is drawn."""
60
+ render = mocker.spy(Renderer, "projected")
61
+
62
+ result = runner.invoke(app, ["--example", "monaco_buildings", "-t", style])
63
+
64
+ assert result.exit_code == 0
65
+ assert render.call_count == 1
66
+
67
+
68
+ @pytest.mark.parametrize(
69
+ "bbox", ["-180,-85,180,85", "7.41855,43.73259,7.42227,43.73528"]
70
+ ) # type: ignore
71
+ def test_bbox(style: str, bbox: str) -> None:
72
+ """Test if basemap is drawn for the world and for a few streets."""
73
+ result = runner.invoke(app, ["--example", "monaco_buildings", "-t", style, "--bbox", bbox])
74
+
75
+ assert result.exit_code == 0
76
+
77
+
78
+ @pytest.mark.parametrize(
79
+ "args,source", [(["--dark"], "OpenFreeMap.Dark"), (["--light"], "OpenFreeMap.Positron")]
80
+ ) # type: ignore
81
+ def test_default_basemaps(args: list[str], source: str, mocker: MockerFixture) -> None:
82
+ """Test if default basemaps are OpenFreeMap styles without labels."""
83
+ add_basemap = mocker.patch("pixel_map.plotter.bml.add_basemap")
84
+
85
+ result = runner.invoke(app, ["--example", "monaco_buildings", *args])
86
+
87
+ assert result.exit_code == 0
88
+ (call,) = add_basemap.call_args_list
89
+ assert call.kwargs["source"] == source
90
+ assert call.kwargs["labels"] is False
91
+
92
+
93
+ def test_no_background(mocker: MockerFixture) -> None:
94
+ """Test if basemap isn't drawn without background."""
95
+ add_basemap = mocker.patch("pixel_map.plotter.bml.add_basemap")
96
+
97
+ result = runner.invoke(app, ["--example", "monaco_buildings", "--no-bg"])
98
+
99
+ assert result.exit_code == 0
100
+ assert not add_basemap.called
101
+
102
+
103
+ def test_raster_tiles_with_contextily(monkeypatch: pytest.MonkeyPatch) -> None:
104
+ """Test if raster tiles are left to contextily."""
105
+ calls: list[dict[str, Any]] = []
106
+ contextily = SimpleNamespace(add_basemap=lambda ax, **kwargs: calls.append(kwargs))
107
+ monkeypatch.setitem(sys.modules, "contextily", contextily)
108
+
109
+ result = runner.invoke(app, ["--example", "monaco_buildings", "-t", "Esri.WorldImagery"])
110
+
111
+ assert result.exit_code == 0
112
+ assert [call["source"] for call in calls] == ["Esri.WorldImagery"]
113
+
114
+
115
+ def test_raster_tiles_without_contextily(monkeypatch: pytest.MonkeyPatch) -> None:
116
+ """Test if missing contextily is reported."""
117
+ monkeypatch.setitem(sys.modules, "contextily", None)
118
+
119
+ result = runner.invoke(app, ["--example", "monaco_buildings", "-t", "Esri.WorldImagery"])
120
+
121
+ assert result.exit_code == 2
122
+ # The lines are wrapped in a box and may be coloured.
123
+ output = Text.from_ansi(result.output).plain
124
+ assert "pip install contextily" in " ".join(output.replace("│", " ").split())
125
+
126
+
127
+ def test_misspelled_style() -> None:
128
+ """Test if a similar name of a style is suggested."""
129
+ result = runner.invoke(app, ["--example", "monaco_buildings", "-t", "OpenFreeMap.Positro"])
130
+
131
+ assert result.exit_code == 2
132
+ assert "OpenFreeMap.Positron" in result.output
133
+
134
+
135
+ def test_missing_style() -> None:
136
+ """Test if a missing file of a style is reported."""
137
+ result = runner.invoke(app, ["--example", "monaco_buildings", "-t", "missing.json"])
138
+
139
+ assert result.exit_code == 2
140
+ assert "missing.json" in result.output
141
+
142
+
143
+ def test_network_error(mocker: MockerFixture) -> None:
144
+ """Test if a style that cannot be downloaded is reported."""
145
+ mocker.patch(
146
+ "pixel_map.plotter.bml.add_basemap", side_effect=httpx.ConnectError("no connection")
147
+ )
148
+
149
+ result = runner.invoke(app, ["--example", "monaco_buildings"])
150
+
151
+ assert result.exit_code == 2
152
+ assert "no connection" in result.output
153
+
154
+
155
+ def test_raster_error(monkeypatch: pytest.MonkeyPatch, mocker: MockerFixture) -> None:
156
+ """Test if errors of contextily are reported."""
157
+ add_basemap = mocker.Mock(side_effect=ValueError("no overlap"))
158
+ monkeypatch.setitem(sys.modules, "contextily", SimpleNamespace(add_basemap=add_basemap))
159
+
160
+ result = runner.invoke(app, ["--example", "monaco_buildings", "-t", "raster.tif"])
161
+
162
+ assert result.exit_code == 2
163
+ assert "no overlap" in result.output
@@ -7,7 +7,7 @@ import pytest
7
7
  import typer
8
8
  from parametrization import Parametrization as P
9
9
 
10
- from pixel_map.__main__ import BboxParser
10
+ from pixel_map.__main__ import _parse_bbox
11
11
 
12
12
 
13
13
  @P.parameters("value", "expectation") # type: ignore
@@ -44,6 +44,6 @@ from pixel_map.__main__ import BboxParser
44
44
  def test_bbox_loading(value: str, expectation: Any) -> None:
45
45
  """Test if extracts finding by name works."""
46
46
  with expectation:
47
- bbox = BboxParser().convert(value) # type: ignore[no-untyped-call]
47
+ bbox = _parse_bbox(value)
48
48
  assert len(bbox) == 4
49
49
  assert all(isinstance(v, float) for v in bbox)
@@ -4,6 +4,7 @@ import uuid
4
4
 
5
5
  import pytest
6
6
  from parametrization import Parametrization as P
7
+ from rich.text import Text
7
8
  from typer.testing import CliRunner
8
9
 
9
10
  from pixel_map import __app_name__, __version__
@@ -36,6 +37,16 @@ def test_pbf_file_or_geometry_filter_is_required() -> None:
36
37
  assert "Missing argument" in result.output
37
38
 
38
39
 
40
+ def test_value_names_in_help() -> None:
41
+ """Test if names of the parsed values are in the help."""
42
+ result = runner.invoke(app, ["--help"], env={"COLUMNS": "200"})
43
+
44
+ assert result.exit_code == 0
45
+ lines = Text.from_ansi(result.output).plain.splitlines()
46
+ for option, name in (("--bbox", "BBOX"), ("--color", "COLOR"), ("--opacity", "FLOAT")):
47
+ assert any(option in line and name in line for line in lines)
48
+
49
+
39
50
  def test_basic_run() -> None:
40
51
  """Test if runs properly without options."""
41
52
  result = runner.invoke(app, ["--example", "monaco_buildings"])
@@ -7,6 +7,7 @@ from pixel_map.terminal_renderers import (
7
7
  _ASCII_CHARSET,
8
8
  AVAILABLE_RENDERERS,
9
9
  TerminalRenderer,
10
+ _braille_template,
10
11
  _get_charset,
11
12
  )
12
13
 
@@ -156,6 +157,25 @@ def test_braille_codepoints_round_trip() -> None:
156
157
  assert 0x2800 <= c <= 0x28FF
157
158
 
158
159
 
160
+ @pytest.mark.parametrize(
161
+ "character,rows",
162
+ [
163
+ ("⡇", ["#.", "#.", "#.", "#."]),
164
+ ("⢸", [".#", ".#", ".#", ".#"]),
165
+ ("⠉", ["##", "..", "..", ".."]),
166
+ ("⣀", ["..", "..", "..", "##"]),
167
+ ("⠈", [".#", "..", "..", ".."]),
168
+ ("⡀", ["..", "..", "..", "#."]),
169
+ ],
170
+ ) # type: ignore
171
+ def test_braille_template_follows_unicode_layout(character: str, rows: list[str]) -> None:
172
+ """Dots of a template are where the character has them."""
173
+ dots = np.array([[dot == "#" for dot in row] for row in rows])
174
+ np.testing.assert_array_equal(
175
+ _braille_template(ord(character)), dots.repeat(2, axis=0).repeat(4, axis=1)
176
+ )
177
+
178
+
159
179
  def test_monochrome_density_gradient() -> None:
160
180
  """Brighter cells should use denser braille glyphs than darker ones."""
161
181
  renderer = _make_renderer("braille-bw")
File without changes
File without changes