Skip to content

class_sphere.py

Contains a class with strategy to trim a grid based on sphere.

StrategySphereTrimming

Bases: StrategyTrimming

A class to define strategies to trim a grid based on sphere.

Inheritance

This class is the child of StrategyTrimming. Check this one for other
attributes and methods definitions.

Source code in src/smiffer/grid/trimming_strategy/class_sphere.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
44
class StrategySphereTrimming(StrategyTrimming):
    """A class to define strategies to trim a grid based on sphere.

    Inheritance
    -----------
    This class is the child of `StrategyTrimming`. Check this one for other
    **attributes** and **methods** definitions.
    """

    def trim_box(self, grid_object):
        """Trim a grid mask based on sphere trimming method.

        Parameters
        ----------
        grid_object : `Grid`
            The grid object to access all attributes.
        """
        cog: np.ndarray = np.array(
            [
                grid_object.yaml["box_center_x"],
                grid_object.yaml["box_center_y"],
                grid_object.yaml["box_center_z"],
            ]
        )

        distance = np.linalg.norm(grid_object.trimming_coord - cog, axis=-1).T

        grid_object.mask[distance > grid_object.yaml["box_radius"]] = True

trim_box(grid_object)

Trim a grid mask based on sphere trimming method.

Parameters

grid_object : Grid
The grid object to access all attributes.

Source code in src/smiffer/grid/trimming_strategy/class_sphere.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def trim_box(self, grid_object):
    """Trim a grid mask based on sphere trimming method.

    Parameters
    ----------
    grid_object : `Grid`
        The grid object to access all attributes.
    """
    cog: np.ndarray = np.array(
        [
            grid_object.yaml["box_center_x"],
            grid_object.yaml["box_center_y"],
            grid_object.yaml["box_center_z"],
        ]
    )

    distance = np.linalg.norm(grid_object.trimming_coord - cog, axis=-1).T

    grid_object.mask[distance > grid_object.yaml["box_radius"]] = True