Skip to content

Parameters

Parameters

The Parameters class represents the parameters for a simulation, including wavelength, refractive indices, scattering particles, and initial field, and provides methods for computing angular frequency and wave vectors.

Initializes the class with the given parameters and sets up the necessary variables.

Parameters:

Name Type Description Default
wavelength array

An array that represents the wavelengths of the light being used. It contains the values of the wavelengths at which the simulation will be performed.

required
medium_refractive_index array

An array that represents the refractive index of the medium in which the particles are located. It contains the refractive index values at different wavelengths.

required
particles Particles

An instance of the "Particles" class. It represents the particles present in the medium.

required
initial_field InitialField

An object of the InitialField class. It represents the initial field configuration for the simulation.

required
Source code in yasfpy/parameters.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
def __init__(
    self,
    wavelength: np.array,
    medium_refractive_index: np.array,
    particles: Particles,
    initial_field: InitialField,
):
    """Initializes the class with the given parameters and sets up the necessary variables.

    Args:
        wavelength (np.array): An array that represents the wavelengths of the light being used.
            It contains the values of the wavelengths at which the simulation will be performed.
        medium_refractive_index (np.array): An array that represents the refractive index of the
            medium in which the particles are located. It contains the refractive index values at different
            wavelengths.
        particles (Particles): An instance of the "Particles" class. It represents the particles
            present in the medium.
        initial_field (InitialField): An object of the `InitialField` class. It represents the
            initial field configuration for the simulation.
    """
    self.wavelength = wavelength
    self.medium_refractive_index = medium_refractive_index
    self.wavelengths_number = wavelength.size
    self.particles = particles
    self.initial_field = initial_field

    self.__setup()

wavelength = wavelength instance-attribute

medium_refractive_index = medium_refractive_index instance-attribute

wavelengths_number = wavelength.size instance-attribute

particles = particles instance-attribute

initial_field = initial_field instance-attribute

__setup

The function sets up the necessary computations for omega and ks.

Source code in yasfpy/parameters.py
45
46
47
48
def __setup(self):
    """The function sets up the necessary computations for omega and ks."""
    self.__compute_omega()
    self.__compute_ks()

__compute_omega

The function calculates the value of omega using the wavelength.

Source code in yasfpy/parameters.py
50
51
52
def __compute_omega(self):
    """The function calculates the value of omega using the wavelength."""
    self.omega = 2 * np.pi / self.wavelength

__interpolate_refractive_index_from_table

Interpolates the refractive index values from a table for different wavelengths.

Returns:

Name Type Description
refractive_index_interpolated array

An array that contains the interpolated refractive index values for the particles at different wavelengths.

Source code in yasfpy/parameters.py
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
def __interpolate_refractive_index_from_table(self):
    """Interpolates the refractive index values from a table for different wavelengths.

    Returns:
        refractive_index_interpolated (np.array): An array that contains the interpolated refractive index values for the particles
            at different wavelengths.
    """
    refractive_index_interpolated = np.zeros(
        (self.particles.num_unique_refractive_indices, self.wavelength.size),
        dtype=complex,
    )
    for idx, data in enumerate(self.particles.refractive_index_table):
        table = data["ref_idx"].to_numpy().astype(float)
        n = np.interp(
            self.wavelength / 1e3,
            table[:, 0],
            table[:, 1],
            left=table[0, 1],
            right=table[-1, 1],
        )
        k = np.interp(
            self.wavelength / 1e3,
            table[:, 0],
            table[:, 2],
            left=table[0, 2],
            right=table[-1, 2],
        )
        refractive_index_interpolated[idx, :] = n + 1j * k
    return refractive_index_interpolated

__index_to_table

Source code in yasfpy/parameters.py
84
85
86
def __index_to_table(self):
    # TODO: do all the idx to value conversion here
    pass

__compute_ks

Computes the values of k_medium and k_particle based on the refractive index of the medium and particles.

Source code in yasfpy/parameters.py
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
def __compute_ks(self):
    """Computes the values of k_medium and k_particle based on the refractive index of the
    medium and particles.
    """
    self.k_medium = self.omega * self.medium_refractive_index
    if self.particles.refractive_index_table is None:
        self.k_particle = np.outer(self.particles.refractive_index, self.omega)
    else:
        table = self.__interpolate_refractive_index_from_table()
        self.k_particle = (
            np.take(table, self.particles.refractive_index, axis=0)
            * self.omega[np.newaxis, :]
        )

        unique_radius_index_pairs = np.zeros(
            (
                self.particles.unique_radius_index_pairs.shape[0],
                self.wavelength.size + 1,
            ),
            dtype=complex,
        )
        unique_radius_index_pairs[:, 0] = self.particles.unique_radius_index_pairs[
            :, 0
        ]
        unique_radius_index_pairs[:, 1:] = np.take(
            table,
            self.particles.unique_radius_index_pairs[:, 1].astype(int),
            axis=0,
        )

        self.particles.unique_radius_index_pairs = unique_radius_index_pairs

Comments