def draw(asw,xc,yc): print asw N,R = 100,50 if sim[asw][0] == 'quasar': flag,R = 'Q',20 if sim[asw][0] == 'galaxy': flag,R = 'G',20 if sim[asw][0] == 'cluster': flag,R = 'C',42 x = linspace(-R,R,N) y = 1*x kappa,arriv = many.grids(asw,x,y) fig = figure() panel = fig.add_subplot(1,1,1) panel.set_aspect('equal') swsquare = imread('asw/'+asw+'.png') panel.imshow(swsquare[yc-R:yc+R+1,xc-R:xc+R+1]) lo,hi = amin(arriv), amax(arriv) lev = linspace(lo,lo+.2*(hi-lo),100) # x = 1.2*x # y = 1.2*y panel.contour(x+R,-y+R,arriv,lev) show()
def draw_sim(asw, sim): path = os.path.join(simdir, asw) # try: # path = os.path.join(simdir, asw) # #os.makedirs(path) # except OSError as e: # print 'error creating dir', e # #return filenames = ['arriv', 'kappa', 'm_encl'] print '> drawing sim %s'%asw, #prevent submodules prints.. old_stdout = sys.stdout old_stderr = sys.stderr devnull = open(os.devnull, 'w') sys.stdout = devnull #sys.stderr = devnull print asw N,R = 100,50 if sim[asw][0] == 'quasar': flag,R = 'Q',20 if sim[asw][0] == 'galaxy': flag,R = 'G',20 if sim[asw][0] == 'cluster': flag,R = 'C',50 x = np.linspace(-R,R,N) y = 1*x kappa,arriv = many.grids(asw,x,y) fig = pl.figure() panel = fig.add_subplot(1,1,1) panel.set_aspect('equal') lev = np.linspace(0,10,41) pc = panel.contour(x,y,kappa,lev) panel.clabel(pc, inline=1, fontsize=10) pl.savefig(os.path.join(path, '%s.%s'%(filenames[1],ext))) fig = pl.figure() panel = fig.add_subplot(1,1,1) rad = np.linspace(0,R,20)[1:] radq = rad*rad sum = 0*rad for i in range(len(x)): for j in range(len(y)): rsq = x[i]**2 + y[j]**2 for k in range(len(rad)): if rsq < radq[k]: sum[k] += kappa[j,i] dx = x[1]-x[0] for k in range(len(rad)): sum[k] *= dx*dx/(pi*radq[k]) fil = open(os.path.join(path, asw+'.txt'),'w') for k in range(len(rad)): fil.write('%9.2e %9.2e\n' % (rad[k],sum[k])) fil.close() fil = open(os.path.join(simdir, asw+'.txt'),'w') for k in range(len(rad)): fil.write('%9.2e %9.2e\n' % (rad[k],sum[k])) fil.close() panel.scatter(rad,sum) panel.set_xlabel('radius [pixels]') panel.set_ylabel('average interior \textkappa [1]') pl.savefig(os.path.join(path, '%s.%s'%(filenames[2],ext))) fig = pl.figure() panel = fig.add_subplot(1,1,1) panel.set_aspect('equal') lo,hi = np.amin(arriv), np.amax(arriv) lev = np.linspace(lo,lo+.2*(hi-lo),100) panel.contour(x,y,arriv,lev) pl.savefig(os.path.join(path, '%s.%s'%(filenames[0],ext))) #restore stdout sys.stdout = old_stdout sys.stderr = old_stderr print '...DONE.' for f in filenames: print ' - %s'%(f+'.'+ext)