Skip to content

Particles

Particles

The Particles class represents a collection of particles with various properties such as position, radius, and refractive index, and provides methods for computing unique properties and characteristics of the particles.

Initializes an object with position, radius, refractive index, refractive index table, and shape type attributes.

Parameters:

Name Type Description Default
position array

A numpy array representing the position of the shape.

required
r array

A numpy array containing the radius values for each shape in the system.

required
refractive_index array

A numpy array representing the refractive index of the shape. It can be either a complex number or a two-column matrix.

required
refractive_index_table list

A list containing the refractive index values for different materials. Each element in the list represents a material, and the refractive index values for that material are stored as a complex number.

None
shape_type str

A string specifying the type of shape for the object. Defaults to "sphere" or any other supported shape type.

'sphere'
Source code in yasfpy/particles.py
16
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def __init__(
    self,
    position: np.array,
    r: np.array,
    refractive_index: np.array,
    refractive_index_table: list = None,
    shape_type: str = "sphere",
):
    """Initializes an object with position, radius, refractive index, refractive index table, and shape type attributes.

    Args:
        position (np.array): A numpy array representing the position of the shape.
        r (np.array): A numpy array containing the radius values for each shape in the system.
        refractive_index (np.array): A numpy array representing the refractive index of the shape.
            It can be either a complex number or a two-column matrix.
        refractive_index_table (list): A list containing the refractive index values for different materials.
            Each element in the list represents a material, and the refractive index values for that material are stored as a complex number.
        shape_type (str, optional): A string specifying the type of shape for the object.
            Defaults to "sphere" or any other supported shape type.

    """
    self.position = position
    self.r = r
    self.refractive_index = refractive_index
    self.type = shape_type

    self.log = log.scattering_logger(__name__)

    # TODO: Keep it for now, remove later...
    self.refractive_index_table = refractive_index_table

    if refractive_index_table is None:
        if self.refractive_index.shape[1] == 2:
            self.refractive_index = (
                self.refractive_index[:, 0] + 1j * self.refractive_index[:, 1]
            )
    elif self.refractive_index.shape[1] > 2:
        self.log.error(
            "Refractive index should be either complex or a two column matrix!"
        )
    else:
        self.refractive_index = refractive_index.astype(int)
        self.refractive_index_table = refractive_index_table

    self.number = r.shape[0]
    self.__setup_impl()

position = position instance-attribute

r = r instance-attribute

refractive_index = refractive_index instance-attribute

type = shape_type instance-attribute

log = log.scattering_logger(__name__) instance-attribute

refractive_index_table = refractive_index_table instance-attribute

number = r.shape[0] instance-attribute

generate_refractive_index_table staticmethod

The function generate_refractive_index_table takes a list of URLs, retrieves data from each URL using the material_handler function, and returns a list of the retrieved data.

Parameters:

Name Type Description Default
urls list

A list of URLs representing different materials.

required

Returns:

Name Type Description
data list

A list of data. Each element in the list corresponds to a URL in the input list, and the data is obtained by calling the material_handler function on each URL.

Source code in yasfpy/particles.py
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
@staticmethod
def generate_refractive_index_table(urls: list):
    """The function `generate_refractive_index_table` takes a list of URLs, retrieves data from each
    URL using the `material_handler` function, and returns a list of the retrieved data.

    Args:
        urls (list): A list of URLs representing different materials.

    Returns:
        data (list): A list of data. Each element in the list corresponds to a URL in the input list,
            and the data is obtained by calling the `material_handler` function on each URL.

    """
    data = [None] * len(urls)
    for k, url in enumerate(urls):
        data[k] = material_handler(url)

    return data

compute_unique_refractive_indices

Computes the unique refractive indices and their indices.

Source code in yasfpy/particles.py
82
83
84
85
86
87
def compute_unique_refractive_indices(self):
    """Computes the unique refractive indices and their indices."""
    self.unique_refractive_indices, self.refractive_index_array_idx = np.unique(
        self.refractive_index, return_inverse=True, axis=0
    )
    self.num_unique_refractive_indices = self.unique_refractive_indices.shape[0]

compute_unique_radii

The function computes the unique radii from an array and stores them in a variable.

Source code in yasfpy/particles.py
89
90
91
92
93
94
def compute_unique_radii(self):
    """The function computes the unique radii from an array and stores them in a variable."""
    self.unqiue_radii, self.radius_array_idx = np.unique(
        self.r, return_inverse=True, axis=0
    )
    self.num_unique_radii = self.unqiue_radii.shape[0]

compute_unique_radii_index_pairs

The function computes unique pairs of radii and refractive indices and stores them in different arrays.

Source code in yasfpy/particles.py
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
def compute_unique_radii_index_pairs(self):
    """The function computes unique pairs of radii and refractive indices and stores them in different
    arrays.

    """
    self.unique_radius_index_pairs, self.single_unique_array_idx = np.unique(
        np.column_stack((self.r, self.refractive_index)),
        return_inverse=True,
        axis=0,
    )
    self.unique_single_radius_index_pairs = np.unique(
        np.column_stack((self.radius_array_idx, self.refractive_index_array_idx)),
        axis=0,
    )

compute_single_unique_idx

The function computes a single unique index based on the sum of pairs of values and their corresponding indices.

Source code in yasfpy/particles.py
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
def compute_single_unique_idx(self):
    """The function computes a single unique index based on the sum of pairs of values and their
    corresponding indices.

    """
    self.single_unique_idx = (
        np.sum(self.unique_single_radius_index_pairs, axis=1)
        * (np.sum(self.unique_single_radius_index_pairs, axis=1) + 1)
    ) // 2 + self.unique_single_radius_index_pairs[:, 1]

    # pairedArray = (
    #   self.radius_array_idx + self.refractive_index_array_idx *
    #   (self.radius_array_idx + self.refractive_index_array_idx + 1)
    # ) // 2 + self.refractive_index_array_idx

    # self.single_unique_idx, self.single_unique_array_idx = np.unique(
    #   pairedArray,
    #   return_inverse=True,
    #   axis=0)

    self.num_unique_pairs = self.unique_radius_index_pairs.shape[0]

compute_maximal_particle_distance

The function computes the maximum distance between particles using the ConvexHull algorithm.

Source code in yasfpy/particles.py
133
134
135
136
137
def compute_maximal_particle_distance(self):
    """The function computes the maximum distance between particles using the ConvexHull algorithm."""
    hull = ConvexHull(self.position)
    vert = self.position[hull.vertices, :]
    self.max_particle_distance = max(pdist(vert))

compute_volume_equivalent_area

The function computes the volume equivalent area by calculating the geometric projection.

Source code in yasfpy/particles.py
139
140
141
142
def compute_volume_equivalent_area(self):
    """The function computes the volume equivalent area by calculating the geometric projection."""
    r3 = np.power(self.r, 3)
    self.geometric_projection = np.pi * np.power(np.sum(r3), 2 / 3)

__setup_impl

The function sets up various computations related to refractive indices, radii, and particle distances.

Source code in yasfpy/particles.py
144
145
146
147
148
149
150
151
152
153
154
def __setup_impl(self):
    """The function sets up various computations related to refractive indices, radii, and particle
    distances.

    """
    self.compute_unique_refractive_indices()
    self.compute_unique_radii()
    self.compute_unique_radii_index_pairs()
    self.compute_single_unique_idx()
    self.compute_maximal_particle_distance()
    self.compute_volume_equivalent_area()

Comments