<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Backscattering Efficiency Validation
Scott Prahl
Apr 2021
If miepython is not installed, uncomment the following cell (i.e., delete the #) and run (shift-enter)
Step1:  Wiscombe tests
Since the backscattering efficiency is $|2S_1(-180^\circ)/x|^2$, it is easy to see that that backscattering
should be the best comparison.  For example, the asymmetry factor for this test case only has three significant
digits and the scattering efficiency only has two!
A typical test result looks like this
Step2:  Spheres with a smaller refractive index than their environment
Step3:  Non-absorbing spheres
Step4:  Water droplets
Step5:  Moderately absorbing spheres
Step6:  Spheres with really big index of refraction
Step7:  Backscattering Efficiency for Large Absorbing Spheres
For large spheres with absorption, backscattering efficiency should just be equal to the reflection for perpendicular light on a planar surface.
<ASSISTANT_TASK:>
Python Code:
#!pip install --user miepython
import numpy as np
import matplotlib.pyplot as plt
try:
    import miepython
except ModuleNotFoundError:
    print('miepython not installed. To install, uncomment and run the cell above.')
    print('Once installation is successful, rerun this cell again.')
Explanation: Backscattering Efficiency Validation
Scott Prahl
Apr 2021
If miepython is not installed, uncomment the following cell (i.e., delete the #) and run (shift-enter)
End of explanation
print("                                 miepython      Wiscombe")
print("     X       m.real   m.imag        Qback         Qback      ratio")
m=complex(1.55, 0.0)
x   = 2*3.1415926535*0.525/0.6328
ref = 2.92534
qext, qsca, qback, g = miepython.mie(m,x)
print("%9.3f   % 8.4f % 8.4f   % 8e % 8e %8.5f" % (x,m.real,m.imag,qback,ref,qback/ref))
m=complex(0.0, -1000.0)
x=0.099
ref = (4.77373E-07*4.77373E-07 +  1.45416E-03*1.45416E-03)/x/x*4
qext, qsca, qback, g = miepython.mie(m,x)
print("%9.3f   % 8.4f % 8.2f   % 8e % 8e %8.5f" % (x,m.real,m.imag,qback,ref,qback/ref))
x=0.101
ref = (5.37209E-07*5.37209E-07 +  1.54399E-03*1.54399E-03)/x/x*4
qext, qsca, qback, g = miepython.mie(m,x)
print("%9.3f   % 8.4f % 8.2f   % 8e % 8e %8.5f" % (x,m.real,m.imag,qback,ref,qback/ref))
x=100
ref = (4.35251E+01*4.35251E+01 +  2.45587E+01*2.45587E+01)/x/x*4
qext, qsca, qback, g = miepython.mie(m,x)
print("%9.3f   % 8.4f % 8.2f   % 8e % 8e %8.5f" % (x,m.real,m.imag,qback,ref,qback/ref))
x=10000
ref = abs(2.91013E+03-4.06585E+03*1j)**2/x/x*4
qext, qsca, qback, g = miepython.mie(m,x)
print("%9.3f   % 8.4f % 8.2f   % 8e % 8e %8.5f" % (x,m.real,m.imag,qback,ref,qback/ref))
print()
Explanation: Wiscombe tests
Since the backscattering efficiency is $|2S_1(-180^\circ)/x|^2$, it is easy to see that that backscattering
should be the best comparison.  For example, the asymmetry factor for this test case only has three significant
digits and the scattering efficiency only has two!
A typical test result looks like this:
```
MIEV0 Test Case 12:  Refractive index:  real    1.500  imag  -1.000E+00,  Mie size parameter =     0.055
                    NUMANG =   7 angles symmetric about 90 degrees
Angle    Cosine           S-sub-1                     S-sub-2               Intensity  Deg of Polzn
   0.00  1.000000   7.67526E-05   8.34388E-05   7.67526E-05   8.34388E-05   1.28530E-08        0.0000
                   (  1.000000)  (  1.000000)  (  1.000000)  (  1.000000)  (  1.000000)
  30.00  0.866025   7.67433E-05   8.34349E-05   6.64695E-05   7.22517E-05   1.12447E-08       -0.1428
                   (  1.000000)  (  1.000000)  (  1.000000)  (  1.000000)  (  1.000000)
  60.00  0.500000   7.67179E-05   8.34245E-05   3.83825E-05   4.16969E-05   8.02857E-09       -0.5999
                   (  1.000000)  (  1.000000)  (  1.000000)  (  1.000000)  (  1.000000)
  90.00  0.000000   7.66833E-05   8.34101E-05   3.13207E-08  -2.03740E-08   6.41879E-09       -1.0000
                   (  1.000000)  (  1.000000)  (  1.000000)  (  1.000000)  (  1.000000)
 120.00 -0.500000   7.66486E-05   8.33958E-05  -3.83008E-05  -4.17132E-05   8.01841E-09       -0.6001
                   (  1.000000)  (  1.000000)  (  1.000000)  (  1.000000)  (  1.000000)
 150.00 -0.866025   7.66233E-05   8.33853E-05  -6.63499E-05  -7.22189E-05   1.12210E-08       -0.1429
                   (  1.000000)  (  1.000000)  (  1.000000)  (  1.000000)  (  1.000000)
 180.00 -1.000000   7.66140E-05   8.33814E-05  -7.66140E-05  -8.33814E-05   1.28222E-08        0.0000
                   (  1.000000)  (  1.000000)  (  1.000000)  (  1.000000)  (  1.000000)
Angle          S-sub-1                     T-sub-1                     T-sub-2
   0.00   7.67526E-05   8.34388E-05   3.13207E-08  -2.03740E-08   7.67213E-05   8.34592E-05
         (  1.000000)  (  1.000000)  (  1.000000)  (  1.000000)  (  1.000000)  (  1.000000)
 180.00   7.66140E-05   8.33814E-05   3.13207E-08  -2.03740E-08   7.66453E-05   8.33611E-05
         (  1.000000)  (  1.000000)  (  1.000000)  (  1.000000)  (  1.000000)  (  1.000000)
        Efficiency factors for             Asymmetry
Extinction    Scattering    Absorption        Factor
  0.101491      0.000011      0.101480      0.000491
(  1.000000)  (  1.000000)  (  1.000000)  (  1.000000)
```
Perfectly conducting spheres
End of explanation
print("                                 miepython      Wiscombe")
print("     X       m.real   m.imag        Qback         Qback      ratio")
m=complex(0.75, 0.0)
x=0.099
ref = (1.81756E-08*1.81756E-08 + 1.64810E-04*1.64810E-04)/x/x*4
qext, qsca, qback, g = miepython.mie(m,x)
print("%9.3f   % 8.4f % 8.4f   % 8e % 8e %8.5f" % (x,m.real,m.imag,qback,ref,qback/ref))
x=0.101
ref = (2.04875E-08*2.04875E-08 + 1.74965E-04*1.74965E-04)/x/x*4
qext, qsca, qback, g = miepython.mie(m,x)
print("%9.3f   % 8.4f % 8.4f   % 8e % 8e %8.5f" % (x,m.real,m.imag,qback,ref,qback/ref))
x=10.0
ref = (1.07857E+00*1.07857E+00 + 3.60881E-02*3.60881E-02)/x/x*4
qext, qsca, qback, g = miepython.mie(m,x)
print("%9.3f   % 8.4f % 8.4f   % 8e % 8e %8.5f" % (x,m.real,m.imag,qback,ref,qback/ref))
x=1000.0
ref = (1.70578E+01*1.70578E+01 +  4.84251E+02* 4.84251E+02)/x/x*4
qext, qsca, qback, g = miepython.mie(m,x)
print("%9.3f   % 8.4f % 8.4f   % 8e % 8e %8.5f" % (x,m.real,m.imag,qback,ref,qback/ref))
print()
Explanation: Spheres with a smaller refractive index than their environment
End of explanation
print("                                 miepython      Wiscombe")
print("     X       m.real   m.imag        Qback         Qback      ratio")
m=complex(1.5, 0)
x=10
ref = abs(4.322E+00 + 4.868E+00*1j)**2/x/x*4
qext, qsca, qback, g = miepython.mie(m,x)
print("%9.3f   % 8.4f % 8.5f   % 8e % 8e %8.5f" % (x,m.real,m.imag,qback,ref,qback/ref))
x=100
ref = abs(4.077E+01 + 5.175E+01*1j)**2/x/x*4
qext, qsca, qback, g = miepython.mie(m,x)
print("%9.3f   % 8.4f % 8.5f   % 8e % 8e %8.5f" % (x,m.real,m.imag,qback,ref,qback/ref))
x=1000
ref = abs(5.652E+02 + 1.502E+03*1j)**2/x/x*4
qext, qsca, qback, g = miepython.mie(m,x)
print("%9.3f   % 8.4f % 8.5f   % 8e % 8e %8.5f" % (x,m.real,m.imag,qback,ref,qback/ref))
print()
Explanation: Non-absorbing spheres
End of explanation
print("                                                  old")
print("                                 miepython      Wiscombe")
print("     X       m.real   m.imag        Qback         Qback      ratio")
m=complex(1.33, -0.00001)
x=1
ref = (2.24362E-02*2.24362E-02 +  1.43711E-01*1.43711E-01)/x/x*4
qext, qsca, qback, g = miepython.mie(m,x)
print("%9.3f   % 8.4f % 8.5f   % 8e % 8e %8.5f" % (x,m.real,m.imag,qback,ref,qback/ref))
x=100
ref = (5.65921E+01*5.65921E+01 +  4.65097E+01*4.65097E+01)/x/x*4
qext, qsca, qback, g = miepython.mie(m,x)
print("%9.3f   % 8.4f % 8.5f   % 8e % 8e %8.5f" % (x,m.real,m.imag,qback,ref,qback/ref))
x=10000
ref = abs(-1.82119E+02  -9.51912E+02*1j)**2/x/x*4
qext, qsca, qback, g = miepython.mie(m,x)
print("%9.3f   % 8.4f % 8.5f   % 8e % 8e %8.5f" % (x,m.real,m.imag,qback,ref,qback/ref))
print()
Explanation: Water droplets
End of explanation
print("                                 miepython      Wiscombe")
print("     X       m.real   m.imag        Qback         Qback      ratio")
m=complex(1.5, -1.0)
x=0.055
ref = abs(7.66140E-05 + 8.33814E-05*1j)**2/x/x*4
qext, qsca, qback, g = miepython.mie(m,x)
print("%9.3f   % 8.4f % 8.4f   % 8e % 8e %8.5f" % (x,m.real,m.imag,qback,ref,qback/ref))
x=0.056
ref = (8.08721E-05*8.08721E-05 +  8.80098E-05*8.80098E-05)/x/x*4
qext, qsca, qback, g = miepython.mie(m,x)
print("%9.3f   % 8.4f % 8.4f   % 8e % 8e %8.5f" % (x,m.real,m.imag,qback,ref,qback/ref))
x=1.0
ref = (3.48844E-01*3.48844E-01 +  1.46829E-01*1.46829E-01)/x/x*4
qext, qsca, qback, g = miepython.mie(m,x)
print("%9.3f   % 8.4f % 8.4f   % 8e % 8e %8.5f" % (x,m.real,m.imag,qback,ref,qback/ref))
x=100.0
ref = (2.02936E+01*2.02936E+01 +  4.38444E+00*4.38444E+00)/x/x*4
qext, qsca, qback, g = miepython.mie(m,x)
print("%9.3f   % 8.4f % 8.4f   % 8e % 8e %8.5f" % (x,m.real,m.imag,qback,ref,qback/ref))
x=10000
ref = abs(-2.18472E+02  -2.06461E+03*1j)**2/x/x*4
qext, qsca, qback, g = miepython.mie(m,x)
print("%9.3f   % 8.4f % 8.4f   % 8e % 8e %8.5f" % (x,m.real,m.imag,qback,ref,qback/ref))
print()
Explanation: Moderately absorbing spheres
End of explanation
print("                                 miepython      Wiscombe")
print("     X       m.real   m.imag        Qback         Qback      ratio")
m=complex(10, -10.0)
x=1
ref = abs(4.48546E-01 + 7.91237E-01*1j)**2/x/x*4
qext, qsca, qback, g = miepython.mie(m,x)
print("%9.3f   % 8.4f % 8.4f   % 8e % 8e %8.5f" % (x,m.real,m.imag,qback,ref,qback/ref))
x=100
ref = abs(-4.14538E+01  -1.82181E+01*1j)**2/x/x*4
qext, qsca, qback, g = miepython.mie(m,x)
print("%9.3f   % 8.4f % 8.4f   % 8e % 8e %8.5f" % (x,m.real,m.imag,qback,ref,qback/ref))
x=10000
ref = abs(2.25248E+03  -3.92447E+03*1j)**2/x/x*4
qext, qsca, qback, g = miepython.mie(m,x)
print("%9.3f   % 8.4f % 8.4f   % 8e % 8e %8.5f" % (x,m.real,m.imag,qback,ref,qback/ref))
Explanation: Spheres with really big index of refraction
End of explanation
x = np.logspace(1, 5, 20)  # also in microns
kappa=1
m = 1.5 - kappa*1j
R = abs(m-1)**2/abs(m+1)**2
Qbig = R * np.ones_like(x)
qext, qsca, qback, g = miepython.mie(m,x)
plt.semilogx(x, qback, '+')
plt.semilogx(x, Qbig, ':')
plt.text(x[-1],Qbig[-1],"$\kappa$=%.3f" % kappa,va="bottom",ha='right')
kappa=0.001
m = 1.5 - kappa*1j
R = abs(m-1)**2/abs(m+1)**2
Qbig = R * np.ones_like(x)
qext, qsca, qback, g = miepython.mie(m,x)
plt.semilogx(x, qback, '+')
plt.semilogx(x, Qbig, ':')
plt.text(x[-1],Qbig[-1],"$\kappa$=%.3f" % kappa,va="bottom",ha='right')
plt.ylim(0,0.2)
plt.title("Backscattering Efficiency for m=1.5 - i $\kappa$")
plt.xlabel("Size Parameter")
plt.ylabel("$Q_{back}$")
plt.grid()
Explanation: Backscattering Efficiency for Large Absorbing Spheres
For large spheres with absorption, backscattering efficiency should just be equal to the reflection for perpendicular light on a planar surface.
End of explanation
<END_TASK>