Advertisement
UF6

Abundance Distribution

UF6
Mar 13th, 2021
880
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.68 KB | None | 0 0
  1. ###This script can be used to plot the pos_x and pos_y and then
  2. ###scheme the particles by their abundances distribution.
  3.  
  4. import numpy as np
  5. import matplotlib.pyplot as plt
  6. import glob as glob
  7.  
  8.  
  9. plt.style.use('dark_background')
  10.  
  11. # to read the pos_ and pos_y
  12. with open('testtime.dat', 'r') as f:
  13.     lines = f.readlines()
  14.     size=len(lines)
  15.     x = [float(line.split()[0]) for line in lines] # will read the column one
  16.     y = [float(line.split()[1]) for line in lines] # will read the column two
  17.     s=[3] # the size of the particle on the plot
  18.    
  19. x = np.array(x)
  20. #print(x)
  21.  
  22.  
  23. y= np.array(y)
  24. color_array=[]
  25.  
  26. c12_app= [] #empty list to stor the c12
  27. o16_app= [] #empty list to stor the o16
  28. si28_app= [] #empty list to stor the si28
  29. #print(size)
  30. # to read the abundances and shade the particles
  31. for file in os.listdir('/work/07422/tg867218/stampede2/test'):#Reads where the file is in the diractory
  32.    if file.endswith("_z1.dat"):#This should read the file in the folder that ends with .dat
  33.      with open(file) as ab:
  34.          file = os.listdir('_z1.dat')
  35. abundance = f.readlines()
  36. for file in files:
  37.   if files.strip()[0].isdigit():#This seperates the files be useful data abd splits off anything that is not
  38.     cols = files.strip().split()
  39.     #print('file', file)
  40.     # To append the atom. baryon, and mass fraction to empty lists
  41.     atom_number=[] # to append the atomic number from the abundance files
  42.     baryon_number=[] # to append the baryon number from the abundance files
  43.     mass_fraction=[] # to append the mass fraction from the abundance files
  44.     # this loop to read the columns from the abundance files
  45.     for w in abundance:
  46.         line = w.split()
  47.         atom_number.append(int(line[0]))
  48.         baryon_number.append(int(line[1]))
  49.         mass_fraction.append(float(line[2]))
  50.     #print ('ato', atom_number)
  51.     #print ('bar', baryon_number)
  52.     #print ('mass', mass_fraction)
  53.     #print ('isotope', isotope_symbols)
  54.    
  55.     # to calssfiy the baryon number to empity lists according to the colors that we want
  56.     green_app= 0
  57.     blue_app= 0
  58.     red_app= 0
  59.     white_app= 0
  60.  
  61.     for j in range (229):      # 229 is the number of the line in every abundance file
  62.         #The white color represents 56Ni, and the green, blue, and red colors in
  63.         #the figure represent isotopes with A <= 16, intermediate-mass isotopes with 16 < A <= 40,
  64.         #and iron-peak isotopes for all A > 40 (except 56Ni) respectively
  65.         if(baryon_number[j] <= 16):
  66.             green_app += mass_fraction[j]
  67.         elif (baryon_number[j] > 16 and baryon_number[j] <= 40):
  68.             blue_app += mass_fraction[j]
  69.         elif (baryon_number[j] > 40 and (atom_number[j] != 28 or baryon_number[j] != 56)):
  70.             red_app += mass_fraction[j]
  71.         else:
  72.             white_app = mass_fraction[j]
  73.    
  74.     # To find the max abundances for C12, O16, and Si28
  75.     for k in range (229):
  76.         if (baryon_number[k] == 12 and atom_number[k] == 6):
  77.             c12_app.append(mass_fraction[k])
  78.         elif (baryon_number[k] == 16 and atom_number[k] == 8):
  79.             o16_app.append(mass_fraction[k])
  80.         elif (baryon_number[k] == 28 and atom_number[k] == 14):
  81.             si28_app.append(mass_fraction[k])
  82.        
  83.        
  84.     #print('green_app', green_app)
  85.     #print('blue_app', blue_app)
  86.     #print('red_app', red_app)
  87.     #print('white_app', white_app)
  88.     #print ('c12_app', c12_app)
  89.     #print ('o16_app', o16_app)
  90.     #print ('si28_app', si28_app)
  91.  
  92.     color_max = np.zeros(4)
  93.  
  94.     color_max[0] = green_app
  95.     color_max[1] = blue_app
  96.     color_max[2] = red_app
  97.     color_max[3] = white_app
  98.     #print('green', color_max[0])
  99.     #print('blue', color_max[1])
  100.     #print('red', color_max[2])
  101.     #print('white', color_max[3])
  102.    
  103.     # Max value
  104.     color_ind = np.argmax(color_max)
  105.     #print('color_ind', color_ind)
  106.     res_max_c12 = max(float(sub) for sub in c12_app)
  107.     res_max_o16 = max(float(sub) for sub in o16_app)
  108.     res_max_si28 = max(float(sub) for sub in si28_app)
  109.  
  110.  
  111.     if color_ind == 0:
  112.         color_array.append('g')
  113.     elif color_ind == 1:
  114.         color_array.append('b')
  115.     elif color_ind == 2:
  116.         color_array.append('r')
  117.     else:
  118.         color_array.append('w')
  119.        
  120.  
  121. color_array= np.array(color_array, dtype=object)
  122. #print('color_array', color_array)
  123.  
  124.  
  125.  
  126. print('max_c12', res_max_c12)
  127. print('max_o16', res_max_o16)
  128. print('max_si28', res_max_si28)
  129. plt.figure(figsize=(10,20))
  130. plt.xlabel('r(cm)', fontsize=18)
  131. plt.ylabel('z(cm)', fontsize=18)
  132. plt.title('last time step 1.9 s', fontsize=18)
  133. plt.xlim(0, 13e9)
  134. plt.ylim(-13e9, 13e9)
  135. plt.scatter(x, y, s, c= color_array)
  136. plt.savefig('afteredit')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement