skais_mapper.utils
All utility functions can be imported from here.
Modules:
Name | Description |
---|---|
colors |
Color module for more beautiful plots. |
config |
Configuration and runtime utility functions. |
helper |
Generic helper functions and other stuff. |
primes |
Functions for checking and computing prime numbers. |
Classes:
Name | Description |
---|---|
SkaisColorMaps |
An assortment of linearly interpolated colormaps based on 4+ colors each. |
SkaisColors |
An assortment of colors and palettes. |
Functions:
Name | Description |
---|---|
alias_kw |
Decorator for aliasing a keyword argument in a function. |
compress_encode |
Compress and encode a string for shorter representations. |
current_time |
Get current time as string. |
extract_decode |
Decompress and decode a short representation string. |
get_run_id |
Fetch a run-specific identifier. |
next_prime |
Next prime strictly larger than n. |
set_run_id |
Set the run-specific identifier. |
SkaisColorMaps
An assortment of linearly interpolated colormaps based on 4+ colors each.
Methods:
Name | Description |
---|---|
gen |
Generate colormaps. |
palette |
Return a palette of a colormap with N linearly interpolated color points. |
plot_gradients |
Plot all color-map gradients. |
random |
Choose a random color map. |
register_all |
Register colormaps with matplotlib. |
reverse |
Reverse the specified colormap. |
gen
classmethod
gen()
Generate colormaps.
Returns:
Type | Description |
---|---|
mpl.colors.LinearSegmentedColormap object
|
colormap generated from custom list |
Source code in skais_mapper/utils/colors.py
271 272 273 274 275 276 277 278 |
|
palette
classmethod
palette(cmap_name: str, N: int)
Return a palette of a colormap with N linearly interpolated color points.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cmap_name
|
str
|
name of the colormap |
required |
N
|
int
|
number of colors in the palette |
required |
Source code in skais_mapper/utils/colors.py
318 319 320 321 322 323 324 325 326 327 328 329 |
|
plot_gradients
classmethod
plot_gradients(savefig: bool = False)
Plot all color-map gradients.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
savefig
|
bool
|
save figure as palettes.png |
False
|
Source code in skais_mapper/utils/colors.py
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
|
random
classmethod
random() -> LinearSegmentedColormap
Choose a random color map.
Returns:
Name | Type | Description |
---|---|---|
cmap |
LinearSegmentedColormap
|
random colormap from custom list |
Source code in skais_mapper/utils/colors.py
262 263 264 265 266 267 268 269 |
|
register_all
staticmethod
register_all(verbose: bool = False)
Register colormaps with matplotlib.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
verbose
|
bool
|
If True, print information to command line |
False
|
Source code in skais_mapper/utils/colors.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
|
reverse
classmethod
reverse(
cmap: Colormap,
set_bad: str = None,
set_under: str = None,
set_over: str = None,
) -> LinearSegmentedColormap
Reverse the specified colormap.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cmap
|
mpl.colors.LinearSegmentedColormap object
|
colormap to be reversed |
required |
set_bad
|
str
|
set colormaps bad values to a different color |
None
|
set_under
|
str
|
set colormaps under values to a different color |
None
|
set_over
|
str
|
set colormaps over values to a different color |
None
|
Returns:
Type | Description |
---|---|
mpl.colors.LinearSegmentedColormap object
|
reversed colormap |
Source code in skais_mapper/utils/colors.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
|
SkaisColors
An assortment of colors and palettes.
Methods:
Name | Description |
---|---|
cmap_from_color |
Create a colormap from a single color. |
cmap_from_color
classmethod
cmap_from_color(
color_str: str, secondary_color: str | None = None
) -> LinearSegmentedColormap
Create a colormap from a single color.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
color_str
|
str
|
color string of the class color |
required |
secondary_color
|
str | None
|
color into which the color changes in the colormap |
None
|
Returns:
Type | Description |
---|---|
mpl.colors.LinearSegmentedColormap object
|
reversed colormap |
Source code in skais_mapper/utils/colors.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
|
alias_kw
alias_kw(key: str, alias: str) -> Callable
Decorator for aliasing a keyword argument in a function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
Name of keyword argument in function to alias |
required |
alias
|
str
|
Alias that can be used for this keyword argument |
required |
Source code in skais_mapper/utils/helper.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
compress_encode
compress_encode(string: str) -> str
Compress and encode a string for shorter representations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string
|
str
|
String to be encoded. |
required |
Source code in skais_mapper/utils/helper.py
33 34 35 36 37 38 39 40 41 |
|
current_time
current_time(
date_only: bool = True,
as_str: bool = True,
no_delim: bool = True,
) -> datetime.datetime | str
Get current time as string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
date_only
|
bool
|
If True, only the date is returned. |
True
|
as_str
|
bool
|
If True, a string is returned instead of a datetime object. |
True
|
no_delim
|
bool
|
If a string is returned, remove the standard delimiters. |
True
|
Source code in skais_mapper/utils/helper.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
extract_decode
extract_decode(string: str) -> str
Decompress and decode a short representation string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string
|
str
|
Compressed base64 string to be decoded. |
required |
Source code in skais_mapper/utils/helper.py
44 45 46 47 48 49 50 51 52 |
|
get_run_id
get_run_id(length: int = 8) -> str
Fetch a run-specific identifier.
Source code in skais_mapper/utils/config.py
13 14 15 16 17 |
|
next_prime
next_prime(n: int) -> int
Next prime strictly larger than n.
Source code in skais_mapper/utils/primes.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
|
set_run_id
set_run_id(run_id: uuid.UUID | str | None = None)
Set the run-specific identifier.
Source code in skais_mapper/utils/config.py
20 21 22 23 24 25 26 |
|