<jupyter_start><jupyter_text>Sample: linear retarder with specified transmission and degree of polarization  Sample retardance: $\delta$, fast axis:$\theta$, slow axis: $\phi = \theta + \pi/2$<jupyter_code>delta, phi = sp.symbols('delta, phi')
M_retarder = M_Retarder(phi - sp.pi/2, delta)

M_retarder<jupyter_output><empty_output><jupyter_text>Sample may also have transmission $t$ and degree of polarization $p$<jupyter_code>t, p = sp.symbols('t, p')
M_tp = sp.Matrix([[t, 0, 0, 0], [0, t*p, 0, 0], [0, 0, t*p, 0], [0, 0, 0, t*p]])
M_sample = M_tp * M_retarder

M_sample<jupyter_output><empty_output><jupyter_text>Illumination: Stokes vectors<jupyter_code>S_unp = sp.Matrix([[1, 0, 0, 0]]).T
S_rcp = sp.Matrix([[1, 0, 0, 1]]).T
S_lcp = sp.Matrix([[1, 0, 0, -1]]).T
S = sp.Matrix([sp.symbols('s0:4')]).T<jupyter_output><empty_output><jupyter_text>model 1: illumination by right circularly polarized light The microscope measures the following Stokes vector of ligth $S_{sample}= \left$ after interacting with the sample.<jupyter_code>S_sample = M_sample * S_rcp

S_sample<jupyter_output><empty_output><jupyter_text>From the above Stokes vector, physical properties can be computed as follows.<jupyter_code>transmission = S[0]
slow_axis = 0.5 * sp.atan(-S[1]/S[2])
retardance = sp.atan(sp.sqrt(S[1]**2+S[2]**2)/S[3])
polarization = sp.sqrt(S[1]**2+S[2]**2+S[3]**2)/S[0]

display(Math('transmission = '+sp.latex(transmission)))
display(Math('slow\, axis = '+sp.latex(slow_axis)))
display(Math('retardance = '+sp.latex(retardance)))
display(Math('polarization = '+sp.latex(polarization)))<jupyter_output><empty_output><jupyter_text>model 2: background as ellitpical illumination. We model the background as elliptial illumination. Experimentally, this is the polarization state in the background where no specimen is present.<jupyter_code>S_bg = sp.Matrix([sp.symbols('s_0:4^{bg}')]).T
S_out = sp.Matrix([sp.symbols('s_0:4^{out}')]).T
S_measured = M_sample * S_bg

display(Math(sp.latex(S_out)+'='+sp.latex(M_sample * S_bg)))<jupyter_output><empty_output><jupyter_text>2a. If S_in = S_rcp<jupyter_code>display(Math(sp.latex(S_out)+'='+sp.latex(S_measured.subs({'s_0^{bg}':1,'s_1^{bg}':0,'s_2^{bg}':0,'s_3^{bg}':1}))))<jupyter_output><empty_output><jupyter_text>2b. If sample retardance is small, it is possible to correct for large background use Taylor series expansion of $cos(\delta)$  $cos(\delta)=1-\frac{x^2}{2!}+\frac{x^4}{4!}+...$<jupyter_code>S2 = S_measured.subs({sp.cos(delta):1,p:1})
display(Math(sp.latex(S_out)+'='+sp.latex(sp.trigsimp(S2))))<jupyter_output><empty_output><jupyter_text>$t=\frac{s_0^{out}}{s_0^{bg}}$ Now, normalize the LHS by $s_0^{out}$ and the RHS by $s_0^{bg}t$ and define  $s_{*n}=s_{*}/s_0$<jupyter_code>S2n = S2.subs({'s_0^{bg}':1,'t':1,'s_1^{bg}':'s_{1n}^{bg}','s_2^{bg}':'s_{2n}^{bg}','s_3^{bg}':'s_{3n}^{bg}'})
S_outn = S_out.subs({'s_0^{out}':1,'s_1^{out}':'s_{1n}^{out}','s_2^{out}':'s_{2n}^{out}','s_3^{out}':'s_{3n}^{out}'})
display(Math(sp.latex(S_outn)+'='+sp.latex(sp.trigsimp(S2n))))<jupyter_output><empty_output><jupyter_text>$\phi=\frac{1}{2}\arctan(-\frac{s_{1n}^{out}-s_{1n}^{bg}}{s_{2n}^{out}-s_{2n}^{bg}})$ $\delta=\arcsin(\frac{\sqrt{(s_{1n}^{out}-s_{1n}^{bg})^2+(s_{2n}^{out}-s_{2n}^{bg})^2}}{s_{3n}^{bg}})$  model 3: background as non-ideal linear retarder<jupyter_code>delta_bg, phi_bg = sp.symbols('delta_bg, phi_bg')

M_bg = M_Retarder(phi_bg - sp.pi/2, delta_bg)
M_bg<jupyter_output><empty_output><jupyter_text>How does changing the order of background retarder affect the output Stokes vector?<jupyter_code>S_bgBefore = M_sample * M_bg * S_rcp
display(Math(sp.latex(S_bgBefore)))
sp.trigsimp(S_bgBefore.subs({sp.cos(delta_bg):1,sp.sin(delta_bg):delta_bg}))
S_bgAfter =  M_bg * M_sample * S_rcp
S_bgAfter
S_bgAfter.subs({sp.cos(delta_bg):1,sp.sin(delta_bg):0})
sp.trigsimp(S_bgAfter.subs({sp.cos(delta_bg):1,sp.sin(delta_bg):delta_bg}))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.21273885350318472, 'fraction_numerical': 0.029044585987261146, 'mean_word_length': 8.599022004889976, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '451474', 'license': 'Unlicense', 'n_tokens_mistral': 1763, 'n_tokens_neox': 1680, 'n_words': 251, 'path': 'simulations/BackgroundCorrection.ipynb', 'repo_name': 'czbiohub/reconstruct-order', 'size': '3925'}