Skip to content

Commit b720a1a

Browse files
authored
Merge pull request #18 from ImageMarkup/isic-162-add-tbp-tile-type
2 parents 8c7b33e + 1fa9a15 commit b720a1a

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

isic_metadata/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
MelType,
1919
NevusType,
2020
Sex,
21+
TBPTileType,
2122
)
2223

2324
try:
@@ -26,7 +27,6 @@
2627
# package is not installed
2728
pass
2829

29-
3030
FIELD_REGISTRY = {}
3131

3232
for field in [
@@ -55,6 +55,7 @@
5555
("nevus_type", NevusType),
5656
("image_type", ImageType),
5757
("dermoscopic_type", DermoscopicType),
58+
("tbp_tile_type", TBPTileType),
5859
("mel_type", MelType),
5960
("mel_class", MelClass),
6061
("mel_mitotic_index", MelMitoticIndex),

isic_metadata/fields.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,20 @@ def validate(cls, value: str) -> Optional[str]:
211211
return value
212212

213213

214+
class TBPTileTypeEnum(str, Enum):
215+
tbp_3d_white = "3D: white"
216+
tbp_3d_xp = "3D: XP"
217+
tbp_2d = "2D"
218+
219+
220+
class TBPTileType(BaseStr):
221+
@classmethod
222+
def validate(cls, value: str) -> Optional[str]:
223+
if value not in TBPTileTypeEnum._value2member_map_:
224+
raise ValueError(f"Invalid TBP tile type of: {value}.")
225+
return value
226+
227+
214228
class MelTypeEnum(str, Enum):
215229
superficial_spreading_melanoma = "superficial spreading melanoma"
216230
nodular_melanoma = "nodular melanoma"

isic_metadata/metadata.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
MelTypeEnum,
3535
NevusTypeEnum,
3636
Sex,
37+
TBPTileTypeEnum,
3738
)
3839

3940

@@ -123,6 +124,9 @@ class MetadataRow(BaseModel):
123124
DermoscopicTypeEnum, EnumErrorMessageValidator(DermoscopicTypeEnum, "dermoscopic_type")
124125
]
125126
] = None
127+
tbp_tile_type: Optional[
128+
Annotated[TBPTileTypeEnum, EnumErrorMessageValidator(TBPTileTypeEnum, "tbp_tile_type")]
129+
] = None
126130
anatom_site_general: Optional[
127131
Annotated[
128132
AnatomSiteGeneralEnum,
@@ -261,3 +265,17 @@ def validate_dermoscopic_fields(cls, v, info: FieldValidationInfo):
261265
f"Image type {image_type or 'None'} inconsistent with dermoscopic type '{v.value}'."
262266
)
263267
return v
268+
269+
@field_validator("tbp_tile_type")
270+
@classmethod
271+
def validate_tbp_tile_fields(cls, v, info: FieldValidationInfo):
272+
if (
273+
info.data.get("image_type")
274+
not in [ImageTypeEnum.tbp_tile_close_up, ImageTypeEnum.tbp_tile_overview]
275+
and v
276+
):
277+
image_type = info.data.get("tbp_tile_type", "")
278+
raise ValueError(
279+
f"Image type {image_type or 'None'} inconsistent with TBP tile type '{v.value}'."
280+
)
281+
return v

tests/test_dependent_fields.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,13 @@ def test_dermoscopic_type_requires_image_type_dermoscopic():
9595
assert excinfo.value.errors()[0]["loc"][0] == "dermoscopic_type"
9696

9797
MetadataRow(dermoscopic_type="contact polarized", image_type="dermoscopic")
98+
99+
100+
def test_tbp_tile_type_requires_image_type_tbp_tile():
101+
with pytest.raises(ValidationError) as excinfo:
102+
MetadataRow(tbp_tile_type="2D")
103+
assert len(excinfo.value.errors()) == 1
104+
assert excinfo.value.errors()[0]["loc"][0] == "tbp_tile_type"
105+
106+
MetadataRow(tbp_tile_type="2D", image_type="TBP tile: close-up")
107+
MetadataRow(tbp_tile_type="2D", image_type="TBP tile: overview")

0 commit comments

Comments
 (0)