bioimageio.spec.dataset.v0_3
1from typing import TYPE_CHECKING, Any, ClassVar, Dict, Literal, Optional, cast 2 3from pydantic import model_validator 4 5from .._internal.common_nodes import InvalidDescr 6from .._internal.io import FileDescr as FileDescr 7from .._internal.io_basics import AbsoluteFilePath as AbsoluteFilePath 8from .._internal.io_basics import Sha256 as Sha256 9from .._internal.url import HttpUrl as HttpUrl 10from ..generic.v0_3 import VALID_COVER_IMAGE_EXTENSIONS as VALID_COVER_IMAGE_EXTENSIONS 11from ..generic.v0_3 import Author as Author 12from ..generic.v0_3 import BadgeDescr as BadgeDescr 13from ..generic.v0_3 import BioimageioConfig as BioimageioConfig 14from ..generic.v0_3 import CiteEntry as CiteEntry 15from ..generic.v0_3 import Config as Config 16from ..generic.v0_3 import DeprecatedLicenseId as DeprecatedLicenseId 17from ..generic.v0_3 import ( 18 DocumentationSource, 19 GenericDescrBase, 20 LinkedResourceBase, 21 _author_conv, # pyright: ignore[reportPrivateUsage] 22 _maintainer_conv, # pyright: ignore[reportPrivateUsage] 23) 24from ..generic.v0_3 import Doi as Doi 25from ..generic.v0_3 import LicenseId as LicenseId 26from ..generic.v0_3 import LinkedResource as LinkedResource 27from ..generic.v0_3 import Maintainer as Maintainer 28from ..generic.v0_3 import OrcidId as OrcidId 29from ..generic.v0_3 import RelativeFilePath as RelativeFilePath 30from ..generic.v0_3 import ResourceId as ResourceId 31from ..generic.v0_3 import Uploader as Uploader 32from ..generic.v0_3 import Version as Version 33from .v0_2 import DatasetDescr as DatasetDescr02 34 35 36class DatasetId(ResourceId): 37 pass 38 39 40class DatasetDescr(GenericDescrBase): 41 """A bioimage.io dataset resource description file (dataset RDF) describes a dataset relevant to bioimage 42 processing. 43 """ 44 45 implemented_type: ClassVar[Literal["dataset"]] = "dataset" 46 if TYPE_CHECKING: 47 type: Literal["dataset"] = "dataset" 48 else: 49 type: Literal["dataset"] 50 51 id: Optional[DatasetId] = None 52 """bioimage.io-wide unique resource identifier 53 assigned by bioimage.io; version **un**specific.""" 54 55 parent: Optional[DatasetId] = None 56 """The description from which this one is derived""" 57 58 source: Optional[HttpUrl] = None 59 """"URL to the source of the dataset.""" 60 61 @model_validator(mode="before") 62 @classmethod 63 def _convert(cls, data: Dict[str, Any], /) -> Dict[str, Any]: 64 if ( 65 data.get("type") == "dataset" 66 and isinstance(fv := data.get("format_version"), str) 67 and fv.startswith("0.2.") 68 ): 69 old = DatasetDescr02.load(data) 70 if isinstance(old, InvalidDescr): 71 return data 72 73 return cast( 74 Dict[str, Any], 75 (cls if TYPE_CHECKING else dict)( 76 attachments=( 77 [] 78 if old.attachments is None 79 else [FileDescr(source=f) for f in old.attachments.files] 80 ), 81 authors=[ 82 _author_conv.convert_as_dict(a) for a in old.authors 83 ], # pyright: ignore[reportArgumentType] 84 badges=old.badges, 85 cite=[ 86 {"text": c.text, "doi": c.doi, "url": c.url} for c in old.cite 87 ], # pyright: ignore[reportArgumentType] 88 config=old.config, # pyright: ignore[reportArgumentType] 89 covers=old.covers, 90 description=old.description, 91 documentation=cast(DocumentationSource, old.documentation), 92 format_version="0.3.0", 93 git_repo=old.git_repo, # pyright: ignore[reportArgumentType] 94 icon=old.icon, 95 id=None if old.id is None else DatasetId(old.id), 96 license=old.license, # type: ignore 97 links=old.links, 98 maintainers=[ 99 _maintainer_conv.convert_as_dict(m) for m in old.maintainers 100 ], # pyright: ignore[reportArgumentType] 101 name=old.name, 102 source=old.source, 103 tags=old.tags, 104 type=old.type, 105 uploader=old.uploader, 106 version=old.version, 107 **(old.model_extra or {}), 108 ), 109 ) 110 111 return data 112 113 114class LinkedDataset(LinkedResourceBase): 115 """Reference to a bioimage.io dataset.""" 116 117 id: DatasetId 118 """A valid dataset `id` from the bioimage.io collection."""
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
Inherited Members
41class DatasetDescr(GenericDescrBase): 42 """A bioimage.io dataset resource description file (dataset RDF) describes a dataset relevant to bioimage 43 processing. 44 """ 45 46 implemented_type: ClassVar[Literal["dataset"]] = "dataset" 47 if TYPE_CHECKING: 48 type: Literal["dataset"] = "dataset" 49 else: 50 type: Literal["dataset"] 51 52 id: Optional[DatasetId] = None 53 """bioimage.io-wide unique resource identifier 54 assigned by bioimage.io; version **un**specific.""" 55 56 parent: Optional[DatasetId] = None 57 """The description from which this one is derived""" 58 59 source: Optional[HttpUrl] = None 60 """"URL to the source of the dataset.""" 61 62 @model_validator(mode="before") 63 @classmethod 64 def _convert(cls, data: Dict[str, Any], /) -> Dict[str, Any]: 65 if ( 66 data.get("type") == "dataset" 67 and isinstance(fv := data.get("format_version"), str) 68 and fv.startswith("0.2.") 69 ): 70 old = DatasetDescr02.load(data) 71 if isinstance(old, InvalidDescr): 72 return data 73 74 return cast( 75 Dict[str, Any], 76 (cls if TYPE_CHECKING else dict)( 77 attachments=( 78 [] 79 if old.attachments is None 80 else [FileDescr(source=f) for f in old.attachments.files] 81 ), 82 authors=[ 83 _author_conv.convert_as_dict(a) for a in old.authors 84 ], # pyright: ignore[reportArgumentType] 85 badges=old.badges, 86 cite=[ 87 {"text": c.text, "doi": c.doi, "url": c.url} for c in old.cite 88 ], # pyright: ignore[reportArgumentType] 89 config=old.config, # pyright: ignore[reportArgumentType] 90 covers=old.covers, 91 description=old.description, 92 documentation=cast(DocumentationSource, old.documentation), 93 format_version="0.3.0", 94 git_repo=old.git_repo, # pyright: ignore[reportArgumentType] 95 icon=old.icon, 96 id=None if old.id is None else DatasetId(old.id), 97 license=old.license, # type: ignore 98 links=old.links, 99 maintainers=[ 100 _maintainer_conv.convert_as_dict(m) for m in old.maintainers 101 ], # pyright: ignore[reportArgumentType] 102 name=old.name, 103 source=old.source, 104 tags=old.tags, 105 type=old.type, 106 uploader=old.uploader, 107 version=old.version, 108 **(old.model_extra or {}), 109 ), 110 ) 111 112 return data
A bioimage.io dataset resource description file (dataset RDF) describes a dataset relevant to bioimage processing.
bioimage.io-wide unique resource identifier assigned by bioimage.io; version unspecific.
124 def wrapped_model_post_init(self: BaseModel, context: Any, /) -> None: 125 """We need to both initialize private attributes and call the user-defined model_post_init 126 method. 127 """ 128 init_private_attributes(self, context) 129 original_model_post_init(self, context)
We need to both initialize private attributes and call the user-defined model_post_init method.
Inherited Members
115class LinkedDataset(LinkedResourceBase): 116 """Reference to a bioimage.io dataset.""" 117 118 id: DatasetId 119 """A valid dataset `id` from the bioimage.io collection."""
Reference to a bioimage.io dataset.