Source code for openworld_radio_twin.rendering

import os
import tempfile
from functools import lru_cache
from pathlib import Path

import numpy as np

_cache_directory = Path(tempfile.gettempdir()) / "openworld-radio-twin" / "matplotlib"
_cache_directory.mkdir(parents=True, exist_ok=True)
os.environ.setdefault("MPLCONFIGDIR", str(_cache_directory))

from matplotlib import colormaps  # noqa: E402


[docs] @lru_cache def rgba_lookup(name: str) -> np.ndarray: """Return a shared 256-entry uint8 lookup table for a Matplotlib colormap.""" return np.rint(colormaps[name](np.linspace(0.0, 1.0, 256)) * 255).astype(np.uint8)