4141chromophoresMeasuredData = Array .CreateInstance (IChromophoreAbsorber , 2 )
4242chromophoresMeasuredData [0 ] = ChromophoreAbsorber (ChromophoreType .HbO2 , measuredData [0 ])
4343chromophoresMeasuredData [1 ] = ChromophoreAbsorber (ChromophoreType .Hb , measuredData [1 ])
44+ # len(opsMeasured)=8 per number of wavelengths
4445opsMeasured = Tissue (chromophoresMeasuredData , scattererMeasuredData , "" , n = 1.4 ).GetOpticalProperties (wavelengths )
4546# Create measurements using Nurbs-based white Monte Carlo forward solver
4647measurementForwardSolver = NurbsForwardSolver ()
48+ # len(measuredROfFx)=16 (#wavelengths)x(#fxs) organized [op1fx1, op1fx2, op2fx1, op2fx2, ...]
4749measuredROfFx = measurementForwardSolver .ROfFx (opsMeasured , fxs )
4850# Create a forward solver as a model function for inversion
4951forwardSolverForInversion = PointSourceSDAForwardSolver ()
@@ -63,11 +65,9 @@ def CalculateReflectanceVsWavelengthFromChromophoreConcentration(
6365 scattererLocal = PowerLawScatterer (valuesSought [2 ], valuesSought [3 ])
6466 # Compose local tissue to obtain optical properties
6567 opsLocal = Tissue (chromophoresLocal , scattererLocal , "" , n = 1.4 ).GetOpticalProperties (wavelengths )
66- print ('opsLocal[0]=' ,opsLocal [0 ])
6768 # Compute reflectance for local absorbers
6869 modelDataLocal = Array .CreateInstance (float , len (wavelengths ) * len (fxs ))
6970 modelDataLocal = forwardSolver .ROfFx (opsLocal , fxs )
70- print ('modelDataLocal dims=' ,len (modelDataLocal ))
7171 modelDataForReturn = Array .CreateInstance (float , len (wavelengths ) * len (fxs ))
7272 for i in range (0 , len (wavelengths ) * len (fxs )):
7373 modelDataForReturn [i ] = modelDataLocal [i ]
@@ -107,28 +107,32 @@ def residual(valuesSought, wavelengths, fxs, measuredROfFx, forwardSolver):
107107# Compose tissue for fit data to obtain OPs
108108opsFit = Tissue (chromophoresFit , scattererFit , "" , n = 1.4 ).GetOpticalProperties (wavelengths )
109109fitROfFx = forwardSolverForInversion .ROfFx (opsFit , fxs )
110- # plot the results using Plotly
110+ # plot the results using Plotly data organization [op1fx1, op1fx2, op2fx1, op2,fx2,...]
111+ chart = go .Figure ()
111112xLabel = "wavelength [nm]"
112113yLabel = "R(wavelength)"
113114wvs = [w for w in wavelengths ]
114- # plot measured data
115- meas = [m for m in measuredROfFx ]
116- chart = go .Figure ( )
117- chart .add_trace (go .Scatter (x = wvs , y = meas , mode = 'markers' , name = 'measured data' ))
115+ # plot measured data first fx first
116+ meas = [m for m in measuredROfFx ]
117+ chart . add_trace ( go .Scatter ( x = wvs , y = meas [:: 2 ], mode = 'markers' , name = 'measured data: fx1' ) )
118+ chart .add_trace (go .Scatter (x = wvs , y = meas [ 1 : len ( meas ): 2 ] , mode = 'markers' , name = 'measured data: fx2 ' ))
118119# plot initial guess data
119120ig = [i for i in initialGuessROfFx ]
120- chart .add_trace (go .Scatter (x = wvs , y = ig , mode = 'markers' , name = 'initial guess' ))
121- # plot fit
121+ chart .add_trace (go .Scatter (x = wvs , y = ig [::2 ], mode = 'markers' , name = 'initial guess: fx1' ))
122+ chart .add_trace (go .Scatter (x = wvs , y = ig [1 :len (ig ):2 ], mode = 'markers' , name = 'initial guess: fx2' ))
123+ # plot fit: need to organize by fx
122124conv = [f for f in fitROfFx ]
123- chart .add_trace (go .Scatter (x = wvs , y = conv , mode = 'lines' , name = 'converged' ))
125+ chart .add_trace (go .Scatter (x = wvs , y = conv [::2 ], mode = 'lines' , name = 'converged: fx1' ))
126+ chart .add_trace (go .Scatter (x = wvs , y = conv [1 :len (conv ):2 ], mode = 'lines' , name = 'converged: fx2' ))
124127chart .update_layout ( title = "ROfFx (inverse solution for chromophore concentrations, multiple wavelengths, multiple fx)" , xaxis_title = xLabel , yaxis_title = yLabel )
128+
125129chart .show (renderer = "browser" )
126130# output results
127131print ("Meas = [%5.3f %5.3f %5.3f %5.3f]" % (measuredData [0 ], measuredData [1 ], measuredData [2 ], measuredData [3 ]))
128132print ("IG = [%5.3f %5.3f %5.3f %5.3f] Chi2=%5.3e" % (
129133 initialGuess [0 ], initialGuess [1 ], initialGuess [2 ], initialGuess [3 ],
130134 np .dot (measuredROfFx ,initialGuessROfFx )))
131- print ("Conv = [%5.3f %5.3f %5.3f] Chi2=%5.3e" % (fit .x [0 ], fit .x [1 ], fit .x [2 ], fit .x [3 ],
135+ print ("Conv = [%5.3f %5.3f %5.3f %5.3f ] Chi2=%5.3e" % (fit .x [0 ], fit .x [1 ], fit .x [2 ], fit .x [3 ],
132136 np .dot (measuredROfFx ,fitROfFx )))
133137print ("error = [%5.3f %5.3f %5.3f %5.3f]" % (
134138 abs ((measuredData [0 ]- fit .x [0 ])/ measuredData [0 ]),
0 commit comments