6. Example of masks

6.1. Creating an instance

An instance must be created before starting to operate with vector masks. The initialization accepts several arguments.

[1]:
%matplotlib inline
[2]:
from diffractio import degrees, mm, np, plt, sp, um
from diffractio.scalar_fields_XY import Scalar_field_XY
from diffractio.scalar_masks_XY import Scalar_mask_XY
from diffractio.scalar_sources_XY import Scalar_source_XY
from diffractio.utils_tests import save_figure_test
from diffractio.vector_paraxial_fields_XY import Vector_paraxial_field_XY
from diffractio.vector_paraxial_masks_XY import Vector_paraxial_mask_XY
from diffractio.vector_paraxial_sources_XY import Vector_paraxial_source_XY

from py_pol.jones_matrix import Jones_matrix
number of processors: 8
[3]:
from matplotlib import rcParams
rcParams['figure.figsize']=[8,6]
rcParams['figure.dpi']=125

6.2. Polarization from standard elements

6.2.1. Using defined polarizers

There are several standard polarizers: - polarized_linear - quarter_waveplate - half_waveplate - polarizer_retarder

[4]:
x0 = np.linspace(-125*um, 125*um, 512)
y0 =  np.linspace(-125*um, 125*um, 512)
wavelength = 0.6328 * um


# mask vectorial
vc = Vector_paraxial_mask_XY(x0, y0, wavelength)
vc.polarizer_linear(azimuth=22.5*degrees)
vc.draw(kind='amplitude')
<Figure size 1000x750 with 0 Axes>
../../../_images/source_tutorial_vector_paraxial_XY_tutorial_vector_paraxial_masks_XY_7_1.png

6.2.2. Using py_pol module

If more general polarizer is required, we han use py_pol module

[5]:
x0 = np.linspace(-125*um, 125*um, 512)
y0 =  np.linspace(-125*um, 125*um, 512)
wavelength = 0.6328 * um


PL = Jones_matrix('m0')
PL.from_components([0.9, 0, 0, 0.2 * np.exp(1j)])

vp = Vector_paraxial_mask_XY(x0, y0, wavelength)
vp.from_py_pol(PL)

vp.draw(kind='all');
<Figure size 1000x750 with 0 Axes>
../../../_images/source_tutorial_vector_paraxial_XY_tutorial_vector_paraxial_masks_XY_9_1.png
<Figure size 1000x750 with 0 Axes>
../../../_images/source_tutorial_vector_paraxial_XY_tutorial_vector_paraxial_masks_XY_9_3.png

6.3. Apply a mask to the polarizer

[6]:
x0 = np.linspace(-125*um, 125*um, 512)
y0 =  np.linspace(-125*um, 125*um, 512)
wavelength = 0.6328 * um

mask = Scalar_mask_XY(x=x0, y=y0, wavelength=wavelength)
mask.square(
    r0=(0 * um, 0 * um),
    size = (100*um, 100*um),
    angle=0 * degrees)

# mask vectorial
vc = Vector_paraxial_mask_XY(x0, y0, wavelength)
vc.polarizer_linear(azimuth=22.5*degrees)
vc.apply_scalar_mask(u_mask=mask)
vc.draw(kind='amplitude')
<Figure size 1000x750 with 0 Axes>
../../../_images/source_tutorial_vector_paraxial_XY_tutorial_vector_paraxial_masks_XY_11_1.png

6.4. circle

Since normally a circular mask is used, a function for this is defined. Therefore, an Scalar_XY mask is not required.

[7]:
x0 = np.linspace(-125*um, 125*um, 512)
y0 =  np.linspace(-125*um, 125*um, 512)
wavelength = 0.6328 * um

# mask vectorial
vc = Vector_paraxial_mask_XY(x0, y0, wavelength)
vc.polarizer_linear(azimuth=22.5*degrees)
vc.apply_circle()
vc.draw(kind='amplitude')
<Figure size 1000x750 with 0 Axes>
../../../_images/source_tutorial_vector_paraxial_XY_tutorial_vector_paraxial_masks_XY_13_1.png

6.5. Complementary mask

When we provide a binary mask, the 1 mask is converted to v1 polarization and 0 mask is converted to v2 polarization.

[8]:
x0 = np.linspace(-125*um, 125*um, 512)
y0 =  np.linspace(-125*um, 125*um, 512)
wavelength = 0.6328 * um

mask = Scalar_mask_XY(x=x0, y=y0, wavelength=wavelength)
mask.fresnel_lens(
    r0=(0 * um, 0 * um),
    radius=(125 * um, 125 * um),
    focal=(2 * mm, 2 * mm),
    angle=0 * degrees,
    mask=True,
    kind='amplitude')

EM0 = Vector_paraxial_mask_XY(x0, y0, wavelength)
EM0.complementary_masks(mask=mask,
                        state_0=np.array([[1-1j, 0], [0, 0]]),
                        state_1=np.array([[0, 0], [0, 1+1j]]))
EM0.draw(kind='all');
<Figure size 1000x750 with 0 Axes>
../../../_images/source_tutorial_vector_paraxial_XY_tutorial_vector_paraxial_masks_XY_15_1.png
<Figure size 1000x750 with 0 Axes>
../../../_images/source_tutorial_vector_paraxial_XY_tutorial_vector_paraxial_masks_XY_15_3.png

6.6. Pass to py_pol

[9]:
m0 = EM0.to_py_pol()
[10]:
m0.parameters.get_all(draw=True)
The matrix components of from Diffractio are:
The mean value of param J00 is (0.59796142578125-0.59796142578125j) +- 0.6934025656988942
The mean value of param J01 is 0j +- 0.0
The mean value of param J10 is 0j +- 0.0
The mean value of param J11 is (0.40203857421875+0.40203857421875j) +- 0.6934025656988942
../../../_images/source_tutorial_vector_paraxial_XY_tutorial_vector_paraxial_masks_XY_18_1.png

/home/luismiguel/bitbucket/py_pol/py_pol/jones_matrix.py:2333: ComplexWarning: Casting complex values to real discards the imaginary part
  D = np.array(D, dtype=float)
The diattenuation of from Diffractio is:
The mean value is 1.0 +- 0.0
../../../_images/source_tutorial_vector_paraxial_XY_tutorial_vector_paraxial_masks_XY_18_5.png

The retardance of from Diffractio is (deg.):
The mean value is 0.0 +- 0.0
../../../_images/source_tutorial_vector_paraxial_XY_tutorial_vector_paraxial_masks_XY_18_7.png

The global phase of from Diffractio is (deg.):
The mean value is 188.35784912109375 +- 154.44754173381918
../../../_images/source_tutorial_vector_paraxial_XY_tutorial_vector_paraxial_masks_XY_18_9.png

The inhomogeneity parameter of from Diffractio is:
The mean value is 1.1102230246251565e-16 +- 0.0
../../../_images/source_tutorial_vector_paraxial_XY_tutorial_vector_paraxial_masks_XY_18_11.png

The intensity transmissions of from Diffractio are:
The mean value of param Maximum (int.) is 2.0000000000000004 +- 0.0
The mean value of param Minimum (int.) is 0.0 +- 0.0
../../../_images/source_tutorial_vector_paraxial_XY_tutorial_vector_paraxial_masks_XY_18_13.png

The field transmissions of from Diffractio are:
The mean value of param Maximum (int.) is 1.4142135623730947 +- 4.440892098500626e-16
The mean value of param Minimum (int.) is 0.0 +- 0.0
../../../_images/source_tutorial_vector_paraxial_XY_tutorial_vector_paraxial_masks_XY_18_15.png

The mean transmission of from Diffractio is:
The mean value is 1.0000000000000002 +- 0.0
../../../_images/source_tutorial_vector_paraxial_XY_tutorial_vector_paraxial_masks_XY_18_17.png

The determinant of from Diffractio is:
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-10-70870a31de1b> in <module>
----> 1 m0.parameters.get_all(draw=True)

~/bitbucket/py_pol/py_pol/jones_matrix.py in get_all(self, verbose, draw)
   2153         self.dict_params['mean_transmission'] = self.mean_transmission(
   2154             verbose=verbose, draw=draw)
-> 2155         self.dict_params['det'] = self.det(verbose=verbose, draw=draw)
   2156         self.dict_params['trace'] = self.trace(verbose=verbose, draw=draw)
   2157         self.dict_params['norm'] = self.norm(verbose=verbose, draw=draw)

~/bitbucket/py_pol/py_pol/jones_matrix.py in det(self, out_number, shape_like, shape, verbose, draw)
   2885         if verbose or draw:
   2886             heading = 'The determinant of {} is:'.format(self.parent.name)
-> 2887             PrintParam(param=det,
   2888                        shape=self.parent.shape,
   2889                        title='Determinant',

~/bitbucket/py_pol/py_pol/utils.py in PrintParam(param, verbose, draw, statistics, shape, title, heading)
    509                 if is_bool:
    510                     param = param.astype(float)
--> 511                 plt.imshow(param)
    512                 plt.title(title)
    513                 plt.colorbar()

~/.local/lib/python3.8/site-packages/matplotlib/pyplot.py in imshow(X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, filternorm, filterrad, resample, url, data, **kwargs)
   2722         filternorm=True, filterrad=4.0, resample=None, url=None,
   2723         data=None, **kwargs):
-> 2724     __ret = gca().imshow(
   2725         X, cmap=cmap, norm=norm, aspect=aspect,
   2726         interpolation=interpolation, alpha=alpha, vmin=vmin,

~/.local/lib/python3.8/site-packages/matplotlib/__init__.py in inner(ax, data, *args, **kwargs)
   1436     def inner(ax, *args, data=None, **kwargs):
   1437         if data is None:
-> 1438             return func(ax, *map(sanitize_sequence, args), **kwargs)
   1439
   1440         bound = new_sig.bind(ax, *args, **kwargs)

~/.local/lib/python3.8/site-packages/matplotlib/axes/_axes.py in imshow(self, X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, filternorm, filterrad, resample, url, **kwargs)
   5521                               resample=resample, **kwargs)
   5522
-> 5523         im.set_data(X)
   5524         im.set_alpha(alpha)
   5525         if im.get_clip_path() is None:

~/.local/lib/python3.8/site-packages/matplotlib/image.py in set_data(self, A)
    698         if (self._A.dtype != np.uint8 and
    699                 not np.can_cast(self._A.dtype, float, "same_kind")):
--> 700             raise TypeError("Image data of dtype {} cannot be converted to "
    701                             "float".format(self._A.dtype))
    702

TypeError: Image data of dtype complex128 cannot be converted to float
../../../_images/source_tutorial_vector_paraxial_XY_tutorial_vector_paraxial_masks_XY_18_20.png
[ ]: