Skip to content

Commit

Permalink
Cdr response objects (#37)
Browse files Browse the repository at this point in the history
* Adding CDR response objects
  • Loading branch information
marshHawk4 authored Jun 21, 2024
1 parent 3734554 commit d1651ad
Show file tree
Hide file tree
Showing 4 changed files with 245 additions and 2 deletions.
48 changes: 48 additions & 0 deletions cdr_schemas/cdr_responses/area_extractions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from typing import List, Optional, Union

from pydantic import BaseModel, Field

from cdr_schemas.area_extraction import AreaType
from cdr_schemas.cdr_responses.features import ProjectedFeature
from cdr_schemas.features.polygon_features import Polygon


class AreaExtractionResponse(BaseModel):
area_extraction_id: str = Field(default="", description="Area extraction id")
cog_id: str = Field(default="", description="Cog id")
reference_id: Union[str, None] = Field(
default=None, description="Legend id of older version of this legend item."
)
px_bbox: List[Union[float, int]] = Field(
default_factory=list,
description="""The rough 2 point bounding box of the item.
Format is expected to be [x1,y1,x2,y2].""",
)
px_geojson: Optional[Polygon]
system: str = Field(default="", description="System that published this item")
system_version: str = Field(
default="", description="System version that published this item"
)
model_id: str = Field(
default="", description="Model id for the model used to generate this item"
)
validated: bool = Field(default=False, description="Validated by human")
confidence: Optional[float] = None
category: AreaType = Field(
...,
description="""
The type of area extraction.
""",
)
text: str = Field(
default="",
description="""
The text within the extraction area.
""",
)
projected_feature: List[ProjectedFeature] = Field(
default_factory=list,
description="""
List of projected versions of this feature. Probably will only be one result.
""",
)
133 changes: 133 additions & 0 deletions cdr_schemas/cdr_responses/features.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
from typing import Any, List, Optional, Union

from pydantic import BaseModel, Field

from cdr_schemas.features.line_features import Line
from cdr_schemas.features.point_features import Point
from cdr_schemas.features.polygon_features import Polygon


class ProjectedFeature(BaseModel):
cdr_projection_id: str = Field(
description="CDR projection id used for creating transform"
)
feature_type: str = Field(description="Feature type. E.g. polygon, point, line")
projected_geojson: Optional[Union[Polygon, Point, Line]] = Field(
description="Projected geojson in EPSG 4326"
)
projected_bbox: List[Union[float, int]] = Field(
default_factory=list, description="Projected bbox in EPSG 4326"
)


class PolygonExtractionResponse(BaseModel):
polygon_id: str = Field(default="", description="CDR polygon id")
cog_id: str = Field(default="", description="Cog id")
px_bbox: List[Union[float, int]] = Field(
default_factory=list,
description="""The rough 2 point bounding box of the item.
Format is expected to be [x1,y1,x2,y2].""",
)
px_geojson: Polygon
reference_id: Union[str, None] = Field(
default=None, description="Polygon id of older version of this polygon."
)
confidence: Optional[float] = None
model_id: str = Field(
default="", description="CDR model id for the model used to generate this item"
)
system: str = Field(default="", description="System that published this item")
system_version: str = Field(
default="", description="System version that published this item"
)
validated: bool = Field(default=False, description="Validated by human")
legend_id: str = Field(default="", description="Associated CDR legend id")
projected_feature: List[ProjectedFeature] = Field(
default_factory=list,
description="""
List of projected versions of this feature. Probably will only be one result.
""",
)
legend_item: Optional[Any] = Field(
default=None,
description="Some CDR endpoints can allow legend item data attached to each feature.",
)


class PointExtractionResponse(BaseModel):
point_id: str = Field(default="", description="CDR point id")
cog_id: str = Field(default="", description="Cog id")
px_bbox: List[Union[float, int]] = Field(
default_factory=list,
description="""The rough 2 point bounding box of the item.
Format is expected to be [x1,y1,x2,y2].""",
)
px_geojson: Point
dip: Optional[Union[int, None]] = Field(
default=None, description="Point dip value."
)
dip_direction: Optional[Union[int, None]] = Field(
default=None, description="Point dip direction value."
)
reference_id: Union[str, None] = Field(
default=None, description="Point id of older version of this point."
)
confidence: Optional[float] = None
model_id: str = Field(
default="",
description="""
Model id associated with the model and version used to generate this item
""",
)
system: str = Field(default="", description="System that published this item")
system_version: str = Field(
default="", description="System Version that published this item"
)
validated: bool = Field(default=False, description="Validated by human")
legend_id: str = Field(default="", description="Associated legend id")
projected_feature: List[ProjectedFeature] = Field(
default_factory=list,
description="""
List of projected versions of this feature. Probably will only be one result.
""",
)
legend_item: Optional[Any] = Field(
default=None,
description="Some CDR endpoints can allow legend item data attached to each feature",
)


class LineExtractionResponse(BaseModel):
line_id: str = Field(default="", description="CDR line id")
cog_id: str = Field(default="", description="Cog id")
px_bbox: List[Union[float, int]] = Field(
default_factory=list,
description="""The rough 2 point bounding box of the item.
Format is expected to be [x1,y1,x2,y2].""",
)
px_geojson: Line
dash_pattern: str = Field(default="", description="Dash pattern of line")
symbol: str = Field(default="", description="Symbol on line")
reference_id: Union[str, None] = Field(
default=None, description="Line id of older version of this line."
)
confidence: Optional[float] = None
model_id: str = Field(
default="", description="model id for the model used to generate this item"
)
system: str = Field(default="", description="System that published this item")
system_version: str = Field(
default="", description="System version that published this item"
)
validated: bool = Field(default=False, description="Validated by human")
legend_id: str = Field(default="", description="Associated legend id")
projected_feature: List[ProjectedFeature] = Field(
default_factory=list,
description="""
List of projected versions of this feature. Probably will only be one result.
""",
)
legend_item: Optional[Any] = Field(
default=None,
description="Some CDR endpoints can allow a legend item data attached to each feature.",
)
61 changes: 61 additions & 0 deletions cdr_schemas/cdr_responses/legend_items.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from typing import List, Optional, Union

from pydantic import BaseModel, Field

from cdr_schemas.cdr_responses.features import (
LineExtractionResponse,
PointExtractionResponse,
PolygonExtractionResponse,
)
from cdr_schemas.features.polygon_features import Polygon


class LegendItemResponse(BaseModel):
legend_id: str = Field(default="", description="CDR legend id")
abbreviation: str = Field(default="", description="Abbreviation of legend item")
description: str = Field(default="", description="Legend item description")
color: str = Field(default="", description="Color")
reference_id: Union[str, None] = Field(
default=None, description="Legend id of older version of this legend item."
)
label: str = Field(default="", description="Label of legend item")
pattern: str = Field(
default="",
description="If category of type polygon this can be filled in with pattern type",
)
px_bbox: List[Union[float, int]] = Field(
default_factory=list,
description="""The rough 2 point bounding box of the item.
Format is expected to be [x1,y1,x2,y2].""",
)
px_geojson: Optional[Polygon]
cog_id: str = Field(default="", description="Cog id")
category: str = Field(
default="", description="Category of legend item. Polygon, point, or line."
)
system: str = Field(default="", description="System that published this item")
system_version: str = Field(
default="", description="System version that published this item"
)
model_id: str = Field(
default="", description="Model id for the model used to generate this item"
)
validated: bool = Field(default=False, description="Validated by human")
confidence: Optional[float] = None
map_unit_age_text: str = Field(default="", description="Age of map unit")
map_unit_lithology: str = Field(default="", description="Map unit lithology")
map_unit_b_age: Optional[float] = None
map_unit_t_age: Optional[float] = None

point_extractions: List[PointExtractionResponse] = Field(
default_factory=list,
description="Optionally added point extractions associated with this legend item",
)
polygon_extractions: List[PolygonExtractionResponse] = Field(
default_factory=list,
description="Optionally added polygon extractions associated with this legend item",
)
line_extractions: List[LineExtractionResponse] = Field(
default_factory=list,
description="Optionally added line extractions associated with this legend item",
)
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
[tool.poetry]
name = "cdr_schemas"
version = "0.2.9"
version = "0.3.0"
description = "CDR Schemas"
authors = []
readme = "README.md"
packages = [
{include = "cdr_schemas"},
{include = "cdr_schemas/**/*.py"}
{include = "cdr_schemas/**/*.py"},
{include = "cdr_schemas/**/**/*.py"}
]

[tool.poetry.dependencies]
Expand Down

0 comments on commit d1651ad

Please sign in to comment.