ab_utils / data_view / pyramid / data_view / data_view / views.py

The default branch has multiple heads

import numpy
from pyramid.view import view_config

from pyramid.response import Response

filename = 'cube_data.h5'
# h5f = tables.openFile(filename, 'r')
#arr = h5f.root.array
arr = numpy.random.rand((100, 100, 100))

def get_slice(cube, axis, idx):
    if axis == 'x':
        return cube[idx, :, :]
    elif axis == 'y':
        return cube[:, idx, :]
    elif axis == 'z':
        return cube[:, :, idx]

@view_config(route_name='home',
             renderer='templates/mytemplate.pt')
def my_view(request):
    return {'project':'data_view'}

@view_config(name='cube_info',
             request_method='GET',
             renderer='templates/info.pt')
def info(request):
    return {
        'filename': filename,
        'arr': arr
    }

@view_config(route_name='view_slice',
             request_method='GET')
def view_slice(request):
    return Response(
        '<html><img src="/image/{}/{}"/></html>'.format(
            request.matchdict['axis'],
            request.matchdict['index']))

@view_config(route_name='slice_image',
             request_method='GET')
def slice_image(request):
    axis = request.matchdict['axis']
    index = int(request.matchdict['index'])
    data = get_slice(arr, axis, index)

    # im = Image.new('RGB', data.shape)
    #     for i in range(data.shape[0]):
    #         for j in range(data.shape[1]):
    #             im.putpixel((i, j), (int(data[i,j] / 1000.0 * 255), 0, 0))

    #     with tempfile.TemporaryFile() as f:
    #         im.save(f, format='PNG')
    #         f.seek(0)
    #         web.header('Content-type', 'image/raw')
    #         return f.read()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.