Skip to content

Instantly share code, notes, and snippets.

@dyens
Last active March 10, 2021 09:54
Show Gist options
  • Save dyens/bc51a5556da56f237a9eb35c2f39aa98 to your computer and use it in GitHub Desktop.
Save dyens/bc51a5556da56f237a9eb35c2f39aa98 to your computer and use it in GitHub Desktop.
Ambra. Get modalities in study
from ambra_sdk.api import Api
# Init api
api = Api.with_creds(
url=url,
username=username,
password=password,
client_name=my_client_name,
)
# Get some study
study = api.Study.list().first()
##############################################
# Get modalities using Storage.Study.schema: #
##############################################
study_schema = api.Storage.Study.schema(
engine_fqdn=study.engine_fqdn,
namespace=study.storage_namespace,
study_uid=study.study_uid,
)
for series in study_schema['series']:
print(series['modality'])
############################################
# Get modalities using Storage.Study.json: #
############################################
# Get metadata for all images in study
study_json = api.Storage.Study.json(
engine_fqdn=study.engine_fqdn,
namespace=study.storage_namespace,
study_uid=study.study_uid,
)
# Get all tags with name == Modality
# and print modality value
for image_json in study_json:
modality_tag = image_json.tag_by_name('Modality')
print(modality_tag.value)
# Actually study_json is json object.
# You can handle it however you like.
# But in this case using tag_by_name function
# makes everything a little more convenient.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment