diff --git a/README.md b/README.md index d841dd5..0592165 100644 --- a/README.md +++ b/README.md @@ -50,26 +50,10 @@ poetry run docs ```mermaid classDiagram - class GroundControlPoint { - gcp_id: str - map_geom: Geom_Point - px_geom: Pixel_Point - confidence: Optional[float] - model: str - model_version: str - crs: Optional[str] - } - - class ProjectionResult { - crs: str - gcp_ids: list[str] - file_name: str - } - - class GeoreferenceResult { - likely_CRSs: Optional[list[str]] - map_area: Optional[Area_Extraction] - projections: Optional[list[ProjectionResult]] + class Pixel_Point { + rows_from_top: Union[float, int] + columns_from_left: Union[float, int] + type: GeomType = GeomType.Point } class GeoreferenceResults { @@ -87,18 +71,6 @@ classDiagram Polygon: str = 'Polygon' } - class Pixel_Point { - rows_from_top: Union[float, int] - columns_from_left: Union[float, int] - type: GeomType = GeomType.Point - } - - class Geom_Point { - latitude: Union[float, int, NoneType] - longitude: Union[float, int, NoneType] - type: GeomType = GeomType.Point - } - class Area_Extraction { type: GeomType = GeomType.Polygon coordinates: list[list[list[Union[float, int]]]] @@ -110,16 +82,44 @@ classDiagram model_version: Optional[str] } + class Geom_Point { + latitude: Union[float, int, NoneType] + longitude: Union[float, int, NoneType] + type: GeomType = GeomType.Point + } + + class ProjectionResult { + crs: str + gcp_ids: list[str] + file_name: str + } + + class GroundControlPoint { + gcp_id: str + map_geom: Geom_Point + px_geom: Pixel_Point + confidence: Optional[float] + model: str + model_version: str + crs: Optional[str] + } + + class GeoreferenceResult { + likely_CRSs: Optional[list[str]] + map_area: Optional[Area_Extraction] + projections: Optional[list[ProjectionResult]] + } + Area_Extraction ..> GeomType Area_Extraction ..> AreaType Geom_Point ..> GeomType Pixel_Point ..> GeomType - GroundControlPoint ..> Geom_Point GroundControlPoint ..> Pixel_Point + GroundControlPoint ..> Geom_Point GeoreferenceResult ..> ProjectionResult GeoreferenceResult ..> Area_Extraction - GeoreferenceResults ..> GeoreferenceResult GeoreferenceResults ..> GroundControlPoint + GeoreferenceResults ..> GeoreferenceResult ``` @@ -134,17 +134,12 @@ classDiagram ```mermaid classDiagram - class MapShapeTypes { - <> - rectangular: str = 'rectangular' - non_rectangular: str = 'non_rectangular' - } - - class MapColorSchemeTypes { - <> - full_color: str = 'full_color' - monochrome: str = 'monochrome' - grayscale: str = 'grayscale' + class CogMetaData { + cog_id: str + system: str + system_version: str + multiple_maps: Optional[bool] + map_metadata: Optional[list[MapMetaData]] } class MapMetaData { @@ -163,17 +158,331 @@ classDiagram model_version: str } - class CogMetaData { + class MapColorSchemeTypes { + <> + full_color: str = 'full_color' + monochrome: str = 'monochrome' + grayscale: str = 'grayscale' + } + + class MapShapeTypes { + <> + rectangular: str = 'rectangular' + non_rectangular: str = 'non_rectangular' + } + + MapMetaData ..> MapColorSchemeTypes + MapMetaData ..> MapShapeTypes + CogMetaData ..> MapMetaData + + +``` + + + +### Feature Results + +
+ feature results + +```mermaid +classDiagram + + class PointLegendAndFeaturesResult { + id: str + crs: str + cdr_projection_id: Optional[str] + name: Optional[str] + description: Optional[str] + legend_bbox: Optional[list[Union[float, int]]] + point_features: Optional[list[PointFeatureCollection]] + } + + class LineLegendAndFeaturesResult { + id: str + crs: str + cdr_projection_id: Optional[str] + name: Optional[str] + description: Optional[str] + legend_bbox: Optional[list[Union[float, int]]] + line_features: Optional[LineFeatureCollection] + } + + class Area_Extraction { + type: GeomType = GeomType.Polygon + coordinates: list[list[list[Union[float, int]]]] + bbox: Optional[list[Union[float, int]]] + category: AreaType + text: Optional[str] + confidence: Optional[float] + model: Optional[str] + model_version: Optional[str] + } + + class FeatureResults { cog_id: str + line_feature_results: Optional[list[LineLegendAndFeaturesResult]] + point_feature_results: Optional[list[PointLegendAndFeaturesResult]] + polygon_feature_results: Optional[list[PolygonLegendAndFeauturesResult]] + map_area_extractions: Optional[list[Area_Extraction]] system: str system_version: str - multiple_maps: Optional[bool] - map_metadata: Optional[list[MapMetaData]] } - MapMetaData ..> MapShapeTypes - MapMetaData ..> MapColorSchemeTypes - CogMetaData ..> MapMetaData + class PolygonLegendAndFeauturesResult { + id: str + crs: str + cdr_projection_id: Optional[str] + map_unit: Optional[MapUnit] + abbreviation: Optional[str] + legend_bbox: Optional[list[Union[float, int]]] + category: Optional[str] + color: Optional[str] + description: Optional[str] + pattern: Optional[str] + polygon_features: Optional[PolygonFeatureCollection] + } + + Area_Extraction ..> GeomType + Area_Extraction ..> AreaType + LineLegendAndFeaturesResult ..> LineFeatureCollection + PointLegendAndFeaturesResult ..> PointFeatureCollection + PolygonLegendAndFeauturesResult ..> MapUnit + PolygonLegendAndFeauturesResult ..> PolygonFeatureCollection + FeatureResults ..> PointLegendAndFeaturesResult + FeatureResults ..> PolygonLegendAndFeauturesResult + FeatureResults ..> LineLegendAndFeaturesResult + FeatureResults ..> Area_Extraction + + +``` + +
+ +### Point Feature + +
+ point feature + +```mermaid +classDiagram + + class PointLegendAndFeaturesResult { + id: str + crs: str + cdr_projection_id: Optional[str] + name: Optional[str] + description: Optional[str] + legend_bbox: Optional[list[Union[float, int]]] + point_features: Optional[list[PointFeatureCollection]] + } + + class GeomType { + <> + Point: str = 'Point' + LineString: str = 'LineString' + Polygon: str = 'Polygon' + } + + class PointFeature { + type: GeoJsonType = GeoJsonType.Feature + id: str + geometry: Point + properties: PointProperties + } + + class Point { + coordinates: list[Union[float, int]] + type: GeomType = GeomType.Point + } + + class PointProperties { + model: Optional[str] + model_version: Optional[str] + confidence: Optional[float] + bbox: Optional[list[Union[float, int]]] + dip: Optional[int] + dip_direction: Optional[int] + } + + class PointFeatureCollection { + type: GeoJsonType = GeoJsonType.FeatureCollection + features: list[PointFeature] + } + + class GeoJsonType { + <> + Feature: str = 'Feature' + FeatureCollection: str = 'FeatureCollection' + } + + Point ..> GeomType + PointFeature ..> PointProperties + PointFeature ..> Point + PointFeature ..> GeoJsonType + PointFeatureCollection ..> PointFeature + PointFeatureCollection ..> GeoJsonType + PointLegendAndFeaturesResult ..> PointFeatureCollection + + +``` + +
+ +### Line Feature + +
+ line feature + +```mermaid +classDiagram + + class LineProperty { + model: Optional[str] + model_version: Optional[str] + confidence: Optional[float] + dash_pattern: Optional[DashType] = None + symbol: Optional[str] + } + + class LineFeature { + type: GeoJsonType = GeoJsonType.Feature + id: str + geometry: Line + properties: LineProperty + } + + class Line { + coordinates: list[list[Union[float, int]]] + type: GeomType = GeomType.LineString + } + + class DashType { + <> + solid: str = 'solid' + dash: str = 'dash' + dotted: str = 'dotted' + } + + class GeoJsonType { + <> + Feature: str = 'Feature' + FeatureCollection: str = 'FeatureCollection' + } + + class GeomType { + <> + Point: str = 'Point' + LineString: str = 'LineString' + Polygon: str = 'Polygon' + } + + class LineLegendAndFeaturesResult { + id: str + crs: str + cdr_projection_id: Optional[str] + name: Optional[str] + description: Optional[str] + legend_bbox: Optional[list[Union[float, int]]] + line_features: Optional[LineFeatureCollection] + } + + class LineFeatureCollection { + type: GeoJsonType = GeoJsonType.FeatureCollection + features: Optional[list[LineFeature]] + } + + Line ..> GeomType + LineProperty ..> DashType + LineFeature ..> Line + LineFeature ..> LineProperty + LineFeature ..> GeoJsonType + LineFeatureCollection ..> LineFeature + LineFeatureCollection ..> GeoJsonType + LineLegendAndFeaturesResult ..> LineFeatureCollection + + +``` + +
+ +### Polygon Feature + +
+ polygon feature + +```mermaid +classDiagram + + class PolygonFeatureCollection { + type: GeoJsonType = GeoJsonType.FeatureCollection + features: Optional[list[PolygonFeature]] + } + + class PolygonProperty { + model: Optional[str] + model_version: Optional[str] + confidence: Optional[float] + } + + class PolygonFeature { + type: GeoJsonType = GeoJsonType.Feature + id: str + geometry: Polygon + properties: PolygonProperty + } + + class GeoJsonType { + <> + Feature: str = 'Feature' + FeatureCollection: str = 'FeatureCollection' + } + + class GeomType { + <> + Point: str = 'Point' + LineString: str = 'LineString' + Polygon: str = 'Polygon' + } + + class MapUnit { + age_text: Optional[str] + b_age: Optional[float] + b_interval: Optional[str] + lithology: Optional[str] + name: Optional[str] + t_age: Optional[float] + t_interval: Optional[str] + comments: Optional[str] + } + + class PolygonLegendAndFeauturesResult { + id: str + crs: str + cdr_projection_id: Optional[str] + map_unit: Optional[MapUnit] + abbreviation: Optional[str] + legend_bbox: Optional[list[Union[float, int]]] + category: Optional[str] + color: Optional[str] + description: Optional[str] + pattern: Optional[str] + polygon_features: Optional[PolygonFeatureCollection] + } + + class Polygon { + coordinates: list[list[list[Union[float, int]]]] + type: GeomType = GeomType.Polygon + } + + Polygon ..> GeomType + PolygonFeature ..> PolygonProperty + PolygonFeature ..> Polygon + PolygonFeature ..> GeoJsonType + PolygonFeatureCollection ..> PolygonFeature + PolygonFeatureCollection ..> GeoJsonType + PolygonLegendAndFeauturesResult ..> MapUnit + PolygonLegendAndFeauturesResult ..> PolygonFeatureCollection ``` diff --git a/cdr_schemas/feature_results.py b/cdr_schemas/feature_results.py index 580af6a..18f2a49 100644 --- a/cdr_schemas/feature_results.py +++ b/cdr_schemas/feature_results.py @@ -3,9 +3,9 @@ from pydantic import BaseModel, Field from cdr_schemas.area_extraction import Area_Extraction -from cdr_schemas.line_features import LineLegendAndFeaturesResult -from cdr_schemas.point_features import PointLegendAndFeaturesResult -from cdr_schemas.polygon_features import PolygonLegendAndFeauturesResult +from cdr_schemas.features.line_features import LineLegendAndFeaturesResult +from cdr_schemas.features.point_features import PointLegendAndFeaturesResult +from cdr_schemas.features.polygon_features import PolygonLegendAndFeauturesResult class FeatureResults(BaseModel): diff --git a/cdr_schemas/line_features.py b/cdr_schemas/features/line_features.py similarity index 70% rename from cdr_schemas/line_features.py rename to cdr_schemas/features/line_features.py index c0fb921..75bbffd 100644 --- a/cdr_schemas/line_features.py +++ b/cdr_schemas/features/line_features.py @@ -1,5 +1,5 @@ from enum import Enum -from typing import List, Literal, Optional, Union +from typing import List, Optional, Union from pydantic import BaseModel, ConfigDict, Field @@ -7,9 +7,9 @@ class DashType(str, Enum): - Point = "solid" - LineString = "dash" - Polygon = "dotted" + solid = "solid" + dash = "dash" + dotted = "dotted" class Line(BaseModel): @@ -18,7 +18,7 @@ class Line(BaseModel): """ coordinates: List[List[Union[float, int]]] - type: str = Field(default=GeomType.LineString) + type: GeomType = GeomType.LineString class LineProperty(BaseModel): @@ -26,7 +26,6 @@ class LineProperty(BaseModel): Properties of the line. """ - id: str = Field(description="your internal id") model: Optional[str] = Field(description="model name used for extraction") model_version: Optional[str] = Field( description="model version used for extraction" @@ -34,6 +33,10 @@ class LineProperty(BaseModel): confidence: Optional[float] = Field( description="The prediction probability from the ML model" ) + dash_pattern: Optional[DashType] = Field( + default=None, description="values = {solid, dash, dotted}" + ) + symbol: Optional[str] model_config = ConfigDict(protected_namespaces=()) @@ -43,7 +46,11 @@ class LineFeature(BaseModel): Line Feature. """ - type: str = GeoJsonType.Feature + type: GeoJsonType = GeoJsonType.Feature + id: str = Field( + description="""Each line geometry has a unique id. + The ids are used to link the line geometries is px-coord and geo-coord.""" + ) geometry: Line properties: LineProperty @@ -53,7 +60,7 @@ class LineFeatureCollection(BaseModel): All line features for legend item. """ - type: Literal[GeoJsonType.FeatureCollection] = GeoJsonType.FeatureCollection + type: GeoJsonType = GeoJsonType.FeatureCollection features: Optional[List[LineFeature]] @@ -63,12 +70,14 @@ class LineLegendAndFeaturesResult(BaseModel): """ id: str = Field(description="your internal id") - name: Optional[str] - dash_pattern: Optional[DashType] = Field( - default=None, description="values = {solid, dash, dotted}" + crs: str = Field(description="values={CRITICALMAAS:pixel, EPSG:*}") + cdr_projection_id: Optional[str] = Field( + description=""" + A cdr projection id used to georeference the features + """ ) + name: Optional[str] description: Optional[str] - symbol: Optional[str] legend_bbox: Optional[List[Union[float, int]]] = Field( description="""The extacted bounding box of the legend item. Column value from left, row value from bottom.""" diff --git a/cdr_schemas/point_features.py b/cdr_schemas/features/point_features.py similarity index 69% rename from cdr_schemas/point_features.py rename to cdr_schemas/features/point_features.py index ac8d231..b5c9ff6 100644 --- a/cdr_schemas/point_features.py +++ b/cdr_schemas/features/point_features.py @@ -1,6 +1,6 @@ -from typing import List, Literal, Optional, Union +from typing import List, Optional, Union -from pydantic import BaseModel, Field +from pydantic import BaseModel, ConfigDict, Field from cdr_schemas.common import GeoJsonType, GeomType @@ -11,7 +11,7 @@ class Point(BaseModel): """ coordinates: List[Union[float, int]] - type: str = Field(default=GeomType.Point) + type: GeomType = GeomType.Point class PointProperties(BaseModel): @@ -19,7 +19,6 @@ class PointProperties(BaseModel): Properties of the Point. """ - id: str = Field(description="your internal id") model: Optional[str] = Field(description="model name used for extraction") model_version: Optional[str] = Field( description="model version used for extraction" @@ -34,13 +33,19 @@ class PointProperties(BaseModel): dip: Optional[int] dip_direction: Optional[int] + model_config = ConfigDict(protected_namespaces=()) + class PointFeature(BaseModel): """ Point feature. """ - type: Literal[GeoJsonType.Feature] = GeoJsonType.Feature + type: GeoJsonType = GeoJsonType.Feature + id: str = Field( + description="""Each point geometry has a unique id. + The ids are used to link the point geometries is px-coord and geo-coord.""" + ) geometry: Point properties: PointProperties @@ -50,7 +55,7 @@ class PointFeatureCollection(BaseModel): All point features for legend item. """ - type: Literal[GeoJsonType.FeatureCollection] = GeoJsonType.FeatureCollection + type: GeoJsonType = GeoJsonType.FeatureCollection features: List[PointFeature] @@ -60,6 +65,12 @@ class PointLegendAndFeaturesResult(BaseModel): """ id: str = Field(description="your internal id") + crs: str = Field(description="values={CRITICALMAAS:pixel, EPSG:*}") + cdr_projection_id: Optional[str] = Field( + description=""" + A cdr projection id used to georeference the features + """ + ) name: Optional[str] = Field(description="name of legend item") description: Optional[str] legend_bbox: Optional[List[Union[float, int]]] = Field( diff --git a/cdr_schemas/polygon_features.py b/cdr_schemas/features/polygon_features.py similarity index 75% rename from cdr_schemas/polygon_features.py rename to cdr_schemas/features/polygon_features.py index 8f50a49..1572504 100644 --- a/cdr_schemas/polygon_features.py +++ b/cdr_schemas/features/polygon_features.py @@ -1,4 +1,4 @@ -from typing import List, Literal, Optional, Union +from typing import List, Optional, Union from pydantic import BaseModel, ConfigDict, Field @@ -11,7 +11,7 @@ class Polygon(BaseModel): """ coordinates: List[List[List[Union[float, int]]]] - type: str = Field(default=GeomType.Polygon) + type: GeomType = GeomType.Polygon class PolygonProperty(BaseModel): @@ -19,7 +19,6 @@ class PolygonProperty(BaseModel): Properties of the polygon. """ - id: str = Field(description="your internal id") model: Optional[str] = Field(description="model name used for extraction") model_version: Optional[str] = Field( description="model version used for extraction" @@ -36,7 +35,11 @@ class PolygonFeature(BaseModel): Polygon feature. """ - type: str = GeoJsonType.Feature + type: GeoJsonType = GeoJsonType.Feature + id: str = Field( + description="""Each polygon geometry has a unique id. + The ids are used to link the polygon geometries is px-coord and geo-coord.""" + ) geometry: Polygon properties: PolygonProperty @@ -46,7 +49,7 @@ class PolygonFeatureCollection(BaseModel): All polygon features for legend item. """ - type: Literal[GeoJsonType.FeatureCollection] = GeoJsonType.FeatureCollection + type: GeoJsonType = GeoJsonType.FeatureCollection features: Optional[List[PolygonFeature]] @@ -58,7 +61,6 @@ class MapUnit(BaseModel): age_text: Optional[str] b_age: Optional[float] b_interval: Optional[str] - description: Optional[str] lithology: Optional[str] name: Optional[str] t_age: Optional[float] @@ -72,6 +74,12 @@ class PolygonLegendAndFeauturesResult(BaseModel): """ id: str = Field(description="your internal id") + crs: str = Field(description="values={CRITICALMAAS:pixel, EPSG:*}") + cdr_projection_id: Optional[str] = Field( + description=""" + A cdr projection id used to georeference the features + """ + ) map_unit: Optional[MapUnit] abbreviation: Optional[str] legend_bbox: Optional[List[Union[float, int]]] = Field( diff --git a/dev/docs.py b/dev/docs.py index 2e2296f..7544b99 100644 --- a/dev/docs.py +++ b/dev/docs.py @@ -6,6 +6,10 @@ from pydantic_mermaid import MermaidGenerator import cdr_schemas.events +import cdr_schemas.feature_results +import cdr_schemas.features.line_features +import cdr_schemas.features.point_features +import cdr_schemas.features.polygon_features import cdr_schemas.georeference import cdr_schemas.metadata @@ -45,6 +49,10 @@ def run(): modules = [ Module(title="georeference", ref=cdr_schemas.georeference), Module(title="metadata", ref=cdr_schemas.metadata), + Module(title="feature results", ref=cdr_schemas.feature_results), + Module(title="point feature", ref=cdr_schemas.features.point_features), + Module(title="line feature", ref=cdr_schemas.features.line_features), + Module(title="polygon feature", ref=cdr_schemas.features.polygon_features), ] for m in modules: