monailabel.datastore.xnat module

class monailabel.datastore.xnat.XNATDatastore(api_url, username=None, password=None, project=None, asset_path='', cache_path='')[source]

Bases: monailabel.interfaces.datastore.Datastore

add_image(image_id, image_filename, image_info)[source]

Save a image for the given image id and return the newly saved image’s id

Parameters
  • image_id (str) – the image id for the image; If None then base filename will be used

  • image_filename (str) – the path to the image file

  • image_info (Dict[str, Any]) – additional info for the image

Return type

str

Returns

the image id for the saved image filename

datalist()[source]

Return a dictionary of image and label pairs corresponding to the ‘image’ and ‘label’ keys respectively

Return type

List[Dict[str, Any]]

Returns

the {‘image’: image, ‘label’: label} pairs for training

description()[source]

Return the user-set description of the dataset

Return type

str

Returns

the user-set description of the dataset

get_dataset_archive(limit_cases)[source]

Retrieve ZIP archive of the full dataset containing images, labels and metadata

Parameters

limit_cases (Optional[int]) – limit the included cases to this number

Return type

str

Returns

path to ZIP archive of the full dataset

get_image(image_id, params=None)[source]

Retrieve image object based on image id

Parameters
  • image_id (str) – the desired image’s id

  • params – any optional params

Return type

Any

Returns

return the “image”

get_image_info(image_id)[source]

Get the image information for the given image id

Parameters

image_id (str) – the desired image id

Return type

Dict[str, Any]

Returns

image info as a list of dictionaries Dict[str, Any]

get_image_uri(image_id)[source]

Retrieve image uri based on image id

Parameters

image_id (str) – the desired image’s id

Return type

str

Returns

return the image uri

get_label(label_id, label_tag, params=None)[source]

Retrieve image object based on label id

Parameters
  • label_id (str) – the desired label’s id

  • label_tag (str) – the matching label’s tag

  • params – any optional params

Return type

Any

Returns

return the “label”

get_label_by_image_id(image_id, tag)[source]

Retrieve label id for the given image id and tag

Parameters
  • image_id (str) – the desired image’s id

  • tag (str) – matching tag name

Return type

str

Returns

label id

get_label_info(label_id, label_tag)[source]

Get the label information for the given label id

Parameters
  • label_id (str) – the desired label id

  • label_tag (str) – the matching label tag

Return type

Dict[str, Any]

Returns

label info as a list of dictionaries Dict[str, Any]

get_label_uri(label_id, label_tag)[source]

Retrieve label uri based on image id

Parameters
  • label_id (str) – the desired label’s id

  • label_tag (str) – the matching label’s tag

Return type

str

Returns

return the label uri

get_labeled_images(label_tag=None, labels=None)[source]

Get all images that have a corresponding final label

Parameters
  • label_tag (Optional[str]) – the matching label tag

  • labels (Optional[List[str]]) – list of matching labels

Return type

List[str]

Returns

list of image ids List[str]

get_labels_by_image_id(image_id)[source]

Retrieve all label ids for the given image id

Parameters

image_id (str) – the desired image’s id

Return type

Dict[str, str]

Returns

label ids mapped to the appropriate LabelTag as Dict[LabelTag, str]

get_unlabeled_images(label_tag=None, labels=None)[source]

Get all images that have no corresponding final label

Parameters
  • label_tag (Optional[str]) – the matching label tag

  • labels (Optional[List[str]]) – list of matching labels

Return type

List[str]

Returns

list of image ids List[str]

json()[source]

Return json representation of datastore

list_images()[source]

Return list of image ids available in the datastore

Return type

List[str]

Returns

list of image ids List[str]

name()[source]

Return the human-readable name of the datastore

Return type

str

Returns

the name of the dataset

refresh()[source]

Refresh the datastore

Return type

None

remove_image(image_id)[source]

Remove image for the datastore. This will also remove all associated labels.

Parameters

image_id (str) – the image id for the image to be removed from datastore

Return type

None

remove_label(label_id, label_tag)[source]

Remove label from the datastore

Parameters
  • label_id (str) – the label id for the label to be removed from datastore

  • label_tag (str) – the label tag for the label to be removed from datastore

Return type

None

save_label(image_id, label_filename, label_tag, label_info)[source]

Save a label for the given image id and return the newly saved label’s id

Parameters
  • image_id (str) – the image id for the label

  • label_filename (str) – the path to the label file

  • label_tag (str) – the user-provided tag for the label

  • label_info (Dict[str, Any]) – additional info for the label

Return type

str

Returns

the label id for the given label filename

set_description(description)[source]

A human-readable description of the datastore

Parameters

description (str) – string for description

set_name(name)[source]

Set the name of the datastore

Parameters

name (str) – a human-readable name for the datastore

status()[source]

Return current statistics of datastore

Return type

Dict[str, Any]

update_image_info(image_id, info)[source]

Update (or create a new) info tag for the desired image

Parameters
  • image_id (str) – the id of the image we want to add/update info

  • info (Dict[str, Any]) – a dictionary of custom image information Dict[str, Any]

Return type

None

update_label_info(label_id, label_tag, info)[source]

Update (or create a new) info tag for the desired label

Parameters
  • label_id (str) – the id of the label we want to add/update info

  • label_tag (str) – the matching label tag

  • info (Dict[str, Any]) – a dictionary of custom label information Dict[str, Any]

Return type

None