|
30 | 30 | CoordinateSystem, |
31 | 31 | ImageClassification, |
32 | 32 | LineAnnotation, |
| 33 | + NumericAnnotation, |
33 | 34 | annotation_from_dict, |
34 | 35 | ) |
35 | 36 | from datamint.exceptions import ItemNotFoundError, ServerError |
@@ -1151,6 +1152,46 @@ def create_image_classification(self, |
1151 | 1152 | raise TypeError('Expected a single annotation id for image classification creation.') |
1152 | 1153 | return created |
1153 | 1154 |
|
| 1155 | + def create_numeric_annotation(self, |
| 1156 | + resource: str | Resource, |
| 1157 | + identifier: str, |
| 1158 | + value: int | float, |
| 1159 | + units: str | None = None, |
| 1160 | + imported_from: str | None = None, |
| 1161 | + model_id: str | None = None, |
| 1162 | + source: str | None = 'imported', |
| 1163 | + ) -> str: |
| 1164 | + """ |
| 1165 | + Create a numeric value annotation (e.g. a measurement or count). |
| 1166 | +
|
| 1167 | + Args: |
| 1168 | + resource: The resource unique id or Resource instance. |
| 1169 | + identifier: The annotation identifier/label. |
| 1170 | + value: The numeric value. ``int`` maps to :attr:`AnnotationType.INTEGER`, |
| 1171 | + ``float`` maps to :attr:`AnnotationType.FLOAT`. |
| 1172 | + units: Optional unit label for the value (e.g. 'years', 'mm'). |
| 1173 | + imported_from: The imported from source value. |
| 1174 | + model_id: The model unique id. |
| 1175 | + source: Annotation source tag. Defaults to 'imported' since this is a direct API |
| 1176 | + entry point; :meth:`upload_predictions` overrides it with 'model_pipeline'/'model_deploy'. |
| 1177 | +
|
| 1178 | + Returns: |
| 1179 | + The id of the created annotation. |
| 1180 | + """ |
| 1181 | + annotation = NumericAnnotation( |
| 1182 | + name=identifier, |
| 1183 | + value=value, |
| 1184 | + units=units, |
| 1185 | + imported_from=imported_from, |
| 1186 | + model_id=model_id, |
| 1187 | + source=source, |
| 1188 | + ) |
| 1189 | + |
| 1190 | + created = self.create(resource, annotation) |
| 1191 | + if not isinstance(created, str): |
| 1192 | + raise TypeError('Expected a single annotation id for numeric annotation creation.') |
| 1193 | + return created |
| 1194 | + |
1154 | 1195 | def upload_predictions( |
1155 | 1196 | self, |
1156 | 1197 | resource: str | Resource, |
|
0 commit comments