Mock Image
siapy.entities.images.mock
¶
MockImage
¶
MockImage(array: NDArray[floating[Any]])
Bases: ImageBase
PARAMETER | DESCRIPTION |
---|---|
array
|
A 3D numpy array with shape (height, width, bands) containing spectral data. The array will be automatically converted to float32 dtype.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
InvalidInputError
|
If the input array is not 3-dimensional. |
Example
import numpy as np
# Create a synthetic spectral image
data = np.random.rand(100, 100, 10).astype(np.float32)
mock_image = MockImage(data)
Note
The input array is automatically converted to float32 dtype regardless of input type.
Source code in siapy/entities/images/mock.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
filepath
property
¶
filepath: Path
Get a placeholder file path for the mock image.
RETURNS | DESCRIPTION |
---|---|
Path
|
An empty Path object since mock images are not associated with files. |
metadata
property
¶
shape
property
¶
bands
property
¶
bands: int
Get the number of spectral bands in the mock image.
RETURNS | DESCRIPTION |
---|---|
int
|
The number of bands (third dimension) in the underlying array. |
default_bands
property
¶
wavelengths
property
¶
camera_id
property
¶
camera_id: str
Get a placeholder camera identifier for the mock image.
RETURNS | DESCRIPTION |
---|---|
str
|
An empty string since mock images are not associated with real cameras. |
open
classmethod
¶
Create a MockImage instance from a numpy array.
PARAMETER | DESCRIPTION |
---|---|
array
|
A 3D numpy array with shape (height, width, bands) containing spectral data.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
MockImage
|
A MockImage instance wrapping the provided array. |
Example
import numpy as np
# Create synthetic data
data = np.random.rand(50, 50, 5).astype(np.float32)
mock_image = MockImage.open(data)
Source code in siapy/entities/images/mock.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
to_display
¶
to_display(equalize: bool = True) -> Image
Convert the mock image to a PIL Image for display purposes.
PARAMETER | DESCRIPTION |
---|---|
equalize
|
Whether to apply histogram equalization to enhance contrast. Defaults to True.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Image
|
A PIL Image object suitable for display. For images with 3+ bands, uses the first 3 bands as RGB. For images with fewer bands, duplicates the first band across all RGB channels. |
Example
# Display the mock image
pil_image = mock_image.to_display()
pil_image.show()
# Display without histogram equalization
pil_image = mock_image.to_display(equalize=False)
Note
NaN values in the image are automatically handled by replacing them with 0 during the scaling process. The method always returns an RGB image regardless of the number of input bands.
Source code in siapy/entities/images/mock.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
|
to_numpy
¶
Convert the mock image to a numpy array.
PARAMETER | DESCRIPTION |
---|---|
nan_value
|
Optional value to replace NaN values with. If None, NaN values are preserved.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
NDArray[floating[Any]]
|
A copy of the underlying 3D numpy array with shape (height, width, bands). If nan_value is provided, all NaN values are replaced with this value. |
Example
# Get the raw data with NaN values preserved
data = mock_image.to_numpy()
# Replace NaN values with zero
data = mock_image.to_numpy(nan_value=0.0)
Source code in siapy/entities/images/mock.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
|
to_xarray
¶
to_xarray() -> XarrayType
Convert the mock image to an xarray DataArray.
RETURNS | DESCRIPTION |
---|---|
XarrayType
|
An xarray DataArray with labeled dimensions (y, x, band) and coordinates, including mock wavelength values and minimal metadata. |
Example
# Convert to xarray for analysis
xr_data = mock_image.to_xarray()
# Access specific bands
first_band = xr_data.sel(band=0)
Source code in siapy/entities/images/mock.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
|