-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIR_Model_PlotPriorFit.py
110 lines (80 loc) · 3.67 KB
/
IR_Model_PlotPriorFit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# -*- coding: utf-8 -*-
"""
author: Jack Palmer
email: jpalmer1028@gmail.com
"""
##############################################################################
################################ USER INPUTS #################################
##############################################################################
args = {# Fitting results output folder
'folder' : 'C:/Users/someuser/folder_with_data',
# Any "run number" within the fit output. Integer.
'start' : 1,
# An integer or 'all'. All will plot all spectra from the fit
'amount' : 'all'
}
##############################################################################
##############################################################################
##############################################################################
def PlotPriorFit(args):
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.pylab as pl
import os
from natsort import natsorted
# store filenames
files = os.listdir(args['folder']+'/curves')
# Create a list keys and store the file names minus '.csv' there
keys = []
for i in range(len(files)):
keys.append(files[i][:-4])
#sort the list keys in a natural order
keys = natsorted(keys)
# Create a list 'counter' and populate with the spectrum number
counter = []
for i in range(len(files)):
counter.append(keys[i].split(sep='_')[-1])
# Extract the desired data from the curves folder and store to the dict 'curves'
curves = {}
if args['amount'] == 'all' or args['amount'] == 'All':
for i in range(len(files)):
curves[keys[i]] = pd.read_csv(args['folder'] + '/curves/' + files[i])
else:
# Define indices to retrieve desired data
ind1 = counter.index(str(args['start']))
ind2 = ind1 + args['amount']
for i in np.arange(ind1,ind2):
curves[keys[i]] = pd.read_csv(args['folder'] + '/curves/' + files[i])
# iterate over curves dictionary to plot everything
for key in curves.keys():
plt.figure(figsize=(4.5,4))
plt.figure(dpi = 200)
plt.xlabel("Wavenumber ($cm^{-1}$)", fontsize=12)
plt.ylabel("Absorbance (a.u.)", fontsize=12)
# create a color scheme
colors = pl.cm.jet(np.linspace(0,1,len(curves[key].columns)-3))
cols = list(curves[key].columns)
cols.sort()
# iteratively add all components to the plot
for i in np.arange(1,len(cols)-2):
plt.plot(curves[key]['Wavenumber'],
curves[key][cols[i]],
label = cols[i],
color=colors[i-1])
# shade the area under the curve
plt.fill_between(curves[key]['Wavenumber'],
0,
curves[key][cols[i]],
alpha=0.3,
color=colors[i-1])
# add the raw data to the plot
plt.plot(curves[key]['Wavenumber'], curves[key]['Raw_Data'], linewidth=2, label='Raw Data',color = 'hotpink')
# add the best fit to the plot
plt.plot(curves[key]['Wavenumber'],curves[key]['Best_Fit'], '--', label='Best Fit',alpha = 0.5,color = 'black')
plt.title(key)
plt.xlim(max(curves[key]['Wavenumber']),min(curves[key]['Wavenumber']))
plt.legend(fontsize=5)
plt.xticks(fontsize=12)
plt.yticks(fontsize=12)
PlotPriorFit(args)