Beispiel #1
0
    def plotObj3D(self, gen, gen_tot):
        """

        :param gen:
        :param gen_tot:
        :return:
        """
        color = iter(cm.gray(np.linspace(1, 0.1, gen_tot)))
        # color = iter(cm.rainbow(np.linspace(0,1,gen_tot)))

        fig = plt.figure()
        ax = fig.add_subplot(111, projection='3d')
        for index, item in enumerate(gen):
            obj = item["objective"][0]
            x = []
            y = []
            z = []
            # r = index / gen_tot
            # g = index / gen_tot
            # b = index / gen_tot
            for iobj in obj:
                x.append(iobj[0])
                y.append(iobj[1])
                z.append(iobj[2])
                # print '['+'\t'.join(map(str,iobj))+']'
            ax.scatter(x, y, z, 'o', color=next(color), label=str(index))
        ax.scatter(x, y, z, '.', c='red')

        ax.set_title('moea.json')
        ax.set_xlabel('obj1')
        ax.set_ylabel('obj2')
        ax.set_zlabel('obj3')
        plt.grid(True)
        plt.savefig(self.fileName + '.png')
        plt.clf()
Beispiel #2
0
    def plotObj2D(self, gen, gen_tot):
        """

        :param gen:
        :param gen_tot:
        :return:
        """
        color = iter(cm.gray(np.linspace(1, 0.1, gen_tot)))
        # color = iter(cm.rainbow(np.linspace(0,1,gen_tot)))
        for index, item in enumerate(gen):
            obj = item["objective"][0]
            x = []
            y = []
            # r = index / gen_tot
            # g = index / gen_tot
            # b = index / gen_tot
            for iobj in obj:
                x.append(iobj[0])
                y.append(iobj[1])
                # print '['+'\t'.join(map(str,iobj))+']'
            plt.plot(x, y, 'o', color=next(color), label=str(index))
        plt.plot(x, y, '.', mec='red', mfc='red')

        plt.title('moea.json')
        plt.xlabel('obj1')
        plt.ylabel('obj2')
        plt.grid(True)
        plt.savefig(self.fileName + '.png')
        plt.clf()
Beispiel #3
0
    def savePlot(self):
        with open(self.fileName) as data_file:
            data = json.load(data_file)

        gen = data["generation"]
        gen_tot = len(gen)

        color = iter(cm.gray(np.linspace(1, 0.1, gen_tot)))
        # color = iter(cm.rainbow(np.linspace(0,1,gen_tot)))
        for index, item in enumerate(gen):
            obj = item["objective"][0]
            obj_tot = len(obj)
            x = []
            y = []
            r = index / gen_tot
            g = index / gen_tot
            b = index / gen_tot

            for iobj in obj:
                x.append(iobj[0])
                y.append(iobj[1])

                # print '['+'\t'.join(map(str,iobj))+']'
            plt.plot(x, y, 'o', color=next(color), label=str(index))

        # minmax = [min(x), max(x), min(y), max(y)]

        plt.title('moea.json')
        plt.xlabel('obj1')
        # if minmax[0]==0.0 and minmax[1]==0.0:
        #     plt.xlim([minmax[0]-0.05,minmax[1]+0.05])
        # elif minmax[0]==0.0 and minmax[1]!=0.0:
        #     plt.xlim([minmax[0]-0.05,minmax[1]+0.05*abs(minmax[1])])
        # elif minmax[0]!=0.0 and minmax[1]==0.0:
        #     plt.xlim([minmax[0]-0.05*abs(minmax[0]),minmax[1]+0.05])
        # else:
        #     plt.xlim([minmax[0]-0.05*abs(minmax[0]),minmax[1]+0.05*abs(minmax[1])])
        # # plt.xlim([minmax[0]-0.05*abs(minmax[0]),minmax[1]+0.05*abs(minmax[1])])
        plt.ylabel('obj2')
        # if minmax[2]==0.0 and minmax[3]==0.0:
        #     plt.ylim([minmax[2]-0.05,minmax[3]+0.05])
        # elif minmax[2]==0.0 and minmax[3]!=0.0:
        #     plt.ylim([minmax[2]-0.05,minmax[3]+0.05*abs(minmax[3])])
        # elif minmax[2]!=0.0 and minmax[3]==0.0:
        #     plt.ylim([minmax[2]-0.05*abs(minmax[2]),minmax[3]+0.05])
        # else:
        #     plt.ylim([minmax[2]-0.05*abs(minmax[2]),minmax[3]+0.05*abs(minmax[3])])
        # # plt.ylim([minmax[2]-0.05*abs(minmax[2]),minmax[3]+0.05*abs(minmax[3])])
        plt.grid(True)
        # plt.legend(loc='best')
        plt.savefig(self.fileName + '.png')
        # plt.show()
        plt.clf()
Beispiel #4
0
def main():
    opts = docopt(__doc__)
    if opts['--verbose']:
        logging.basicConfig(level=logging.INFO)
    else:
        logging.basicConfig(level=logging.WARN)

    logging.info('Using filename suffix: {0}'.format(opts['--suffix']))

    if len(opts['<IMAGE>']) == 0:
        logging.info('No images specified. Exiting successfully.')
        sys.exit(0)

    logging.info('Pre-scanning images...')

    min_val, max_val = np.inf, -np.inf
    for filename in opts['<IMAGE>']:
        logging.info('Scanning {0}'.format(filename))
        A = imread(filename)
        max_val = max(np.max(A), max_val)
        min_val = min(np.min(A), min_val)

    logging.info('Input images have values on interval [{0}, {1}].'.format(
        min_val, max_val))
    if max_val == min_val:
        logging.error(
            'Images all have the same value pixels. Rescaling is meaningless.')
        sys.exit(1)

    for filename in opts['<IMAGE>']:
        out_filename = filename + opts['--suffix']
        logging.info('Re-scaling {0} to {1}'.format(filename, out_filename))
        A = np.array(imread(filename), dtype=np.float32)
        A -= min_val
        A /= max_val - min_val

        if len(A.shape) == 2:
            A = cm.gray(A)

        imsave(out_filename, A, format='png')

    logging.info('Finished')
Beispiel #5
0
def main():
    opts = docopt(__doc__)
    if opts['--verbose']:
        logging.basicConfig(level=logging.INFO)
    else:
        logging.basicConfig(level=logging.WARN)

    logging.info('Using filename suffix: {0}'.format(opts['--suffix']))

    if len(opts['<IMAGE>']) == 0:
        logging.info('No images specified. Exiting successfully.')
        sys.exit(0)

    logging.info('Pre-scanning images...')

    min_val, max_val = np.inf, -np.inf
    for filename in opts['<IMAGE>']:
        logging.info('Scanning {0}'.format(filename))
        A = imread(filename)
        max_val = max(np.max(A), max_val)
        min_val = min(np.min(A), min_val)

    logging.info('Input images have values on interval [{0}, {1}].'.format(min_val, max_val))
    if max_val == min_val:
        logging.error('Images all have the same value pixels. Rescaling is meaningless.')
        sys.exit(1)

    for filename in opts['<IMAGE>']:
        out_filename = filename + opts['--suffix']
        logging.info('Re-scaling {0} to {1}'.format(filename, out_filename))
        A = np.array(imread(filename), dtype=np.float32)
        A -= min_val
        A /= max_val - min_val

        if len(A.shape) == 2:
            A = cm.gray(A)
        
        imsave(out_filename, A, format='png')

    logging.info('Finished')
Beispiel #6
0
def figureCaRatio(ax1, ax2):

    stimlist = [
        simDataPath +
        'PSim_ConstrainUp_noGABAcontrol_16spinesp3tertdend1_81.8e-05TimeDelay0Mirror_0BranchOffset_0_',
        simDataPath +
        'PSim_ConstrainUp_GABAAfast_tertdend1_8_0_16spinesp3tertdend1_81.8e-05TimeDelay0Mirror_0BranchOffset_0.1_',
        simDataPath +
        'PSim_ConstrainUp_GABAAslow_tertdend1_8_0_16spinesp3tertdend1_81.8e-05TimeDelay0Mirror_0BranchOffset_0.1_',
    ]
    labels = ['Control', 'Fast GABA', 'Slow GABA']
    colors = [
        cm.gray(5 / 10.),
        cm.Reds(np.linspace(1, 0, 10))[1],
        cm.Reds(np.linspace(1, 0, 10))[4]
    ]
    ax = ax1
    normdata = importGABA(stimlist, labels)
    handles = []
    for i, key in enumerate(normdata):
        spy = normdata[key]['spy']
        cay = normdata[key]['cay']
        mspy = normdata[key]['mspy']
        handle, = ax.plot(mspy[:, 0],
                          mspy[:, 1],
                          label='',
                          marker='s',
                          markersize=4,
                          c=colors[i])
        handles.append(handle)
        handle, = ax2.plot(cay[:, 0],
                           cay[:, 1],
                           label='',
                           marker='o',
                           c=colors[i],
                           markersize=4,
                           linestyle=':',
                           alpha=.9)
        handles.append(handle)
    ax.legend([handles[i] for i in [0, 2, 4]],
              labels,
              title='Non-Stim Spine',
              frameon=True,
              fancybox=True,
              loc='upper left')
    ax2.legend([handles[i] for i in [1, 3, 5]],
               labels,
               title='Dendrite',
               frameon=True,
               fancybox=True,
               loc='upper left')
    format0(ax)
    ax.set_xlabel(u'Distance from Soma (µm)', labelpad=0)
    ax.set_ylabel('Peak $\it{[Ca^{2+}]}$ / Stim Spine Peak $\it{[Ca^{2+}]}$',
                  labelpad=0)
    ax.set_xlim([20, 220])
    ax.set_ylim([-.01, .36])
    format1(ax2)
    ax2.set_xlabel(u'Distance from Soma (µm)', labelpad=0)
    ax2.set_xlim(ax.get_xlim())
    ax2.set_ylim([-.01, .36])
    return ax, normdata
def plotJson(folder, fileName, issave=False):
    import matplotlib as mpl
    if os.environ.get('DISPLAY', '') == '':
        # print('--py:Warning:: No display found. Using non-interactive Agg backend')
        mpl.use('Agg')
    import matplotlib.pyplot as plt

    import numpy as np
    import json

    from matplotlib.pyplot import cm

    fileName = folder + '/' + fileName
    with open(fileName) as data_file:
        data = json.load(data_file)

    gen = data["generation"]
    gen_tot = len(gen)

    color = iter(cm.gray(np.linspace(1, 0.1, gen_tot)))
    # color = iter(cm.rainbow(np.linspace(0,1,gen_tot)))
    for index, item in enumerate(gen):
        obj = item["objective"][0]
        obj_tot = len(obj)
        x = []
        y = []
        r = index / gen_tot
        g = index / gen_tot
        b = index / gen_tot

        for iobj in obj:
            x.append(iobj[0])
            y.append(iobj[1])

            # print '['+'\t'.join(map(str,iobj))+']'
        plt.plot(x, y, 'o', color=next(color), label=str(index))

    minmax = [min(x), max(x), min(y), max(y)]

    plt.title(folder)
    plt.xlabel('obj1')
    if minmax[0] == 0.0 and minmax[1] == 0.0:
        plt.xlim([minmax[0] - 0.05, minmax[1] + 0.05])
    elif minmax[0] == 0.0 and minmax[1] != 0.0:
        plt.xlim([minmax[0] - 0.05, minmax[1] + 0.05 * abs(minmax[1])])
    elif minmax[0] != 0.0 and minmax[1] == 0.0:
        plt.xlim([minmax[0] - 0.05 * abs(minmax[0]), minmax[1] + 0.05])
    else:
        plt.xlim([
            minmax[0] - 0.05 * abs(minmax[0]),
            minmax[1] + 0.05 * abs(minmax[1])
        ])
    # plt.xlim([minmax[0]-0.05*abs(minmax[0]),minmax[1]+0.05*abs(minmax[1])])
    plt.ylabel('obj2')
    if minmax[2] == 0.0 and minmax[3] == 0.0:
        plt.ylim([minmax[2] - 0.05, minmax[3] + 0.05])
    elif minmax[2] == 0.0 and minmax[3] != 0.0:
        plt.ylim([minmax[2] - 0.05, minmax[3] + 0.05 * abs(minmax[3])])
    elif minmax[2] != 0.0 and minmax[3] == 0.0:
        plt.ylim([minmax[2] - 0.05 * abs(minmax[2]), minmax[3] + 0.05])
    else:
        plt.ylim([
            minmax[2] - 0.05 * abs(minmax[2]),
            minmax[3] + 0.05 * abs(minmax[3])
        ])
    # plt.ylim([minmax[2]-0.05*abs(minmax[2]),minmax[3]+0.05*abs(minmax[3])])
    plt.grid(True)
    # plt.legend(loc='best')
    if issave:
        plt.savefig(fileName + '.png')
        plt.clf()
    else:
        plt.show()

    return obj