Guest User

diff_compare

a guest
Jan 4th, 2022
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.00 KB | None | 0 0
  1. import numpy as np
  2. import math
  3. import sys
  4.  
  5. #python3 diff_compare.py name_file_IMD name_file_xraydb
  6. #examples:
  7. #python3 diff_compare.py Pt_substrate.dat Pt.dat
  8. #python3 diff_compare.py Pd_substrate.dat Pd.dat
  9.  
  10. n = len(sys.argv)
  11. print("Total arguments passed:", n)
  12. if n!=3:
  13.     print("2 args needed: name_file_IMD name_file_xraydb")
  14. else:
  15.     #filename="Pd.dat"
  16.     filename=sys.argv[2]
  17.  
  18.     with open(filename) as f:
  19.         lines=f.readlines()
  20.  
  21.     compteur=1
  22.  
  23.     list_matrix=[]
  24.     for elt in lines:
  25.         if compteur<=7:
  26.             #print(elt)
  27.             pass
  28.         else:
  29.             list_strings=elt.strip('\n').strip().split("      ")
  30.             toadd=[float(i) for i in list_strings]
  31.             list_matrix.append(toadd)
  32.         compteur+=1
  33.        
  34.     npArrayXraydb = np.array(list_matrix)
  35.  
  36.     #filename="Pd_substrate.dat"
  37.     filename=sys.argv[1]
  38.     with open(filename) as ff:
  39.         lines=ff.readlines()
  40.  
  41.     compteur=1
  42.  
  43.     list_matrix=[]
  44.     for elt in lines:
  45.         if compteur<=7:
  46.             #print(elt)
  47.             pass
  48.         else:
  49.             list_strings=elt.strip('\n').strip().split(" ")
  50.             toadd=[float(i) for i in list_strings]
  51.             list_matrix.append(toadd)
  52.         compteur+=1
  53.        
  54.     npArrayImd = np.array(list_matrix)
  55.  
  56.     diff_matrices = np.absolute(npArrayXraydb-npArrayImd)
  57.  
  58.     max_elt = 0
  59.     sum_elt = 0
  60.  
  61.     for rows in diff_matrices:
  62.         for elt in rows:
  63.             #print(elt)
  64.             if elt<0:
  65.                 print(elt)  
  66.             if(max_elt<elt):
  67.                 max_elt=elt
  68.             sum_elt += elt
  69.  
  70.     sum_elt=sum_elt/(2000*200)
  71.      
  72.     print("max difference: ",max_elt)
  73.     print("mean difference: ",sum_elt)
  74.  
  75.     #https://fr.wikipedia.org/wiki/Norme_matricielle#Norme_de_Frobenius
  76.     diff_matrices_adjointe=diff_matrices.conj().T
  77.  
  78.     a_astar = np.dot(diff_matrices , diff_matrices_adjointe)
  79.     trace = np.trace(a_astar)
  80.     print("Frobenius norm: ",math.sqrt(trace))
  81.  
  82.  
Advertisement
Add Comment
Please, Sign In to add comment