Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ default_language_version:
python: python3.10
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
rev: v6.0.0
hooks:
- id: check-added-large-files
- id: check-toml
Expand All @@ -14,7 +14,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.11.13
rev: v0.16.4
hooks:
- id: ruff
args:
Expand All @@ -23,17 +23,17 @@ repos:
files: ^(siapy|tests)/
- id: ruff-format
- repo: https://github.com/gitleaks/gitleaks
rev: v8.27.2
rev: v8.30.0
hooks:
- id: gitleaks
- repo: https://github.com/codespell-project/codespell
rev: v2.4.1
rev: v2.4.3
hooks:
- id: codespell
additional_dependencies:
- tomli
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v4.2.0
rev: v4.4.0
hooks:
- id: conventional-pre-commit
stages: [commit-msg]
Expand Down
8 changes: 4 additions & 4 deletions siapy/core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
from typing import Any

__all__ = [
"SiapyError",
"ConfigurationError",
"DirectInitializationError",
"InvalidFilepathError",
"InvalidInputError",
"InvalidTypeError",
"ProcessingError",
"ConfigurationError",
"MethodNotImplementedError",
"DirectInitializationError",
"ProcessingError",
"SiapyError",
]


Expand Down
15 changes: 8 additions & 7 deletions siapy/core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
and consistency across the codebase.
"""

from typing import Any, Sequence
from collections.abc import Sequence
from typing import Any

import numpy as np
import pandas as pd
Expand All @@ -17,14 +18,14 @@
from siapy.entities import SpectralImage, SpectralImageSet

__all__ = [
"SpectralLibType",
"XarrayType",
"ImageType",
"ImageSizeType",
"ImageDataType",
"ImageContainerType",
"ArrayLike1dType",
"ArrayLike2dType",
"ImageContainerType",
"ImageDataType",
"ImageSizeType",
"ImageType",
"SpectralLibType",
"XarrayType",
]

SpectralLibType = sp.io.envi.BilFile | sp.io.envi.BipFile | sp.io.envi.BsqFile
Expand Down
1 change: 0 additions & 1 deletion siapy/datasets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from .tabular import TabularDataset


__all__ = [
"TabularDataset",
]
1 change: 0 additions & 1 deletion siapy/datasets/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,3 @@ def merge_signals_from_multiple_cameras(data: "TabularDatasetData") -> None:
Implement the actual merging logic based on camera specifications
and data alignment requirements.
"""
pass
5 changes: 3 additions & 2 deletions siapy/datasets/schemas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from abc import ABC, abstractmethod
from collections.abc import Iterable
from dataclasses import dataclass
from typing import Any, Iterable, Optional
from typing import Any

import pandas as pd
from pydantic import BaseModel, ConfigDict
Expand Down Expand Up @@ -368,7 +369,7 @@ def from_dict(cls, data: dict[str, Any]) -> "TabularDatasetData":
return cls(signatures=signatures, metadata=metadata, target=target)

@staticmethod
def target_from_dict(data: dict[str, Any] | None = None) -> Optional[Target]:
def target_from_dict(data: dict[str, Any] | None = None) -> Target | None:
"""Create an appropriate Target instance from a dictionary.

Automatically determines whether to create a ClassificationTarget or
Expand Down
2 changes: 1 addition & 1 deletion siapy/datasets/tabular.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections.abc import Iterator
from dataclasses import dataclass
from pathlib import Path
from typing import Iterator

import pandas as pd
from pydantic import BaseModel, ConfigDict
Expand Down
6 changes: 3 additions & 3 deletions siapy/entities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from .signatures import Signatures

__all__ = [
"SpectralImage",
"SpectralImageSet",
"Pixels",
"Signatures",
"Shape",
"Signatures",
"SpectralImage",
"SpectralImageSet",
]
2 changes: 1 addition & 1 deletion siapy/entities/images/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

__all__ = [
"ImageBase",
"SpectralLibImage",
"RasterioLibImage",
"SpectralImage",
"SpectralLibImage",
]
11 changes: 0 additions & 11 deletions siapy/entities/images/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def open(cls: type["ImageBase"], *args: Any, **kwargs: Any) -> "ImageBase":
Each implementation defines its own signature for this method
based on the specific requirements of the underlying library.
"""
pass

@property
@abstractmethod
Expand All @@ -51,7 +50,6 @@ def filepath(self) -> Path:
Returns:
A Path object representing the location of the image file. For in-memory images, this may return an empty Path.
"""
pass

@property
@abstractmethod
Expand All @@ -61,7 +59,6 @@ def metadata(self) -> dict[str, Any]:
Returns:
A dictionary containing image metadata such as coordinate reference system, geotransform information, wavelength data, and other image properties. The specific contents depend on the underlying format and library.
"""
pass

@property
@abstractmethod
Expand All @@ -71,7 +68,6 @@ def shape(self) -> tuple[int, int, int]:
Returns:
A tuple (height, width, bands) representing the image dimensions.
"""
pass

@property
@abstractmethod
Expand All @@ -81,7 +77,6 @@ def bands(self) -> int:
Returns:
The number of spectral bands (channels) in the image.
"""
pass

@property
@abstractmethod
Expand All @@ -91,7 +86,6 @@ def default_bands(self) -> list[int]:
Returns:
A list of band indices typically used for red, green, and blue channels when displaying the image as an RGB composite.
"""
pass

@property
@abstractmethod
Expand All @@ -101,7 +95,6 @@ def wavelengths(self) -> list[float]:
Returns:
A list of wavelength values (typically in nanometers) for each band. For non-spectral data, this may return band numbers or other identifiers.
"""
pass

@property
@abstractmethod
Expand All @@ -111,7 +104,6 @@ def camera_id(self) -> str:
Returns:
A string identifying the camera or sensor used to capture the image. May return an empty string if no camera information is available.
"""
pass

@abstractmethod
def to_display(self, equalize: bool = True) -> Image.Image:
Expand All @@ -123,7 +115,6 @@ def to_display(self, equalize: bool = True) -> Image.Image:
Returns:
A PIL Image object suitable for display, typically as an RGB composite created from the default bands with appropriate scaling and normalization.
"""
pass

@abstractmethod
def to_numpy(self, nan_value: float | None = None) -> NDArray[np.floating[Any]]:
Expand All @@ -135,7 +126,6 @@ def to_numpy(self, nan_value: float | None = None) -> NDArray[np.floating[Any]]:
Returns:
A 3D numpy array with shape (height, width, bands) containing the image data. The array dtype should be a floating-point type.
"""
pass

@abstractmethod
def to_xarray(self) -> "XarrayType":
Expand All @@ -144,4 +134,3 @@ def to_xarray(self) -> "XarrayType":
Returns:
An xarray DataArray with labeled dimensions and coordinates, suitable for advanced analysis and visualization. The array should include appropriate coordinate information and metadata attributes.
"""
pass
5 changes: 3 additions & 2 deletions siapy/entities/images/spimage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections.abc import Iterable, Sequence
from dataclasses import dataclass
from pathlib import Path
from typing import TYPE_CHECKING, Any, Generic, Iterable, Sequence, TypeVar
from typing import TYPE_CHECKING, Any, Generic, TypeVar

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -61,7 +62,7 @@ def __lt__(self, other: "SpectralImage[Any]") -> bool:
"""
return self.filepath.name < other.filepath.name

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
"""Check equality between two SpectralImage instances.

Args:
Expand Down
3 changes: 2 additions & 1 deletion siapy/entities/imagesets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections.abc import Iterator, Sequence
from dataclasses import dataclass
from pathlib import Path
from typing import Any, Iterator, Sequence
from typing import Any

import numpy as np
from rich.progress import track
Expand Down
23 changes: 12 additions & 11 deletions siapy/entities/pixels.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations

from collections.abc import Iterable, Sequence
from dataclasses import dataclass
from pathlib import Path
from typing import Any, ClassVar, Iterable, NamedTuple, Sequence, TypeAlias
from typing import Any, ClassVar, NamedTuple, TypeAlias

import numpy as np
import pandas as pd
Expand All @@ -11,10 +12,10 @@
from siapy.core.exceptions import InvalidInputError, InvalidTypeError

__all__ = [
"Pixels",
"PixelCoordinate",
"CoordinateInput",
"HomogeneousCoordinate",
"PixelCoordinate",
"Pixels",
"validate_pixel_input",
]

Expand Down Expand Up @@ -45,13 +46,13 @@ def __len__(self) -> int:
def __repr__(self) -> str:
return f"Pixels(\n{self.df}\n)"

def __getitem__(self, indices: Any) -> "Pixels":
def __getitem__(self, indices: Any) -> Pixels:
df_slice = self.df.iloc[indices]
if isinstance(df_slice, pd.Series):
df_slice = df_slice.to_frame().T
return Pixels(df_slice)

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
if not isinstance(other, Pixels):
return False
return self.df.equals(other.df)
Expand All @@ -67,13 +68,13 @@ def __post_init__(self) -> None:
validate_pixel_input_dimensions(self._data)

@classmethod
def from_iterable(cls, iterable: Iterable[CoordinateInput]) -> "Pixels":
def from_iterable(cls, iterable: Iterable[CoordinateInput]) -> Pixels:
df = pd.DataFrame(iterable, columns=[cls.coords.X, cls.coords.Y])
validate_pixel_input_dimensions(df)
return cls(df)

@classmethod
def load_from_parquet(cls, filepath: str | Path) -> "Pixels":
def load_from_parquet(cls, filepath: str | Path) -> Pixels:
df = pd.read_parquet(filepath)
validate_pixel_input_dimensions(df)
return cls(df)
Expand All @@ -87,10 +88,10 @@ def df_homogenious(self) -> pd.DataFrame:
df_homo[self.coords.H] = 1
return df_homo

def x(self) -> "pd.Series[float]":
def x(self) -> pd.Series[float]:
return self.df[self.coords.X]

def y(self) -> "pd.Series[float]":
def y(self) -> pd.Series[float]:
return self.df[self.coords.Y]

def to_numpy(self) -> NDArray[np.floating[Any]]:
Expand All @@ -102,7 +103,7 @@ def to_list(self) -> list[PixelCoordinate]:
def save_to_parquet(self, filepath: str | Path) -> None:
self.df.to_parquet(filepath, index=True)

def as_type(self, dtype: type) -> "Pixels":
def as_type(self, dtype: type) -> Pixels:
converted_df = self.df.copy()
converted_df[self.coords.X] = converted_df[self.coords.X].astype(dtype)
converted_df[self.coords.Y] = converted_df[self.coords.Y].astype(dtype)
Expand Down Expand Up @@ -173,7 +174,7 @@ def validate_pixel_input(input_data: Pixels | pd.DataFrame | Iterable[Coordinate

raise InvalidInputError(
input_value=input_data,
message=f"Failed to convert input to Pixels: {str(e)}"
message=f"Failed to convert input to Pixels: {e!s}"
f"\nExpected a Pixels instance or an iterable (e.g. list, np.array, tuple, pd.DataFrame)."
f"\nThe input must contain 2D coordinates with x and y values.",
)
5 changes: 3 additions & 2 deletions siapy/entities/shapes/geometric_shapes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
from collections.abc import Iterable, Iterator
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Iterable, Iterator, Optional
from typing import TYPE_CHECKING, Any, Optional

from siapy.core.exceptions import InvalidInputError

Expand Down Expand Up @@ -42,7 +43,7 @@ def __setitem__(self, index: int, shape: "Shape") -> None:
def __len__(self) -> int:
return len(self._geometric_shapes)

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
if not isinstance(other, GeometricShapes):
raise InvalidInputError(
{
Expand Down
9 changes: 5 additions & 4 deletions siapy/entities/shapes/shape.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from collections.abc import Iterable
from dataclasses import dataclass
from enum import Enum
from pathlib import Path
from typing import Any, Iterable, Optional
from typing import Any

import geopandas as gpd
import numpy as np
Expand Down Expand Up @@ -50,8 +51,8 @@ class Shape:
def __init__(
self,
label: str = "",
geometry: Optional[BaseGeometry] = None,
geo_dataframe: Optional[gpd.GeoDataFrame] = None,
geometry: BaseGeometry | None = None,
geo_dataframe: gpd.GeoDataFrame | None = None,
):
"""Initialize Shape with either a geometry or geodataframe"""
self._label = label
Expand Down Expand Up @@ -149,7 +150,7 @@ def from_multiline(
def from_polygon(
cls,
exterior: Pixels | pd.DataFrame | Iterable[CoordinateInput],
holes: Optional[list[Pixels | pd.DataFrame | Iterable[CoordinateInput]]] = None,
holes: list[Pixels | pd.DataFrame | Iterable[CoordinateInput]] | None = None,
label: str = "",
) -> "Shape":
exterior = validate_pixel_input(exterior)
Expand Down
Loading
Loading