Newer
Older
import pytest
import json
import numpy as np
def test_cell():
"""Test `dycpm.Cell`"""
side = 100
volume = round(np.mean(dycpm.DIVISION_VOLUME_DISTRIBUTION) / 2)
partition = round(np.cbrt(volume));
margin = round(np.floor((side - partition) / 2));
cell = dycpm.Cell(
type_id=dycpm.EPI, parent_id=0, age=0, preferred_volume=volume,
division_volume=dycpm.sample_division_volume(),
voxel_ids=[round(
margin + (n - 1) % partition**2 % partition
+ side * (margin + (n - 1) % partition**2 // partition)
+ side**2 * (margin + (n - 1) // partition**2)
) for n in range(volume)]
)
assert 475144 in cell.voxel_ids
assert cell.type_id == dycpm.EPI
assert cell.type_id != dycpm.PRE
cell.type_id = dycpm.PRE
assert cell.type_id == dycpm.PRE
def test_state(tmp_path):
"""Test JSON-format export and import of a state"""
state = dycpm.State(
side=10, action_probabilities=3 * [0.3],
growth_rate=2 * [1.6], volume_elasticity=2 * [1],
active_exponents = [0.1, -1.2, 2.3, -3.4, 0.5, -0.6, 7.7],
surface_tension=5 * [10], cells={
1: {
'type_id': dycpm.EPI, 'parent_id': 0, 'age': 0,
'preferred_volume': 1,
'division_volume': 1,
"voxel_ids": [1]
}
}
)
assert state.side == 10
assert state.active_exponents == [0.1, -1.2, 2.3, -3.4, 0.5, -0.6, 7.7]
state.to_json_file(path)
assert isinstance(state.cells[1], dycpm.Cell)
state = dycpm.State.from_json_file(path)
assert state.side == 10
assert state.surface_tension[0] == 10
state.surface_tension = [20, 5, 10, 15, 10]
assert state.surface_tension[0] == 20
state.surface_tension[0] = 25
assert state.surface_tension[0] == 25
assert state.cells[1].type_id == dycpm.EPI
assert state.cells[1].type_id != dycpm.PRE
state.cells[1].type_id = dycpm.PRE
assert state.cells[1].type_id != dycpm.EPI
assert state.cells[1].type_id == dycpm.PRE
assert state.active_exponents == [0.1, -1.2, 2.3, -3.4, 0.5, -0.6, 7.7]
def test_simulation():
"""Test simulation flow"""
side = 100
volume = round(np.mean(dycpm.DIVISION_VOLUME_DISTRIBUTION) / 2)
partition = round(np.cbrt(volume));
margin = round(np.floor((side - partition) / 2));
state = dycpm.State(
time=0, side=side, action_probabilities=3 * [0.3], death_probability=1e-4,
growth_rate=2 * [1.6], volume_elasticity=2 * [1], surface_tension=5 * [10],
division_distribution=dycpm.DIVISION_VOLUME_DISTRIBUTION,
cells={
1: {
'type_id': 1, 'parent_id': 0, 'age': 0,
'preferred_volume': volume,
'division_volume': dycpm.sample_division_volume(),
"voxel_ids": [round(
margin + (n - 1) % partition**2 % partition
+ side * (margin + (n - 1) % partition**2 // partition)
+ side**2 * (margin + (n - 1) // partition**2)
) for n in range(volume)]
}
}
)
assert 1 in state.cells
kernel = dycpm.Kernel(state)
assert kernel.cell_number == 1
for _ in range(2): kernel.advance()
state = kernel.state
assert state.time == 2
assert state.side == 100
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
def test_lattice():
"""Test `State.lattice()"""
side = 100
volume = round(np.mean(dycpm.DIVISION_VOLUME_DISTRIBUTION) / 2)
partition = round(np.cbrt(volume));
margin = round(np.floor((side - partition) / 2));
state = dycpm.State(
time=0, side=side, action_probabilities=3 * [0.3], death_probability=1e-4,
growth_rate=2 * [1.6], volume_elasticity=2 * [1], surface_tension=5 * [10],
division_distribution=dycpm.DIVISION_VOLUME_DISTRIBUTION,
cells={
1: {
'type_id': 1, 'parent_id': 0, 'age': 0,
'preferred_volume': volume,
'division_volume': dycpm.sample_division_volume(),
"voxel_ids": [round(
margin + (n - 1) % partition**2 % partition
+ side * (margin + (n - 1) % partition**2 // partition)
+ side**2 * (margin + (n - 1) // partition**2)
) for n in range(volume)]
}
}
)
lattice = state.lattice()
assert lattice.shape == (side, ) * 3
assert lattice[49, 49, 49] == 1
assert lattice[0, 0, 0] == 0
assert np.count_nonzero(lattice.ravel() == 1) == volume
def test_analysis_neighborIndex():
""" Test `dycpm.analysis.neighbor_index()`"""
state = dycpm.State(
time=0, side=10, action_probabilities=3 * [0.3], death_probability=1e-4,
growth_rate=2 * [1.6], volume_elasticity=2 * [1], surface_tension=5 * [10],
division_distribution=dycpm.DIVISION_VOLUME_DISTRIBUTION,
cells={
1: {
'type_id': 1, 'parent_id': 0, 'age': 0,
'preferred_volume': 1,
'division_volume': dycpm.sample_division_volume(),
"voxel_ids": [4 * 10**2 + 4 * 10 + 4]
},
2: {
'type_id': 1, 'parent_id': 0, 'age': 0,
'preferred_volume': 1,
'division_volume': dycpm.sample_division_volume(),
"voxel_ids": [4 * 10**2 + 4 * 10 + 5]
},
3: {
'type_id': 2, 'parent_id': 0, 'age': 0,
'preferred_volume': 1,
'division_volume': dycpm.sample_division_volume(),
"voxel_ids": [4 * 10**2 + 5 * 10 + 4]
}
}
)
assert dycpm.analysis.neighbor_index(state, [1], [2]) == 0.5
assert dycpm.analysis.neighbor_index(state, [1], [0, 2]) == 2 / 3
assert dycpm.analysis.neighbor_index(state, [2], [1]) == 1
assert dycpm.analysis.neighbor_index(state, [2], [0, 1]) == 1
""" Test `dycpm.analysis`"""
state = dycpm.State(
time=0, side=10, action_probabilities=3 * [0.3], death_probability=1e-4,
growth_rate=2 * [1.6], volume_elasticity=2 * [1], surface_tension=5 * [10],
division_distribution=dycpm.DIVISION_VOLUME_DISTRIBUTION,
cells={
1: {
'type_id': 1, 'parent_id': 0, 'age': 0,
'preferred_volume': 1,
'division_volume': dycpm.sample_division_volume(),
"voxel_ids": [4 * 10**2 + 4 * 10 + 4]
},
2: {
'type_id': 1, 'parent_id': 0, 'age': 0,
'preferred_volume': 1,
'division_volume': dycpm.sample_division_volume(),
"voxel_ids": [4 * 10**2 + 4 * 10 + 5]
},
3: {
'type_id': 2, 'parent_id': 0, 'age': 0,
'preferred_volume': 1,
'division_volume': dycpm.sample_division_volume(),
"voxel_ids": [4 * 10**2 + 5 * 10 + 4]
},
4: {
'type_id': 2, 'parent_id': 0, 'age': 0,
'preferred_volume': 1,
'division_volume': dycpm.sample_division_volume(),
"voxel_ids": [0 * 10**2 + 0 * 10 + 0]
},
5: {
'type_id': 2, 'parent_id': 0, 'age': 0,
'preferred_volume': 1,
'division_volume': dycpm.sample_division_volume(),
"voxel_ids": [1 * 10**2 + 0 * 10 + 0]
}
}
)
assert dycpm.analysis.neighbor_index(state, [1], [2]) == 0.5
assert dycpm.analysis.neighbor_index(state, [1], [0, 2]) == 2 / 3
assert dycpm.analysis.neighbor_index(state, [2], [1]) == 1 / 3
assert dycpm.analysis.neighbor_index(state, [2], [0, 1]) == 2 / 3