Skip to content
Snippets Groups Projects
sources.py 1.85 KiB
Newer Older
Constantin Pape's avatar
Constantin Pape committed
import json
Constantin Pape's avatar
Constantin Pape committed
SOURCE_FILE = '../data/sources.json'
SEGMENTATION_FILE = '../data/segmentations.json'
IMAGE_FILE = '../data/images.json'


def get_sources():
Constantin Pape's avatar
Constantin Pape committed
    """ Get names of the current data sources.

    See https://git.embl.de/tischer/platy-browser-tables/README.md#file-naming
    for the source naming conventions.
    """
    with open(SOURCE_FILE) as f:
        sources = json.load(f)
    return sources


def add_source(modality, stage, id=1, region='whole'):
    """ Add a new data source

    See https://git.embl.de/tischer/platy-browser-tables/README.md#file-naming
    for the source naming conventions.
    """
    if not isinstance(modality, str):
        raise ValueError("Expected modality to be a string, not %s" % type(modality))
    if not isinstance(stage, str):
        raise ValueError("Expected stage to be a string, not %s" % type(id))
    if not isinstance(id, int):
        raise ValueError("Expected id to be an integer, not %s" % type(id))
    if not isinstance(region, str):
        raise ValueError("Expected region to be a string, not %s" % type(id))
    sources = get_sources()
    sources.append({'modality': modality, 'stage': stage, 'id': str(id), 'region': region})
    with open(SOURCE_FILE, 'w') as f:
        json.dump(sources, f)


def source_to_prefix(source):
    return '%s-%s-%s-%s' % (source['modality'],
                            source['stage'],
                            source['id'],
                            source['region'])


def get_name_prefixes():
Constantin Pape's avatar
Constantin Pape committed
    """ Get the name prefixes corresponding to all sources.
    """
    sources = get_sources()
    prefixes = [source_to_prefix(source) for source in sources]
    return prefixes
Constantin Pape's avatar
Constantin Pape committed


def add_image(input_path):
    """ Add image volume to the platy browser data.
    """
    pass


def add_segmentation():
    """ Add segmentation volume to the platy browser data.
    """
    pass