VirtualPhotonics / VTS

Virtual Tissue Simulator
https://virtualphotonics.org
Other
34 stars 9 forks source link

Intralipid scatterer in VTS Matlab requires redundant fields #16

Closed ccampb19 closed 5 years ago

ccampb19 commented 5 years ago

Following the scatterer.type='Intralipid' example in GetOP_help.m doesn't work. VtsSpectroscopy requires an additional field, "scatterer.VolumeFraction" in addition to "scatterer.vol_frac" to work correctly.

Application: VTS Matlab v4.5.0 Beta

To Reproduce: Use the code below. It produces a figure with three distinct scattering curves, as expected. Comment out only the "scatterer.VolumeFraction" line and get an error. Comment out only the "scatterer.vol_frac" line and get three identical scattering curves, indicating the default volume fraction is being used.

clear
absorbers.Names = {'HbO2', 'Hb', 'H2O'};
absorbers.Concentrations =  [70, 30, 0.8];
wv = 650:0.5:1000;

scatterer.Type = 'Intralipid';

for i = 1:3
    scatterer.VolumeFraction = 0.006+.002*i;
    scatterer.vol_frac = 0.006+.002*i;

    op(:,:,i) = VtsSpectroscopy.GetOP(absorbers, scatterer, wv);
end

figure
hold on
for i = 1:3
    plot(wv,op(:,2,i))
end
xlabel('Wavelength (nm)')
ylabel('\mu_S''')

Expected Behavior: GetOP_help.m lists only the vol_frac field. VolumeFraction should not be required. or vice-versa

hayakawa16 commented 5 years ago

Dear Chris,

Thank you for finding another bug! In VtsSpectroscopy.m the call to the Vts.dll IntralipidScatterer was erroneously using VolumeFraction instead of vol_frac. VolumeFraction is the property within the class, however in the matlab script we have simplified the names of those scatterer properties to ease use. So vol_frac is the one that should be used in the matlab script and I have updated VtsSpectroscopy.m to use vol_frac so when the next release of our matlab inter code is provided, it will be fixed.

While I was editing VtsSpectroscopy.m I expanded the Mie scatterer properties to include vol_frac. I also added two examples in vts_solver_demo.m that uses an Intralipid scatterer and an example that uses a Mie scatterer specification.

Just a comment about your script. For scatterers, the volume fraction is expected to be a real number between 0 and 1, not complex. Are you by chance wanting to specify a complex refractive index? If so using the Mie scatterer properties might work for you.

Thanks again for helping us improve our code. Best, Carole

ccampb19 commented 5 years ago

Hi again Carole,

Thanks for being so responsive! I frequently use 'i' as an increment, which may not be the best practice here, but Matlab doesn't seem to notice. For complex numbers I think Matlab prefers 1i*(theComplexNumber).

hayakawa16 commented 5 years ago

Thanks for the clarification about 'i'. I'll post here when the new Matlab download is available. I'm glad you have a workaround in the meantime.

hayakawa16 commented 5 years ago

The latest Matlab Interop download, version 4.6, has this bug fix.