sphericolor 0.1.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.

Potentially problematic release.


This version of sphericolor might be problematic. Click here for more details.

Files changed (30) hide show
  1. sphericolor-0.1.0/.gitignore +11 -0
  2. sphericolor-0.1.0/CHANGELOG.md +8 -0
  3. sphericolor-0.1.0/CITATION.cff +36 -0
  4. sphericolor-0.1.0/LICENSE +22 -0
  5. sphericolor-0.1.0/PKG-INFO +150 -0
  6. sphericolor-0.1.0/README.md +97 -0
  7. sphericolor-0.1.0/docs/teaser.png +0 -0
  8. sphericolor-0.1.0/pyproject.toml +76 -0
  9. sphericolor-0.1.0/src/sphericolor/__init__.py +8 -0
  10. sphericolor-0.1.0/src/sphericolor/api.py +154 -0
  11. sphericolor-0.1.0/src/sphericolor/colors.py +47 -0
  12. sphericolor-0.1.0/src/sphericolor/data/__init__.py +0 -0
  13. sphericolor-0.1.0/src/sphericolor/data/srgb_cam16ucs.ply +6443 -0
  14. sphericolor-0.1.0/src/sphericolor/diagnostics.py +24 -0
  15. sphericolor-0.1.0/src/sphericolor/distances.py +24 -0
  16. sphericolor-0.1.0/src/sphericolor/embedding.py +31 -0
  17. sphericolor-0.1.0/src/sphericolor/gamut.py +42 -0
  18. sphericolor-0.1.0/src/sphericolor/methods/__init__.py +0 -0
  19. sphericolor-0.1.0/src/sphericolor/methods/bivariate.py +38 -0
  20. sphericolor-0.1.0/src/sphericolor/methods/hsluv.py +18 -0
  21. sphericolor-0.1.0/src/sphericolor/methods/ray.py +51 -0
  22. sphericolor-0.1.0/src/sphericolor/methods/simplex.py +89 -0
  23. sphericolor-0.1.0/src/sphericolor/result.py +50 -0
  24. sphericolor-0.1.0/src/sphericolor/validation.py +108 -0
  25. sphericolor-0.1.0/tests/test_baselines.py +43 -0
  26. sphericolor-0.1.0/tests/test_distances.py +16 -0
  27. sphericolor-0.1.0/tests/test_package.py +18 -0
  28. sphericolor-0.1.0/tests/test_ray.py +48 -0
  29. sphericolor-0.1.0/tests/test_simplex.py +32 -0
  30. sphericolor-0.1.0/tests/test_validation.py +54 -0
@@ -0,0 +1,11 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ .coverage
5
+ .mypy_cache/
6
+ .pytest_cache/
7
+ .ruff_cache/
8
+ .venv/
9
+ build/
10
+ dist/
11
+
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ - Initial Python package.
6
+ - Add Ray, Simplex, HSLuv, and six bivariate mappings.
7
+ - Add latitude-longitude and distance-matrix APIs.
8
+
@@ -0,0 +1,36 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use SpheriColor in academic work, please cite the associated paper."
3
+ title: "SpheriColor"
4
+ type: software
5
+ version: 0.1.0
6
+ date-released: 2026-11-11
7
+ license: MIT
8
+ authors:
9
+ - family-names: Rauscher
10
+ given-names: Julius
11
+ orcid: "https://orcid.org/0000-0003-1318-9642"
12
+ - family-names: Fuchs
13
+ given-names: Johannes
14
+ - family-names: Keim
15
+ given-names: Daniel A.
16
+ orcid: "https://orcid.org/0000-0001-7966-9740"
17
+ - family-names: Dennig
18
+ given-names: Frederik L.
19
+ orcid: "https://orcid.org/0000-0003-1116-8450"
20
+ preferred-citation:
21
+ type: conference-paper
22
+ title: "SpheriColor: Colormaps for Spherical Geospatial Input Topographies"
23
+ authors:
24
+ - family-names: Rauscher
25
+ given-names: Julius
26
+ orcid: "https://orcid.org/0000-0003-1318-9642"
27
+ - family-names: Fuchs
28
+ given-names: Johannes
29
+ - family-names: Keim
30
+ given-names: Daniel A.
31
+ orcid: "https://orcid.org/0000-0001-7966-9740"
32
+ - family-names: Dennig
33
+ given-names: Frederik L.
34
+ orcid: "https://orcid.org/0000-0003-1116-8450"
35
+ collection-title: "EuroVis 2026 Short Papers"
36
+ year: 2026
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 University of Konstanz and the SpheriColor authors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,150 @@
1
+ Metadata-Version: 2.5
2
+ Name: sphericolor
3
+ Version: 0.1.0
4
+ Summary: Dataset-specific color mappings for spherical geographic data
5
+ Project-URL: Repository, https://github.com/dbvis-ukon/sphericolor
6
+ Author: Julius Rauscher, Johannes Fuchs, Daniel A. Keim, Frederik L. Dennig
7
+ License: MIT License
8
+
9
+ Copyright (c) 2026 University of Konstanz and the SpheriColor authors
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+
29
+ License-File: LICENSE
30
+ Keywords: CAM16-UCS,colormap,geospatial,visualization
31
+ Classifier: Development Status :: 3 - Alpha
32
+ Classifier: License :: OSI Approved :: MIT License
33
+ Classifier: Programming Language :: Python :: 3
34
+ Classifier: Programming Language :: Python :: 3.10
35
+ Classifier: Programming Language :: Python :: 3.11
36
+ Classifier: Programming Language :: Python :: 3.12
37
+ Classifier: Programming Language :: Python :: 3.13
38
+ Classifier: Topic :: Scientific/Engineering :: Visualization
39
+ Requires-Python: <3.14,>=3.10
40
+ Requires-Dist: coloraide>=3.3
41
+ Requires-Dist: hsluv>=5
42
+ Requires-Dist: numpy>=1.24
43
+ Requires-Dist: pycolormap-2d>=1.1.7
44
+ Requires-Dist: scikit-learn>=1.4
45
+ Requires-Dist: scipy>=1.10
46
+ Provides-Extra: build
47
+ Requires-Dist: build>=1.2; extra == 'build'
48
+ Provides-Extra: test
49
+ Requires-Dist: mypy>=1.10; extra == 'test'
50
+ Requires-Dist: pytest>=8; extra == 'test'
51
+ Requires-Dist: ruff>=0.6; extra == 'test'
52
+ Description-Content-Type: text/markdown
53
+
54
+ # SpheriColor
55
+
56
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
57
+
58
+ SpheriColor generates dataset-specific colors for spherical geographic references. It maps
59
+ geographic or custom pairwise distances into CAM16-UCS and the displayable sRGB gamut.
60
+
61
+ ![Comparison of SpheriColor and baseline colormap methods](docs/teaser.png)
62
+
63
+ ## Installation
64
+
65
+ ```bash
66
+ pip install sphericolor
67
+ ```
68
+
69
+ SpheriColor supports Python 3.10 through 3.13. It needs no Rust compiler or Numba installation.
70
+
71
+ ## Geographic coordinates
72
+
73
+ ```python
74
+ from sphericolor import from_latlon
75
+
76
+ mapping = from_latlon(
77
+ latitudes=[52.52, 48.86, 41.90, 40.42],
78
+ longitudes=[13.40, 2.35, 12.50, -3.70],
79
+ labels=["Berlin", "Paris", "Rome", "Madrid"],
80
+ method="ray",
81
+ )
82
+
83
+ print(dict(zip(mapping.labels, mapping.hex)))
84
+ ```
85
+
86
+ Coordinate input uses great-circle distances in kilometers for Ray and Simplex.
87
+
88
+ ## Precomputed distances
89
+
90
+ ```python
91
+ import numpy as np
92
+ from sphericolor import from_distance_matrix
93
+
94
+ distances = np.array([
95
+ [0.0, 1.0, 2.0, 1.0],
96
+ [1.0, 0.0, 1.0, 2.0],
97
+ [2.0, 1.0, 0.0, 1.0],
98
+ [1.0, 2.0, 1.0, 0.0],
99
+ ])
100
+ mapping = from_distance_matrix(distances, method="simplex")
101
+ ```
102
+
103
+ Distance-matrix input supports Ray and Simplex. HSLuv and bivariate mappings require geographic
104
+ coordinates because they use latitude and longitude orientation directly.
105
+
106
+ ## Methods
107
+
108
+ ```python
109
+ ray = from_latlon(latitudes, longitudes, method="ray")
110
+ simplex = from_latlon(latitudes, longitudes, method="simplex")
111
+ hsluv = from_latlon(latitudes, longitudes, method="hsluv")
112
+ bivariate = from_latlon(
113
+ latitudes,
114
+ longitudes,
115
+ method="bivariate",
116
+ bivariate_map="steiger",
117
+ )
118
+ ```
119
+
120
+ Available bivariate maps are `bremm`, `cube_diagonal`, `schumann`, `steiger`, `teuling2`, and
121
+ `ziegler`.
122
+
123
+ Set `diagnostics=True` to include condensed input and output distances plus intermediate MDS
124
+ embeddings. Diagnostics require quadratic memory and are disabled by default.
125
+
126
+ ### Stability
127
+
128
+ Ray and Simplex derive their colors from an MDS embedding of the complete input set. Because MDS
129
+ is sensitive to the point configuration, changing the entity set may produce a different color
130
+ mapping. HSLuv and the bivariate methods provide dataset-independent alternatives when consistent
131
+ colors across datasets are needed.
132
+
133
+ ## License and citation
134
+
135
+ SpheriColor and its bundled gamut asset are MIT licensed. If you use SpheriColor in academic
136
+ work, please cite the associated paper:
137
+
138
+ > Julius Rauscher, Johannes Fuchs, Daniel A. Keim, and Frederik L. Dennig. “SpheriColor:
139
+ > Colormaps for Spherical Geospatial Input Topographies.” EuroVis 2026 Short Papers, 2026.
140
+
141
+ ```bibtex
142
+ @inproceedings{rauscher2026sphericolor,
143
+ title = {{SpheriColor}: Colormaps for Spherical Geospatial Input Topographies},
144
+ author = {Rauscher, Julius and Fuchs, Johannes and Keim, Daniel A. and Dennig, Frederik L.},
145
+ booktitle = {EuroVis 2026 Short Papers},
146
+ year = {2026}
147
+ }
148
+ ```
149
+
150
+ See `CITATION.cff` for machine-readable software and paper citation metadata.
@@ -0,0 +1,97 @@
1
+ # SpheriColor
2
+
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
4
+
5
+ SpheriColor generates dataset-specific colors for spherical geographic references. It maps
6
+ geographic or custom pairwise distances into CAM16-UCS and the displayable sRGB gamut.
7
+
8
+ ![Comparison of SpheriColor and baseline colormap methods](docs/teaser.png)
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ pip install sphericolor
14
+ ```
15
+
16
+ SpheriColor supports Python 3.10 through 3.13. It needs no Rust compiler or Numba installation.
17
+
18
+ ## Geographic coordinates
19
+
20
+ ```python
21
+ from sphericolor import from_latlon
22
+
23
+ mapping = from_latlon(
24
+ latitudes=[52.52, 48.86, 41.90, 40.42],
25
+ longitudes=[13.40, 2.35, 12.50, -3.70],
26
+ labels=["Berlin", "Paris", "Rome", "Madrid"],
27
+ method="ray",
28
+ )
29
+
30
+ print(dict(zip(mapping.labels, mapping.hex)))
31
+ ```
32
+
33
+ Coordinate input uses great-circle distances in kilometers for Ray and Simplex.
34
+
35
+ ## Precomputed distances
36
+
37
+ ```python
38
+ import numpy as np
39
+ from sphericolor import from_distance_matrix
40
+
41
+ distances = np.array([
42
+ [0.0, 1.0, 2.0, 1.0],
43
+ [1.0, 0.0, 1.0, 2.0],
44
+ [2.0, 1.0, 0.0, 1.0],
45
+ [1.0, 2.0, 1.0, 0.0],
46
+ ])
47
+ mapping = from_distance_matrix(distances, method="simplex")
48
+ ```
49
+
50
+ Distance-matrix input supports Ray and Simplex. HSLuv and bivariate mappings require geographic
51
+ coordinates because they use latitude and longitude orientation directly.
52
+
53
+ ## Methods
54
+
55
+ ```python
56
+ ray = from_latlon(latitudes, longitudes, method="ray")
57
+ simplex = from_latlon(latitudes, longitudes, method="simplex")
58
+ hsluv = from_latlon(latitudes, longitudes, method="hsluv")
59
+ bivariate = from_latlon(
60
+ latitudes,
61
+ longitudes,
62
+ method="bivariate",
63
+ bivariate_map="steiger",
64
+ )
65
+ ```
66
+
67
+ Available bivariate maps are `bremm`, `cube_diagonal`, `schumann`, `steiger`, `teuling2`, and
68
+ `ziegler`.
69
+
70
+ Set `diagnostics=True` to include condensed input and output distances plus intermediate MDS
71
+ embeddings. Diagnostics require quadratic memory and are disabled by default.
72
+
73
+ ### Stability
74
+
75
+ Ray and Simplex derive their colors from an MDS embedding of the complete input set. Because MDS
76
+ is sensitive to the point configuration, changing the entity set may produce a different color
77
+ mapping. HSLuv and the bivariate methods provide dataset-independent alternatives when consistent
78
+ colors across datasets are needed.
79
+
80
+ ## License and citation
81
+
82
+ SpheriColor and its bundled gamut asset are MIT licensed. If you use SpheriColor in academic
83
+ work, please cite the associated paper:
84
+
85
+ > Julius Rauscher, Johannes Fuchs, Daniel A. Keim, and Frederik L. Dennig. “SpheriColor:
86
+ > Colormaps for Spherical Geospatial Input Topographies.” EuroVis 2026 Short Papers, 2026.
87
+
88
+ ```bibtex
89
+ @inproceedings{rauscher2026sphericolor,
90
+ title = {{SpheriColor}: Colormaps for Spherical Geospatial Input Topographies},
91
+ author = {Rauscher, Julius and Fuchs, Johannes and Keim, Daniel A. and Dennig, Frederik L.},
92
+ booktitle = {EuroVis 2026 Short Papers},
93
+ year = {2026}
94
+ }
95
+ ```
96
+
97
+ See `CITATION.cff` for machine-readable software and paper citation metadata.
Binary file
@@ -0,0 +1,76 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.25"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "sphericolor"
7
+ version = "0.1.0"
8
+ description = "Dataset-specific color mappings for spherical geographic data"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10,<3.14"
11
+ license = { file = "LICENSE" }
12
+ authors = [
13
+ { name = "Julius Rauscher" },
14
+ { name = "Johannes Fuchs" },
15
+ { name = "Daniel A. Keim" },
16
+ { name = "Frederik L. Dennig" },
17
+ ]
18
+ keywords = ["colormap", "geospatial", "visualization", "CAM16-UCS"]
19
+ classifiers = [
20
+ "Development Status :: 3 - Alpha",
21
+ "License :: OSI Approved :: MIT License",
22
+ "Programming Language :: Python :: 3",
23
+ "Programming Language :: Python :: 3.10",
24
+ "Programming Language :: Python :: 3.11",
25
+ "Programming Language :: Python :: 3.12",
26
+ "Programming Language :: Python :: 3.13",
27
+ "Topic :: Scientific/Engineering :: Visualization",
28
+ ]
29
+ dependencies = [
30
+ "numpy>=1.24",
31
+ "scipy>=1.10",
32
+ "scikit-learn>=1.4",
33
+ "coloraide>=3.3",
34
+ "hsluv>=5",
35
+ "pycolormap-2d>=1.1.7",
36
+ ]
37
+
38
+ [project.optional-dependencies]
39
+ test = ["mypy>=1.10", "pytest>=8", "ruff>=0.6"]
40
+ build = ["build>=1.2"]
41
+
42
+ [project.urls]
43
+ Repository = "https://github.com/dbvis-ukon/sphericolor"
44
+
45
+ [tool.hatch.build.targets.wheel]
46
+ packages = ["src/sphericolor"]
47
+
48
+ [tool.hatch.build.targets.sdist]
49
+ include = [
50
+ "/src",
51
+ "/tests",
52
+ "/docs",
53
+ "/README.md",
54
+ "/LICENSE",
55
+ "/CITATION.cff",
56
+ "/CHANGELOG.md",
57
+ ]
58
+
59
+ [tool.pytest.ini_options]
60
+ addopts = "-ra"
61
+ testpaths = ["tests"]
62
+
63
+ [tool.ruff]
64
+ line-length = 100
65
+ target-version = "py310"
66
+
67
+ [tool.ruff.lint]
68
+ select = ["E", "F", "I", "UP", "B", "SIM"]
69
+
70
+ [tool.mypy]
71
+ python_version = "3.10"
72
+ strict = true
73
+ packages = ["sphericolor"]
74
+ mypy_path = "src"
75
+ exclude = ["tests"]
76
+ ignore_missing_imports = true
@@ -0,0 +1,8 @@
1
+ """Spherical geographic color mappings."""
2
+
3
+ from .api import from_distance_matrix, from_latlon
4
+ from .result import ColorMapping, Diagnostics
5
+
6
+ __all__ = ["ColorMapping", "Diagnostics", "from_distance_matrix", "from_latlon"]
7
+ __version__ = "0.1.0"
8
+
@@ -0,0 +1,154 @@
1
+ """Public generation API."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Sequence
6
+ from typing import Any
7
+
8
+ import numpy as np
9
+ from numpy.typing import ArrayLike, NDArray
10
+
11
+ from .colors import cam16ucs_to_rgb, rgb_to_cam16ucs, rgb_to_hex
12
+ from .diagnostics import build_diagnostics
13
+ from .distances import great_circle_matrix
14
+ from .embedding import metric_mds
15
+ from .methods.bivariate import bivariate_colors
16
+ from .methods.hsluv import hsluv_colors
17
+ from .methods.ray import project_directions_to_gamut
18
+ from .methods.simplex import fit_embedding_to_gamut
19
+ from .result import ColorMapping, Diagnostics, immutable_metadata, readonly
20
+ from .validation import (
21
+ DISTANCE_METHODS,
22
+ validate_bivariate_map,
23
+ validate_colors,
24
+ validate_coordinates,
25
+ validate_distance_matrix,
26
+ validate_labels,
27
+ validate_method,
28
+ )
29
+
30
+
31
+ def _mapping(
32
+ *,
33
+ labels: tuple[Any, ...],
34
+ rgb: NDArray[np.float64],
35
+ method: str,
36
+ metadata: dict[str, Any],
37
+ diagnostics: Diagnostics | None,
38
+ ) -> ColorMapping:
39
+ checked_rgb = validate_colors(rgb, len(labels))
40
+ cam16ucs = rgb_to_cam16ucs(checked_rgb)
41
+ return ColorMapping(
42
+ labels=labels,
43
+ rgb=readonly(checked_rgb),
44
+ hex=readonly(rgb_to_hex(checked_rgb)),
45
+ cam16ucs=readonly(cam16ucs),
46
+ method=method,
47
+ metadata=immutable_metadata(metadata),
48
+ diagnostics=diagnostics,
49
+ )
50
+
51
+
52
+ def _distance_mapping(
53
+ distances: NDArray[np.float64],
54
+ labels: tuple[Any, ...],
55
+ method: str,
56
+ random_state: int | None,
57
+ diagnostics: bool,
58
+ metadata: dict[str, Any],
59
+ ) -> ColorMapping:
60
+ embedding = metric_mds(distances, random_state)
61
+ if method == "ray":
62
+ mapped, method_metadata = project_directions_to_gamut(embedding)
63
+ else:
64
+ mapped, method_metadata = fit_embedding_to_gamut(embedding, distances)
65
+ rgb, clipped = cam16ucs_to_rgb(mapped)
66
+ displayed_cam16ucs = rgb_to_cam16ucs(rgb)
67
+ metadata.update(method_metadata)
68
+ metadata.update({"clipped_color_count": clipped, "random_state": random_state})
69
+ diagnostic_result = (
70
+ build_diagnostics(distances, displayed_cam16ucs, embedding, mapped)
71
+ if diagnostics
72
+ else None
73
+ )
74
+ return _mapping(
75
+ labels=labels,
76
+ rgb=rgb,
77
+ method=method,
78
+ metadata=metadata,
79
+ diagnostics=diagnostic_result,
80
+ )
81
+
82
+
83
+ def from_latlon(
84
+ latitudes: ArrayLike,
85
+ longitudes: ArrayLike,
86
+ *,
87
+ labels: Sequence[Any] | None = None,
88
+ method: str = "ray",
89
+ random_state: int | None = 69,
90
+ diagnostics: bool = False,
91
+ bivariate_map: str = "cube_diagonal",
92
+ ) -> ColorMapping:
93
+ """Generate colors for an ordered set of latitude-longitude points."""
94
+ selected_method = validate_method(method)
95
+ lat, lon = validate_coordinates(latitudes, longitudes)
96
+ checked_labels = validate_labels(labels, lat.size)
97
+ distances = great_circle_matrix(lat, lon)
98
+ metadata: dict[str, Any] = {
99
+ "input": "latitude_longitude",
100
+ "distance": "great_circle_km",
101
+ }
102
+
103
+ if selected_method in DISTANCE_METHODS:
104
+ return _distance_mapping(
105
+ distances,
106
+ checked_labels,
107
+ selected_method,
108
+ random_state,
109
+ diagnostics,
110
+ metadata,
111
+ )
112
+
113
+ if selected_method == "hsluv":
114
+ rgb = hsluv_colors(lat, lon)
115
+ else:
116
+ selected_bivariate = validate_bivariate_map(bivariate_map)
117
+ rgb = bivariate_colors(lat, lon, selected_bivariate)
118
+ metadata["bivariate_map"] = selected_bivariate
119
+ cam16ucs = rgb_to_cam16ucs(rgb)
120
+ diagnostic_result = (
121
+ build_diagnostics(distances, cam16ucs, None, None) if diagnostics else None
122
+ )
123
+ metadata["clipped_color_count"] = 0
124
+ return _mapping(
125
+ labels=checked_labels,
126
+ rgb=rgb,
127
+ method=selected_method,
128
+ metadata=metadata,
129
+ diagnostics=diagnostic_result,
130
+ )
131
+
132
+
133
+ def from_distance_matrix(
134
+ distances: ArrayLike,
135
+ *,
136
+ labels: Sequence[Any] | None = None,
137
+ method: str = "ray",
138
+ random_state: int | None = 69,
139
+ diagnostics: bool = False,
140
+ ) -> ColorMapping:
141
+ """Generate colors from an ordered pairwise-distance matrix."""
142
+ selected_method = validate_method(method)
143
+ if selected_method not in DISTANCE_METHODS:
144
+ raise ValueError("distance-matrix input supports only ray and simplex")
145
+ matrix = validate_distance_matrix(distances)
146
+ checked_labels = validate_labels(labels, matrix.shape[0])
147
+ return _distance_mapping(
148
+ matrix,
149
+ checked_labels,
150
+ selected_method,
151
+ random_state,
152
+ diagnostics,
153
+ {"input": "distance_matrix", "distance": "user_supplied"},
154
+ )
@@ -0,0 +1,47 @@
1
+ """Color-space conversions and serialization."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import numpy as np
6
+ from coloraide import Color as BaseColor
7
+ from coloraide.distance.delta_e_cam16 import DECAM16
8
+ from coloraide.spaces.cam16_ucs import CAM16LCD, CAM16SCD, CAM16UCS, CAM16JMh # type: ignore[attr-defined]
9
+ from numpy.typing import ArrayLike, NDArray
10
+
11
+
12
+ class Color(BaseColor):
13
+ """Package-local ColorAide registry."""
14
+
15
+
16
+ Color.register([CAM16UCS(), CAM16SCD(), CAM16LCD(), DECAM16(), CAM16JMh()])
17
+
18
+
19
+ def rgb_to_cam16ucs(rgb: ArrayLike) -> NDArray[np.float64]:
20
+ values = np.asarray(rgb, dtype=np.float64)
21
+ output = np.empty_like(values)
22
+ for index, color in enumerate(values):
23
+ converted = Color("srgb", color.tolist()).convert("cam16-ucs")
24
+ output[index] = converted.coords()
25
+ return output
26
+
27
+
28
+ def cam16ucs_to_rgb(
29
+ cam16ucs: ArrayLike,
30
+ ) -> tuple[NDArray[np.float64], int]:
31
+ values = np.asarray(cam16ucs, dtype=np.float64)
32
+ output = np.empty_like(values)
33
+ clipped = 0
34
+ for index, color in enumerate(values):
35
+ converted = np.asarray(
36
+ Color("cam16-ucs", color.tolist()).convert("srgb").coords(), dtype=np.float64
37
+ )
38
+ clipped += int(np.any((converted < 0.0) | (converted > 1.0)))
39
+ output[index] = np.clip(converted, 0.0, 1.0)
40
+ return output, clipped
41
+
42
+
43
+ def rgb_to_hex(rgb: ArrayLike) -> NDArray[np.str_]:
44
+ values = np.rint(np.asarray(rgb, dtype=np.float64) * 255.0).astype(np.uint8)
45
+ return np.asarray(
46
+ [f"#{red:02x}{green:02x}{blue:02x}" for red, green, blue in values], dtype=np.str_
47
+ )
File without changes