API for iadpython package

iadpython.ad Module

Class for doing adding-doubling calculations for a sample.

Example:

>>> import iadpython as iad
>>> n=4
>>> sample = iad.Sample(a=0.9, b=10, g=0.9, n=1.5, quad_pts=4)
>>> ur1, ut1, uru, utu = sample.rt()
>>> print(ur1)
>>> print(ut1)

Functions

sanitize_anisotropy(g)

Map singular anisotropy endpoint g=-1 to a nearby finite value.

stringify(form, x)

Create a string from x.

Classes

Sample([a, b, g, d, n, n_above, n_below, ...])

Container class for details of a sample.

iadpython.combine Module

Module for adding layers together.

Two types of starting methods are possible.

Example:

>>> import iadpython as iad

>>> # Isotropic finite layer with mismatched slides the hard way.
>>> s = iad.Sample(a=0.5, b=1, g=0.0, n=1.4, n_above=1.5, n_below=1.6)
>>> s.quad_pts = 4
>>> R01, R10, T01, T10 = iad.boundary_matrices(s, top=True)
>>> R23, R32, T23, T32 = iad.boundary_matrices(s, top=False)
>>> R12, T12 = iad.simple_layer_matrices(s)
>>> R02, R20, T02, T20 = iad.add_layers(s, R01, R10, T01, T10, R12, R12, T12, T12)
>>> rr03, rr30, tt03, tt30 = iad.add_layers(s, R02, R20, T02, T20, R23, R32, T23, T32)

Functions

add_layers(sample, R01, R10, T01, T10, R12, ...)

Add two layers together.

add_layers_basic(sample, R10, T01, R12, R21, ...)

Add two layers together.

simple_layer_matrices(sample)

Create R and T matrices for multiple layers without boundaries.

add_slide_above(sample, R01, R10, T01, T10, ...)

Calculate matrices for a slab with a boundary placed above.

add_slide_below(sample, R01, R10, T01, T10, ...)

Calculate matrices for a slab with a boundary placed below.

add_same_slides(sample, R01, R10, T01, T10, R, T)

Find matrix when slab is sandwiched between identical slides.

iadpython.fresnel Module

Module for generating boundary matrices.

Two types of starting methods are possible.

Example

>>> import iadpython as iad
>>> n = 4
>>> slab = iad.Slab(a = 0.9, b = 10, g = 0.9, n = 1.5)
>>> method = iad.Method(slab)
>>> r, t = iad.init_layer(slab, method)
>>> print(r)
>>> print(t)

Functions

cos_critical(n_i, n_t)

Calculate the cosine of the critical angle.

cos_snell(n_i, nu_i, n_t)

Return the cosine of the transmitted angle.

fresnel_reflection(n_i, nu_i, n_t)

Fresnel Reflection.

absorbing_glass_RT(n_i, n_g, n_t, nu_i, b)

Reflection and transmission of an absorbing slide.

specular_rt(n_top, n_slab, n_bot, b_slab, nu)

Unscattered refl and trans for a sample.

diffuse_glass_R(n_air, n_slide, n_slab)

Calculate the total diffuse specular reflection for air-glass-tissue interface.

glass(n_i, n_g, n_t, nu_i)

Reflection from a glass slide.

iadpython.grid Module

Class for doing inverse adding-doubling calculations for a sample.

Example:

>>> import iadpython

>>> exp = iadpython.Experiment(0.5, 0.1, default_g=0.5)
>>> grid = iadpython.Grid()
>>> grid.calc(exp)
>>> print(grid)

Functions

matrix_as_string(x[, label])

Return matrix as a string.

Classes

Grid([search, default, N])

Class to track pre-calculated R & T values.

iadpython.iad Module

Class for doing inverse adding-doubling calculations for a sample.

Example:

>>> import iadpython as iad

>>> exp = iad.Experiment(0.5,0.1,0.01)
>>> a, b, g = exp.invert()
>>> print("a = %7.3f" % a)
>>> print("b = %7.3f" % b)
>>> print("g = %7.3f" % g)

>>> s = iad.Sample(0.5,0.1,0.01,n=1.4, n_top=1.5, n_bottom=1.5)
>>> exp = iad.Experiment(s)
>>> a, b, g = exp.invert()
>>> print("a = %7.3f" % a)
>>> print("b = %7.3f" % b)
>>> print("g = %7.3f" % g)

Functions

abfun(x, *args)

Vary the ab.

afun(x, *args)

Vary the albedo.

agfun(x, *args)

Vary the ag.

bafun(x, *args)

Vary the absorption optical depth with scattering optical depth fixed.

bagfun(x, *args)

Vary absorption optical depth and anisotropy with scattering fixed.

bfun(x, *args)

Vary the optical thickness.

bgfun(x, *args)

Vary the bg.

bsfun(x, *args)

Vary the scattering optical depth with absorption optical depth fixed.

bsgfun(x, *args)

Vary scattering optical depth and anisotropy with absorption fixed.

gfun(x, *args)

Vary the anisotropy.

run_mc_lost(a, b, g, *[, n_sample, n_slide, ...])

Call the mc_lost binary and return the four lost-light fractions.

Classes

Experiment([r, t, u, sample, r_sphere, ...])

Container class for details of an experiment.

iadpython.nist Module

Module for importing reflection spectra from NIST database.

Example:

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> import iadpython as iad

>>> # Retrieve and plot subject 5

>>> subject_number = 5
>>> lambda0, R = iad.subject_average_reflectance(subject_number)
>>> plt.plot(lambda0, R)
>>> plt.xlabel("Wavelength (nm)")
>>> plt.ylabel("Total Reflectance")
>>> plt.title("Subject #%d" % subject_number)
>>> plt.show()

>>> # Retrieve and plot all subjects

>>> lambda0, R = iad.all_average_reflectances()
>>> for i in range(100):
>>>     plt.plot(lambda0, R[:, i])
>>> plt.xlabel("Wavelength (nm)")
>>> plt.ylabel("Total Reflectance")
>>> plt.title("All Subjects")
>>> plt.show()
Reference:

<https://nvlpubs.nist.gov/nistpubs/jres/122/jres.122.026.pdf> nist_db = ‘https://doi.org/10.18434/M38597

Functions

subject_reflectances(subject_number)

Extract all reflection data for one subject.

subject_average_reflectance(subject_number)

Extract average reflection for one subject.

all_average_reflectances()

Extract average reflectance for all subjects.

iadpython.quadrature Module

Module for obtaining quadrature points and weights.

Three types of gaussian quadrature are supported: normal Gaussian, Radau quadrature, and Lobatto quadrature. The first method does not include either endpoint of integration, Radau quadrature includes one endpoint of the integration range, and Lobatto quadrature includes both endpoints.

Example:

>>> import iad.quadrature

>>> n=8
>>> x, w = iad.quadrature.gauss(n)
>>> print(" i        x         weight")
>>> for i,x in enumerate(xi):
>>>     print("%2d   %+.12f %+.12f" % (i, x[i], w[i]))

>>> x, w = iad.quadrature.radau(n)
>>> print(" i        x         weight")
>>> for i,x in enumerate(xi):
>>>     print("%2d   %+.12f %+.12f" % (i, x[i], w[i]))

>>> x, w = iad.quadrature.lobatto(n)
>>> print(" i        x         weight")
>>> for i,x in enumerate(xi):
>>>     print("%2d   %+.12f %+.12f" % (i, x[i], w[i]))

Functions

gauss(n[, a, b])

Return abscissas and weights for Gaussian quadrature.

radau(n[, a, b])

Return abscissas and weights for Radau quadrature.

lobatto(n[, a, b])

Return abscissas and weights for Lobatto quadrature.

iadpython.redistribution Module

Module for calculating the redistribution function.

The single scattering phase function ..math:p(nu) for a tissue determines the amount of light scattered at an angle nu=cos(theta) from the direction of incidence. The subtended angle nu is the dot product incident and exiting of the unit vectors.

The redistribution function ..math:h[i,j] determines the fraction of light scattered from an incidence cone with angle nu_i into a cone with angle ..math:nu_j. The redistribution function is calculated by averaging the phase function over all possible azimuthal angles for fixed angles ..math:nu_i and ..math:nu_j,

Note that the angles ..math:nu_i and ..math:nu_j may also be negative (light travelling in the opposite direction).

When the cosine of the angle of incidence or exitance is unity (..math:nu_i=1 or ..math:nu_j=1), then the redistribution function is equivalent to the phase function ..math:p(nu_j).

Functions

hg_elliptic(sample)

Calculate redistribution function using elliptic integrals.

hg_legendre(sample)

Calculate the HG redistribution matrix using Legendre polynomials.

iadpython.sphere Module

Class for managing integrating spheres.

This module contains the Sphere class, designed to simulate and analyze the behavior of light within an integrating sphere. An integrating sphere is a device used in optical measurements, which allows for the uniform scattering of light. It is commonly used for reflection and transmission measurements of materials.

The Sphere class models the geometrical and optical properties of an integrating sphere, enabling the calculation of various parameters such as the areas of spherical caps given port diameters, relative port areas, and the gain caused by reflections within the sphere. It supports different measurements scenarios by adjusting port diameters, detector reflectivity, wall reflectivity, and using a reflectance standard.

iadpython.sphere.d_sphere

Diameter of the integrating sphere in millimeters.

Type:

float

iadpython.sphere.d_sample

Diameter of the port that holds the sample.

Type:

float

iadpython.sphere.d_third

Diameter of the third port.

Type:

float

iadpython.sphere.d_detector

Diameter of the port with the detector.

Type:

float

iadpython.sphere.r_detector

Reflectivity of the detector.

Type:

float

iadpython.sphere.r_wall

Reflectivity of the sphere’s internal wall.

Type:

float

iadpython.sphere.r_std

Reflectivity of the standard used for calibration.

Type:

float

iadpython.sphere.cap_area()

actual area of a spherical cap for a port

iadpython.sphere.relative_cap_area()

relative area of spherical cap to the sphere’s area.

iadpython.sphere.gain()

sphere gain relative to isotropic diffuse source in center of black sphere

Example usage:
>>> import iadpython
>>> s = iadpython.Sphere(250,20)
>>> print(s)
>>> s = iadpython.Sphere(200, 20, d_third=10, d_detector=10, r_detector=0.8, r_wall=0.99, r_std=0.99)
>>> print(sphere)
>>> area_sample = sphere.cap_area(sphere.d_sample)
>>> print(f"Sample port area: {area_sample:.2f} mm²")

Classes

Enum(value[, names, module, qualname, type, ...])

Create a collection of name/value pairs.

PortType(value[, names, module, qualname, ...])

Possible sphere wall locations.

Sphere(d_sphere, d_sample[, d_third, ...])

Container class for a three-port integrating sphere.

iadpython.start Module

Module for generating the starting layer for adding-doubling.

Two types of starting methods are possible IGI and Diamond.

Example:

>>> import iadpython as iad
>>> s = iad.Sample(a=0.9, b=10, g=0.9, n=1.5)
>>> r, t = iad.init_layer(s)
>>> print(r)
>>> print(t)

Functions

zero_layer(sample)

Create R and T matrices for thinnest_layer with zero thickness.

starting_thickness(sample)

Find the best starting thickness to start the doubling process.

igi(sample)

Infinitesmal Generator Initialization.

diamond(sample)

Diamond initialization.

thinnest_layer(sample)

Reflection and transmission matrices for a thin thinnest_layer.

boundary_layer(s[, top])

Create reflection and transmission arrays for a boundary_layer.

boundary_matrices(s[, top])

Create reflection and transmission matrices for a boundary_layer.

unscattered_rt(s)

Unscattered reflection and transmission for a slide-slab-slide sandwich.