-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerateData-v1.py
More file actions
126 lines (100 loc) · 3.13 KB
/
Copy pathGenerateData-v1.py
File metadata and controls
126 lines (100 loc) · 3.13 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# -*- coding: utf-8 -*-
"""
Key point here - we use this code to generate the output files!!
"""
#filename
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
import rs_tools as rt
rt.plot_format(10)
from copy import deepcopy
from scipy.ndimage import median_filter
import fit_spc as ft
def process_rs(rs):
#This would be used for doing any preprocessing to the rs
#Data saved as PNG appear to be 0-1. We convert back to ADC values (65535).
adc_conv = 65535
rs = rs *adc_conv
return rs
def convert_rs_weight(rs):
#USed if you want to calculate error on a RS. This is used to weight the fit model if 'weights' is set to 'true'.
#Here, we take in the "Raw" raman spectrum, and compute the error as sqrt(I/3) where I is the raman intensity.
# Note that we return the weight:1/w
nreps=3
wght_cmp= np.sqrt(np.true_divide(rs,nreps))
wght = np.true_divide(1,wght_cmp)
return wght
mult = 65535
xmin = 213
xmax=511
###################################################
#
# Optionally - load data, plot data and fits to data.
#
# Key point: we do not want to assume that the numbers line up.
load_data = False
if load_data == True:
file_rdat = 'alldata_r13_TimeSeries_2_ClCsBkr.rdat'
file_rmta = 'alldata_r13_TimeSeries_2_ClCsBkr.rmta'
rdatdata = np.loadtxt(file_rdat,delimiter=',')
dt_meta = pd.read_table(file_rmta,sep=',')
rdatdata_nobk = np.loadtxt('alldata_r13_TimeSeries_0_Cl.rdat',delimiter=',')
x_values = rdatdata[0,:]
raman_values = rdatdata[1::,:]*mult
raman_values_nobk = rdatdata_nobk[1::,:]*mult
wn_fit = x_values[xmin:xmax]
####################################################
#
#
# Selected Examples
#
#
#
#
#
allinds_d = [(63471,''),
(44428,''),
(12281,''),
(36982,''),
(96065,''),
(31624,''),
(16909,''),
(1070,''),
(88054,''),
(50840,''),
(10485,''),
(68027,''),
(151,''),
(4424,''),
(8837,''),
(10952,''),
(36980,''),
(21248,''),
(3914,''),
(20031,''),
(10420,''),
(57832,''),
(4494,''),
(68027,''),
(43052,''),
(30881,''),
(96919,'')]
#Generate output file for fitting code.
for i,myind in enumerate(allinds_d):
myRaman = raman_values[myind[0]]
myRaman_raw = raman_values_nobk[myind[0]]
myweights = convert_rs_weight(myRaman_raw)
myx_values = x_values
myDG = dt_meta.iloc[myind[0]]
all_data = np.hstack((myx_values[:,np.newaxis],myRaman[:,np.newaxis],myweights[:,np.newaxis]))
my_serialdate = str(myDG.DateTime).replace(' ','_').replace(":","").replace("-","")
f,ax = plt.subplots()
ax.plot(myx_values,myRaman)
axa = ax.twinx()
axa.plot(myx_values,myRaman_raw,'C1')
ax.set_xlim([800,1900])
f.savefig(f'selected_v1_{myind[0]}.png')
fname = f'selected_{myind[0]}_{my_serialdate}_{myDG.x:.1f}_{myDG.y:.1f}.txt'
np.savetxt(fname,all_data,delimiter=' ')