Plot Spectrum2
In [1]:
Copied!
import numpy as np
import os
import pandas as pd
from glob import glob
import matplotlib.pyplot as plt
import json
import numpy as np
import os
import pandas as pd
from glob import glob
import matplotlib.pyplot as plt
import json
In [2]:
Copied!
with open(os.path.join("OPs_used", "bloodConc.json"), "r") as f:
bloodConc = json.load(f)
bloodConc = bloodConc['bloodConc']
with open(os.path.join("OPs_used", "wavelength.json"), 'r') as f:
wavelength = json.load(f)
wavelength = wavelength['wavelength']
with open(os.path.join("OPs_used", "SO2.json"), 'r') as f:
SO2 = json.load(f)
train_SO2 = SO2['train_SO2']
test_SO2 = SO2['test_SO2']
with open(os.path.join("OPs_used", "bloodConc.json"), "r") as f:
bloodConc = json.load(f)
bloodConc = bloodConc['bloodConc']
with open(os.path.join("OPs_used", "wavelength.json"), 'r') as f:
wavelength = json.load(f)
wavelength = wavelength['wavelength']
with open(os.path.join("OPs_used", "SO2.json"), 'r') as f:
SO2 = json.load(f)
train_SO2 = SO2['train_SO2']
test_SO2 = SO2['test_SO2']
In [3]:
Copied!
file_set = glob(os.path.join('dataset', 'prediction_model_formula3', 'test','*'))
len(file_set)
file_set = glob(os.path.join('dataset', 'prediction_model_formula3', 'test','*'))
len(file_set)
Out[3]:
4000
In [4]:
Copied!
file_set[0]
file_set[0]
Out[4]:
'dataset\\prediction_model_formula3\\test\\0_blc_138.npy'
In [5]:
Copied!
data = np.load(file_set[2000])
data.shape
data = np.load(file_set[2000])
data.shape
Out[5]:
(51, 805)
In [6]:
Copied!
OD_spec = data[25,:800]
for i in range(20):
plt.plot(OD_spec[i*20:i*20+20])
plt.show()
OD_spec = data[25,:800]
for i in range(20):
plt.plot(OD_spec[i*20:i*20+20])
plt.show()
In [7]:
Copied!
file_set = glob(os.path.join('dataset', 'surrogate_result', 'test','bloodConc_138', 'SO2_0.7', '*'))
len(file_set)
file_set = glob(os.path.join('dataset', 'surrogate_result', 'test','bloodConc_138', 'SO2_0.7', '*'))
len(file_set)
Out[7]:
200
In [77]:
Copied!
file_set[0]
file_set[0]
Out[77]:
'dataset\\surrogate_result\\test\\bloodConc_138\\SO2_0.7\\0_test.csv'
In [ ]:
Copied!
baseline =
baseline =
In [75]:
Copied!
for filename in file_set:
data = pd.read_csv(filename)
plt.plot(wavelength, data['largeIJV_SDS2'])
plt.xlabel('wavelength (nm)')
plt.ylabel('reflectance')
plt.show()
for filename in file_set:
data = pd.read_csv(filename)
plt.plot(wavelength, data['largeIJV_SDS2'])
plt.xlabel('wavelength (nm)')
plt.ylabel('reflectance')
plt.show()
In [21]:
Copied!
plt.plot(wavelength, data['smallIJV_SDS2'])
plt.show()
plt.plot(wavelength, data['smallIJV_SDS2'])
plt.show()
In [4]:
Copied!
with open(os.path.join("OPs_used", "bloodConc.json"), "r") as f:
bloodConc = json.load(f)
bloodConc = bloodConc['bloodConc']
with open(os.path.join("OPs_used", "wavelength.json"), 'r') as f:
wavelength = json.load(f)
wavelength = wavelength['wavelength']
with open(os.path.join("OPs_used", "SO2.json"), 'r') as f:
SO2 = json.load(f)
train_SO2 = SO2['train_SO2']
test_SO2 = SO2['test_SO2']
with open(os.path.join("OPs_used", "bloodConc.json"), "r") as f:
bloodConc = json.load(f)
bloodConc = bloodConc['bloodConc']
with open(os.path.join("OPs_used", "wavelength.json"), 'r') as f:
wavelength = json.load(f)
wavelength = wavelength['wavelength']
with open(os.path.join("OPs_used", "SO2.json"), 'r') as f:
SO2 = json.load(f)
train_SO2 = SO2['train_SO2']
test_SO2 = SO2['test_SO2']
In [5]:
Copied!
result_OD1_spec = np.load(os.path.join('dataset', 'result_OD1_spec.npy'))
result_OD2_spec = np.load(os.path.join('dataset', 'result_OD2_spec.npy'))
result_diff_spec = result_OD2_spec - result_OD1_spec
result_OD1_spec = np.load(os.path.join('dataset', 'result_OD1_spec.npy'))
result_OD2_spec = np.load(os.path.join('dataset', 'result_OD2_spec.npy'))
result_diff_spec = result_OD2_spec - result_OD1_spec
In [6]:
Copied!
blc = 138
id = 199
for id in range(1):
# for blc in bloodConc:
for blc in [138]:
print(f'now processing test_{id}...')
prediction_input = np.empty((len(test_SO2),2*len(wavelength)*len(wavelength)+5)) # T1_large_SDS1/SDS2 T1_small_SDS1/SDS2 T2_large_SDS1/SDS2 T2_small_SDS1/SDS2 bloodConc ans id
for i, s in enumerate(test_SO2):
surrogate_result_T1 = pd.read_csv(os.path.join("dataset", "surrogate_result", 'test',
f'bloodConc_{blc}', 'SO2_0.7', f'{id}_test.csv'))
surrogate_result_T2 = pd.read_csv(os.path.join("dataset", "surrogate_result", 'test',
f'bloodConc_{blc}', f'SO2_{s}', f'{id}_test.csv'))
for wl_idx in range(len(wavelength)):
T2_large_SDS2 = surrogate_result_T2['largeIJV_SDS2'].to_numpy()
T2_large_SDS1 = surrogate_result_T2['largeIJV_SDS1'][wl_idx]
T1_large_SDS2 = surrogate_result_T1['largeIJV_SDS2'].to_numpy()
T1_large_SDS1 = surrogate_result_T1['largeIJV_SDS1'][wl_idx]
T2_small_SDS2 = surrogate_result_T2['smallIJV_SDS2'].to_numpy()
T2_small_SDS1 = surrogate_result_T2['smallIJV_SDS1'][wl_idx]
T1_small_SDS2 = surrogate_result_T1['smallIJV_SDS2'].to_numpy()
T1_small_SDS1 = surrogate_result_T1['smallIJV_SDS1'][wl_idx]
prediction_input[i][wl_idx*20 : wl_idx*20+20] = T2_large_SDS1 /T2_large_SDS2 - T1_large_SDS1 /T1_large_SDS2
prediction_input[i][400+wl_idx*20 : 400+wl_idx*20+20] = T2_small_SDS1 / T2_small_SDS2 - T1_small_SDS1 / T1_small_SDS2
# invivo_OD2_spec_set = result_OD2_spec
# for SO2_idx in range(51):
# OD_spec = prediction_input[SO2_idx,:800]
# for i in range(20):
# plt.plot(OD_spec[i*20:i*20+20], 'b--')
# for invivo_spec in result_diff_spec:
# for i in range(20):
# plt.plot(invivo_spec[i*20:i*20+20], 'r')
# plt.show()
blc = 138
id = 199
for id in range(1):
# for blc in bloodConc:
for blc in [138]:
print(f'now processing test_{id}...')
prediction_input = np.empty((len(test_SO2),2*len(wavelength)*len(wavelength)+5)) # T1_large_SDS1/SDS2 T1_small_SDS1/SDS2 T2_large_SDS1/SDS2 T2_small_SDS1/SDS2 bloodConc ans id
for i, s in enumerate(test_SO2):
surrogate_result_T1 = pd.read_csv(os.path.join("dataset", "surrogate_result", 'test',
f'bloodConc_{blc}', 'SO2_0.7', f'{id}_test.csv'))
surrogate_result_T2 = pd.read_csv(os.path.join("dataset", "surrogate_result", 'test',
f'bloodConc_{blc}', f'SO2_{s}', f'{id}_test.csv'))
for wl_idx in range(len(wavelength)):
T2_large_SDS2 = surrogate_result_T2['largeIJV_SDS2'].to_numpy()
T2_large_SDS1 = surrogate_result_T2['largeIJV_SDS1'][wl_idx]
T1_large_SDS2 = surrogate_result_T1['largeIJV_SDS2'].to_numpy()
T1_large_SDS1 = surrogate_result_T1['largeIJV_SDS1'][wl_idx]
T2_small_SDS2 = surrogate_result_T2['smallIJV_SDS2'].to_numpy()
T2_small_SDS1 = surrogate_result_T2['smallIJV_SDS1'][wl_idx]
T1_small_SDS2 = surrogate_result_T1['smallIJV_SDS2'].to_numpy()
T1_small_SDS1 = surrogate_result_T1['smallIJV_SDS1'][wl_idx]
prediction_input[i][wl_idx*20 : wl_idx*20+20] = T2_large_SDS1 /T2_large_SDS2 - T1_large_SDS1 /T1_large_SDS2
prediction_input[i][400+wl_idx*20 : 400+wl_idx*20+20] = T2_small_SDS1 / T2_small_SDS2 - T1_small_SDS1 / T1_small_SDS2
# invivo_OD2_spec_set = result_OD2_spec
# for SO2_idx in range(51):
# OD_spec = prediction_input[SO2_idx,:800]
# for i in range(20):
# plt.plot(OD_spec[i*20:i*20+20], 'b--')
# for invivo_spec in result_diff_spec:
# for i in range(20):
# plt.plot(invivo_spec[i*20:i*20+20], 'r')
# plt.show()
now processing test_0...
In [7]:
Copied!
invivo_OD2_spec_set = result_OD2_spec
for SO2_idx in range(51):
OD_spec = prediction_input[SO2_idx,:800]
for i in range(20):
plt.plot(OD_spec[i*20:i*20+20], 'b')
for invivo_spec in result_diff_spec:
for i in range(20):
plt.plot(invivo_spec[i*20:i*20+20], 'r')
plt.show()
invivo_OD2_spec_set = result_OD2_spec
for SO2_idx in range(51):
OD_spec = prediction_input[SO2_idx,:800]
for i in range(20):
plt.plot(OD_spec[i*20:i*20+20], 'b')
for invivo_spec in result_diff_spec:
for i in range(20):
plt.plot(invivo_spec[i*20:i*20+20], 'r')
plt.show()
In [8]:
Copied!
for invivo_OD2_spec in invivo_OD2_spec_set:
for i in range(20):
plt.plot(invivo_OD2_spec[i*20:i*20+20], 'r')
plt.show()
for invivo_OD2_spec in invivo_OD2_spec_set:
for i in range(20):
plt.plot(invivo_OD2_spec[i*20:i*20+20], 'r')
plt.show()
In [9]:
Copied!
result_diff_spec.shape
result_diff_spec.shape
Out[9]:
(84, 800)
In [10]:
Copied!
for invivo_spec in result_diff_spec[:1]:
for i in range(20):
plt.plot(invivo_spec[i*20:i*20+20], 'r')
plt.show()
for invivo_spec in result_diff_spec[:1]:
for i in range(20):
plt.plot(invivo_spec[i*20:i*20+20], 'r')
plt.show()
In [11]:
Copied!
result_diff_spec.shape
result_diff_spec.shape
Out[11]:
(84, 800)
In [12]:
Copied!
prediction_input.shape
prediction_input.shape
Out[12]:
(51, 805)
In [13]:
Copied!
os.makedirs(os.path.join('pic', 'ctchen', 'invivo'), exist_ok=True)
os.makedirs(os.path.join('pic', 'ctchen', 'invivo'), exist_ok=True)
In [14]:
Copied!
def find_best_sol(invivo_diff_spec):
min_RMSPE = 1000000000
for id in range(1):
print(f'now processing test_{id}...')
for blc in bloodConc:
# for blc in [138]:
prediction_input = np.empty((len(test_SO2),2*len(wavelength)*len(wavelength)+5)) # T1_large_SDS1/SDS2 T1_small_SDS1/SDS2 T2_large_SDS1/SDS2 T2_small_SDS1/SDS2 bloodConc ans id
for i, s in enumerate(test_SO2):
surrogate_result_T1 = pd.read_csv(os.path.join("dataset", "surrogate_result", 'test',
f'bloodConc_{blc}', 'SO2_0.7', f'{id}_test.csv'))
surrogate_result_T2 = pd.read_csv(os.path.join("dataset", "surrogate_result", 'test',
f'bloodConc_{blc}', f'SO2_{s}', f'{id}_test.csv'))
for wl_idx in range(len(wavelength)):
T2_large_SDS2 = surrogate_result_T2['largeIJV_SDS2'].to_numpy()
T2_large_SDS1 = surrogate_result_T2['largeIJV_SDS1'][wl_idx]
T1_large_SDS2 = surrogate_result_T1['largeIJV_SDS2'].to_numpy()
T1_large_SDS1 = surrogate_result_T1['largeIJV_SDS1'][wl_idx]
T2_small_SDS2 = surrogate_result_T2['smallIJV_SDS2'].to_numpy()
T2_small_SDS1 = surrogate_result_T2['smallIJV_SDS1'][wl_idx]
T1_small_SDS2 = surrogate_result_T1['smallIJV_SDS2'].to_numpy()
T1_small_SDS1 = surrogate_result_T1['smallIJV_SDS1'][wl_idx]
prediction_input[i][wl_idx*20 : wl_idx*20+20] = T2_large_SDS1 /T2_large_SDS2 - T1_large_SDS1 /T1_large_SDS2
prediction_input[i][400+wl_idx*20 : 400+wl_idx*20+20] = T2_small_SDS1 / T2_small_SDS2 - T1_small_SDS1 / T1_small_SDS2
rmspe = np.sqrt(np.mean(np.square((prediction_input[:, :800] - invivo_diff_spec)/invivo_diff_spec), axis=1))
rmspe_second_small = rmspe[np.argsort(rmspe)[1]]
if rmspe_second_small < min_RMSPE:
min_RMSPE = rmspe.min()
used_rmspe = rmspe_second_small
closest_idx = np.argsort(rmspe)[1]
now_ijv_SO2 = (test_SO2[closest_idx] - 0.7)*100
sim_spec = prediction_input[closest_idx][:800]
invivo_spec = invivo_diff_spec
return used_rmspe, closest_idx, now_ijv_SO2, sim_spec, invivo_spec
def find_best_sol(invivo_diff_spec):
min_RMSPE = 1000000000
for id in range(1):
print(f'now processing test_{id}...')
for blc in bloodConc:
# for blc in [138]:
prediction_input = np.empty((len(test_SO2),2*len(wavelength)*len(wavelength)+5)) # T1_large_SDS1/SDS2 T1_small_SDS1/SDS2 T2_large_SDS1/SDS2 T2_small_SDS1/SDS2 bloodConc ans id
for i, s in enumerate(test_SO2):
surrogate_result_T1 = pd.read_csv(os.path.join("dataset", "surrogate_result", 'test',
f'bloodConc_{blc}', 'SO2_0.7', f'{id}_test.csv'))
surrogate_result_T2 = pd.read_csv(os.path.join("dataset", "surrogate_result", 'test',
f'bloodConc_{blc}', f'SO2_{s}', f'{id}_test.csv'))
for wl_idx in range(len(wavelength)):
T2_large_SDS2 = surrogate_result_T2['largeIJV_SDS2'].to_numpy()
T2_large_SDS1 = surrogate_result_T2['largeIJV_SDS1'][wl_idx]
T1_large_SDS2 = surrogate_result_T1['largeIJV_SDS2'].to_numpy()
T1_large_SDS1 = surrogate_result_T1['largeIJV_SDS1'][wl_idx]
T2_small_SDS2 = surrogate_result_T2['smallIJV_SDS2'].to_numpy()
T2_small_SDS1 = surrogate_result_T2['smallIJV_SDS1'][wl_idx]
T1_small_SDS2 = surrogate_result_T1['smallIJV_SDS2'].to_numpy()
T1_small_SDS1 = surrogate_result_T1['smallIJV_SDS1'][wl_idx]
prediction_input[i][wl_idx*20 : wl_idx*20+20] = T2_large_SDS1 /T2_large_SDS2 - T1_large_SDS1 /T1_large_SDS2
prediction_input[i][400+wl_idx*20 : 400+wl_idx*20+20] = T2_small_SDS1 / T2_small_SDS2 - T1_small_SDS1 / T1_small_SDS2
rmspe = np.sqrt(np.mean(np.square((prediction_input[:, :800] - invivo_diff_spec)/invivo_diff_spec), axis=1))
rmspe_second_small = rmspe[np.argsort(rmspe)[1]]
if rmspe_second_small < min_RMSPE:
min_RMSPE = rmspe.min()
used_rmspe = rmspe_second_small
closest_idx = np.argsort(rmspe)[1]
now_ijv_SO2 = (test_SO2[closest_idx] - 0.7)*100
sim_spec = prediction_input[closest_idx][:800]
invivo_spec = invivo_diff_spec
return used_rmspe, closest_idx, now_ijv_SO2, sim_spec, invivo_spec
In [15]:
Copied!
invivo_spec
invivo_spec
Out[15]:
array([-4.34866232e-03, 4.44104607e-03, -3.71014418e-03, -4.07704647e-03, 2.40704735e-04, 2.59785130e-04, -1.97301559e-03, -2.58951565e-03, 1.17146121e-03, -1.73363479e-03, -2.75308140e-03, 3.06206924e-03, -1.90739940e-03, 2.45120717e-03, -7.37323720e-04, 1.36217378e-03, -2.79570509e-03, 4.29579797e-04, 3.65923785e-03, 1.67253261e-03, -2.46066213e-03, 6.32904626e-03, -1.82214399e-03, -2.18904628e-03, 2.12870492e-03, 2.14778532e-03, -8.50153992e-05, -7.01515465e-04, 3.05946140e-03, 1.54365399e-04, -8.65081211e-04, 4.95006943e-03, -1.93992131e-05, 4.33920736e-03, 1.15067647e-03, 3.25017397e-03, -9.07704906e-04, 2.31757999e-03, 5.54723804e-03, 3.56053280e-03, -2.02245674e-03, 6.76725165e-03, -1.38393860e-03, -1.75084090e-03, 2.56691031e-03, 2.58599070e-03, 3.53189985e-04, -2.63310081e-04, 3.49766679e-03, 5.92570783e-04, -4.26875827e-04, 5.38827482e-03, 4.18806171e-04, 4.77741274e-03, 1.58888185e-03, 3.68837935e-03, -4.69499522e-04, 2.75578537e-03, 5.98544342e-03, 3.99873818e-03, -1.18393309e-03, 7.60577530e-03, -5.45414948e-04, -9.12317240e-04, 3.40543396e-03, 3.42451436e-03, 1.19171364e-03, 5.75213576e-04, 4.33619044e-03, 1.43109444e-03, 4.11647830e-04, 6.22679847e-03, 1.25732983e-03, 5.61593640e-03, 2.42740551e-03, 4.52690301e-03, 3.69024135e-04, 3.59430903e-03, 6.82396708e-03, 4.83726184e-03, -1.99341403e-03, 6.79629436e-03, -1.35489589e-03, -1.72179818e-03, 2.59595302e-03, 2.61503342e-03, 3.82232698e-04, -2.34267368e-04, 3.52670950e-03, 6.21613496e-04, -3.97833114e-04, 5.41731753e-03, 4.47848884e-04, 4.80645546e-03, 1.61792457e-03, 3.71742207e-03, -4.40456809e-04, 2.78482808e-03, 6.01448613e-03, 4.02778089e-03, -2.50218071e-03, 6.28752768e-03, -1.86366257e-03, -2.23056487e-03, 2.08718634e-03, 2.10626673e-03, -1.26533984e-04, -7.43034049e-04, 3.01794282e-03, 1.12846815e-04, -9.06599796e-04, 4.90855085e-03, -6.09177977e-05, 4.29768877e-03, 1.10915788e-03, 3.20865538e-03, -9.49223490e-04, 2.27606140e-03, 5.50571945e-03, 3.51901421e-03, -2.40002126e-03, 6.38968713e-03, -1.76150312e-03, -2.12840541e-03, 2.18934579e-03, 2.20842618e-03, -2.43745329e-05, -6.40874598e-04, 3.12010227e-03, 2.15006266e-04, -8.04440345e-04, 5.01071030e-03, 4.12416533e-05, 4.39984822e-03, 1.21131734e-03, 3.31081484e-03, -8.47064039e-04, 2.37822085e-03, 5.60787890e-03, 3.62117366e-03, -3.26457225e-03, 5.52513614e-03, -2.62605411e-03, -2.99295640e-03, 1.32479480e-03, 1.34387520e-03, -8.88925519e-04, -1.50542558e-03, 2.25555128e-03, -6.49544720e-04, -1.66899133e-03, 4.14615931e-03, -8.23309333e-04, 3.53529724e-03, 3.46766349e-04, 2.44626385e-03, -1.71161503e-03, 1.51366987e-03, 4.74332792e-03, 2.75662268e-03, -3.07209410e-03, 5.71761429e-03, -2.43357596e-03, -2.80047825e-03, 1.51727295e-03, 1.53635335e-03, -6.96447370e-04, -1.31294744e-03, 2.44802943e-03, -4.57066572e-04, -1.47651318e-03, 4.33863746e-03, -6.30831184e-04, 3.72777539e-03, 5.39244498e-04, 2.63874200e-03, -1.51913688e-03, 1.70614801e-03, 4.93580606e-03, 2.94910083e-03, -3.26271858e-03, 5.52698981e-03, -2.62420044e-03, -2.99110273e-03, 1.32664847e-03, 1.34572887e-03, -8.87071852e-04, -1.50357192e-03, 2.25740495e-03, -6.47691053e-04, -1.66713766e-03, 4.14801298e-03, -8.21455666e-04, 3.53715091e-03, 3.48620016e-04, 2.44811752e-03, -1.70976136e-03, 1.51552353e-03, 4.74518158e-03, 2.75847634e-03, -2.91958763e-03, 5.87012076e-03, -2.28106949e-03, -2.64797178e-03, 1.66977942e-03, 1.68885982e-03, -5.43940899e-04, -1.16044096e-03, 2.60053590e-03, -3.04560101e-04, -1.32400671e-03, 4.49114393e-03, -4.78324713e-04, 3.88028186e-03, 6.91750969e-04, 2.79124847e-03, -1.36663041e-03, 1.85865449e-03, 5.08831254e-03, 3.10160730e-03, -3.70214319e-03, 5.08756520e-03, -3.06362505e-03, -3.43052734e-03, 8.87223866e-04, 9.06304261e-04, -1.32649646e-03, -1.94299652e-03, 1.81798034e-03, -1.08711566e-03, -2.10656227e-03, 3.70858837e-03, -1.26088027e-03, 3.09772630e-03, -9.08045888e-05, 2.00869291e-03, -2.14918596e-03, 1.07609893e-03, 4.30575698e-03, 2.31905174e-03, -4.20634415e-03, 4.58336424e-03, -3.56782601e-03, -3.93472830e-03, 3.83022906e-04, 4.02103300e-04, -1.83069742e-03, -2.44719748e-03, 1.31377938e-03, -1.59131662e-03, -2.61076323e-03, 3.20438741e-03, -1.76508123e-03, 2.59352534e-03, -5.95005549e-04, 1.50449195e-03, -2.65338692e-03, 5.71897968e-04, 3.80155602e-03, 1.81485078e-03, -4.28705190e-03, 4.50265649e-03, -3.64853376e-03, -4.01543606e-03, 3.02315148e-04, 3.21395543e-04, -1.91140517e-03, -2.52790524e-03, 1.23307163e-03, -1.67202438e-03, -2.69147099e-03, 3.12367966e-03, -1.84578899e-03, 2.51281758e-03, -6.75713307e-04, 1.42378419e-03, -2.73409468e-03, 4.91190210e-04, 3.72084826e-03, 1.73414302e-03, -3.36048305e-03, 5.42922534e-03, -2.72196491e-03, -3.08886720e-03, 1.22888400e-03, 1.24796440e-03, -9.84836322e-04, -1.60133639e-03, 2.15964048e-03, -7.45455523e-04, -1.76490213e-03, 4.05024851e-03, -9.19220135e-04, 3.43938644e-03, 2.50855547e-04, 2.35035305e-03, -1.80752583e-03, 1.41775906e-03, 4.64741711e-03, 2.66071188e-03, -4.35554544e-03, 4.43416295e-03, -3.71702730e-03, -4.08392959e-03, 2.33821612e-04, 2.52902007e-04, -1.97989871e-03, -2.59639878e-03, 1.16457809e-03, -1.74051791e-03, -2.75996452e-03, 3.05518612e-03, -1.91428252e-03, 2.44432405e-03, -7.44206843e-04, 1.35529066e-03, -2.80258822e-03, 4.22696674e-04, 3.65235472e-03, 1.66564949e-03, -5.73380002e-03, 3.05590837e-03, -5.09528188e-03, -5.46218417e-03, -1.14443297e-03, -1.12535257e-03, -3.35815329e-03, -3.97465336e-03, -2.13676489e-04, -3.11877249e-03, -4.13821910e-03, 1.67693154e-03, -3.29253710e-03, 1.06606947e-03, -2.12246142e-03, -2.29639216e-05, -4.18084280e-03, -9.55557905e-04, 2.27410014e-03, 2.87394907e-04, -6.01879469e-03, 2.77091370e-03, -5.38027655e-03, -5.74717884e-03, -1.42942764e-03, -1.41034724e-03, -3.64314796e-03, -4.25964803e-03, -4.98671161e-04, -3.40376716e-03, -4.42321377e-03, 1.39193687e-03, -3.57753178e-03, 7.81074795e-04, -2.40745609e-03, -3.07958594e-04, -4.46583747e-03, -1.24055258e-03, 1.98910547e-03, 2.40023442e-06, -4.64198401e-03, 4.14772438e-03, -4.00346587e-03, -4.37036816e-03, -5.26169531e-05, -3.35365585e-05, -2.26633728e-03, -2.88283734e-03, 8.78139525e-04, -2.02695648e-03, -3.04640309e-03, 2.76874755e-03, -2.20072109e-03, 2.15788548e-03, -1.03064541e-03, 1.06885209e-03, -3.08902678e-03, 1.36258109e-04, 3.36591616e-03, 1.37921092e-03, -4.34652412e-03, 4.44318427e-03, -3.70800598e-03, -4.07490827e-03, 2.42842931e-04, 2.61923326e-04, -1.97087739e-03, -2.58737746e-03, 1.17359941e-03, -1.73149659e-03, -2.75094320e-03, 3.06420744e-03, -1.90526121e-03, 2.45334537e-03, -7.35185524e-04, 1.36431198e-03, -2.79356690e-03, 4.31717993e-04, 3.66137604e-03, 1.67467080e-03, -2.85654121e-03, 6.03985868e-03, 3.17827249e-05, 2.36331217e-03, 1.32256512e-03, 2.97415804e-03, 1.83038309e-03, 1.90622865e-03, 1.67036487e-03, -1.23197709e-03, 6.29734151e-03, 4.13714069e-03, 1.33449405e-03, 2.12263255e-05, -1.60613543e-03, 7.89558750e-04, -3.65257352e-04, -1.53186226e-03, 3.31795581e-03, 1.80975550e-03, -7.90116414e-04, 8.10628348e-03, 2.09820752e-03, 4.42973696e-03, 3.38898991e-03, 5.04058283e-03, 3.89680788e-03, 3.97265344e-03, 3.73678966e-03, 8.34447708e-04, 8.36376630e-03, 6.20356548e-03, 3.40091884e-03, 2.08765112e-03, 4.60289366e-04, 2.85598354e-03, 1.70116744e-03, 5.34562536e-04, 5.38438061e-03, 3.87618030e-03, -1.10977169e-03, 7.78662821e-03, 1.77855225e-03, 4.11008169e-03, 3.06933464e-03, 4.72092756e-03, 3.57715261e-03, 3.65299817e-03, 3.41713439e-03, 5.14792437e-04, 8.04411103e-03, 5.88391021e-03, 3.08126357e-03, 1.76799585e-03, 1.40634095e-04, 2.53632827e-03, 1.38151217e-03, 2.14907264e-04, 5.06472533e-03, 3.55652503e-03, -1.71518356e-03, 7.18121634e-03, 1.17314038e-03, 3.50466982e-03, 2.46392277e-03, 4.11551569e-03, 2.97174074e-03, 3.04758630e-03, 2.81172252e-03, -9.06194332e-05, 7.43869916e-03, 5.27849834e-03, 2.47585170e-03, 1.16258398e-03, -4.64777775e-04, 1.93091640e-03, 7.76100300e-04, -3.90504606e-04, 4.45931346e-03, 2.95111316e-03, -5.47233235e-04, 8.34916666e-03, 2.34109070e-03, 4.67262014e-03, 3.63187309e-03, 5.28346601e-03, 4.13969106e-03, 4.21553662e-03, 3.97967284e-03, 1.07733089e-03, 8.60664948e-03, 6.44644866e-03, 3.64380202e-03, 2.33053430e-03, 7.03172545e-04, 3.09886672e-03, 1.94405062e-03, 7.77445714e-04, 5.62726378e-03, 4.11906348e-03, -1.73306408e-03, 7.16333582e-03, 1.15525986e-03, 3.48678930e-03, 2.44604225e-03, 4.09763517e-03, 2.95386022e-03, 3.02970578e-03, 2.79384200e-03, -1.08499953e-04, 7.42081864e-03, 5.26061782e-03, 2.45797118e-03, 1.14470346e-03, -4.82658295e-04, 1.91303588e-03, 7.58219780e-04, -4.08385126e-04, 4.44143294e-03, 2.93323264e-03, -1.34592565e-03, 7.55047424e-03, 1.54239828e-03, 3.87392773e-03, 2.83318067e-03, 4.48477359e-03, 3.34099864e-03, 3.41684421e-03, 3.18098043e-03, 2.78638472e-04, 7.80795707e-03, 5.64775625e-03, 2.84510961e-03, 1.53184188e-03, -9.55198702e-05, 2.30017431e-03, 1.14535820e-03, -2.12467010e-05, 4.82857137e-03, 3.32037106e-03, -1.21000765e-03, 7.68639225e-03, 1.67831629e-03, 4.00984573e-03, 2.96909868e-03, 4.62069160e-03, 3.47691665e-03, 3.55276221e-03, 3.31689843e-03, 4.14556476e-04, 7.94387507e-03, 5.78367425e-03, 2.98102761e-03, 1.66775989e-03, 4.03981339e-05, 2.43609231e-03, 1.28127621e-03, 1.14671303e-04, 4.96448937e-03, 3.45628907e-03, -1.82440819e-03, 7.07199171e-03, 1.06391575e-03, 3.39544519e-03, 2.35469814e-03, 4.00629106e-03, 2.86251611e-03, 2.93836167e-03, 2.70249789e-03, -1.99844064e-04, 7.32947453e-03, 5.16927371e-03, 2.36662707e-03, 1.05335935e-03, -5.74002406e-04, 1.82169177e-03, 6.66875669e-04, -4.99729237e-04, 4.35008883e-03, 2.84188852e-03, -2.59397362e-03, 6.30242628e-03, 2.94350315e-04, 2.62587976e-03, 1.58513271e-03, 3.23672563e-03, 2.09295068e-03, 2.16879624e-03, 1.93293246e-03, -9.69409495e-04, 6.55990910e-03, 4.39970828e-03, 1.59706164e-03, 2.83793916e-04, -1.34356784e-03, 1.05212634e-03, -1.02689762e-04, -1.26929467e-03, 3.58052340e-03, 2.07232309e-03, -2.66333282e-03, 6.23306708e-03, 2.24991116e-04, 2.55652056e-03, 1.51577351e-03, 3.16736643e-03, 2.02359148e-03, 2.09943704e-03, 1.86357326e-03, -1.03876869e-03, 6.49054990e-03, 4.33034908e-03, 1.52770244e-03, 2.14434717e-04, -1.41292704e-03, 9.82767141e-04, -1.72048961e-04, -1.33865387e-03, 3.51116420e-03, 2.00296390e-03, -1.14511217e-03, 7.75128772e-03, 1.74321176e-03, 4.07474121e-03, 3.03399415e-03, 4.68558707e-03, 3.54181212e-03, 3.61765768e-03, 3.38179390e-03, 4.79451949e-04, 8.00877054e-03, 5.84856972e-03, 3.04592308e-03, 1.73265536e-03, 1.05293607e-04, 2.50098778e-03, 1.34617168e-03, 1.79566777e-04, 5.02938485e-03, 3.52118454e-03, -1.82455589e-03, 7.07184400e-03, 1.06376804e-03, 3.39529749e-03, 2.35455043e-03, 4.00614335e-03, 2.86236840e-03, 2.93821397e-03, 2.70235019e-03, -1.99991767e-04, 7.32932683e-03, 5.16912601e-03, 2.36647937e-03, 1.05321164e-03, -5.74150109e-04, 1.82154407e-03, 6.66727966e-04, -4.99876940e-04, 4.34994113e-03, 2.84174082e-03, -3.23011902e-03, 5.66628088e-03, -3.41795084e-04, 1.98973436e-03, 9.48987307e-04, 2.60058023e-03, 1.45680528e-03, 1.53265084e-03, 1.29678706e-03, -1.60555489e-03, 5.92376370e-03, 3.76356288e-03, 9.60916240e-04, -3.52351484e-04, -1.97971324e-03, 4.15980941e-04, -7.38835161e-04, -1.90544007e-03, 2.94437800e-03, 1.43617770e-03, -3.72321188e-03, 5.17318801e-03, -8.34887950e-04, 1.49664150e-03, 4.55894441e-04, 2.10748736e-03, 9.63712410e-04, 1.03955797e-03, 8.03694195e-04, -2.09864776e-03, 5.43067083e-03, 3.27047002e-03, 4.67823374e-04, -8.45444350e-04, -2.47280610e-03, -7.71119253e-05, -1.23192803e-03, -2.39853293e-03, 2.45128514e-03, 9.43084829e-04, -2.99357266e-03, 5.90282723e-03, -1.05248729e-04, 2.22628072e-03, 1.18553366e-03, 2.83712658e-03, 1.69335163e-03, 1.76919720e-03, 1.53333342e-03, -1.36900854e-03, 6.16031006e-03, 4.00010924e-03, 1.19746260e-03, -1.15805128e-04, -1.74316688e-03, 6.52527296e-04, -5.02288806e-04, -1.66889371e-03, 3.18092436e-03, 1.67272405e-03, -2.72958176e-03, 6.16681813e-03, 1.58742174e-04, 2.49027162e-03, 1.44952457e-03, 3.10111749e-03, 1.95734253e-03, 2.03318810e-03, 1.79732432e-03, -1.10501764e-03, 6.42430096e-03, 4.26410014e-03, 1.46145350e-03, 1.48185775e-04, -1.47917598e-03, 9.16518199e-04, -2.38297903e-04, -1.40490281e-03, 3.44491526e-03, 1.93671495e-03, -4.28015498e-03, 4.61624491e-03, -1.39183105e-03, 9.39698397e-04, -1.01048658e-04, 1.55054426e-03, 4.06769311e-04, 4.82614875e-04, 2.46751096e-04, -2.65559086e-03, 4.87372774e-03, 2.71352692e-03, -8.91197248e-05, -1.40238745e-03, -3.02974920e-03, -6.34055024e-04, -1.78887113e-03, -2.95547603e-03, 1.89434204e-03, 3.86141730e-04, -4.24135065e-03, 4.65504924e-03, -1.35302672e-03, 9.78502727e-04, -6.22443281e-05, 1.58934859e-03, 4.45573641e-04, 5.21419205e-04, 2.85555425e-04, -2.61678653e-03, 4.91253207e-03, 2.75233125e-03, -5.03153951e-05, -1.36358312e-03, -2.99094487e-03, -5.95250695e-04, -1.75006680e-03, -2.91667170e-03, 1.93314637e-03, 4.24946060e-04, -3.78239745e-03, 5.11400245e-03, -8.94073514e-04, 1.43745593e-03, 3.96708878e-04, 2.04830180e-03, 9.04526846e-04, 9.80372410e-04, 7.44508631e-04, -2.15783332e-03, 5.37148527e-03, 3.21128445e-03, 4.08637811e-04, -9.04629913e-04, -2.53199167e-03, -1.36297489e-04, -1.29111359e-03, -2.45771850e-03, 2.39209957e-03, 8.83899266e-04])
In [16]:
Copied!
for invivo_idx in range(result_diff_spec.shape[0]):
# rmspe = np.sqrt(np.mean(np.square((prediction_input[:, :800] - result_diff_spec[invivo_idx])/result_diff_spec[invivo_idx]), axis=1))
# closest_idx = np.argsort(rmspe)[1]
# now_ijv_SO2 = (test_SO2[closest_idx] - 0.7)*100
# sim_spec = prediction_input[closest_idx][:800]
# invivo_spec = result_diff_spec[invivo_idx]
used_rmspe, closest_idx, now_ijv_SO2, sim_spec, invivo_spec = find_best_sol(invivo_diff_spec=result_diff_spec[invivo_idx])
fig, ax = plt.subplots(5,4,figsize=(16,12))
fig.suptitle(r'$\Delta$OD spectrum @ $\Delta$SO2 :' + f'{now_ijv_SO2:.2f}%, RMSPE : {used_rmspe:.2f}%', fontsize=20)
sim_ijv_large_spec = []
sim_ijv_small_spec = []
ijv_large_spec = []
ijv_small_spec = []
for i in range(20):
ijv_large_spec = invivo_spec[i*20:i*20+20]
ijv_small_spec = invivo_spec[i*20+400:i*20+20+400]
sim_ijv_large_spec = sim_spec[i*20:i*20+20]
sim_ijv_small_spec = sim_spec[i*20+400:i*20+20+400]
ax[i//4][i%4].plot(wavelength, sim_ijv_large_spec, linestyle='--', color = 'blue', label=r'$IJV_{large}$ sim')
ax[i//4][i%4].plot(wavelength, sim_ijv_small_spec, linestyle='--', color = 'orange', label=r'$IJV_{small}$ sim')
ax[i//4][i%4].plot(wavelength, ijv_large_spec, color = 'blue', label=r'$IJV_{large}$ in vivo')
ax[i//4][i%4].plot(wavelength, ijv_small_spec, color = 'orange', label=r'$IJV_{small}$ in vivo')
ax[i//4][i%4].set_xlabel("wavelength(nm)")
ax[i//4][i%4].set_ylabel(f"$\Delta$OD")
ax[i//4][i%4].title.set_text(f'based on {wavelength[i]} nm')
# ax[i//4][i%4].legend()
fig.tight_layout()
plt.legend(loc='center left', bbox_to_anchor=(1.05, 0.5),
fancybox=True, shadow=True)
plt.savefig(os.path.join("pic", 'ctchen', 'invivo', f"invivo_{invivo_idx+1}.png"), dpi=300, format='png', bbox_inches='tight')
# plt.show()
plt.close()
for invivo_idx in range(result_diff_spec.shape[0]):
# rmspe = np.sqrt(np.mean(np.square((prediction_input[:, :800] - result_diff_spec[invivo_idx])/result_diff_spec[invivo_idx]), axis=1))
# closest_idx = np.argsort(rmspe)[1]
# now_ijv_SO2 = (test_SO2[closest_idx] - 0.7)*100
# sim_spec = prediction_input[closest_idx][:800]
# invivo_spec = result_diff_spec[invivo_idx]
used_rmspe, closest_idx, now_ijv_SO2, sim_spec, invivo_spec = find_best_sol(invivo_diff_spec=result_diff_spec[invivo_idx])
fig, ax = plt.subplots(5,4,figsize=(16,12))
fig.suptitle(r'$\Delta$OD spectrum @ $\Delta$SO2 :' + f'{now_ijv_SO2:.2f}%, RMSPE : {used_rmspe:.2f}%', fontsize=20)
sim_ijv_large_spec = []
sim_ijv_small_spec = []
ijv_large_spec = []
ijv_small_spec = []
for i in range(20):
ijv_large_spec = invivo_spec[i*20:i*20+20]
ijv_small_spec = invivo_spec[i*20+400:i*20+20+400]
sim_ijv_large_spec = sim_spec[i*20:i*20+20]
sim_ijv_small_spec = sim_spec[i*20+400:i*20+20+400]
ax[i//4][i%4].plot(wavelength, sim_ijv_large_spec, linestyle='--', color = 'blue', label=r'$IJV_{large}$ sim')
ax[i//4][i%4].plot(wavelength, sim_ijv_small_spec, linestyle='--', color = 'orange', label=r'$IJV_{small}$ sim')
ax[i//4][i%4].plot(wavelength, ijv_large_spec, color = 'blue', label=r'$IJV_{large}$ in vivo')
ax[i//4][i%4].plot(wavelength, ijv_small_spec, color = 'orange', label=r'$IJV_{small}$ in vivo')
ax[i//4][i%4].set_xlabel("wavelength(nm)")
ax[i//4][i%4].set_ylabel(f"$\Delta$OD")
ax[i//4][i%4].title.set_text(f'based on {wavelength[i]} nm')
# ax[i//4][i%4].legend()
fig.tight_layout()
plt.legend(loc='center left', bbox_to_anchor=(1.05, 0.5),
fancybox=True, shadow=True)
plt.savefig(os.path.join("pic", 'ctchen', 'invivo', f"invivo_{invivo_idx+1}.png"), dpi=300, format='png', bbox_inches='tight')
# plt.show()
plt.close()
now processing test_0... now processing test_0...
--------------------------------------------------------------------------- KeyboardInterrupt Traceback (most recent call last) Cell In[16], line 9 1 for invivo_idx in range(result_diff_spec.shape[0]): 2 # rmspe = np.sqrt(np.mean(np.square((prediction_input[:, :800] - result_diff_spec[invivo_idx])/result_diff_spec[invivo_idx]), axis=1)) 3 # closest_idx = np.argsort(rmspe)[1] (...) 6 # sim_spec = prediction_input[closest_idx][:800] 7 # invivo_spec = result_diff_spec[invivo_idx] ----> 9 used_rmspe, closest_idx, now_ijv_SO2, sim_spec, invivo_spec = find_best_sol(invivo_diff_spec=result_diff_spec[invivo_idx]) 10 fig, ax = plt.subplots(5,4,figsize=(16,12)) 11 fig.suptitle(r'$\Delta$OD spectrum @ $\Delta$SO2 :' + f'{now_ijv_SO2:.2f}%, RMSPE : {used_rmspe:.2f}%', fontsize=20) Cell In[14], line 10, in find_best_sol(invivo_diff_spec) 7 prediction_input = np.empty((len(test_SO2),2*len(wavelength)*len(wavelength)+5)) # T1_large_SDS1/SDS2 T1_small_SDS1/SDS2 T2_large_SDS1/SDS2 T2_small_SDS1/SDS2 bloodConc ans id 8 for i, s in enumerate(test_SO2): ---> 10 surrogate_result_T1 = pd.read_csv(os.path.join("dataset", "surrogate_result", 'test', 11 f'bloodConc_{blc}', 'SO2_0.7', f'{id}_test.csv')) 12 surrogate_result_T2 = pd.read_csv(os.path.join("dataset", "surrogate_result", 'test', 13 f'bloodConc_{blc}', f'SO2_{s}', f'{id}_test.csv')) 14 for wl_idx in range(len(wavelength)): File d:\ijv_code_organized\venv\lib\site-packages\pandas\io\parsers\readers.py:912, in read_csv(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, date_format, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, encoding_errors, dialect, on_bad_lines, delim_whitespace, low_memory, memory_map, float_precision, storage_options, dtype_backend) 899 kwds_defaults = _refine_defaults_read( 900 dialect, 901 delimiter, (...) 908 dtype_backend=dtype_backend, 909 ) 910 kwds.update(kwds_defaults) --> 912 return _read(filepath_or_buffer, kwds) File d:\ijv_code_organized\venv\lib\site-packages\pandas\io\parsers\readers.py:583, in _read(filepath_or_buffer, kwds) 580 return parser 582 with parser: --> 583 return parser.read(nrows) File d:\ijv_code_organized\venv\lib\site-packages\pandas\io\parsers\readers.py:1721, in TextFileReader.read(self, nrows) 1718 else: 1719 new_rows = len(index) -> 1721 df = DataFrame(col_dict, columns=columns, index=index) 1723 self._currow += new_rows 1724 return df File d:\ijv_code_organized\venv\lib\site-packages\pandas\core\frame.py:708, in DataFrame.__init__(self, data, index, columns, dtype, copy) 702 mgr = self._init_mgr( 703 data, axes={"index": index, "columns": columns}, dtype=dtype, copy=copy 704 ) 706 elif isinstance(data, dict): 707 # GH#38939 de facto copy defaults to False only in non-dict cases --> 708 mgr = dict_to_mgr(data, index, columns, dtype=dtype, copy=copy, typ=manager) 709 elif isinstance(data, ma.MaskedArray): 710 from numpy.ma import mrecords File d:\ijv_code_organized\venv\lib\site-packages\pandas\core\internals\construction.py:481, in dict_to_mgr(data, index, columns, dtype, typ, copy) 477 else: 478 # dtype check to exclude e.g. range objects, scalars 479 arrays = [x.copy() if hasattr(x, "dtype") else x for x in arrays] --> 481 return arrays_to_mgr(arrays, columns, index, dtype=dtype, typ=typ, consolidate=copy) File d:\ijv_code_organized\venv\lib\site-packages\pandas\core\internals\construction.py:153, in arrays_to_mgr(arrays, columns, index, dtype, verify_integrity, typ, consolidate) 150 axes = [columns, index] 152 if typ == "block": --> 153 return create_block_manager_from_column_arrays( 154 arrays, axes, consolidate=consolidate, refs=refs 155 ) 156 elif typ == "array": 157 return ArrayManager(arrays, [index, columns]) File d:\ijv_code_organized\venv\lib\site-packages\pandas\core\internals\managers.py:2137, in create_block_manager_from_column_arrays(arrays, axes, consolidate, refs) 2119 def create_block_manager_from_column_arrays( 2120 arrays: list[ArrayLike], 2121 axes: list[Index], (...) 2133 # These last three are sufficient to allow us to safely pass 2134 # verify_integrity=False below. 2136 try: -> 2137 blocks = _form_blocks(arrays, consolidate, refs) 2138 mgr = BlockManager(blocks, axes, verify_integrity=False) 2139 except ValueError as e: File d:\ijv_code_organized\venv\lib\site-packages\pandas\core\internals\managers.py:2215, in _form_blocks(arrays, consolidate, refs) 2212 if issubclass(dtype.type, (str, bytes)): 2213 dtype = np.dtype(object) -> 2215 values, placement = _stack_arrays(list(tup_block), dtype) 2216 if is_dtlike: 2217 values = ensure_wrapped_if_datetimelike(values) File d:\ijv_code_organized\venv\lib\site-packages\pandas\core\internals\managers.py:2257, in _stack_arrays(tuples, dtype) 2255 stacked = np.empty(shape, dtype=dtype) 2256 for i, arr in enumerate(arrays): -> 2257 stacked[i] = arr 2259 return stacked, placement KeyboardInterrupt:
In [5]:
Copied!
for id in range(1):
id = 150
print(f'now processing test_{id}...')
# for blc in bloodConc:
for blc in [138]:
prediction_input = np.empty((len(test_SO2),2*len(wavelength)*len(wavelength)+5)) # T1_large_SDS1/SDS2 T1_small_SDS1/SDS2 T2_large_SDS1/SDS2 T2_small_SDS1/SDS2 bloodConc ans id
for i, s in enumerate(test_SO2):
surrogate_result_T1 = pd.read_csv(os.path.join("dataset", "surrogate_result", 'test',
f'bloodConc_{blc}', 'SO2_0.7', f'{id}_test.csv'))
surrogate_result_T2 = pd.read_csv(os.path.join("dataset", "surrogate_result", 'test',
f'bloodConc_{blc}', f'SO2_{s}', f'{id}_test.csv'))
for wl_idx in range(len(wavelength)):
T2_large_SDS2 = surrogate_result_T2['largeIJV_SDS2'].to_numpy()
T2_large_SDS1 = surrogate_result_T2['largeIJV_SDS1'][wl_idx]
T1_large_SDS2 = surrogate_result_T1['largeIJV_SDS2'].to_numpy()
T1_large_SDS1 = surrogate_result_T1['largeIJV_SDS1'][wl_idx]
T2_small_SDS2 = surrogate_result_T2['smallIJV_SDS2'].to_numpy()
T2_small_SDS1 = surrogate_result_T2['smallIJV_SDS1'][wl_idx]
T1_small_SDS2 = surrogate_result_T1['smallIJV_SDS2'].to_numpy()
T1_small_SDS1 = surrogate_result_T1['smallIJV_SDS1'][wl_idx]
prediction_input[i][wl_idx*20 : wl_idx*20+20] = T2_large_SDS1 /T2_large_SDS2 - T1_large_SDS1 /T1_large_SDS2
prediction_input[i][400+wl_idx*20 : 400+wl_idx*20+20] = T2_small_SDS1 / T2_small_SDS2 - T1_small_SDS1 / T1_small_SDS2
for id in range(1):
id = 150
print(f'now processing test_{id}...')
# for blc in bloodConc:
for blc in [138]:
prediction_input = np.empty((len(test_SO2),2*len(wavelength)*len(wavelength)+5)) # T1_large_SDS1/SDS2 T1_small_SDS1/SDS2 T2_large_SDS1/SDS2 T2_small_SDS1/SDS2 bloodConc ans id
for i, s in enumerate(test_SO2):
surrogate_result_T1 = pd.read_csv(os.path.join("dataset", "surrogate_result", 'test',
f'bloodConc_{blc}', 'SO2_0.7', f'{id}_test.csv'))
surrogate_result_T2 = pd.read_csv(os.path.join("dataset", "surrogate_result", 'test',
f'bloodConc_{blc}', f'SO2_{s}', f'{id}_test.csv'))
for wl_idx in range(len(wavelength)):
T2_large_SDS2 = surrogate_result_T2['largeIJV_SDS2'].to_numpy()
T2_large_SDS1 = surrogate_result_T2['largeIJV_SDS1'][wl_idx]
T1_large_SDS2 = surrogate_result_T1['largeIJV_SDS2'].to_numpy()
T1_large_SDS1 = surrogate_result_T1['largeIJV_SDS1'][wl_idx]
T2_small_SDS2 = surrogate_result_T2['smallIJV_SDS2'].to_numpy()
T2_small_SDS1 = surrogate_result_T2['smallIJV_SDS1'][wl_idx]
T1_small_SDS2 = surrogate_result_T1['smallIJV_SDS2'].to_numpy()
T1_small_SDS1 = surrogate_result_T1['smallIJV_SDS1'][wl_idx]
prediction_input[i][wl_idx*20 : wl_idx*20+20] = T2_large_SDS1 /T2_large_SDS2 - T1_large_SDS1 /T1_large_SDS2
prediction_input[i][400+wl_idx*20 : 400+wl_idx*20+20] = T2_small_SDS1 / T2_small_SDS2 - T1_small_SDS1 / T1_small_SDS2
now processing test_150...
In [17]:
Copied!
result_OD1_spec.shape
result_OD1_spec.shape
Out[17]:
(84, 800)
In [18]:
Copied!
invivo_spec.mean()
invivo_spec.mean()
Out[18]:
0.001201502604287068
In [19]:
Copied!
result_diff_spec = result_OD2_spec - result_OD1_spec
result_diff_spec.shape
result_diff_spec = result_OD2_spec - result_OD1_spec
result_diff_spec.shape
Out[19]:
(84, 800)
In [20]:
Copied!
# sim_spec = prediction_input[33][:800]
invivo_spec = result_diff_spec[16]
now_ijv_SO2 = 0
used_rmspe = 0
# invivo_spec = (invivo_spec - invivo_spec.max())/ (invivo_spec.max()-invivo_spec.min())
fig, ax = plt.subplots(5,4,figsize=(16,12))
fig.suptitle(r'$\Delta$OD spectrum @ $\Delta$SO2 :' + f'{now_ijv_SO2:.2f}%, RMSPE : {used_rmspe:.2f}%', fontsize=20)
sim_ijv_large_spec = []
sim_ijv_small_spec = []
ijv_large_spec = []
ijv_small_spec = []
for label_idx, sim_spec in enumerate(prediction_input[25:35]):
sim_spec = sim_spec[:800]
# sim_spec = (sim_spec - prediction_input.max())/ (prediction_input.max()-prediction_input.min())
for i in range(20):
ijv_large_spec = invivo_spec[i*20:i*20+20]
ijv_small_spec = invivo_spec[i*20+400:i*20+20+400]
sim_ijv_large_spec = sim_spec[i*20:i*20+20]
sim_ijv_small_spec = sim_spec[i*20+400:i*20+20+400]
if label_idx == 0:
ax[i//4][i%4].plot(wavelength, sim_ijv_large_spec, linestyle='--', color = 'blue', label=r'$IJV_{large}$ sim')
# ax[i//4][i%4].plot(wavelength, sim_ijv_small_spec, linestyle='--', color = 'orange', label=r'$IJV_{small}$ sim')
ax[i//4][i%4].plot(wavelength, ijv_large_spec, color = 'red', label=r'$IJV_{large}$ in vivo')
# ax[i//4][i%4].plot(wavelength, ijv_small_spec, color = 'orange', label=r'$IJV_{small}$ in vivo')
else:
ax[i//4][i%4].plot(wavelength, sim_ijv_large_spec, linestyle='--', color = 'blue')
ax[i//4][i%4].plot(wavelength, ijv_large_spec, color = 'red')
ax[i//4][i%4].set_xlabel("wavelength(nm)")
ax[i//4][i%4].set_ylabel(f"$\Delta$OD")
ax[i//4][i%4].title.set_text(f'based on {wavelength[i]} nm')
# ax[i//4][i%4].legend()
fig.tight_layout()
plt.legend(loc='center left', bbox_to_anchor=(1.05, 0.5),
fancybox=True, shadow=True)
plt.show()
# sim_spec = prediction_input[33][:800]
invivo_spec = result_diff_spec[16]
now_ijv_SO2 = 0
used_rmspe = 0
# invivo_spec = (invivo_spec - invivo_spec.max())/ (invivo_spec.max()-invivo_spec.min())
fig, ax = plt.subplots(5,4,figsize=(16,12))
fig.suptitle(r'$\Delta$OD spectrum @ $\Delta$SO2 :' + f'{now_ijv_SO2:.2f}%, RMSPE : {used_rmspe:.2f}%', fontsize=20)
sim_ijv_large_spec = []
sim_ijv_small_spec = []
ijv_large_spec = []
ijv_small_spec = []
for label_idx, sim_spec in enumerate(prediction_input[25:35]):
sim_spec = sim_spec[:800]
# sim_spec = (sim_spec - prediction_input.max())/ (prediction_input.max()-prediction_input.min())
for i in range(20):
ijv_large_spec = invivo_spec[i*20:i*20+20]
ijv_small_spec = invivo_spec[i*20+400:i*20+20+400]
sim_ijv_large_spec = sim_spec[i*20:i*20+20]
sim_ijv_small_spec = sim_spec[i*20+400:i*20+20+400]
if label_idx == 0:
ax[i//4][i%4].plot(wavelength, sim_ijv_large_spec, linestyle='--', color = 'blue', label=r'$IJV_{large}$ sim')
# ax[i//4][i%4].plot(wavelength, sim_ijv_small_spec, linestyle='--', color = 'orange', label=r'$IJV_{small}$ sim')
ax[i//4][i%4].plot(wavelength, ijv_large_spec, color = 'red', label=r'$IJV_{large}$ in vivo')
# ax[i//4][i%4].plot(wavelength, ijv_small_spec, color = 'orange', label=r'$IJV_{small}$ in vivo')
else:
ax[i//4][i%4].plot(wavelength, sim_ijv_large_spec, linestyle='--', color = 'blue')
ax[i//4][i%4].plot(wavelength, ijv_large_spec, color = 'red')
ax[i//4][i%4].set_xlabel("wavelength(nm)")
ax[i//4][i%4].set_ylabel(f"$\Delta$OD")
ax[i//4][i%4].title.set_text(f'based on {wavelength[i]} nm')
# ax[i//4][i%4].legend()
fig.tight_layout()
plt.legend(loc='center left', bbox_to_anchor=(1.05, 0.5),
fancybox=True, shadow=True)
plt.show()
In [21]:
Copied!
fig, ax = plt.subplots(5,4,figsize=(16,12))
fig.suptitle(r'$\Delta$OD spectrum in vivo', fontsize=20)
sim_ijv_large_spec = []
sim_ijv_small_spec = []
ijv_large_spec = []
ijv_small_spec = []
# invivo_spec = result_diff_spec[15]*10
baseline_spec_set = result_OD1_spec[:5]
HP_spec_set = result_OD1_spec[8:15]
recovery_spec_set = result_OD1_spec[-5:]
for i in range(20):
# ijv_large_spec = invivo_spec[i*20:i*20+20]
# ijv_small_spec = invivo_spec[i*20+400:i*20+20+400]
# sim_ijv_large_spec = sim_spec[i*20:i*20+20]
# sim_ijv_small_spec = sim_spec[i*20+400:i*20+20+400]
for b_idx, baseline_spec in enumerate(baseline_spec_set):
if (i==19) & (b_idx==0):
ax[i//4][i%4].plot(wavelength, baseline_spec[i*20:i*20+20], linestyle='--', color = 'b', label=r'$IJV_{large}$ baseline sim')
else:
ax[i//4][i%4].plot(wavelength, baseline_spec[i*20:i*20+20], linestyle='--', color = 'b')
for HP_idx, HP_spec in enumerate(HP_spec_set):
if (i==19) & (HP_idx==0):
ax[i//4][i%4].plot(wavelength, HP_spec[i*20:i*20+20], linestyle='--', color = 'r', label=r'$IJV_{large}$ HP sim')
else:
ax[i//4][i%4].plot(wavelength, HP_spec[i*20:i*20+20], linestyle='--', color = 'r')
for r_idx, recovery_spec in enumerate(recovery_spec_set):
if (i==19) & (r_idx==0):
ax[i//4][i%4].plot(wavelength, recovery_spec[i*20:i*20+20], linestyle='--', color = 'g', label=r'$IJV_{large}$ recovery sim')
else:
ax[i//4][i%4].plot(wavelength, recovery_spec[i*20:i*20+20], linestyle='--', color = 'g')
# ax[i//4][i%4].plot(wavelength, sim_ijv_large_spec, linestyle='--', color = 'blue', label=r'$IJV_{large}$ sim')
# ax[i//4][i%4].plot(wavelength, sim_ijv_small_spec, linestyle='--', color = 'orange', label=r'$IJV_{small}$ sim')
# ax[i//4][i%4].plot(wavelength, ijv_large_spec, color = 'blue', label=r'$IJV_{large}$ in vivo')
# ax[i//4][i%4].plot(wavelength, ijv_small_spec, color = 'orange', label=r'$IJV_{small}$ in vivo')
ax[i//4][i%4].set_xlabel("wavelength(nm)")
ax[i//4][i%4].set_ylabel(f"$\Delta$OD")
ax[i//4][i%4].title.set_text(f'based on {wavelength[i]} nm')
# ax[i//4][i%4].legend()
fig.tight_layout()
plt.legend(loc='center left', bbox_to_anchor=(1.05, 0.5),
fancybox=True, shadow=True)
plt.show()
fig, ax = plt.subplots(5,4,figsize=(16,12))
fig.suptitle(r'$\Delta$OD spectrum in vivo', fontsize=20)
sim_ijv_large_spec = []
sim_ijv_small_spec = []
ijv_large_spec = []
ijv_small_spec = []
# invivo_spec = result_diff_spec[15]*10
baseline_spec_set = result_OD1_spec[:5]
HP_spec_set = result_OD1_spec[8:15]
recovery_spec_set = result_OD1_spec[-5:]
for i in range(20):
# ijv_large_spec = invivo_spec[i*20:i*20+20]
# ijv_small_spec = invivo_spec[i*20+400:i*20+20+400]
# sim_ijv_large_spec = sim_spec[i*20:i*20+20]
# sim_ijv_small_spec = sim_spec[i*20+400:i*20+20+400]
for b_idx, baseline_spec in enumerate(baseline_spec_set):
if (i==19) & (b_idx==0):
ax[i//4][i%4].plot(wavelength, baseline_spec[i*20:i*20+20], linestyle='--', color = 'b', label=r'$IJV_{large}$ baseline sim')
else:
ax[i//4][i%4].plot(wavelength, baseline_spec[i*20:i*20+20], linestyle='--', color = 'b')
for HP_idx, HP_spec in enumerate(HP_spec_set):
if (i==19) & (HP_idx==0):
ax[i//4][i%4].plot(wavelength, HP_spec[i*20:i*20+20], linestyle='--', color = 'r', label=r'$IJV_{large}$ HP sim')
else:
ax[i//4][i%4].plot(wavelength, HP_spec[i*20:i*20+20], linestyle='--', color = 'r')
for r_idx, recovery_spec in enumerate(recovery_spec_set):
if (i==19) & (r_idx==0):
ax[i//4][i%4].plot(wavelength, recovery_spec[i*20:i*20+20], linestyle='--', color = 'g', label=r'$IJV_{large}$ recovery sim')
else:
ax[i//4][i%4].plot(wavelength, recovery_spec[i*20:i*20+20], linestyle='--', color = 'g')
# ax[i//4][i%4].plot(wavelength, sim_ijv_large_spec, linestyle='--', color = 'blue', label=r'$IJV_{large}$ sim')
# ax[i//4][i%4].plot(wavelength, sim_ijv_small_spec, linestyle='--', color = 'orange', label=r'$IJV_{small}$ sim')
# ax[i//4][i%4].plot(wavelength, ijv_large_spec, color = 'blue', label=r'$IJV_{large}$ in vivo')
# ax[i//4][i%4].plot(wavelength, ijv_small_spec, color = 'orange', label=r'$IJV_{small}$ in vivo')
ax[i//4][i%4].set_xlabel("wavelength(nm)")
ax[i//4][i%4].set_ylabel(f"$\Delta$OD")
ax[i//4][i%4].title.set_text(f'based on {wavelength[i]} nm')
# ax[i//4][i%4].legend()
fig.tight_layout()
plt.legend(loc='center left', bbox_to_anchor=(1.05, 0.5),
fancybox=True, shadow=True)
plt.show()