Exemplo n.º 1
0
def convert_all_to_png(vis_path, out_dir="maps_png", size=None):

    units = {
        'gas_density': 'Gas Density [g/cm$^3$]',
        'Tm': 'Temperature [K]',
        'Tew': 'Temperature [K]',
        'S': 'Entropy []',
        'dm': 'DM Density [g/cm$^3$]',
        'v': 'Velocity [km/s]'
    }

    log_list = ['gas_density']

    for vis_file in os.listdir(vis_path):
        if ".dat" not in vis_file:
            continue
        print "converting %s" % vis_file
        map_type = re.search('sigma_(.*)_[xyz]', vis_file).group(1)

        (image, pixel_size,
         axis_values) = read_visualization_data(vis_path + "/" + vis_file,
                                                size)
        print "image width in Mpc/h: ", axis_values[-1] * 2.0

        x, y = np.meshgrid(axis_values, axis_values)

        cmap_max = image.max()
        cmap_min = image.min()
        ''' plotting '''
        plt.figure(figsize=(5, 4))

        if map_type in log_list:
            plt.pcolor(x, y, image, norm=LogNorm(vmax=cmap_max, vmin=cmap_min))
        else:
            plt.pcolor(x, y, image, vmax=cmap_max, vmin=cmap_min)

        cbar = plt.colorbar()
        if map_type in units.keys():
            cbar.ax.set_ylabel(units[map_type])

        plt.axis(
            [axis_values[0], axis_values[-1], axis_values[0], axis_values[-1]])

        del image

        plt.xlabel(r"$Mpc/h$", fontsize=18)
        plt.ylabel(r"$Mpc/h$", fontsize=18)

        out_file = vis_file.replace("dat", "png")

        plt.savefig(out_dir + "/" + out_file, dpi=150)

        plt.close()
        plt.clf()
Exemplo n.º 2
0
def convert_all_to_png(vis_path, out_dir = "maps_png", size = None) :

    units = { 'gas_density' : 'Gas Density [g/cm$^3$]',
              'Tm' : 'Temperature [K]',
              'Tew' : 'Temperature [K]',
              'S' : 'Entropy []',
              'dm' : 'DM Density [g/cm$^3$]',
              'v' : 'Velocity [km/s]' }

    log_list = ['gas_density']

    for vis_file in os.listdir(vis_path) :
        if ".dat" not in vis_file :
            continue
        print "converting %s" % vis_file
        map_type = re.search('sigma_(.*)_[xyz]', vis_file).group(1)

        (image, pixel_size, axis_values) = read_visualization_data(vis_path+"/"+vis_file, size)
        print "image width in Mpc/h: ", axis_values[-1]*2.0

        x, y = np.meshgrid( axis_values, axis_values )

        cmap_max = image.max()
        cmap_min = image.min()


        ''' plotting '''
        plt.figure(figsize=(5,4))

        if map_type in log_list:
            plt.pcolor(x,y,image, norm=LogNorm(vmax=cmap_max, vmin=cmap_min))
        else :
            plt.pcolor(x,y,image, vmax=cmap_max, vmin=cmap_min)

        cbar = plt.colorbar()
        if map_type in units.keys() :
            cbar.ax.set_ylabel(units[map_type])

        plt.axis([axis_values[0], axis_values[-1],axis_values[0], axis_values[-1]])

        del image

        plt.xlabel(r"$Mpc/h$", fontsize=18)
        plt.ylabel(r"$Mpc/h$", fontsize=18)

        out_file = vis_file.replace("dat", "png")

        plt.savefig(out_dir+"/"+out_file, dpi=150 )

        plt.close()
        plt.clf()
Exemplo n.º 3
0
 def _plot(self):
     p = plt.pcolor(self.matrix, cmap=self.cmap, vmin=self.vmin, vmax=self.vmax)
     plt.colorbar(p)
     plt.xlim((0, self.matrix.shape[0]))
     plt.ylim((0, self.matrix.shape[1]))
     if self.labels is not None:
         plt.xticks(numpy.arange(0.5, len(self.labels) + 0.5), self.labels, fontsize=self.fontsize, rotation=90)
         plt.yticks(numpy.arange(0.5, len(self.labels) + 0.5), self.labels, fontsize=self.fontsize)
Exemplo n.º 4
0
 def _plot(self):
     colormap = plt.pcolor(self.x, self.y, self.z, cmap=self.cmap)
     cb = plt.colorbar(colormap)
     cb.set_label('value')
Exemplo n.º 5
0
 def _plot(self):
     colormap = plt.pcolor(self.x, self.y, self.z, cmap=self.cmap)
     cb = plt.colorbar(colormap)
     cb.set_label('value')
Exemplo n.º 6
0
# initially the k-loop was here, and it didn't work for any plot except the first one
# for k in range(1,29):  # so, this didn't work
print 'now function ', k
for i in range(h):
    yc = ylim[1] - i * dy
    for j in range(m):
        xc = xlim[0] + j * dx
        dat[j * n] = xc
        dat[j * n + 1] = yc
    #print "first DNA: ",dat[0],dat[1];
    #print "2nd DNA: ",dat[2],dat[3];
    #print "last DNA: ",dat[2*m-2],dat[2*m-1];
    r1 = tf.test_func(dat, f, ct.c_int(n), ct.c_int(m), ct.c_int(k))
    rarr[i, :] = [f[j] for j in range(m)]

plt.pcolor(x, y, flipud(rarr), vmin=np.min(rarr), vmax=np.max(rarr))
plt.colorbar()
plt.xlim(xlim)
plt.ylim(ylim)
plt.xlabel(r'$x_1$')
plt.ylabel(r'$x_2$')
plt.title('CEC-2013 test function suite:\nno. {0}: {1}'.format(k, fnames[k]))
plt.suptitle('evaluated using ctypes',
             x=0.02,
             y=0.02,
             ha='left',
             va='bottom',
             fontsize=9)
#plt.show()
plt.savefig('./pics/test_func_' + str(k).zfill(2) +
            '_using_ctypes_zoomlevel_2.png')
Exemplo n.º 7
0
# initially the k-loop was here, and it didn't work for any plot except the first one
# for k in range(1,29):  # so, this didn't work
print 'now function ',k
for i in range(h):
    yc=ylim[1]-i*dy
    for j in range(m):
        xc=xlim[0]+j*dx;
        dat[j*n]=xc;
        dat[j*n+1]=yc;
    #print "first DNA: ",dat[0],dat[1];
    #print "2nd DNA: ",dat[2],dat[3];
    #print "last DNA: ",dat[2*m-2],dat[2*m-1];
    r1=tf.test_func(dat,f,ct.c_int(n),ct.c_int(m),ct.c_int(k))
    rarr[i,:]=[f[j] for j in range(m)]



plt.pcolor(x,y,flipud(rarr),vmin=np.min(rarr),vmax=np.max(rarr))
plt.colorbar()
plt.xlim(xlim)
plt.ylim(ylim)
plt.xlabel(r'$x_1$')
plt.ylabel(r'$x_2$')
plt.title('CEC-2013 test function suite:\nno. {0}: {1}'.format(k,fnames[k]))
plt.suptitle('evaluated using ctypes',x=0.02,y=0.02,ha='left',va='bottom',fontsize=9)
#plt.show()
plt.savefig('./pics/test_func_'+str(k).zfill(2)+'_using_ctypes_zoomlevel_2.png')
plt.clf()
plt.close('all')