Example #1
0
def api_get_slide_random_patch(task_id, slide_id, width):
    db = get_db()

    # Find out which machine the slide is currently being served from
    # Get the tiff image from which to sample the region of interest
    sr = get_slide_ref(slide_id)

    # Get the identifiers for the slide
    # TODO: what to do with project here?
    (project, specimen, block, slide_name, slide_ext) = sr.get_id_tuple()

    # Are we de this slide to a different node?
    del_url = find_delegate_for_slide(slide_id)

    # If local, call the method directly
    rawbytes = None
    if del_url is None:
        rawbytes = get_random_patch(project, specimen, block, 'raw',
                                    slide_name, slide_ext, 0, width,
                                    'png').data
    else:
        url = '%s/dzi/random_patch/%s/%s/%s/raw/%s.%s/%d/%d.png' % (
            del_url, project, specimen, block, slide_name, slide_ext, 0, width)
        pr = sr.get_project_ref()
        post_data = urllib.urlencode(
            {'project_data': json.dumps(pr.get_dict())})
        rawbytes = urllib2.urlopen(url, post_data).read()

    # Send the patch
    resp = make_response(rawbytes)
    resp.mimetype = 'image/png'
    return resp
Example #2
0
def api_slide_job_status(task_id, slide_id, jobid):
    db = get_db()
    sr = get_slide_ref(slide_id)
    (project, specimen, block, slide_name, slide_ext) = sr.get_id_tuple()

    # Are we de this slide to a different node?
    del_url = find_delegate_for_slide(slide_id)

    # If local, call the method directly
    if del_url is None:
        return dzi_job_status(project, slide_name, jobid)
    else:
        url = '%s/dzi/job/%s/%s/%s/status' % (
                del_url, project, slide_name, jobid)
        pr = sr.get_project_ref()
        post_data = urllib.urlencode({'project_data': json.dumps(pr.get_dict())})
        return urllib2.urlopen(url, post_data).read()
Example #3
0
    def wrapped_view(**kwargs):

        # Find or allocate an assigned worker for this slide
        worker_url = find_delegate_for_slide(project=kwargs['project'],
                                             slide_name=kwargs['slide_name'])

        # If no worker, just call the method
        if worker_url is None:
            return view(**kwargs)

        # Call the worker's method
        full_url = '%s/%s' % (worker_url, request.full_path)

        # Take the project information and embed it in the call as a POST parameter
        pr = ProjectRef(kwargs['project'])
        post_data = urllib.urlencode(
            {'project_data': json.dumps(pr.get_dict())})
        return urllib2.urlopen(full_url, post_data).read()
Example #4
0
def generate_sample_patch(slide_id, sample_id, rect, dims=(512, 512), level=0):

    # Find out which machine the slide is currently being served from
    # Get the tiff image from which to sample the region of interest
    db = get_db()
    sr = get_slide_ref(slide_id)

    # Get the identifiers for the slide
    # TODO: what to do with project here?
    (project, specimen, block, slide_name, slide_ext) = sr.get_id_tuple()

    # Are we de this slide to a different node?
    del_url = find_delegate_for_slide(slide_id)

    # Compute the parameters
    ctr_x = int((rect[0] + rect[2]) / 2.0 + 0.5)
    ctr_y = int((rect[1] + rect[3]) / 2.0 + 0.5)
    (w, h) = dims
    x = ctr_x - ((w - int(w / 2.0)) - 1)
    y = ctr_y - ((h - int(h / 2.0)) - 1)

    # If local, call the method directly
    rawbytes = None
    if del_url is None:
        rawbytes = get_patch(project, specimen, block, 'raw', slide_name,
                             slide_ext, level, ctr_x, ctr_y, w, h, 'png').data
    else:
        url = '%s/dzi/patch/%s/%s/%s/raw/%s.%s/%d/%d_%d_%d_%d.png' % (
            del_url, project, specimen, block, slide_name, slide_ext, level,
            ctr_x, ctr_y, w, h)
        pr = sr.get_project_ref()
        post_data = urllib.urlencode(
            {'project_data': json.dumps(pr.get_dict())})
        rawbytes = urllib2.urlopen(url, post_data).read()

    # Save as PNG
    with open(get_sample_patch_filename(sample_id), 'wb') as f:
        f.write(rawbytes)

    # Record that patch has been written
    db.execute('UPDATE training_sample SET have_patch=1 where id=?',
               (sample_id, ))
    db.commit()
Example #5
0
def get_sample_custom_png(id, level, w, h):

    # Get the slide reference
    db = get_db()
    sample = db.execute('SELECT * FROM training_sample WHERE id=?',
                        (id, )).fetchone()
    slide_id = sample['slide']
    sr = get_slide_ref(slide_id)

    # Get the identifiers for the slide
    # TODO: what to do with project name here
    (project, specimen, block, slide_name, slide_ext) = sr.get_id_tuple()

    # Are we delegating this slide to a different node?
    del_url = find_delegate_for_slide(slide_id)

    # Compute the parameters
    ctr_x = int((sample['x0'] + sample['x1']) / 2.0 + 0.5)
    ctr_y = int((sample['y0'] + sample['y1']) / 2.0 + 0.5)
    x = ctr_x - ((w - int(w / 2.0)) - 1)
    y = ctr_y - ((h - int(h / 2.0)) - 1)

    # If local, call the method directly
    rawbytes = None
    if del_url is None:
        rawbytes = get_patch(project, specimen, block, 'raw', slide_name,
                             slide_ext, level, ctr_x, ctr_y, w, h, 'png').data
    else:
        url = '%s/dzi/patch/%s/%s/%s/raw/%s.%s/%d/%d_%d_%d_%d.png' % (
            del_url, project, specimen, block, slide_name, slide_ext, level,
            ctr_x, ctr_y, w, h)
        pr = sr.get_project_ref()
        post_data = urllib.urlencode(
            {'project_data': json.dumps(pr.get_dict())})
        rawbytes = urllib2.urlopen(url, post_data).read()

    resp = make_response(rawbytes)
    resp.mimetype = 'image/%s' % format
    return resp