From d1651ad1c05bfd7be7fbb908ca84e4db17d9d65b Mon Sep 17 00:00:00 2001 From: marshHawk4 Date: Fri, 21 Jun 2024 12:00:43 -0400 Subject: [PATCH] Cdr response objects (#37) * Adding CDR response objects --- cdr_schemas/cdr_responses/area_extractions.py | 48 +++++++ cdr_schemas/cdr_responses/features.py | 133 ++++++++++++++++++ cdr_schemas/cdr_responses/legend_items.py | 61 ++++++++ pyproject.toml | 5 +- 4 files changed, 245 insertions(+), 2 deletions(-) create mode 100644 cdr_schemas/cdr_responses/area_extractions.py create mode 100644 cdr_schemas/cdr_responses/features.py create mode 100644 cdr_schemas/cdr_responses/legend_items.py diff --git a/cdr_schemas/cdr_responses/area_extractions.py b/cdr_schemas/cdr_responses/area_extractions.py new file mode 100644 index 0000000..e12054f --- /dev/null +++ b/cdr_schemas/cdr_responses/area_extractions.py @@ -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. + """, + ) diff --git a/cdr_schemas/cdr_responses/features.py b/cdr_schemas/cdr_responses/features.py new file mode 100644 index 0000000..d36abe6 --- /dev/null +++ b/cdr_schemas/cdr_responses/features.py @@ -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.", + ) diff --git a/cdr_schemas/cdr_responses/legend_items.py b/cdr_schemas/cdr_responses/legend_items.py new file mode 100644 index 0000000..33b634a --- /dev/null +++ b/cdr_schemas/cdr_responses/legend_items.py @@ -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", + ) diff --git a/pyproject.toml b/pyproject.toml index 21d8e86..fe50db2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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]