Spaces:
Running on Zero
Running on Zero
File size: 1,576 Bytes
a74054f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | """
Abstract base class for feature extractors.
Dependency Inversion Principle: Depend on abstractions for feature extraction.
"""
from abc import ABC, abstractmethod
from typing import Dict, Any
import geopandas as gpd
class BaseFeatureExtractor(ABC):
"""
Abstract base class for watershed/basin feature extractors.
Each extractor extracts specific category of features (topological, soil, etc.)
"""
def __init__(self, **kwargs):
"""
Initialize extractor.
Args:
**kwargs: Extractor-specific parameters
"""
self.params = kwargs
@abstractmethod
def extract(self, basin_gdf: gpd.GeoDataFrame) -> Dict[str, Any]:
"""
Extract features from basin geometry.
Args:
basin_gdf: GeoDataFrame with basin boundaries
Returns:
Dictionary of extracted features
"""
pass
def get_feature_names(self) -> list:
"""
Get list of feature names this extractor produces.
Returns:
List of feature names
"""
return []
def validate_inputs(self, basin_gdf: gpd.GeoDataFrame) -> bool:
"""
Validate input geodataframe.
Args:
basin_gdf: GeoDataFrame to validate
Returns:
True if valid
"""
if basin_gdf is None or len(basin_gdf) == 0:
return False
if basin_gdf.geometry.is_empty.any():
return False
return True
|