Advertisement
UF6

Abundance Distribution II

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