Skip to content

DiscreteStepAnalyzer

DiscreteStepAnalyzer

Bases: StateAnalyzer

Implements simple utilities for analyzing simulation states which are specified by categorical occupancies for each site in the simulation

Source code in pylattica/discrete/discrete_step_analyzer.py
  7
  8
  9
 10
 11
 12
 13
 14
 15
 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
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
class DiscreteStepAnalyzer(StateAnalyzer):
    """Implements simple utilities for analyzing simulation states which are
    specified by categorical occupancies for each site in the simulation
    """

    def cell_fraction(self, state: SimulationState, phase_name: str) -> float:
        """Returns the fraction of sites in the provided state which are occupied
        by the specified phase.

        Parameters
        ----------
        state : SimulationState
            The state to analyze.
        phase_name : str
            The name of the phase for which a fraction of sites should be calculated

        Returns
        -------
        float
            The fraction of sites occupied by the specified phase.
        """
        phase_count = self.cell_count(state, phase_name)
        total_occupied_cells = state.size
        return phase_count / total_occupied_cells

    def cell_count(self, state: SimulationState, phase_name: str) -> int:
        """Retrieves the number of cells in the given simulation state occupied by
        the specified phase.

        Parameters
        ----------
        state : SimulationState
            The state to analyze.
        phase_name : str
            The name of the phase to count.

        Returns
        -------
        int
            The number of sites occupied by the specified phase.
        """
        return self.get_site_count_where_equal(state, {DISCRETE_OCCUPANCY: phase_name})

    def cell_ratio(self, step: SimulationState, p1: str, p2: str) -> float:
        """Returns the occupancy ratio between two phases in the provided simulation state.

        Parameters
        ----------
        step : SimulationState
            The state to analyze.
        p1 : str
            The name of the first phase.
        p2 : str
            The name of the second phase

        Returns
        -------
        float
            The ratio of the occupancies of the two phases.
        """
        return self.cell_count(step, p1) / self.cell_count(step, p2)

    def phase_count(self, step: SimulationState) -> int:
        """The number of phases present in the specified simulation state.

        Parameters
        ----------
        step : SimulationState
            The state to analyze.

        Returns
        -------
        int
            The number of phases identified.
        """
        return len(self.phases_present(step))

    def phases_present(self, state: SimulationState) -> List[str]:
        """Returns a list of the phases present in the specified state.

        Parameters
        ----------
        state : SimulationState
            The state to analyze.

        Returns
        -------
        List[str]
            A list of the phases identified.
        """
        return list(
            set(
                site_state[DISCRETE_OCCUPANCY] for site_state in state.all_site_states()
            )
        )

cell_count(state, phase_name)

Retrieves the number of cells in the given simulation state occupied by the specified phase.

Parameters
SimulationState

The state to analyze.

str

The name of the phase to count.

Returns

int The number of sites occupied by the specified phase.

Source code in pylattica/discrete/discrete_step_analyzer.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def cell_count(self, state: SimulationState, phase_name: str) -> int:
    """Retrieves the number of cells in the given simulation state occupied by
    the specified phase.

    Parameters
    ----------
    state : SimulationState
        The state to analyze.
    phase_name : str
        The name of the phase to count.

    Returns
    -------
    int
        The number of sites occupied by the specified phase.
    """
    return self.get_site_count_where_equal(state, {DISCRETE_OCCUPANCY: phase_name})

cell_fraction(state, phase_name)

Returns the fraction of sites in the provided state which are occupied by the specified phase.

Parameters
SimulationState

The state to analyze.

str

The name of the phase for which a fraction of sites should be calculated

Returns

float The fraction of sites occupied by the specified phase.

Source code in pylattica/discrete/discrete_step_analyzer.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def cell_fraction(self, state: SimulationState, phase_name: str) -> float:
    """Returns the fraction of sites in the provided state which are occupied
    by the specified phase.

    Parameters
    ----------
    state : SimulationState
        The state to analyze.
    phase_name : str
        The name of the phase for which a fraction of sites should be calculated

    Returns
    -------
    float
        The fraction of sites occupied by the specified phase.
    """
    phase_count = self.cell_count(state, phase_name)
    total_occupied_cells = state.size
    return phase_count / total_occupied_cells

cell_ratio(step, p1, p2)

Returns the occupancy ratio between two phases in the provided simulation state.

Parameters
SimulationState

The state to analyze.

str

The name of the first phase.

str

The name of the second phase

Returns

float The ratio of the occupancies of the two phases.

Source code in pylattica/discrete/discrete_step_analyzer.py
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
def cell_ratio(self, step: SimulationState, p1: str, p2: str) -> float:
    """Returns the occupancy ratio between two phases in the provided simulation state.

    Parameters
    ----------
    step : SimulationState
        The state to analyze.
    p1 : str
        The name of the first phase.
    p2 : str
        The name of the second phase

    Returns
    -------
    float
        The ratio of the occupancies of the two phases.
    """
    return self.cell_count(step, p1) / self.cell_count(step, p2)

phase_count(step)

The number of phases present in the specified simulation state.

Parameters
SimulationState

The state to analyze.

Returns

int The number of phases identified.

Source code in pylattica/discrete/discrete_step_analyzer.py
69
70
71
72
73
74
75
76
77
78
79
80
81
82
def phase_count(self, step: SimulationState) -> int:
    """The number of phases present in the specified simulation state.

    Parameters
    ----------
    step : SimulationState
        The state to analyze.

    Returns
    -------
    int
        The number of phases identified.
    """
    return len(self.phases_present(step))

phases_present(state)

Returns a list of the phases present in the specified state.

Parameters
SimulationState

The state to analyze.

Returns

List[str] A list of the phases identified.

Source code in pylattica/discrete/discrete_step_analyzer.py
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
def phases_present(self, state: SimulationState) -> List[str]:
    """Returns a list of the phases present in the specified state.

    Parameters
    ----------
    state : SimulationState
        The state to analyze.

    Returns
    -------
    List[str]
        A list of the phases identified.
    """
    return list(
        set(
            site_state[DISCRETE_OCCUPANCY] for site_state in state.all_site_states()
        )
    )