Document Model
The document model provides classes for constructing IIIF Presentation API resources from images, 3D models, annotations, and hierarchical collections.
File Resources
- class timeatlas.DocumentModel.FileReference[source]
Bases:
UUIDEntity,RDEReference to a file resource with a unique identifier.
- get_image_metadata()[source]
Extract image metadata using PIL.
- Returns:
Dictionary with ‘width’, ‘height’, and ‘format’ keys.
- Raises:
IOError – If the file cannot be opened or read.
ValueError – If the file is not a valid image.
- Return type:
- generate_page_from_file_reference(uuid_manager, label, range_idx)[source]
Generate a Page object from the file reference.
Extracts image metadata using PIL and creates a Page object.
- Parameters:
uuid_manager (UUIDManager) – Manager for generating unique identifiers.
label (MultiLingualValue) – Multi-language label for the page.
range_idx (int) – Index position within a range or sequence.
- Returns:
Page object with the file reference as its object_ref.
- Raises:
IOError – If the image file cannot be opened.
ValueError – If the file is not a valid image.
- Return type:
- get_model_metadata()[source]
Extract 3D model metadata based on file extension.
- Returns:
Dictionary with ‘format’ key containing the MIME type.
- Return type:
Note
3D models don’t have standardized metadata extraction like images, so format is determined from file extension.
- generate_model_from_file_reference(uuid_manager, label)[source]
Generate a Model object from the file reference.
Extracts model format from file extension and creates a Model object.
- Parameters:
uuid_manager (UUIDManager) – Manager for generating unique identifiers.
label (MultiLingualValue) – Multi-language label for the model.
- Returns:
Model object with the file reference as its object_ref.
- Return type:
Selectors and Annotations
- class timeatlas.DocumentModel.SelectorType[source]
Bases:
EnumEnumeration of Web Annotation selector types for targeting regions.
- POINT
Point selector for single coordinate (x, y).
- SVG
SVG path selector for complex polygon regions.
- XYWH
Rectangle selector defined by x, y, width, height.
- POINT = 'PointSelector'
- SVG = 'SvgSelector'
- XYWH = 'SquareSelector'
- class timeatlas.DocumentModel.Selector[source]
Bases:
objectWeb Annotation selector for targeting specific regions in a resource.
Supports three selector types: POINT (single coordinate), SVG (polygon path), and XYWH (rectangular region).
- type
The selector type (POINT, SVG, or XYWH).
- value
Coordinate data - tuple[int,int] for POINT, list[tuple[int,int]] for SVG, tuple[int,int,int,int] for XYWH.
- source
The resource URI being targeted.
- Raises:
ValueError – If value format doesn’t match the selector type requirements.
- generate_selector_template()[source]
Generate Web Annotation selector JSON structure.
- Returns:
Dictionary or string representing the selector in Web Annotation format. For POINT and SVG types, returns a SpecificResource dict. For XYWH, returns a Media Fragment URI string.
- Raises:
ValueError – If selector type is not recognized.
- Return type:
- class timeatlas.DocumentModel.Annotation[source]
Bases:
UUIDEntity,RDEWeb Annotation for commenting on or linking resources.
Represents a W3C Web Annotation with optional text content, historical record reference, spatial selector, and external resource links.
- selector
Optional Selector for targeting a specific region.
- Type:
- Raises:
ValueError – If language/value pairs are incomplete, or if required fields are missing.
- to_iiif(uuid_manager, canvas_id, canvas_type='Canvas')[source]
Convert annotation to IIIF Presentation API format.
- Parameters:
uuid_manager (UUIDManager) – Manager for generating unique identifiers.
canvas_id (str) – The canvas or resource ID being annotated.
canvas_type (str) – Type of the target resource (default: “Canvas”).
- Returns:
Dictionary containing IIIF annotation in Presentation API format.
- Return type:
IIIF Resources
- class timeatlas.DocumentModel.Page[source]
Bases:
UUIDEntity,RDERepresents a page or canvas in an IIIF document.
A page contains an image or other visual resource with dimensions, format, and optional annotations.
- label
Multi-language label for the page.
- object_ref
Path or reference to the image file.
- annotations
Optional list of annotations on this page.
- Type:
- label: MultiLingualValue
- object_ref: str | FileReference
- annotations: list[Annotation] | None = None
- to_iiif(uuid_manager, url_prefix)[source]
Convert page to IIIF Presentation API Canvas format.
- Parameters:
uuid_manager (UUIDManager) – Manager for generating unique identifiers.
url_prefix (str) – Base URL prefix for the IIIF image service.
- Returns:
Dictionary containing IIIF Canvas in Presentation API v3 format.
- Raises:
ValueError – If object_ref is a FileReference ().
- Return type:
- to_dict()[source]
Convert page to a dictionary representation.
- Returns:
Dictionary containing page attributes.
- Return type:
- __init__(id, label, format, range_idx, height, width, object_ref, annotations=None)
- Parameters:
id (UUID | str | tuple[UUIDManager, str] | None)
label (MultiLingualValue)
format (str)
range_idx (int)
height (int)
width (int)
object_ref (str | FileReference)
annotations (list[Annotation] | None)
- Return type:
None
- class timeatlas.DocumentModel.Model[source]
Bases:
UUIDEntity,RDERepresents a 3D model resource in IIIF.
- label
Multi-language label for the model.
- object_ref
Path or reference to the 3D model file.
- label: MultiLingualValue
- object_ref: str | FileReference
- annotations: list[Annotation] | None = None
- to_iiif(uuid_manager)[source]
Convert 3D model to IIIF Presentation API Scene format.
- Parameters:
uuid_manager (UUIDManager) – Manager for generating unique identifiers.
- Returns:
Dictionary containing IIIF Scene in Presentation API v4 format.
- Raises:
ValueError – If object_ref is a FileReference (only string paths supported).
- Return type:
- __init__(id, label, format, object_ref, annotations=None)
- Parameters:
id (UUID | str | tuple[UUIDManager, str] | None)
label (MultiLingualValue)
format (str)
object_ref (str | FileReference)
annotations (list[Annotation] | None)
- Return type:
None
- class timeatlas.DocumentModel.Document[source]
Bases:
UUIDEntity,RDERepresents an IIIF Manifest containing pages or 3D models.
A document is the primary unit for presenting a sequence of canvases/scenes with optional navigational structures.
- label
Multi-language label for the document.
- items
List of pages (2D images) or models (3D scenes).
- label: MultiLingualValue
- to_iiif(uuid_manager, url_prefix, presentation_version='3')[source]
Convert document to IIIF Presentation API Manifest format.
- Parameters:
uuid_manager (UUIDManager) – Manager for generating unique identifiers.
label – Multi-language label dictionary.
url_prefix (str) – Base URL prefix for the IIIF image service.
presentation_version (str) – IIIF Presentation API version (‘3’ or ‘4’).
- Returns:
Dictionary containing complete IIIF Manifest.
- Return type:
- to_iiif_manifest_item(url_prefix, with_thumbnail=True)[source]
Convert document to a simplified IIIF Manifest reference.
Useful for including in Collection items arrays.
- class timeatlas.DocumentModel.Collection[source]
Bases:
UUIDEntity,RDERepresents an IIIF Collection containing documents or sub-collections.
Collections provide hierarchical organization of IIIF Manifests and other collections for browsing and discovery.
- label
Multi-language label for the collection.
- items
List of documents (manifests) or nested collections.
- presentation_version
IIIF Presentation API version for the collection (default: ‘3’).
- label: MultiLingualValue
- items: list[Document | Collection]
- to_iiif_manifest_item(url_prefix, with_thumbnail=True)[source]
Convert a nested collection to a compact IIIF collection reference.
- to_iiif(url_prefix, with_thumbnails=True, presentation_version='3')[source]
Convert collection to IIIF Presentation API Collection format.
- Parameters:
- Returns:
Dictionary containing IIIF Collection in Presentation API v3 format.
- Return type:
- to_dict()[source]
Convert collection to a dictionary representation.
- Returns:
Dictionary containing collection attributes and items.
- Return type:
- __init__(id, label, items)
- Parameters:
id (UUID | str | tuple[UUIDManager, str] | None)
label (MultiLingualValue)
items (list[Document | Collection])
- Return type:
None
Helper Functions
- timeatlas.DocumentModel.int_tuple_list_to_svg_string(tpl)[source]
Convert a list of integer coordinate tuples to an SVG path string.
- Parameters:
tpl (list[tuple[int, int]]) – List of (x, y) coordinate tuples defining a closed polygon path.
- Returns:
SVG string with a closed path element.
- Return type:
Example
>>> int_tuple_list_to_svg_string([(270, 1900), (1530, 1900), (1530, 1610)]) "<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'><g><path d='M270,1900 L1530,1900 L1530,1610 L270,1900' /></g></svg>"
Note
Understanding the SVG path command: https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths
- timeatlas.DocumentModel.multiindex_to_nested_dict(df)[source]
Convert a DataFrame with MultiIndex to a nested OrderedDict.
Recursively processes each level of the MultiIndex to create a hierarchical dictionary structure, with the final level containing canvas_id values.
- Parameters:
df (DataFrame) – DataFrame with MultiIndex to convert.
- Returns:
Nested OrderedDict representing the MultiIndex hierarchy.
- Return type:
Note
Source: https://gist.github.com/dcragusa/1235704accde2152faa37113cafa95c0 (simplified)
- timeatlas.DocumentModel.ordered_dict_to_iiif_toc_structure(d, lan, val, range_id_pref)[source]
This function returns the IIIF ToC structure from the ordered dict. the ordered dict should be in the format “{“lvl1_label”: {“lvl2_label”: … {“lvln_label”: [canvas_id1, canvas_id2,…,canvas_idn] }…}}. Accepts multiple leveld dict.
- Parameters:
d (OrderedDict)
lan (str)
val (str)
range_id_pref (str)
- Return type: