示例#1
0
def fig10(template_dir, build_dir, bound_radius=0.6,  selectivity_norm=0.07138,
          size_factor=1.0, show_raster=False):
    name = 'fig10'
    if show_raster: return Display(snapshot=name, template_dir=template_dir)
    times=[2000*i for i in range(6)]
    template_path, output_dir = setup(name, template_dir, build_dir)
    pattern = 'jn13_figures/output/Fig10_12/*/*/*.npz'
    files = lancet.FilePattern('npz_file', pattern)
    file_info = lancet.FileInfo(files, 'npz_file', lancet.NumpyFile())

    filter_times = file_info.dframe['time'].map(lambda x: x in times)
    selection = file_info.load(file_info.dframe[filter_times])

    savefig_opts = dict(transparent=True, format='svg', bbox_inches='tight', pad_inches=0)
    development_info = []
    for (index, row) in selection.iterrows():
        time =row['time']
        fname = os.path.join(output_dir, '%%s_%.1f.png' % int(time))
        bounds = imagen.boundingregion.BoundingBox(radius=0.75)
        sheetcoords = imagen.SheetCoordinateSystem(bounds, xdensity=98)
        roi = slice(*sheetcoords.sheet2matrixidx(bound_radius, bound_radius))
        # Not applying ROI as new bounds will be used
        pref = get_pref(row, roi=roi)
        sel = get_sel(row, roi=roi)
        (cfs, coords) = row['afferent_CFs']

        roi = slice(*sheetcoords.sheet2matrixidx(bound_radius, bound_radius))
        # Create the combined preference/selectivity map
        or_map = rasterplots.OR_map(pref,sel)
        or_black = rasterplots.black_selectivity(or_map)
        (dim1,dim2) = pref.shape
        or_black_resized = rasterplots.resize(or_black, (dim1*4,dim2*4))
        # Save the orientation map
        or_black_resized.save(fname % 'OR')
        # Save the row of CF images
        cf_block  = rasterplots.cf_image(cfs, coords, border=5, width=8, height=1,
                                         pos=(1,4),  bg=(255,255,255))
        cf_block.save(fname % 'CF')
        # Save the FFT of the last map
        if time == times[-1]:
            normalized_spectrum = analysis.power_spectrum(pref[roi,roi])
            fft_im = rasterplots.greyscale(normalized_spectrum)
            fft_im.save(fname % 'FFT')

        # Note: ROI not applied and the values of 3 are due to historical reasons
        development_info.append((time,pref[3:-3, 3:-3], np.mean(sel[3:-3,3:-3])))

    ts, prefs, mean_sels = zip(*sorted(development_info))
    # We only need the stabilities up till 10000
    fname = os.path.join(output_dir, 'model_development.svg')
    development_fig = vectorplots.map_development_plot(analysis.stability_index(prefs),
                                                          mean_sels, selectivity_norm)
    development_fig.savefig(fname, **savefig_opts)
    vectorplots.close([development_fig])
    svg_path = os.path.join(output_dir, '%s.svg' % name)
    return Display(compose.apply_template(template_path, svg_path,
                                             size_factor=size_factor))
示例#2
0
def fig11(template_dir, build_dir, input_seed=102, size_factor=1.0, show_raster=False):
    """
    Automatically generates Figure 11 showing the result of simulated
    goggle rearing and comparing to the experimental data (Tanaka
    2009).
    """
    name = 'fig11'
    if show_raster: return Display(snapshot=name, template_dir=template_dir)
    resize_factor = 4
    times = [ 6000,  9000, 12000, 20000]

    template_path, output_dir = setup(name, template_dir, build_dir)
    pattern = 'jn13_figures/output/Fig11/*seed102/*/*.npz'
    files = lancet.FilePattern('npz_file', pattern)
    file_info = lancet.FileInfo(files, 'npz_file', lancet.NumpyFile())

    filter_times = file_info.dframe['time'].map(lambda x: x in times)
    selection = file_info.load(file_info.dframe[filter_times])

    roi = selection[selection['time']==times[-1]]['roi'].iloc[0]
    savefig_opts = dict(transparent=True, format='svg', bbox_inches='tight', pad_inches=0)

    for (index,row) in selection.iterrows():
        fname = os.path.join(output_dir, 'OR_%d.png' % int(row['time']))
        pref = get_pref(row)
        sel = get_sel(row)

        # Rotate the colour key to match the convention in Tanaka et el.
        tanaka_pref = pref + (2.0 / 3.0) % 1
        # Create the combined preference/selectivity map
        or_map = rasterplots.OR_map(tanaka_pref,sel)
        or_black = rasterplots.black_selectivity(or_map)
        # Resize by factor
        (dim1,dim2) = pref.shape
        or_black_resized = rasterplots.resize(or_black, (dim1*resize_factor,
                                                         dim2*resize_factor))
        # Save the orientation maps
        or_black_resized.save(fname)

        # Unbiased experimental histogram
        unbiased_hist = vectorplots.tanaka_histogram('unbiased')
        unbiased_hist.savefig(os.path.join(output_dir, 'unbiased_tanaka.svg'), **savefig_opts)

        # Vertically biased experimental histogram
        biased_hist = vectorplots.tanaka_histogram('biased')
        biased_hist.savefig(os.path.join(output_dir, 'biased_tanaka.svg'), **savefig_opts)

        # Approximation to vertical goggle rearing
        fname = os.path.join(output_dir, 'VGR_%d.svg' % int(row['time']))
        gcal_hist = vectorplots.tanaka_histogram(pref)
        gcal_hist.savefig(fname, **savefig_opts)
        vectorplots.close([biased_hist, gcal_hist])
    svg_path = os.path.join(output_dir, '%s.svg' % name)
    return Display(compose.apply_template(template_path, svg_path,
                                             size_factor=size_factor))
def fig11(template_dir,
          build_dir,
          input_seed=102,
          size_factor=1.0,
          show_raster=False):
    """
    Automatically generates Figure 11 showing the result of simulated
    goggle rearing and comparing to the experimental data (Tanaka
    2009).
    """
    name = 'fig11'
    if show_raster: return Display(snapshot=name, template_dir=template_dir)
    resize_factor = 4
    times = [6000, 9000, 12000, 20000]

    template_path, output_dir = setup(name, template_dir, build_dir)
    pattern = 'jn13_figures/output/Fig11/*seed102/*/*.npz'
    files = lancet.FilePattern('npz_file', pattern)
    file_info = lancet.FileInfo(files, 'npz_file', lancet.NumpyFile())

    filter_times = file_info.dframe['time'].map(lambda x: x in times)
    selection = file_info.load(file_info.dframe[filter_times])

    roi = selection[selection['time'] == times[-1]]['roi'].iloc[0]
    savefig_opts = dict(transparent=True,
                        format='svg',
                        bbox_inches='tight',
                        pad_inches=0)

    for (index, row) in selection.iterrows():
        fname = os.path.join(output_dir, 'OR_%d.png' % int(row['time']))
        pref = get_pref(row)
        sel = get_sel(row)

        # Rotate the colour key to match the convention in Tanaka et el.
        tanaka_pref = pref + (2.0 / 3.0) % 1
        # Create the combined preference/selectivity map
        or_map = rasterplots.OR_map(tanaka_pref, sel)
        or_black = rasterplots.black_selectivity(or_map)
        # Resize by factor
        (dim1, dim2) = pref.shape
        or_black_resized = rasterplots.resize(
            or_black, (dim1 * resize_factor, dim2 * resize_factor))
        # Save the orientation maps
        or_black_resized.save(fname)

        # Unbiased experimental histogram
        unbiased_hist = vectorplots.tanaka_histogram('unbiased')
        unbiased_hist.savefig(os.path.join(output_dir, 'unbiased_tanaka.svg'),
                              **savefig_opts)

        # Vertically biased experimental histogram
        biased_hist = vectorplots.tanaka_histogram('biased')
        biased_hist.savefig(os.path.join(output_dir, 'biased_tanaka.svg'),
                            **savefig_opts)

        # Approximation to vertical goggle rearing
        fname = os.path.join(output_dir, 'VGR_%d.svg' % int(row['time']))
        gcal_hist = vectorplots.tanaka_histogram(pref)
        gcal_hist.savefig(fname, **savefig_opts)
        vectorplots.close([biased_hist, gcal_hist])
    svg_path = os.path.join(output_dir, '%s.svg' % name)
    return Display(
        compose.apply_template(template_path,
                               svg_path,
                               size_factor=size_factor))
def fig10(template_dir,
          build_dir,
          bound_radius=0.6,
          selectivity_norm=0.07138,
          size_factor=1.0,
          show_raster=False):
    name = 'fig10'
    if show_raster: return Display(snapshot=name, template_dir=template_dir)
    times = [2000 * i for i in range(6)]
    template_path, output_dir = setup(name, template_dir, build_dir)
    pattern = 'jn13_figures/output/Fig10_12/*/*/*.npz'
    files = lancet.FilePattern('npz_file', pattern)
    file_info = lancet.FileInfo(files, 'npz_file', lancet.NumpyFile())

    filter_times = file_info.dframe['time'].map(lambda x: x in times)
    selection = file_info.load(file_info.dframe[filter_times])

    savefig_opts = dict(transparent=True,
                        format='svg',
                        bbox_inches='tight',
                        pad_inches=0)
    development_info = []
    for (index, row) in selection.iterrows():
        time = row['time']
        fname = os.path.join(output_dir, '%%s_%.1f.png' % int(time))
        bounds = imagen.boundingregion.BoundingBox(radius=0.75)
        sheetcoords = imagen.SheetCoordinateSystem(bounds, xdensity=98)
        roi = slice(*sheetcoords.sheet2matrixidx(bound_radius, bound_radius))
        # Not applying ROI as new bounds will be used
        pref = get_pref(row, roi=roi)
        sel = get_sel(row, roi=roi)
        (cfs, coords) = row['afferent_CFs']

        roi = slice(*sheetcoords.sheet2matrixidx(bound_radius, bound_radius))
        # Create the combined preference/selectivity map
        or_map = rasterplots.OR_map(pref, sel)
        or_black = rasterplots.black_selectivity(or_map)
        (dim1, dim2) = pref.shape
        or_black_resized = rasterplots.resize(or_black, (dim1 * 4, dim2 * 4))
        # Save the orientation map
        or_black_resized.save(fname % 'OR')
        # Save the row of CF images
        cf_block = rasterplots.cf_image(cfs,
                                        coords,
                                        border=5,
                                        width=8,
                                        height=1,
                                        pos=(1, 4),
                                        bg=(255, 255, 255))
        cf_block.save(fname % 'CF')
        # Save the FFT of the last map
        if time == times[-1]:
            normalized_spectrum = analysis.power_spectrum(pref[roi, roi])
            fft_im = rasterplots.greyscale(normalized_spectrum)
            fft_im.save(fname % 'FFT')

        # Note: ROI not applied and the values of 3 are due to historical reasons
        development_info.append((time, pref[3:-3,
                                            3:-3], np.mean(sel[3:-3, 3:-3])))

    ts, prefs, mean_sels = zip(*sorted(development_info))
    # We only need the stabilities up till 10000
    fname = os.path.join(output_dir, 'model_development.svg')
    development_fig = vectorplots.map_development_plot(
        analysis.stability_index(prefs), mean_sels, selectivity_norm)
    development_fig.savefig(fname, **savefig_opts)
    vectorplots.close([development_fig])
    svg_path = os.path.join(output_dir, '%s.svg' % name)
    return Display(
        compose.apply_template(template_path,
                               svg_path,
                               size_factor=size_factor))