Esempio n. 1
0
def gen_input_norfscreen(config):
    steps = config['General']['steps']
    input_file = config['Photoreceptor']['input_file']
    input_type = config['Photoreceptor']['single_intype']
    input_obj = get_singleinput_cls(input_type)(config)

    with Timer('getting photoreceptor inputs'):
        # although not configurable one can use
        # alternatives like .get_flat_image()
        # if available by manually
        # changing command below
        photor_inputs = input_obj.get_input(steps)

        config['General']['steps'] = photor_inputs[:, 0].size

    sio.write_array(photor_inputs, filename=input_file)
Esempio n. 2
0
def gen_input(config):
    cuda.init()
    ctx = cuda.Device(0).make_context()
    atexit.register(ctx.pop)

    suffix = config['General']['file_suffix']

    eye_num = config['General']['eye_num']

    eulerangles = config['Retina']['eulerangles']
    radius = config['Retina']['radius']

    rings = config['Retina']['rings']
    steps = config['General']['steps']

    screen_write_step = config['Retina']['screen_write_step']
    config['Retina']['screen_write_step'] = 1
    screen_type = config['Retina']['screentype']
    screen_cls = cls_map.get_screen_cls(screen_type)

    for i in range(eye_num):
        screen = screen_cls(config)
        screen_file = 'intensities_tmp{}.h5'.format(i)
        screen.setup_file(screen_file)
    
        retina_elev_file = 'retina_elev{}.h5'.format(i)
        retina_azim_file = 'retina_azim{}.h5'.format(i)

        screen_dima_file = 'grid_dima{}.h5'.format(i)
        screen_dimb_file = 'grid_dimb{}.h5'.format(i)

        retina_dima_file = 'retina_dima{}.h5'.format(i)
        retina_dimb_file = 'retina_dimb{}.h5'.format(i)

        input_file = 'retina_input{}.h5'.format(i)

        transform = AlbersProjectionMap(radius,
                                        eulerangles[3*i:3*(i+1)]).invmap
        hexagon = hx.HexagonArray(num_rings=rings, radius=radius,
                                  transform=transform)
        retina = ret.RetinaArray(hexagon, config)
        print('Acceptance angle: {}'.format(retina.acceptance_angle))
        print('Neurons: {}'.format(retina.num_photoreceptors))

        elev_v, azim_v = retina.get_ommatidia_pos()

        rfs = _get_receptive_fields(retina, screen, screen_type)
        steps_count = steps
        write_mode = 'w'
        while (steps_count > 0):
            steps_batch = min(100, steps_count)
            im = screen.get_screen_intensity_steps(steps_batch)
            photor_inputs = rfs.filter(im)
            sio.write_array(photor_inputs, filename=input_file, mode=write_mode)
            steps_count -= steps_batch
            write_mode = 'a'
        
        tmp = sio.read_array(screen_file)
        sio.write_array(tmp[::screen_write_step],
                        'intensities{}{}.h5'.format(suffix, i),
                        complevel = 9)
        del tmp
        os.remove(screen_file)

        for data, filename in [(elev_v, retina_elev_file),
                               (azim_v, retina_azim_file),
                               (screen.grid[0], screen_dima_file),
                               (screen.grid[1], screen_dimb_file),
                               (rfs.refa, retina_dima_file),
                               (rfs.refb, retina_dimb_file)]:
            sio.write_array(data, filename)
Esempio n. 3
0
def gen_input(config):
    cuda.init()
    ctx = cuda.Device(0).make_context()
    atexit.register(ctx.pop)

    suffix = config['General']['file_suffix']

    eye_num = config['General']['eye_num']

    rings = config['Retina']['rings']
    steps = config['General']['steps']

    input_filename = config['Retina']['input_file']
    
    screen_write_step = config['Retina']['screen_write_step']
    config['Retina']['screen_write_step'] = 1
    
    screen_type = config['Retina']['screentype']
    screen_cls = cls_map.get_screen_cls(screen_type)
    eulerangles = config['Retina']['eulerangles']
    radius = config['Retina']['radius']

    for i in range(eye_num):
        screen = screen_cls(config)
        screen_file = 'intensities_tmp{}.h5'.format(i)
        screen.setup_file(screen_file)
    
        retina_elev_file = 'retina_elev{}.h5'.format(i)
        retina_azim_file = 'retina_azim{}.h5'.format(i)

        screen_dima_file = 'grid_dima{}.h5'.format(i)
        screen_dimb_file = 'grid_dimb{}.h5'.format(i)

        retina_dima_file = 'retina_dima{}.h5'.format(i)
        retina_dimb_file = 'retina_dimb{}.h5'.format(i)

        input_file = '{}{}{}.h5'.format(input_filename, i, suffix)

        transform = AlbersProjectionMap(radius,
                                        eulerangles[3*i:3*(i+1)]).invmap
        hexagon = hx.HexagonArray(num_rings=rings, radius=radius,
                                  transform=transform)
        retina = ret.RetinaArray(hexagon, config=config)
        print('Acceptance angle: {}'.format(retina.acceptance_angle))
        print('Neurons: {}'.format(retina.num_photoreceptors))

        elev_v, azim_v = retina.get_ommatidia_pos()

        rfs = _get_receptive_fields(retina, screen, screen_type)
        steps_count = steps
        write_mode = 'w'
        while (steps_count > 0):
            steps_batch = min(100, steps_count)
            im = screen.get_screen_intensity_steps(steps_batch)
            photor_inputs = rfs.filter(im)
            sio.write_array(photor_inputs, filename=input_file, mode=write_mode)
            steps_count -= steps_batch
            write_mode = 'a'
        
        tmp = sio.read_array(screen_file)
        sio.write_array(tmp[::screen_write_step],
                        'intensities{}{}.h5'.format(suffix, i),
                        complevel = 9)
        del tmp
        os.remove(screen_file)

        for data, filename in [(elev_v, retina_elev_file),
                               (azim_v, retina_azim_file),
                               (screen.grid[0], screen_dima_file),
                               (screen.grid[1], screen_dimb_file),
                               (rfs.refa, retina_dima_file),
                               (rfs.refb, retina_dimb_file)]:
            sio.write_array(data, filename)