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
Binary file modified blocksnet/analysis/land_use/prediction/artifacts/model.joblib
Binary file not shown.
Binary file not shown.
469 changes: 309 additions & 160 deletions blocksnet/analysis/land_use/prediction/core.py

Large diffs are not rendered by default.

677 changes: 552 additions & 125 deletions blocksnet/analysis/land_use/prediction/preprocessing.py

Large diffs are not rendered by default.

20 changes: 18 additions & 2 deletions blocksnet/analysis/land_use/prediction/schemas.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import pandas as pd
from pandera import Field
from pandera.typing import Series
from shapely import MultiPolygon, Polygon
from blocksnet.enums import LandUseCategory
from blocksnet.utils.validation import GdfSchema, LandUseSchema


class BlocksInputSchema(GdfSchema):
category: Series
category: Series = Field(nullable=True)

@classmethod
def _geometry_types(cls):
Expand All @@ -20,7 +21,22 @@ def _before_validate(cls, df: pd.DataFrame) -> pd.DataFrame:
def parse_category(c):
if isinstance(c, LandUseCategory):
return c
return LandUseCategory(c.lower())
if isinstance(c, str):
s = c.strip()
# try value (exact), then case-insensitive by value, then by name
try:
return LandUseCategory(s)
except Exception:
pass
try:
return next(v for v in LandUseCategory if v.value.lower() == s.lower())
except Exception:
pass
try:
return LandUseCategory[s.upper()]
except Exception:
pass
return None

df["category"] = df["category"].map(parse_category)

Expand Down
34 changes: 19 additions & 15 deletions blocksnet/enums/land_use_category.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
from enum import Enum
from blocksnet.enums import LandUse

class LandUseCategory(Enum):
"""Enumeration class representing different categories of land use.

This enum defines three main categories of land use: urban, non-urban, and industrial.
It provides methods to convert between LandUse objects and LandUseCategory instances.
"""High-level land use categories used for prediction.
Supported categories:
- INDUSTRIAL
- RECREATION
- BUSINESS
- RESIDENTIAL
"""
URBAN = "urban"
NON_URBAN = "non_urban"
INDUSTRIAL = "industrial"
RESIDENTIAL = "RESIDENTIAL"
BUSINESS = "BUSINESS"
RECREATION = "RECREATION"
INDUSTRIAL = "INDUSTRIAL"

_REVERSE_MAP = None

@classmethod
Expand Down Expand Up @@ -40,11 +43,12 @@ def to_land_use(self) -> set[LandUse]:
return LandUseCategory._REVERSE_MAP.get(self, set())

LU_MAPPING = {
LandUse.RESIDENTIAL: LandUseCategory.URBAN,
LandUse.BUSINESS: LandUseCategory.URBAN,
LandUse.RECREATION: LandUseCategory.NON_URBAN,
LandUse.TRANSPORT: LandUseCategory.NON_URBAN,
LandUse.SPECIAL: LandUseCategory.NON_URBAN,
LandUse.AGRICULTURE: LandUseCategory.NON_URBAN,
LandUse.RESIDENTIAL: LandUseCategory.RESIDENTIAL,
LandUse.BUSINESS: LandUseCategory.BUSINESS,
LandUse.RECREATION: LandUseCategory.RECREATION,
LandUse.AGRICULTURE: LandUseCategory.RECREATION,
LandUse.SPECIAL: LandUseCategory.RECREATION,
LandUse.INDUSTRIAL: LandUseCategory.INDUSTRIAL,
}
LandUse.TRANSPORT: LandUseCategory.INDUSTRIAL,
# Other LandUse values (e.g., TRANSPORT, SPECIAL, AGRICULTURE) map to None
}
1 change: 1 addition & 0 deletions examples/analysis/land_use/artifacts/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"strategy_cls": "SKLearnVotingClassificationStrategy", "model_cls": "VotingClassifier", "model_params": {"voting": "soft", "n_jobs": -1}}
Binary file added examples/analysis/land_use/artifacts/model.joblib
Binary file not shown.
Loading