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 Sha256 as Sha256 8from .._internal.types import FAIR 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 Doi as Doi 18from ..generic.v0_3 import ( 19 GenericDescrBase, 20 LinkedResourceBase, 21 _author_conv, # pyright: ignore[reportPrivateUsage] 22 _maintainer_conv, # pyright: ignore[reportPrivateUsage] 23) 24from ..generic.v0_3 import LicenseId as LicenseId 25from ..generic.v0_3 import LinkedResource as LinkedResource 26from ..generic.v0_3 import Maintainer as Maintainer 27from ..generic.v0_3 import OrcidId as OrcidId 28from ..generic.v0_3 import RelativeFilePath as RelativeFilePath 29from ..generic.v0_3 import ResourceId as ResourceId 30from ..generic.v0_3 import Uploader as Uploader 31from ..generic.v0_3 import Version as Version 32from .v0_2 import DatasetDescr as DatasetDescr02 33 34 35class DatasetId(ResourceId): 36 pass 37 38 39class DatasetDescr(GenericDescrBase): 40 """A bioimage.io dataset resource description file (dataset RDF) describes a dataset relevant to bioimage 41 processing. 42 """ 43 44 implemented_type: ClassVar[Literal["dataset"]] = "dataset" 45 if TYPE_CHECKING: 46 type: Literal["dataset"] = "dataset" 47 else: 48 type: Literal["dataset"] 49 50 id: Optional[DatasetId] = None 51 """bioimage.io-wide unique resource identifier 52 assigned by bioimage.io; version **un**specific.""" 53 54 parent: Optional[DatasetId] = None 55 """The description from which this one is derived""" 56 57 source: FAIR[Optional[HttpUrl]] = None 58 """"URL to the source of the dataset.""" 59 60 @model_validator(mode="before") 61 @classmethod 62 def _convert(cls, data: Dict[str, Any], /) -> Dict[str, Any]: 63 if ( 64 data.get("type") == "dataset" 65 and isinstance(fv := data.get("format_version"), str) 66 and fv.startswith("0.2.") 67 ): 68 old = DatasetDescr02.load(data) 69 if isinstance(old, InvalidDescr): 70 return data 71 72 return cast( 73 Dict[str, Any], 74 (cls if TYPE_CHECKING else dict)( 75 attachments=( 76 [] 77 if old.attachments is None 78 else [FileDescr(source=f) for f in old.attachments.files] 79 ), 80 authors=[_author_conv.convert_as_dict(a) for a in old.authors], # pyright: ignore[reportArgumentType] 81 badges=old.badges, 82 cite=[ 83 {"text": c.text, "doi": c.doi, "url": c.url} for c in old.cite 84 ], # pyright: ignore[reportArgumentType] 85 config=old.config, # pyright: ignore[reportArgumentType] 86 covers=old.covers, 87 description=old.description, 88 documentation=old.documentation, 89 format_version="0.3.0", 90 git_repo=old.git_repo, # pyright: ignore[reportArgumentType] 91 icon=old.icon, 92 id=None if old.id is None else DatasetId(old.id), 93 license=old.license, # type: ignore 94 links=old.links, 95 maintainers=[ 96 _maintainer_conv.convert_as_dict(m) for m in old.maintainers 97 ], # pyright: ignore[reportArgumentType] 98 name=old.name, 99 source=old.source, 100 tags=old.tags, 101 type=old.type, 102 uploader=old.uploader, 103 version=old.version, 104 **(old.model_extra or {}), 105 ), 106 ) 107 108 return data 109 110 111class LinkedDataset(LinkedResourceBase): 112 """Reference to a bioimage.io dataset.""" 113 114 id: DatasetId 115 """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
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: FAIR[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=[_author_conv.convert_as_dict(a) for a in old.authors], # pyright: ignore[reportArgumentType] 82 badges=old.badges, 83 cite=[ 84 {"text": c.text, "doi": c.doi, "url": c.url} for c in old.cite 85 ], # pyright: ignore[reportArgumentType] 86 config=old.config, # pyright: ignore[reportArgumentType] 87 covers=old.covers, 88 description=old.description, 89 documentation=old.documentation, 90 format_version="0.3.0", 91 git_repo=old.git_repo, # pyright: ignore[reportArgumentType] 92 icon=old.icon, 93 id=None if old.id is None else DatasetId(old.id), 94 license=old.license, # type: ignore 95 links=old.links, 96 maintainers=[ 97 _maintainer_conv.convert_as_dict(m) for m in old.maintainers 98 ], # pyright: ignore[reportArgumentType] 99 name=old.name, 100 source=old.source, 101 tags=old.tags, 102 type=old.type, 103 uploader=old.uploader, 104 version=old.version, 105 **(old.model_extra or {}), 106 ), 107 ) 108 109 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.
"URL to the source of the dataset.
Configuration for the model, should be a dictionary conforming to [ConfigDict
][pydantic.config.ConfigDict].
337def init_private_attributes(self: BaseModel, context: Any, /) -> None: 338 """This function is meant to behave like a BaseModel method to initialise private attributes. 339 340 It takes context as an argument since that's what pydantic-core passes when calling it. 341 342 Args: 343 self: The BaseModel instance. 344 context: The context. 345 """ 346 if getattr(self, '__pydantic_private__', None) is None: 347 pydantic_private = {} 348 for name, private_attr in self.__private_attributes__.items(): 349 default = private_attr.get_default() 350 if default is not PydanticUndefined: 351 pydantic_private[name] = default 352 object_setattr(self, '__pydantic_private__', pydantic_private)
This function is meant to behave like a BaseModel method to initialise private attributes.
It takes context as an argument since that's what pydantic-core passes when calling it.
Arguments:
- self: The BaseModel instance.
- context: The context.
Inherited Members
- bioimageio.spec.generic.v0_3.GenericDescrBase
- implemented_format_version
- convert_from_old_format_wo_validation
- documentation
- badges
- config
- bioimageio.spec.generic.v0_3.GenericModelDescrBase
- name
- description
- covers
- id_emoji
- attachments
- cite
- license
- git_repo
- icon
- links
- uploader
- maintainers
- warn_about_tag_categories
- version
- version_comment
112class LinkedDataset(LinkedResourceBase): 113 """Reference to a bioimage.io dataset.""" 114 115 id: DatasetId 116 """A valid dataset `id` from the bioimage.io collection."""
Reference to a bioimage.io dataset.
Configuration for the model, should be a dictionary conforming to [ConfigDict
][pydantic.config.ConfigDict].