bioimageio.spec.dataset.v0_3

  1from typing import TYPE_CHECKING, Any, 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 CiteEntry as CiteEntry
 14from ..generic.v0_3 import DeprecatedLicenseId as DeprecatedLicenseId
 15from ..generic.v0_3 import (
 16    DocumentationSource,
 17    GenericDescrBase,
 18    LinkedResourceNode,
 19    _author_conv,  # pyright: ignore[reportPrivateUsage]
 20    _maintainer_conv,  # pyright: ignore[reportPrivateUsage]
 21)
 22from ..generic.v0_3 import Doi as Doi
 23from ..generic.v0_3 import LicenseId as LicenseId
 24from ..generic.v0_3 import LinkedResource as LinkedResource
 25from ..generic.v0_3 import Maintainer as Maintainer
 26from ..generic.v0_3 import OrcidId as OrcidId
 27from ..generic.v0_3 import RelativeFilePath as RelativeFilePath
 28from ..generic.v0_3 import ResourceId as ResourceId
 29from ..generic.v0_3 import Uploader as Uploader
 30from ..generic.v0_3 import Version as Version
 31from .v0_2 import DatasetDescr as DatasetDescr02
 32
 33
 34class DatasetId(ResourceId):
 35    pass
 36
 37
 38class DatasetDescr(GenericDescrBase, title="bioimage.io dataset specification"):
 39    """A bioimage.io dataset resource description file (dataset RDF) describes a dataset relevant to bioimage
 40    processing.
 41    """
 42
 43    type: Literal["dataset"] = "dataset"
 44
 45    id: Optional[DatasetId] = None
 46    """bioimage.io-wide unique resource identifier
 47    assigned by bioimage.io; version **un**specific."""
 48
 49    parent: Optional[DatasetId] = None
 50    """The description from which this one is derived"""
 51
 52    source: Optional[HttpUrl] = None
 53    """"URL to the source of the dataset."""
 54
 55    @model_validator(mode="before")
 56    @classmethod
 57    def _convert(cls, data: Dict[str, Any], /) -> Dict[str, Any]:
 58        if (
 59            data.get("type") == "dataset"
 60            and isinstance(fv := data.get("format_version"), str)
 61            and fv.startswith("0.2.")
 62        ):
 63            old = DatasetDescr02.load(data)
 64            if isinstance(old, InvalidDescr):
 65                return data
 66
 67            return cast(
 68                Dict[str, Any],
 69                (cls if TYPE_CHECKING else dict)(
 70                    attachments=(
 71                        []
 72                        if old.attachments is None
 73                        else [FileDescr(source=f) for f in old.attachments.files]
 74                    ),
 75                    authors=[
 76                        _author_conv.convert_as_dict(a) for a in old.authors
 77                    ],  # pyright: ignore[reportArgumentType]
 78                    badges=old.badges,
 79                    cite=[
 80                        {"text": c.text, "doi": c.doi, "url": c.url} for c in old.cite
 81                    ],  # pyright: ignore[reportArgumentType]
 82                    config=old.config,
 83                    covers=old.covers,
 84                    description=old.description,
 85                    documentation=cast(DocumentationSource, old.documentation),
 86                    format_version="0.3.0",
 87                    git_repo=old.git_repo,  # pyright: ignore[reportArgumentType]
 88                    icon=old.icon,
 89                    id=None if old.id is None else DatasetId(old.id),
 90                    license=old.license,  # type: ignore
 91                    links=old.links,
 92                    maintainers=[
 93                        _maintainer_conv.convert_as_dict(m) for m in old.maintainers
 94                    ],  # pyright: ignore[reportArgumentType]
 95                    name=old.name,
 96                    source=old.source,
 97                    tags=old.tags,
 98                    type=old.type,
 99                    uploader=old.uploader,
100                    version=old.version,
101                    **(old.model_extra or {}),
102                ),
103            )
104
105        return data
106
107
108class LinkedDataset(LinkedResourceNode):
109    """Reference to a bioimage.io dataset."""
110
111    id: DatasetId
112    """A valid dataset `id` from the bioimage.io collection."""
class DatasetId(bioimageio.spec.generic.v0_3.ResourceId):
35class DatasetId(ResourceId):
36    pass

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'.

class DatasetDescr(bioimageio.spec.generic.v0_3.GenericDescrBase):
 39class DatasetDescr(GenericDescrBase, title="bioimage.io dataset specification"):
 40    """A bioimage.io dataset resource description file (dataset RDF) describes a dataset relevant to bioimage
 41    processing.
 42    """
 43
 44    type: Literal["dataset"] = "dataset"
 45
 46    id: Optional[DatasetId] = None
 47    """bioimage.io-wide unique resource identifier
 48    assigned by bioimage.io; version **un**specific."""
 49
 50    parent: Optional[DatasetId] = None
 51    """The description from which this one is derived"""
 52
 53    source: Optional[HttpUrl] = None
 54    """"URL to the source of the dataset."""
 55
 56    @model_validator(mode="before")
 57    @classmethod
 58    def _convert(cls, data: Dict[str, Any], /) -> Dict[str, Any]:
 59        if (
 60            data.get("type") == "dataset"
 61            and isinstance(fv := data.get("format_version"), str)
 62            and fv.startswith("0.2.")
 63        ):
 64            old = DatasetDescr02.load(data)
 65            if isinstance(old, InvalidDescr):
 66                return data
 67
 68            return cast(
 69                Dict[str, Any],
 70                (cls if TYPE_CHECKING else dict)(
 71                    attachments=(
 72                        []
 73                        if old.attachments is None
 74                        else [FileDescr(source=f) for f in old.attachments.files]
 75                    ),
 76                    authors=[
 77                        _author_conv.convert_as_dict(a) for a in old.authors
 78                    ],  # pyright: ignore[reportArgumentType]
 79                    badges=old.badges,
 80                    cite=[
 81                        {"text": c.text, "doi": c.doi, "url": c.url} for c in old.cite
 82                    ],  # pyright: ignore[reportArgumentType]
 83                    config=old.config,
 84                    covers=old.covers,
 85                    description=old.description,
 86                    documentation=cast(DocumentationSource, old.documentation),
 87                    format_version="0.3.0",
 88                    git_repo=old.git_repo,  # pyright: ignore[reportArgumentType]
 89                    icon=old.icon,
 90                    id=None if old.id is None else DatasetId(old.id),
 91                    license=old.license,  # type: ignore
 92                    links=old.links,
 93                    maintainers=[
 94                        _maintainer_conv.convert_as_dict(m) for m in old.maintainers
 95                    ],  # pyright: ignore[reportArgumentType]
 96                    name=old.name,
 97                    source=old.source,
 98                    tags=old.tags,
 99                    type=old.type,
100                    uploader=old.uploader,
101                    version=old.version,
102                    **(old.model_extra or {}),
103                ),
104            )
105
106        return data

A bioimage.io dataset resource description file (dataset RDF) describes a dataset relevant to bioimage processing.

type: Literal['dataset']
id: Optional[DatasetId]

bioimage.io-wide unique resource identifier assigned by bioimage.io; version unspecific.

parent: Optional[DatasetId]

The description from which this one is derived

source: Optional[bioimageio.spec._internal.url.HttpUrl]

"URL to the source of the dataset.

implemented_format_version: ClassVar[str] = '0.3.0'
implemented_format_version_tuple: ClassVar[Tuple[int, int, int]] = (0, 3, 0)
def model_post_init(self: pydantic.main.BaseModel, context: Any, /) -> None:
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.

class LinkedDataset(bioimageio.spec.generic.v0_3.LinkedResourceNode):
109class LinkedDataset(LinkedResourceNode):
110    """Reference to a bioimage.io dataset."""
111
112    id: DatasetId
113    """A valid dataset `id` from the bioimage.io collection."""

Reference to a bioimage.io dataset.

id: DatasetId

A valid dataset id from the bioimage.io collection.