14
14
from typing import (
15
15
TYPE_CHECKING ,
16
16
Any ,
17
+ Container ,
17
18
Iterable ,
18
19
Iterator ,
19
20
Literal ,
@@ -94,7 +95,7 @@ class CatalogItem:
94
95
interpolation: bool | Interpolation
95
96
The interpolation method to use when sampling the colormap. One of
96
97
{False, True, "linear", "nearest"}, where False is equivalent to "nearest"
97
- and True is equivalent to "linear".
98
+ and True is equivalent to "linear". If not provided, defaults to "linear".
98
99
tags: list[str]
99
100
A list of tags for the colormap. These are displayed in the documentation.
100
101
aliases: list[str]
@@ -235,7 +236,11 @@ def __init__(
235
236
)
236
237
237
238
def unique_keys (
238
- self , prefer_short_names : bool = True , normalized_names : bool = False
239
+ self ,
240
+ prefer_short_names : bool = True ,
241
+ normalized_names : bool = False ,
242
+ categories : Container [Category ] = (),
243
+ interpolation : Interpolation | None = None ,
239
244
) -> set [str ]:
240
245
"""Return names that refer to unique colormap data.
241
246
@@ -250,6 +255,10 @@ def unique_keys(
250
255
If True, return the normalized names of the colormaps. If False (default),
251
256
return the original names of the colormaps (which may include spaces and/or
252
257
capital letters).
258
+ categories : Container[Category], optional
259
+ If provided, only return colormaps in the given categories.
260
+ interpolation : Interpolation, optional
261
+ If provided, only return colormaps with the given interpolation method.
253
262
254
263
Returns
255
264
-------
@@ -258,8 +267,18 @@ def unique_keys(
258
267
"""
259
268
keys : set [str ] = set ()
260
269
for original_name , normed_name in self ._original_names .items ():
261
- if "alias" in self ._data [normed_name ]:
270
+ data = self ._data [normed_name ]
271
+ if "alias" in data :
262
272
continue
273
+ if categories and data ["category" ] not in categories :
274
+ continue
275
+ if interpolation is not None :
276
+ interp = data .get ("interpolation" , "linear" )
277
+ if isinstance (interp , bool ):
278
+ interp = "linear" if interp else "nearest"
279
+ if interp != interpolation :
280
+ continue
281
+
263
282
if prefer_short_names :
264
283
short_name = normed_name .split (NAMESPACE_DELIMITER , 1 )[- 1 ]
265
284
data2 = self ._data [short_name ]
0 commit comments