from __future__ import annotations
from abc import ABC, abstractmethod
from pathlib import Path
from typing import Literal
import numpy as np
import numpy.typing as npt
from .batch_table import BatchTable
from .feature_table import FeatureTable
[docs]
class TileContent(ABC):
header: TileContentHeader
body: TileContentBody
[docs]
def to_array(self) -> npt.NDArray[np.uint8]:
self.sync()
header_arr = self.header.to_array()
body_arr = self.body.to_array()
return np.concatenate((header_arr, body_arr))
[docs]
def to_hex_str(self) -> str:
arr = self.to_array()
return " ".join(f"{x:02X}" for x in arr)
[docs]
def save_as(self, path: Path) -> None:
tile_arr = self.to_array()
with path.open("bw") as f:
f.write(bytes(tile_arr))
[docs]
@abstractmethod
def print_info(self) -> None:
...
[docs]
@abstractmethod
def sync(self) -> None:
"""
Allow to synchronize headers with contents.
"""
[docs]
@staticmethod
@abstractmethod
def from_array(array: npt.NDArray[np.uint8]) -> TileContent:
...
[docs]
class TileContentBody(ABC):
batch_table: BatchTable
feature_table: FeatureTable
[docs]
@abstractmethod
def to_array(self) -> npt.NDArray[np.uint8]:
...