Ids

class pado.images.ids.FilenamePartsMapper[source]

a plain mapper for ImageId instances based on filename only

pado.images.ids.register_filename_mapper(site, mapper)[source]

used internally to register new mappers for ImageIds

class pado.images.ids.ImageId(*parts: str, site: str | None = None)[source]

Unique identifier for images in pado datasets

classmethod make(parts, site=None)[source]

Create a new ImageId instance from an iterable

property site

return site of the image id

property parts

return the parts of the image id

property last

return the last part of the image id

to_str()

serialize the ImageId instance to str

classmethod from_str(image_id_str)[source]

create a new ImageId instance from an image id string

>>> ImageId.from_str("ImageId('abc', '123.svs')")
ImageId('abc', '123.svs')
>>> ImageId.from_str('ImageId("123.svs", site="somewhere")')
ImageId('123.svs', site='somewhere')
>>> img_id = ImageId('123.svs', site="somewhere")
>>> img_id == ImageId.from_str(img_id.to_str())
True
to_json()[source]

Serialize the ImageId instance to a json object

classmethod from_json(image_id_json)[source]

create a new ImageId instance from an image id json string

>>> ImageId.from_json('{"image_id":["abc","123.svs"]}')
ImageId('abc', '123.svs')
>>> ImageId.from_json('{"image_id":["abc","123.svs"],"site":"somewhere"}')
ImageId('123.svs', site='somewhere')
>>> img_id = ImageId('123.svs', site="somewhere")
>>> img_id == ImageId.from_json(img_id.to_json())
True
to_url_id()[source]

return a base64 encoded string representation of imageid

Return type:

str

to_path(*, ignore_site=False)[source]

return the ImageId as a relative path

Parameters:

ignore_site (bool) – ignore the site for mapping to a PurePath and just rely on parts

Return type:

PurePath

pado.images.ids.match_partial_image_ids_reversed(ids, image_id)[source]

match image_ids from back to front

returns None if no match raises ValueError in case match is ambiguous

pado.images.ids.filter_image_ids(ids, target, *, missing=FilterMissing.WARN)[source]

filter the provided ids to return the subset matching target

pado.images.ids.ensure_image_id(maybe_image_id)[source]

guarantees that ImageId types get cast to ImageId

Return type:

ImageId

pado.images.ids.load_image_ids_from_csv(csv_file, *, csv_columns=None, no_header=False)[source]

load tuples from csv file

Parameters:
  • csv_file – path to your csv file

  • csv_columns – a list of column names or column indices (None or [] means all)

  • no_header – if enabled assume csv file has no header (requires int indices in csv_columns)

Returns:

  • image_ids – tuple of selected cells for each row

  • fieldnames – None if no_header=True else a list of column names