Curlz

From Wiki
Jump to navigation Jump to search

"""In preparation""". Usage (written for python 3.5 and newer):

  1. copy following text to blank file named ""culrz.py""
   # /usr/bin/env python3
   # coding: utf-8
   
   import numpy as np
   import pandas as pd
   import matplotlib.pyplot as plt
   import sys
   
   ###input###
   file=sys.argv[1]
   min=float(sys.argv[2])
   max=float(sys.argv[3])
   sig=0.2 #float(sys.argv[4])
   
   df=pd.read_csv(file, delim_whitespace=True)
   no_of_shifts=len(df)
   
   ###gauss func###
   graphdots=(max-min)/0.01
   graphdots=int(graphdots)
   
   def gaussian(x, mu, sig):
       return np.exp(-np.power(x - mu, 2.) / (2 * np.power(sig, 2.)))
   
   ###loop over rows in list ($1 input) and convert to gaus bell###
   
   tot=pd.DataFrame(np.zeros((graphdots, 2)), columns = ['E / eV', 'intensity'])
   
   for shift in np.arange(0, no_of_shifts, 1):
       atomgaus = []
       trid=df.iloc[shift]['level']
       #print(shift)
       for e in np.arange(min, max, 0.01):
           spect=gaussian(e, trid, sig)
           pair = [e, spect]
           atomgaus.append(pair)
       ef = pd.DataFrame(atomgaus, columns = ['E / eV', 'intensity'])
       tot.iloc[:,1]=tot.iloc[:,1] + ef.iloc[:,1]
       tot.iloc[:,0]=ef.iloc[:,0]
       del spect
       del pair
       del atomgaus
       del ef
   
   with pd.option_context('display.max_rows', None, 'display.max_columns', None):
       print(tot)
   
   fig = tot.plot(x='E / eV',y='intensity', kind='line', linewidth=1.2, color='#000000', layout=None, figsize=(3, 3.2), title=(shift), grid=True, legend=False, xlim=(min, max), fontsize=(10)) 
   plt.savefig(str(file) + str(shift) + ".png", dpi=120)
  1. make ""culrz.py"" executable:
   chmod +x curlz.py
  1. to run script type:
   python3.6 <list_of_xps_shifts.dat> <min_of_ploted> <max_of_ploted>
  1. to write script output to file:
   python3.6 <list_of_xps_shifts.dat> <min_of_ploted> <max_of_ploted> > <output.dat>