Skip to content

Mock Image

siapy.entities.images.mock

MockImage

MockImage(array: NDArray[floating[Any]])

Bases: ImageBase

Source code in siapy/entities/images/mock.py
17
18
19
20
21
22
23
24
25
26
27
def __init__(
    self,
    array: NDArray[np.floating[Any]],
) -> None:
    if len(array.shape) != 3:
        raise InvalidInputError(
            input_value=array.shape,
            message="Input array must be 3-dimensional (height, width, bands)",
        )

    self._array = array.astype(np.float32)

filepath property

filepath: Path

metadata property

metadata: dict[str, Any]

shape property

shape: tuple[int, int, int]

bands property

bands: int

default_bands property

default_bands: list[int]

wavelengths property

wavelengths: list[float]

camera_id property

camera_id: str

open classmethod

open(array: NDArray[floating[Any]]) -> MockImage
Source code in siapy/entities/images/mock.py
29
30
31
@classmethod
def open(cls, array: NDArray[np.floating[Any]]) -> "MockImage":
    return cls(array=array)

to_display

to_display(equalize: bool = True) -> Image
Source code in siapy/entities/images/mock.py
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
def to_display(self, equalize: bool = True) -> Image.Image:
    if self.bands >= 3:
        display_bands = self._array[:, :, self.default_bands]
    else:
        display_bands = np.stack([self._array[:, :, 0]] * 3, axis=2)

    if equalize:
        for i in range(display_bands.shape[2]):
            band = display_bands[:, :, i]
            non_nan = ~np.isnan(band)
            if np.any(non_nan):
                min_val = np.nanmin(band)
                max_val = np.nanmax(band)
                if max_val > min_val:
                    band = (band - min_val) / (max_val - min_val) * 255
                display_bands[:, :, i] = band

    display_array = np.nan_to_num(display_bands).astype(np.uint8)
    return Image.fromarray(display_array)

to_numpy

to_numpy(
    nan_value: float | None = None,
) -> NDArray[floating[Any]]
Source code in siapy/entities/images/mock.py
86
87
88
89
def to_numpy(self, nan_value: float | None = None) -> NDArray[np.floating[Any]]:
    if nan_value is not None:
        return np.nan_to_num(self._array, nan=nan_value)
    return self._array.copy()

to_xarray

to_xarray() -> XarrayType
Source code in siapy/entities/images/mock.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
def to_xarray(self) -> "XarrayType":
    return xr.DataArray(
        self._array,
        dims=["y", "x", "band"],
        coords={
            "band": self.wavelengths,
            "x": np.arange(self.shape[1]),
            "y": np.arange(self.shape[0]),
        },
        attrs={
            "camera_id": self.camera_id,
        },
    )