pixel-map 0.2.0__tar.gz → 0.2.3__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.
@@ -0,0 +1,235 @@
1
+ Metadata-Version: 2.1
2
+ Name: pixel-map
3
+ Version: 0.2.3
4
+ Summary: A Python CLI tool for plotting geo files in the terminal
5
+ Author-Email: Kamil Raczycki <kraczycki@kraina.ai>
6
+ License: MIT
7
+ Classifier: Development Status :: 3 - Alpha
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Topic :: Scientific/Engineering :: GIS
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Operating System :: Unix
18
+ Classifier: Operating System :: MacOS
19
+ Classifier: Operating System :: Microsoft :: Windows
20
+ Project-URL: Homepage, https://github.com/RaczeQ/pixel-map
21
+ Project-URL: Repository, https://github.com/RaczeQ/pixel-map
22
+ Project-URL: Changelog, https://github.com/RaczeQ/pixel-map/blob/main/CHANGELOG.md
23
+ Requires-Python: >=3.9
24
+ Requires-Dist: rich>=12.0.0
25
+ Requires-Dist: typer[all]>=0.9.0
26
+ Requires-Dist: img2unicode[n2]>=0.1a11; sys_platform != "win32" and sys_platform != "darwin"
27
+ Requires-Dist: img2unicode>=0.1a11; sys_platform == "win32" or sys_platform == "darwin"
28
+ Requires-Dist: geopandas>=0.8
29
+ Requires-Dist: numpy>=1.26.0
30
+ Requires-Dist: contextily>=1
31
+ Requires-Dist: matplotlib>=3.2.0
32
+ Requires-Dist: pyarrow>=16.0.0
33
+ Description-Content-Type: text/markdown
34
+
35
+ # pixel-map
36
+
37
+ Python CLI tool for plotting geo data in the terminal
38
+
39
+ <p align="center">
40
+ <img src="https://raw.githubusercontent.com/RaczeQ/pixel-map/main/images/pixel-map-monaco.jpg"><br/>
41
+ </p>
42
+
43
+ <p align="center">
44
+ <img alt="GitHub" src="https://img.shields.io/github/license/raczeq/pixel-map?logo=mit&logoColor=%23fff">
45
+ <img src="https://img.shields.io/github/checks-status/raczeq/pixel-map/main?logo=GitHubActions&logoColor=%23fff" alt="Checks">
46
+ <a href="https://github.com/raczeq/pixel-map/actions/workflows/ci-prod.yml" target="_blank">
47
+ <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">
48
+ </a>
49
+ <a href="https://results.pre-commit.ci/latest/github/raczeq/pixel-map/main" target="_blank">
50
+ <img src="https://results.pre-commit.ci/badge/github/raczeq/pixel-map/main.svg" alt="pre-commit.ci status">
51
+ </a>
52
+ <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>
53
+ <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>
54
+ <a href="https://pypi.org/project/pixel-map" target="_blank">
55
+ <img src="https://img.shields.io/pypi/v/pixel-map?color=%2334D058&label=pypi%20package&logo=pypi&logoColor=%23fff" alt="Package version">
56
+ </a>
57
+ <a href="https://pypi.org/project/pixel-map" target="_blank">
58
+ <img src="https://img.shields.io/pypi/pyversions/pixel-map.svg?color=%2334D058&logo=python&logoColor=%23fff" alt="Supported Python versions">
59
+ </a>
60
+ <a href="https://pypi.org/project/pixel-map" target="_blank">
61
+ <img alt="PyPI - Downloads" src="https://img.shields.io/pypi/dm/pixel-map">
62
+ </a>
63
+ </p>
64
+
65
+ ## Installation
66
+
67
+ PyPI:
68
+
69
+ ```sh
70
+ $ pip install pixel-map
71
+ ```
72
+
73
+ uv:
74
+
75
+ ```sh
76
+ $ uv pip install pixel-map
77
+ ```
78
+
79
+ ## Usage
80
+
81
+ To display your data in the terminal, you can just pass a filename as an argument:
82
+ ```sh
83
+ $ pixel-map <file_name>
84
+ ```
85
+
86
+ Tool can also display data for multiple files at once:
87
+ ```sh
88
+ $ pixel-map <file_name_1> <file_name_2>
89
+ ```
90
+
91
+ See more examples below ⬇️
92
+
93
+ <details>
94
+ <summary>CLI Help output (<code>pixel-map -h</code>)</summary>
95
+
96
+ ```console
97
+ Usage: pixel-map [OPTIONS] FILES...
98
+
99
+ Plot the geo data into a terminal.
100
+ Generates a Matplotlib canvas that is rendered to an image and later transformed into a list of
101
+ unicode characters.
102
+
103
+ ╭─ Arguments ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
104
+ │ * files FILES... List of files to display. Those could be any that can be opened by GeoPandas. [required] │
105
+ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
106
+ ╭─ Options ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
107
+ │ --bbox -b BBOX Clip the map to a given bounding box. Expects 4 floating point numbers separated by commas. │
108
+ │ --renderer -r TEXT Renderer used for generating terminal output. Possible values: all, ascii, ascii-bw, block, braille, braille-bw, half, quad, │
109
+ │ space. │
110
+ │ [default: (block)] │
111
+ │ --dark --light Uses the predefined dark or light style. Can be overriden with user defined style. [default: dark] │
112
+ │ --color -c COLOR Pass color or list of colours per each geo file. │
113
+ │ --alpha,--opacity -a FLOAT Pass opacity or list of opacities per each geo file. │
114
+ │ --basemap,--tileset -t TILES Set the basemap provider. Can be any value parsed by xyzservices library. Defaults to CartoDB.DarkMatterNoLabels if --dark │
115
+ │ or CartoDB.PositronNoLabels if --light. │
116
+ │ --no-border,--fullscreen -f Removes the border around the map. │
117
+ │ --no-background,--no-bg Removes the background of the map and plots only geo data. │
118
+ │ --background-color,--bg-color COLOR Set the background color. Can be used together with --no-background. │
119
+ │ --width INT Override the current console width. │
120
+ │ --height INT Override the current console height. │
121
+ │ --dpi INT DPI used to get better quality matplotlib plot before rendering to terminal. [default: 10] │
122
+ │ --example,--example-files Can be used to load one of example files based on name. Possible values: london_buildings, london_park, london_water, │
123
+ │ monaco_buildings. │
124
+ │ --version -v Show the application's version and exit. │
125
+ │ --install-completion Install completion for the current shell. │
126
+ │ --show-completion Show completion for the current shell, to copy it or customize the installation. │
127
+ │ --help -h Show this message and exit. │
128
+ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
129
+ ```
130
+ </details>
131
+
132
+ ## Examples
133
+
134
+ `pixel-map` is published with few example files for testing.
135
+
136
+ #### Basic usage
137
+
138
+ ```sh
139
+ $ pixel-map --example london_buildings
140
+ ```
141
+ <p align="center">
142
+ <img src="https://raw.githubusercontent.com/RaczeQ/pixel-map/main/images/london_dark.jpg"><br/>
143
+ </p>
144
+
145
+ #### Light mode
146
+
147
+ ```sh
148
+ $ pixel-map --example london_buildings --light
149
+ ```
150
+ <p align="center">
151
+ <img src="https://raw.githubusercontent.com/RaczeQ/pixel-map/main/images/london_light.jpg"><br/>
152
+ </p>
153
+
154
+ #### Multiple files with different colors
155
+
156
+ ```sh
157
+ $ pixel-map --example london_buildings london_water london_park -c C1,C0,C2
158
+ ```
159
+ <p align="center">
160
+ <img src="https://raw.githubusercontent.com/RaczeQ/pixel-map/main/images/london_multiple.jpg"><br/>
161
+ </p>
162
+
163
+ #### Different basemap and changed opacity (alpha)
164
+
165
+ ```sh
166
+ $ pixel-map --example london_water -c C0 -a 0.6 -t Esri.WorldImagery
167
+ ```
168
+ <p align="center">
169
+ <img src="https://raw.githubusercontent.com/RaczeQ/pixel-map/main/images/london_satellite.jpg"><br/>
170
+ </p>
171
+
172
+ #### No background and different renderer
173
+
174
+ You can explore multiple available renderers. Full list available in the `pixel-map` CLI help.
175
+
176
+ ```sh
177
+ $ pixel-map --example london_buildings --no-bg -r ascii-bw
178
+ ```
179
+ <p align="center">
180
+ <img src="https://raw.githubusercontent.com/RaczeQ/pixel-map/main/images/london_ascii.jpg"><br/>
181
+ </p>
182
+
183
+ ## Dependencies
184
+
185
+ - `typer[all] (>=0.9.0)` (click, colorama, rich, shellingham): Required for CLI
186
+
187
+ - `rich (>=12.0.0)`: For showing progress and generating terminal output
188
+
189
+ - `geopandas (>=0.8)`: For reading Geo files and plotting
190
+
191
+ - `pyarrow (>=16.0.0)`: For geoparquet files support
192
+
193
+ - `matplotlib (>=3.2.0)`: For generating the plot with styling and cropping
194
+
195
+ - `contextily (>=1)`: For adding basemap to the plot
196
+
197
+ - `numpy (>=1.26.0)`: For transforming matplotlib array into an image
198
+
199
+ - `img2unicode[n2] (>=0.1a11)`: For transforming generated plot image into a list of unicode characters for the terminal
200
+
201
+ ## How does it work?
202
+
203
+ 1. Files are read by `GeoPandas` to GeoSerieses.
204
+ 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).
205
+ 3. GeoSerieses are plotted to the canvas.
206
+ 4. Plot bounding box is expanded to the canvas ratio (based on terminal size).
207
+ 5. Basemap is loaded with `contextily`.
208
+ 6. Canvas is copied to the image as an `NumPy` array.
209
+ 7. `img2unicode` is used to render image using unicode characters with color.
210
+ 8. `Rich` string output is generated using the list of unicode characters with background and foreground colors.
211
+ 9. Output is printed to the console.
212
+
213
+ ## FAQ
214
+
215
+ - **Why does my terminal render visible characters in the output?**
216
+
217
+ Check if your terminal doesn't have automatic contrast changer for WCAG compatibility.
218
+
219
+ For example in VS Code there is an option `terminal.integrated.minimumContrastRatio` that is set to `4.5` by default.
220
+
221
+ | Contrast: 4.5 | Contrast: 1 |
222
+ | --- | --- |
223
+ | ![](https://raw.githubusercontent.com/RaczeQ/pixel-map/main/images/monaco_contrast.jpg) | ![](https://raw.githubusercontent.com/RaczeQ/pixel-map/main/images/monaco_contrast_low.jpg) |
224
+
225
+ - **Why are there black bars on the left/right, top/bottom of the output?**
226
+
227
+ This can happen when output is bigger than Earth bounding box and basemap doesn't cover that far, but image is stretched to the full terminal size.
228
+
229
+ ## Contributing
230
+
231
+ If you want to contribute, please fork the repository, use `pdm` tool to install the project.
232
+
233
+ To run the tests you can use command `tox -e python3.12` (or other python version, `-e` is for the environment) or with simple `pytest tests`.
234
+
235
+ Please remember to update `CHANGELOG.md` with description your changes.
@@ -0,0 +1,201 @@
1
+ # pixel-map
2
+
3
+ Python CLI tool for plotting geo data in the terminal
4
+
5
+ <p align="center">
6
+ <img src="https://raw.githubusercontent.com/RaczeQ/pixel-map/main/images/pixel-map-monaco.jpg"><br/>
7
+ </p>
8
+
9
+ <p align="center">
10
+ <img alt="GitHub" src="https://img.shields.io/github/license/raczeq/pixel-map?logo=mit&logoColor=%23fff">
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>
18
+ <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
+ <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>
29
+ </p>
30
+
31
+ ## Installation
32
+
33
+ PyPI:
34
+
35
+ ```sh
36
+ $ pip install pixel-map
37
+ ```
38
+
39
+ uv:
40
+
41
+ ```sh
42
+ $ uv pip install pixel-map
43
+ ```
44
+
45
+ ## Usage
46
+
47
+ To display your data in the terminal, you can just pass a filename as an argument:
48
+ ```sh
49
+ $ pixel-map <file_name>
50
+ ```
51
+
52
+ Tool can also display data for multiple files at once:
53
+ ```sh
54
+ $ pixel-map <file_name_1> <file_name_2>
55
+ ```
56
+
57
+ See more examples below ⬇️
58
+
59
+ <details>
60
+ <summary>CLI Help output (<code>pixel-map -h</code>)</summary>
61
+
62
+ ```console
63
+ Usage: pixel-map [OPTIONS] FILES...
64
+
65
+ Plot the geo data into a terminal.
66
+ Generates a Matplotlib canvas that is rendered to an image and later transformed into a list of
67
+ unicode characters.
68
+
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
+ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
95
+ ```
96
+ </details>
97
+
98
+ ## Examples
99
+
100
+ `pixel-map` is published with few example files for testing.
101
+
102
+ #### Basic usage
103
+
104
+ ```sh
105
+ $ pixel-map --example london_buildings
106
+ ```
107
+ <p align="center">
108
+ <img src="https://raw.githubusercontent.com/RaczeQ/pixel-map/main/images/london_dark.jpg"><br/>
109
+ </p>
110
+
111
+ #### Light mode
112
+
113
+ ```sh
114
+ $ pixel-map --example london_buildings --light
115
+ ```
116
+ <p align="center">
117
+ <img src="https://raw.githubusercontent.com/RaczeQ/pixel-map/main/images/london_light.jpg"><br/>
118
+ </p>
119
+
120
+ #### Multiple files with different colors
121
+
122
+ ```sh
123
+ $ pixel-map --example london_buildings london_water london_park -c C1,C0,C2
124
+ ```
125
+ <p align="center">
126
+ <img src="https://raw.githubusercontent.com/RaczeQ/pixel-map/main/images/london_multiple.jpg"><br/>
127
+ </p>
128
+
129
+ #### Different basemap and changed opacity (alpha)
130
+
131
+ ```sh
132
+ $ pixel-map --example london_water -c C0 -a 0.6 -t Esri.WorldImagery
133
+ ```
134
+ <p align="center">
135
+ <img src="https://raw.githubusercontent.com/RaczeQ/pixel-map/main/images/london_satellite.jpg"><br/>
136
+ </p>
137
+
138
+ #### No background and different renderer
139
+
140
+ You can explore multiple available renderers. Full list available in the `pixel-map` CLI help.
141
+
142
+ ```sh
143
+ $ pixel-map --example london_buildings --no-bg -r ascii-bw
144
+ ```
145
+ <p align="center">
146
+ <img src="https://raw.githubusercontent.com/RaczeQ/pixel-map/main/images/london_ascii.jpg"><br/>
147
+ </p>
148
+
149
+ ## Dependencies
150
+
151
+ - `typer[all] (>=0.9.0)` (click, colorama, rich, shellingham): Required for CLI
152
+
153
+ - `rich (>=12.0.0)`: For showing progress and generating terminal output
154
+
155
+ - `geopandas (>=0.8)`: For reading Geo files and plotting
156
+
157
+ - `pyarrow (>=16.0.0)`: For geoparquet files support
158
+
159
+ - `matplotlib (>=3.2.0)`: For generating the plot with styling and cropping
160
+
161
+ - `contextily (>=1)`: For adding basemap to the plot
162
+
163
+ - `numpy (>=1.26.0)`: For transforming matplotlib array into an image
164
+
165
+ - `img2unicode[n2] (>=0.1a11)`: For transforming generated plot image into a list of unicode characters for the terminal
166
+
167
+ ## How does it work?
168
+
169
+ 1. Files are read by `GeoPandas` to GeoSerieses.
170
+ 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
+ 3. GeoSerieses are plotted to the canvas.
172
+ 4. Plot bounding box is expanded to the canvas ratio (based on terminal size).
173
+ 5. Basemap is loaded with `contextily`.
174
+ 6. Canvas is copied to the image as an `NumPy` array.
175
+ 7. `img2unicode` is used to render image using unicode characters with color.
176
+ 8. `Rich` string output is generated using the list of unicode characters with background and foreground colors.
177
+ 9. Output is printed to the console.
178
+
179
+ ## FAQ
180
+
181
+ - **Why does my terminal render visible characters in the output?**
182
+
183
+ Check if your terminal doesn't have automatic contrast changer for WCAG compatibility.
184
+
185
+ For example in VS Code there is an option `terminal.integrated.minimumContrastRatio` that is set to `4.5` by default.
186
+
187
+ | Contrast: 4.5 | Contrast: 1 |
188
+ | --- | --- |
189
+ | ![](https://raw.githubusercontent.com/RaczeQ/pixel-map/main/images/monaco_contrast.jpg) | ![](https://raw.githubusercontent.com/RaczeQ/pixel-map/main/images/monaco_contrast_low.jpg) |
190
+
191
+ - **Why are there black bars on the left/right, top/bottom of the output?**
192
+
193
+ This can happen when output is bigger than Earth bounding box and basemap doesn't cover that far, but image is stretched to the full terminal size.
194
+
195
+ ## Contributing
196
+
197
+ If you want to contribute, please fork the repository, use `pdm` tool to install the project.
198
+
199
+ To run the tests you can use command `tox -e python3.12` (or other python version, `-e` is for the environment) or with simple `pytest tests`.
200
+
201
+ Please remember to update `CHANGELOG.md` with description your changes.
@@ -1,4 +1,4 @@
1
1
  """Pixel-map library."""
2
2
 
3
3
  __app_name__ = "pixel-map"
4
- __version__ = "0.2.0"
4
+ __version__ = "0.2.3"
@@ -21,16 +21,7 @@ example_files_help_string = ", ".join(
21
21
  app = typer.Typer(context_settings={"help_option_names": ["-h", "--help"]}, rich_markup_mode="rich")
22
22
 
23
23
  # TODO:
24
- # - add option to select colours (pass list - must match number of files)
25
24
  # - 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
25
 
35
26
 
36
27
  def _version_callback(value: bool) -> None:
@@ -200,6 +191,33 @@ def plot(
200
191
  show_default=False,
201
192
  ),
202
193
  ] = None,
194
+ console_width: Annotated[
195
+ Optional[int],
196
+ typer.Option(
197
+ "--width",
198
+ metavar="INT",
199
+ help=("Override the current console width."),
200
+ show_default=False,
201
+ ),
202
+ ] = None,
203
+ console_height: Annotated[
204
+ Optional[int],
205
+ typer.Option(
206
+ "--height",
207
+ metavar="INT",
208
+ help=("Override the current console height."),
209
+ show_default=False,
210
+ ),
211
+ ] = None,
212
+ plotting_dpi: Annotated[
213
+ int,
214
+ typer.Option(
215
+ "--dpi",
216
+ metavar="INT",
217
+ help=("DPI used to get better quality matplotlib plot before rendering to terminal."),
218
+ show_default=True,
219
+ ),
220
+ ] = 10,
203
221
  example_files: Annotated[
204
222
  bool,
205
223
  typer.Option(
@@ -262,11 +280,16 @@ def plot(
262
280
  if not basemap_provider:
263
281
  basemap_provider = provider
264
282
 
265
- parsed_colors: Optional[list[str]] = colors # type: ignore[assignment]
283
+ background_color = background_color or ("black" if is_dark_style else "white")
284
+
285
+ if no_background:
286
+ basemap_provider = None
287
+
288
+ parsed_colors: Optional[list[str]] = colors # type: ignore[assignment]
266
289
  if not parsed_colors:
267
290
  parsed_colors = [color]
268
291
 
269
- parsed_alphas: Optional[list[float]] = alphas # type: ignore[assignment]
292
+ parsed_alphas: Optional[list[float]] = alphas # type: ignore[assignment]
270
293
  if not parsed_alphas:
271
294
  parsed_alphas = [1]
272
295
 
@@ -280,10 +303,6 @@ def plot(
280
303
  f"Number of alphas ({len(parsed_alphas)}) and geo files ({len(files)}) doesn't match."
281
304
  ) from None
282
305
 
283
- if no_background:
284
- basemap_provider = None
285
- background_color = background_color or ("black" if is_dark_style else "white")
286
-
287
306
  with warnings.catch_warnings():
288
307
  warnings.filterwarnings("ignore")
289
308
  plot_geo_data(
@@ -295,6 +314,9 @@ def plot(
295
314
  basemap_provider=basemap_provider,
296
315
  background_color=background_color or "black",
297
316
  no_border=no_border,
317
+ console_width=console_width,
318
+ console_height=console_height,
319
+ plotting_dpi=plotting_dpi,
298
320
  )
299
321
 
300
322
 
@@ -5,6 +5,7 @@ Generates a Matplotlib canvas that is rendered to an image and later transformed
5
5
  unicode characters.
6
6
  """
7
7
 
8
+ import os
8
9
  from pathlib import Path
9
10
  from typing import Any, Optional, Union
10
11
 
@@ -18,6 +19,7 @@ from pyproj.enums import TransformDirection
18
19
  from rich import get_console
19
20
  from rich.box import HEAVY
20
21
  from rich.color import Color
22
+ from rich.console import Console
21
23
  from rich.panel import Panel
22
24
  from rich.progress import Progress, SpinnerColumn, TextColumn
23
25
  from rich.style import Style
@@ -27,6 +29,8 @@ from pixel_map.renderers import AVAILABLE_RENDERERS
27
29
 
28
30
  TRANSFORMER = Transformer.from_crs("EPSG:4326", "EPSG:3857", always_xy=True)
29
31
 
32
+ EPSG_3857_BOUNDS = (-20037508.34, -20048966.1, 20037508.34, 20048966.1)
33
+
30
34
 
31
35
  def plot_geo_data(
32
36
  files: list[str],
@@ -37,6 +41,9 @@ def plot_geo_data(
37
41
  basemap_provider: Optional[str] = None,
38
42
  background_color: Optional[str] = None,
39
43
  no_border: bool = False,
44
+ console_width: Optional[int] = None,
45
+ console_height: Optional[int] = None,
46
+ plotting_dpi: int = 10,
40
47
  ) -> None:
41
48
  """
42
49
  Plot the geo data into a terminal.
@@ -59,8 +66,24 @@ def plot_geo_data(
59
66
  background_color (str, optional): Background color. Used then basemap_provider is None.
60
67
  Defaults to None.
61
68
  no_border (bool, optional): Removes the border around the map. Defaults to False.
69
+ console_width (int, optional): Console width. Can be used to set arbitrary value.
70
+ Defaults to None.
71
+ console_height (int, optional): Console height. Can be used to set arbitrary value.
72
+ Defaults to None.
73
+ 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.
62
75
  """
63
- console = get_console()
76
+ force_terminal = os.getenv("FORCE_TERMINAL_MODE", "false").lower() == "true"
77
+ if force_terminal:
78
+ console = Console(force_interactive=False, force_jupyter=False, force_terminal=True)
79
+ else:
80
+ console = get_console()
81
+
82
+ if console_width:
83
+ console.width = console_width
84
+
85
+ if console_height:
86
+ console.height = console_height
64
87
 
65
88
  if no_border:
66
89
  terminal_width = console.width
@@ -74,36 +97,26 @@ def plot_geo_data(
74
97
 
75
98
  map_ratio = map_width / map_height
76
99
 
77
- with Progress(
78
- SpinnerColumn(),
79
- TextColumn("[progress.description]{task.description}"),
80
- transient=True,
81
- console=console,
82
- ) as progress:
100
+ with _get_progress_object(console) as progress:
83
101
  progress.add_task("Calculating bounding box", total=None)
84
102
  bbox_axes_bounds = None
85
103
  if bbox:
86
104
  bbox, bbox_axes_bounds = _expand_bbox_to_match_ratio(bbox, ratio=map_ratio)
87
105
 
88
- with Progress(
89
- SpinnerColumn(),
90
- TextColumn("[progress.description]{task.description}"),
91
- transient=True,
92
- console=console,
93
- ) as progress:
106
+ with _get_progress_object(console) as progress:
94
107
  progress.add_task("Loading Geo data", total=None)
95
108
  gdfs = _load_geo_data(files, bbox=bbox)
96
109
  if bbox:
97
110
  gdfs = [gdf.clip_by_rect(*bbox) for gdf in gdfs]
98
111
 
99
- with Progress(
100
- SpinnerColumn(),
101
- TextColumn("[progress.description]{task.description}"),
102
- transient=True,
103
- console=console,
104
- ) as progress:
112
+ with _get_progress_object(console) as progress:
105
113
  progress.add_task("Plotting geo data", total=None)
106
- f, ax = plt.subplots(figsize=(map_width, map_height), dpi=10)
114
+ f, ax = plt.subplots(figsize=(map_width, map_height), dpi=plotting_dpi)
115
+
116
+ ax.set_axis_off()
117
+ ax.set_xticks([])
118
+ ax.set_yticks([])
119
+
107
120
  f.patch.set_facecolor(background_color)
108
121
  canvas = f.canvas
109
122
  # gdf.to_crs(3857).plot(ax=ax, alpha=0.4)
@@ -115,7 +128,6 @@ def plot_geo_data(
115
128
  plot_color = color[idx % len(color)]
116
129
  plot_alpha = alpha[idx % len(alpha)]
117
130
  gdf.to_crs(3857).plot(ax=ax, color=plot_color, alpha=plot_alpha)
118
- ax.axis("off")
119
131
 
120
132
  if bbox_axes_bounds:
121
133
  left, bottom, right, top = bbox_axes_bounds
@@ -125,24 +137,29 @@ def plot_geo_data(
125
137
  left, bottom, right, top = _expand_axes_limit_to_match_ratio(ax, ratio=map_ratio)
126
138
 
127
139
  if basemap_provider:
128
- cx.add_basemap(
129
- ax,
130
- source=basemap_provider,
131
- crs=3857,
132
- attribution=False,
133
- )
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
+ )
134
155
 
135
156
  ax.set_position((0, 0, 1, 1))
136
157
  canvas.draw()
158
+
137
159
  image_flat = np.frombuffer(canvas.tostring_rgb(), dtype="uint8") # (H * W * 3,)
138
160
  image = image_flat.reshape(*reversed(canvas.get_width_height()), 3)
139
161
 
140
- with Progress(
141
- SpinnerColumn(),
142
- TextColumn("[progress.description]{task.description}"),
143
- transient=True,
144
- console=console,
145
- ) as progress:
162
+ with _get_progress_object(console) as progress:
146
163
  progress.add_task("Rendering geo data", total=None)
147
164
  renderer_object = AVAILABLE_RENDERERS[renderer](
148
165
  terminal_width=terminal_width, terminal_height=terminal_height
@@ -248,13 +265,19 @@ def _expand_axes_limit_to_match_ratio(ax: Axes, ratio: float) -> tuple[float, fl
248
265
  width_padding = (new_width - width) / 2
249
266
  left = left - width_padding
250
267
  right = right + width_padding
251
- ax.set_xlim([left, right])
252
268
  else:
253
269
  new_height = (current_ratio / ratio) * height
254
270
  height_padding = (new_height - height) / 2
255
271
  bottom = bottom - height_padding
256
272
  top = top + height_padding
257
- ax.set_ylim([bottom, top])
273
+
274
+ left = max(left, EPSG_3857_BOUNDS[0])
275
+ bottom = max(bottom, EPSG_3857_BOUNDS[1])
276
+ right = min(right, EPSG_3857_BOUNDS[2])
277
+ top = min(top, EPSG_3857_BOUNDS[3])
278
+
279
+ ax.set_xlim([left, right])
280
+ ax.set_ylim([bottom, top])
258
281
 
259
282
  return left, bottom, right, top
260
283
 
@@ -322,5 +345,14 @@ def _generate_panel_subtitle(
322
345
  return subtitle
323
346
  elif len(bbox_str) <= (terminal_width - 4):
324
347
  return bbox_str
325
- else:
326
- return ""
348
+
349
+ return ""
350
+
351
+
352
+ def _get_progress_object(console: Console) -> Progress:
353
+ return Progress(
354
+ SpinnerColumn(),
355
+ TextColumn("[progress.description]{task.description}"),
356
+ transient=True,
357
+ console=console,
358
+ )
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pixel-map"
3
- version = "0.2.0"
3
+ version = "0.2.3"
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" },
@@ -10,7 +10,7 @@ dependencies = [
10
10
  "typer[all]>=0.9.0",
11
11
  "img2unicode[n2]>=0.1a11; sys_platform != 'win32' and sys_platform != 'darwin'",
12
12
  "img2unicode>=0.1a11; sys_platform == 'win32' or sys_platform == 'darwin'",
13
- "geopandas>=0.6",
13
+ "geopandas>=0.8",
14
14
  "numpy>=1.26.0",
15
15
  "contextily>=1",
16
16
  "matplotlib>=3.2.0",
@@ -18,10 +18,30 @@ dependencies = [
18
18
  ]
19
19
  requires-python = ">=3.9"
20
20
  readme = "README.md"
21
+ classifiers = [
22
+ "Development Status :: 3 - Alpha",
23
+ "License :: OSI Approved :: MIT License",
24
+ "Topic :: Scientific/Engineering :: GIS",
25
+ "Intended Audience :: Science/Research",
26
+ "Intended Audience :: Developers",
27
+ "Programming Language :: Python :: 3",
28
+ "Programming Language :: Python :: 3.9",
29
+ "Programming Language :: Python :: 3.10",
30
+ "Programming Language :: Python :: 3.11",
31
+ "Programming Language :: Python :: 3.12",
32
+ "Operating System :: Unix",
33
+ "Operating System :: MacOS",
34
+ "Operating System :: Microsoft :: Windows",
35
+ ]
21
36
 
22
37
  [project.license]
23
38
  text = "MIT"
24
39
 
40
+ [project.urls]
41
+ Homepage = "https://github.com/RaczeQ/pixel-map"
42
+ Repository = "https://github.com/RaczeQ/pixel-map"
43
+ Changelog = "https://github.com/RaczeQ/pixel-map/blob/main/CHANGELOG.md"
44
+
25
45
  [project.scripts]
26
46
  pixel-map = "pixel_map.__main__:main"
27
47
 
@@ -129,7 +149,7 @@ close-quotes-on-newline = true
129
149
  wrap-one-line = true
130
150
 
131
151
  [tool.bumpver]
132
- current_version = "0.2.0"
152
+ current_version = "0.2.3"
133
153
  version_pattern = "MAJOR.MINOR.PATCH[PYTAGNUM]"
134
154
  commit_message = "chore(CI/CD): bump version {old_version} -> {new_version}"
135
155
  commit = true
@@ -0,0 +1 @@
1
+ """Tests for the pixel-map library."""
@@ -0,0 +1,119 @@
1
+ """Tests for CLI."""
2
+
3
+ import uuid
4
+
5
+ import pytest
6
+ from parametrization import Parametrization as P
7
+ from typer.testing import CliRunner
8
+
9
+ from pixel_map import __app_name__, __version__
10
+ from pixel_map.__main__ import app
11
+ from pixel_map.renderers import AVAILABLE_RENDERERS
12
+
13
+ runner = CliRunner()
14
+
15
+
16
+ def random_str() -> str:
17
+ """Return random string."""
18
+ return str(uuid.uuid4())
19
+
20
+
21
+ def test_version() -> None:
22
+ """Test if version is properly returned."""
23
+ result = runner.invoke(app, ["--version"])
24
+
25
+ assert result.exit_code == 0
26
+ assert f"{__app_name__} {__version__}\n" in result.stdout
27
+
28
+
29
+ def test_pbf_file_or_geometry_filter_is_required() -> None:
30
+ """Test if cannot run without pbf file and without geometry filter."""
31
+ result = runner.invoke(
32
+ app,
33
+ )
34
+
35
+ assert result.exit_code == 2
36
+ assert "Missing argument 'FILES...'." in result.stdout
37
+
38
+
39
+ def test_basic_run() -> None:
40
+ """Test if runs properly without options."""
41
+ result = runner.invoke(app, ["--example", "monaco_buildings"])
42
+ print(result.stdout)
43
+
44
+ assert result.exit_code == 0
45
+ assert "monaco_buildings.parquet" in result.stdout
46
+
47
+
48
+ @P.parameters("args") # type: ignore
49
+ @P.case("Dark mode", ["--dark"]) # type: ignore
50
+ @P.case("Light mode", ["--light"]) # type: ignore
51
+ @P.case("Bounding box short", ["-b", "7.41855,43.73259,7.42227,43.73528"]) # type: ignore
52
+ @P.case("Bounding box long", ["--bbox", "7.41855, 43.73259, 7.42227, 43.73528"]) # type: ignore
53
+ @P.case("Renderer short", ["-r", "ascii"]) # type: ignore
54
+ @P.case("Renderer long", ["--renderer", "ascii"]) # type: ignore
55
+ @P.case("Color short", ["-c", "green"]) # type: ignore
56
+ @P.case("Color long", ["--color", "red"]) # type: ignore
57
+ @P.case("Color multiple", ["london_buildings", "-c", "C0"]) # type: ignore
58
+ @P.case("Color multiple 2", ["london_buildings", "-c", "C0,C1"]) # type: ignore
59
+ @P.case("Opacity short", ["-a", "0.8"]) # type: ignore
60
+ @P.case("Opacity long", ["--alpha", "0.6"]) # type: ignore
61
+ @P.case("Opacity long 2", ["--opacity", "0.3"]) # type: ignore
62
+ @P.case("Opacity multiple", ["london_buildings", "-a", "0"]) # type: ignore
63
+ @P.case("Opacity multiple 2", ["london_buildings", "-a", "0,1"]) # type: ignore
64
+ @P.case("Tileset short", ["-t", "CartoDB.DarkMatterNoLabels"]) # type: ignore
65
+ @P.case("Tileset long", ["--tileset", "CartoDB.DarkMatterNoLabels"]) # type: ignore
66
+ @P.case("Tileset long 2", ["--basemap", "CartoDB.DarkMatterNoLabels"]) # type: ignore
67
+ @P.case("No border short", ["-f"]) # type: ignore
68
+ @P.case("No border long", ["--fullscreen"]) # type: ignore
69
+ @P.case("No border long 2", ["--no-border"]) # type: ignore
70
+ @P.case("No background", ["--no-bg"]) # type: ignore
71
+ @P.case("No background 2", ["--no-background"]) # type: ignore
72
+ @P.case("Background color", ["--bg-color", "white"]) # type: ignore
73
+ @P.case("Background color 2", ["--background-color", "black"]) # type: ignore
74
+ @P.case("Console width", ["--width", "10"]) # type: ignore
75
+ @P.case("Console height", ["--height", "10"]) # type: ignore
76
+ @P.case("Console width and height", ["--width", "10", "--height", "10"]) # type: ignore
77
+ @P.case("Plotting dpi small", ["--dpi", "1"]) # type: ignore
78
+ @P.case("Plotting dpi big", ["--dpi", "100"]) # type: ignore
79
+ def test_proper_args(args: list[str]) -> None:
80
+ """Test if runs properly with options."""
81
+ result = runner.invoke(app, ["--example", "monaco_buildings", *args])
82
+ print(result.stdout)
83
+
84
+ assert result.exit_code == 0
85
+
86
+
87
+ @pytest.mark.parametrize(
88
+ "renderer",
89
+ AVAILABLE_RENDERERS.keys(),
90
+ ) # type: ignore
91
+ def test_renderers(renderer: str) -> None:
92
+ """Test if all renderers are working."""
93
+ result = runner.invoke(app, ["--example", "monaco_buildings", "-r", renderer])
94
+ print(result.stdout)
95
+
96
+ assert result.exit_code == 0
97
+
98
+
99
+ @P.parameters("args") # type: ignore
100
+ @P.case(
101
+ "Random file",
102
+ [random_str()],
103
+ ) # type: ignore
104
+ @P.case("Short bounding box", ["-b", "7.41855,43.73259,7.42227,"]) # type: ignore
105
+ @P.case("Long bounding box", ["-b", "7.41855,43.73259,7.42227,43.73528,7.42227"]) # type: ignore
106
+ @P.case("Wrong renderer", ["-r", random_str()]) # type: ignore
107
+ @P.case("Wrong tileset", ["-t", random_str()]) # type: ignore
108
+ @P.case("Wrong color", ["-c", random_str()]) # type: ignore
109
+ @P.case("Wrong opacity", ["-a", random_str()]) # type: ignore
110
+ @P.case("Wrong background color", ["--bg-color", random_str()]) # type: ignore
111
+ @P.case("Wrong number of colors", ["london_buildings", "-c", "C0,C1,C2"]) # type: ignore
112
+ @P.case("Wrong plotting dpi", ["--dpi", random_str()]) # type: ignore
113
+ def test_wrong_args(args: list[str], capsys: pytest.CaptureFixture) -> None:
114
+ """Test if doesn't run properly with options."""
115
+ # Fix for the I/O error from the Click repository
116
+ # https://github.com/pallets/click/issues/824#issuecomment-1583293065
117
+ with capsys.disabled():
118
+ result = runner.invoke(app, ["--example", "monaco_buildings", *args])
119
+ assert result.exit_code != 0
pixel_map-0.2.0/PKG-INFO DELETED
@@ -1,19 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: pixel-map
3
- Version: 0.2.0
4
- Summary: A Python CLI tool for plotting geo files in the terminal
5
- Author-Email: Kamil Raczycki <kraczycki@kraina.ai>
6
- License: MIT
7
- Requires-Python: >=3.9
8
- Requires-Dist: rich>=12.0.0
9
- Requires-Dist: typer[all]>=0.9.0
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
- Requires-Dist: geopandas>=0.6
13
- Requires-Dist: numpy>=1.26.0
14
- Requires-Dist: contextily>=1
15
- Requires-Dist: matplotlib>=3.2.0
16
- Requires-Dist: pyarrow>=16.0.0
17
- Description-Content-Type: text/markdown
18
-
19
- # pixel-map
pixel_map-0.2.0/README.md DELETED
@@ -1 +0,0 @@
1
- # pixel-map
File without changes
File without changes
File without changes