xopto / pyxopto

PyXOpto is a collection of python tools for performing Monte Carlo simulations of light propagation in turbid media.
GNU General Public License v3.0
30 stars 8 forks source link

Clarifying visualization, and some other things #16

Open Mrinmoyst1 opened 11 months ago

Mrinmoyst1 commented 11 months ago

Hello, I am also facing some problems. These are my configurations: detectors = mc.mcdetector.Detectors( top = mc.mcdetector.Radial( mc.mcdetector.Axis(0.0, 10.0e-3, 1000), cosmin=np.cos(np.deg2rad(20.0)) ))

fluence = mc.mcfluence.Fluence( xaxis=mc.mcfluence.Axis(-5.0e-3, 5.0e-3, 100), yaxis=mc.mcfluence.Axis(-5.0e-3, 5.0e-3, 100), zaxis=mc.mcfluence.Axis(0.0, 10.0e-3, 100))

trace = mc.mctrace.Trace( maxlen=1000, options=mc.mctrace.Trace.TRACE_ALL, filter=mc.mctrace.Filter( z=(-1e-9, 1e-9), pz=(-1, -np.cos(np.arcsin(0.22/1.45))), r=(0, 100e-6, (220e-6, 0)) ) )

I am having some troubles as am really new with PyXopto. Thanks!

xopto commented 11 months ago

What kind of experimental setup are you trying to simulate? Is it a configuration with one optical fiber as a source and one as a detector, where the distance between the two is varied?

Which quantity do you want to simulate/visualize? Is it the fluence, is it the sampling volume, is it the steady state reflectance, or time-resolved reflectance (includes information on the path lengths)?

Path lengths can be simulated with surface/reflectance detectors. Trace is only needed for sampling volume simulations.

Why are trace and fluence detectors used in a single simulation? The packets are filtered only in trace, fluence records data for all the packets. Using the two in a single MC simulation is usually not too efficient and limits the number of photon packets that can be run in a single call (trace consumes a lot of GPU memory per each launched photon packet).

Mrinmoyst1 commented 11 months ago

Thank you for your prompt reply. Actually, I was confused and I didn't find anything there in the documentation that fluence and trace can lead to this type of issue. However, my final goal is to calculate Differential Pathlength Factor (DPF). So, in order to find DPF, I need to simulate only pathlengths for different source to detector distances and at the same time for different wavelengths. So, there would be two loops while running the Monte Carlo simulation:

  1. For wavelengths
  2. For source to detector distances (1mm to 10mm)

I was previously trying to get the pathlength from the trace, now you clarified the thing. But, in the documentation of trace, it was mentioned that Pathlength (pl) can be obtained by using that. What is it then? Please see the image below.

image

Now, please tell me what would be the optimal solution for my case. I have to obtain the same results similar to this study. Hope you can now understand. Please comment on these things:

  1. Which detector to use in my case? I didn't find surface/reflectance detectors there in the documentation. Could you give me the link? Is this Radial detector? Then how can I obtain pathlength from that?
  2. How to control the distances between source and detector for running in a loop?
  3. Where to use "Simulator data types" that was mentioned here so that I can increase the number of photons? Please give an example.: https://xopto.github.io/pyxopto/docs/html/source/mcml/simulator_data_types.html
xopto commented 11 months ago

This would be the RadialPl detector: https://xopto.github.io/pyxopto/docs/html/apidoc/xopto.mcml.mcdetector.radialpl.html Configure the detector to be located at the origin (x,y)=(0,0). Let it have 2 concentric rings, where the diameter of the first/inner ring has the diameter of your detector (the outer/second ring also collects packets that arrive outside of the detector). Move your selected source (fiber, pencil, collimated, ...) to the desired distance (SDS) and run simulations. Use only the accumulated data from the inner ring (the outer ring will also collect packets that arrive beyond the outer diameter of the detector).

Alternatively, use the linear fiber array path length detector (configured to have a single fiber in the linear array): https://xopto.github.io/pyxopto/docs/html/apidoc/xopto.mcml.mcdetector.probe.lineararraypl.html

For arbitrary configuration of multiple fiber detectors use (can be also configured with a single fiber detector): https://xopto.github.io/pyxopto/docs/html/apidoc/xopto.mcml.mcdetector.probe.fiberarraypl.html

Mrinmoyst1 commented 11 months ago

Thank you so much! That's what I was looking for so long!

Mrinmoyst1 commented 11 months ago

Hello, I am going to use RadialPl detector for my case. Could you please tell me which property would return the pathlength here? Would it be pl? Would it be reflectance? Or, would it be normalized? I am getting a bit confused. If you can, could you please write the short code for the detector configuration at (0,0) position and returning the pathlengths after Monte Carlo simulation? It would be then easier for me. Thanks!

Mrinmoyst1 commented 10 months ago

Hello, I waited so long. I am sorry for asking again but I really need help here. Could you please explain me how to get the pathlength from any of these detectors or all if possible, "fiberarraypl, radialpl, or lineararraypl"? I am stuck here. Without knowing the exact method, I am getting confused by the documentation. I saw "reflectance, and transmittance" properties there. But, how to get the pathlength? Would you please send a sample code for getting the exact pathlength? Please guide me.

xopto commented 10 months ago

The following is an example of path length-resolved (time-resolved) simulations using an optical fiber as a source and a linear array of optical fibers as a detector (at distances of 220, 440, 660, 880, and 1100 um from the center of the source fiber). A single Monte Carlo simulation with a radial path length-resolved accumulator is used to produce the reflectance and from there to compute the reflectance collected through the individual fibers. reflectance_fiber_array_pl.zip

The script should produce the following plot: reflectance_fiber_array_pl

Mrinmoyst1 commented 10 months ago

Thank you for your response. In the sample code you have used "detector.top.pl" property. I think, it's returning the center of the pathlength axis from 0 to 10mm range, as stated in the documentation. My intention was not that. I wanted to get the optical pathlength of light after doing light propagation simulation in human skin. I didn't see anything like that in the documentation to obtain optical pathlengths. I hope you can now get it. Would you please guide me how to obtain optical pathlength of light using that? Thanks!

xopto commented 10 months ago

As already pointed out, the results of the MC simulations produce a distribution/histogram of path lengths, where the path length axis provides the x-axis values of the histogram/distribution and reflectance values the y-axis values of the histogram. For example, the first reflactance point contains the weight of all the detected photon packets that traveled from 0 to 40 um (optical path), the second reflectance point the weight of all the detected photon packets that traveled from 40 to 80 um, ... the penultimate reflectance point the weight of all the detected photon packets that traveled from 10 mm - 80 um to 10 mm - 40 um and the last reflectance point the weight of all the detected photon packets that traveled more than 10 mm - 40 um.

From this distribution/histogram, the average optical path length of the photon packets that were collected through a particular optical fiber can be easily computed as a weighted average of the path lengths in the histogram (weight is the reflectance). Using a basic numerical approach this would be: average_pl = np.sum(fiber_reflectance*pl)/np.sum(fiber_reflectance)

Note that the range of the optical path length axis is slightly too short in the example since some packets collected with the optical fibers have path lengths that exceed the range of the axis (10 mm). This is indicated by the reflectance jump in the last bin, which also collects the weight of all packets with a path length exceeding 10 mm.

Mrinmoyst1 commented 10 months ago

Thank you so much! Everything worked perfectly now!