Advertisement
bolverk

offset_supernova_analysis_2

Feb 18th, 2015
491
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1. def main():
  2.  
  3.     import matplotlib
  4.     matplotlib.use('Qt4Agg')
  5.     import glob
  6.     import numpy
  7.     import h5py
  8.     import pylab
  9.  
  10.     all_contour_files = glob.glob('contour_*.h5')
  11.     max_time_index = numpy.max([int(fname.split('_')[1].replace('.h5','')) for fname in all_contour_files])
  12.  
  13.     for i in range(2,max_time_index+1,2):
  14.         current_contour_files = glob.glob('contour_'+str(i)+'_*.h5')
  15.         x_temp = []
  16.         y_temp = []
  17.         for fname in current_contour_files:
  18.             with h5py.File(fname) as f:
  19.                 x_filtered = [x for x,y in zip(f['x'],f['y']) if x**2+y**2>0.02**2]
  20.                 y_filtered = [y for x,y in zip(f['x'],f['y']) if x**2+y**2>0.02**2]
  21.                 x_temp.extend(x_filtered)
  22.                 y_temp.extend(y_filtered)
  23.         angles = numpy.arctan2(numpy.array(y_temp)+1, numpy.array(x_temp))
  24.         x_sorted = numpy.array([x for a,x in sorted(zip(angles,x_temp))])
  25.         y_sorted = numpy.array([y for a,y in sorted(zip(angles,y_temp))])
  26.         pylab.plot(y_sorted, x_sorted)
  27.     pylab.xlabel('x [parsec]')
  28.     pylab.ylabel('y [parsec]')
  29.     pylab.title('Shock fronts at 20 year intervals')
  30.     pylab.axis('equal',adjustable='box')
  31.     pylab.show()
  32.     #pylab.savefig('shock_fronts.png')
  33.  
  34. if __name__ == '__main__':
  35.  
  36.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement