def get_tag_to_uuid(dataset: str, annotation_type: str, tag: str, user: User = Depends(get_user)): """ Returns the corresponding dvid UUID of the given tag for the given scope. Returns: A string of the uuid corresponding to the tag, e.g., "74ea83" """ if not user.can_read(dataset): raise HTTPException( status_code=401, detail=f"no permission to read annotations on dataset {dataset}") tag_to_uuid = cache.get_value(collection_path=[CLIO_ANNOTATIONS_GLOBAL], document='metadata', path=['neurons', 'VNC', 'tag_to_uuid']) if not tag_to_uuid: raise HTTPException( status_code=404, detail= f"Could not find any tag_to_uuid for annotation type {annotation_type} in dataset {dataset}" ) if tag not in tag_to_uuid: raise HTTPException( status_code=404, detail= f"Could not find tag {tag} for annotation type {annotation_type} in dataset {dataset}" ) return tag_to_uuid[tag]
def get_uuid_to_tag(dataset: str, annotation_type: str, uuid: str, user: User = Depends(get_user)): """ Returns the corresponding string tag for the given dvid UUID for the given scope. Returns: A string of the tag corresponding to the uuid, e.g., "v0.3.32" """ if not user.can_read(dataset): raise HTTPException( status_code=401, detail=f"no permission to read annotations on dataset {dataset}") uuid_to_tag = cache.get_value(collection_path=[CLIO_ANNOTATIONS_GLOBAL], document='metadata', path=['neurons', 'VNC', 'uuid_to_tag']) if not uuid_to_tag: raise HTTPException( status_code=404, detail= f"Could not find any uuid_to_tag for annotation type {annotation_type} in dataset {dataset}" ) found_tag = None num_found = 0 for stored_uuid in uuid_to_tag: if len(stored_uuid) < len(uuid) and uuid.startswith(stored_uuid): num_found += 1 found_tag = uuid_to_tag[stored_uuid] if len(stored_uuid) >= len(uuid) and stored_uuid.startswith(uuid): num_found += 1 found_tag = uuid_to_tag[stored_uuid] if num_found > 1: raise HTTPException( status_code=400, detail= f"uuid {uuid} is ambiguous because more than one hit for annotation type {annotation_type} in dataset {dataset}" ) if not found_tag: raise HTTPException( status_code=404, detail= f"Could not find uuid {uuid} for annotation type {annotation_type} in dataset {dataset}" ) return found_tag
def write_annotation(collection, data: dict, replace: bool, id_field: str, conditional: List[str], version: str, user: User): """ Write annotation transactionally, modifying HEAD and archiving old annotation """ if not id_field in data: raise HTTPException( status_code=400, detail= f'the id field "{id_field}" must be included in every annotation: {data}' ) id = data[id_field] head_key = f'id{id}' data["_timestamp"] = time.time() data["_user"] = user.email new_fields = False fields = cache.get_value(collection_path=[CLIO_ANNOTATIONS_GLOBAL], document='metadata', path=['neurons', 'VNC', 'fields']) for cur_field in data: if not cur_field.startswith('_'): if cur_field not in fields: fields.append(cur_field) new_fields = True if new_fields: cache.set_value(collection_path=[CLIO_ANNOTATIONS_GLOBAL], document='metadata', value=fields, path=['neurons', 'VNC', 'fields']) try: transaction = firestore.db.transaction() head_ref = collection.document(head_key) archived_ref = collection.document() update_in_transaction(transaction, head_ref, archived_ref, data, conditional, version, replace) except Exception as e: print(e) raise HTTPException( status_code=400, detail= f"error in writing annotation to version {version}: {e}\n Data: {data}" )
def get_head_uuid(dataset: str, annotation_type: str, user: User = Depends(get_user)): """ Returns the head version uuid for the given scope. Returns: A string of the HEAD version uuid, e.g., "74ea83" """ if not user.can_read(dataset): raise HTTPException( status_code=401, detail=f"no permission to read annotations on dataset {dataset}") head_uuid = cache.get_value(collection_path=[CLIO_ANNOTATIONS_GLOBAL], document='metadata', path=['neurons', 'VNC', 'head_uuid']) if not head_uuid: raise HTTPException( status_code=404, detail= f"Could not find any head_uuid for annotation type {annotation_type} in dataset {dataset}" ) return head_uuid
def get_versions(dataset: str, annotation_type: str, user: User = Depends(get_user)): """ Returns the versions for the given scope. Returns: A dict with tag keys and corresponding dvid UUIDs as value. """ if not user.can_read(dataset): raise HTTPException( status_code=401, detail=f"no permission to read annotations on dataset {dataset}") tag_to_uuid = cache.get_value(collection_path=[CLIO_ANNOTATIONS_GLOBAL], document='metadata', path=['neurons', 'VNC', 'tag_to_uuid']) if not tag_to_uuid: raise HTTPException( status_code=404, detail= f"Could not find any tag_to_uuid for annotation type {annotation_type} in dataset {dataset}" ) return tag_to_uuid
def get_fields(dataset: str, annotation_type: str, user: User = Depends(get_user)): """ Returns all fields within annotations for the given scope. Returns: A JSON list of the fields present in at least one annotation. """ if not user.can_read(dataset): raise HTTPException( status_code=401, detail=f"no permission to read annotations on dataset {dataset}") fields = cache.get_value(collection_path=[CLIO_ANNOTATIONS_GLOBAL], document='metadata', path=['neurons', 'VNC', 'fields']) if not fields: raise HTTPException( status_code=404, detail= f"Could not find any fields for annotation type {annotation_type} in dataset {dataset}" ) return fields