Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import math
- import sys
- #python3 diff_compare.py name_file_IMD name_file_xraydb
- #examples:
- #python3 diff_compare.py Pt_substrate.dat Pt.dat
- #python3 diff_compare.py Pd_substrate.dat Pd.dat
- n = len(sys.argv)
- print("Total arguments passed:", n)
- if n!=3:
- print("2 args needed: name_file_IMD name_file_xraydb")
- else:
- #filename="Pd.dat"
- filename=sys.argv[2]
- with open(filename) as f:
- lines=f.readlines()
- compteur=1
- list_matrix=[]
- for elt in lines:
- if compteur<=7:
- #print(elt)
- pass
- else:
- list_strings=elt.strip('\n').strip().split(" ")
- toadd=[float(i) for i in list_strings]
- list_matrix.append(toadd)
- compteur+=1
- npArrayXraydb = np.array(list_matrix)
- #filename="Pd_substrate.dat"
- filename=sys.argv[1]
- with open(filename) as ff:
- lines=ff.readlines()
- compteur=1
- list_matrix=[]
- for elt in lines:
- if compteur<=7:
- #print(elt)
- pass
- else:
- list_strings=elt.strip('\n').strip().split(" ")
- toadd=[float(i) for i in list_strings]
- list_matrix.append(toadd)
- compteur+=1
- npArrayImd = np.array(list_matrix)
- diff_matrices = np.absolute(npArrayXraydb-npArrayImd)
- max_elt = 0
- sum_elt = 0
- for rows in diff_matrices:
- for elt in rows:
- #print(elt)
- if elt<0:
- print(elt)
- if(max_elt<elt):
- max_elt=elt
- sum_elt += elt
- sum_elt=sum_elt/(2000*200)
- print("max difference: ",max_elt)
- print("mean difference: ",sum_elt)
- #https://fr.wikipedia.org/wiki/Norme_matricielle#Norme_de_Frobenius
- diff_matrices_adjointe=diff_matrices.conj().T
- a_astar = np.dot(diff_matrices , diff_matrices_adjointe)
- trace = np.trace(a_astar)
- print("Frobenius norm: ",math.sqrt(trace))
Advertisement
Add Comment
Please, Sign In to add comment