keys = list(TC.keys())
keys = np.array(keys)
for cell in np.ndenumerate(keys): # for each tumor cell
cell_id = cell[1]
division, migration, death = TC[cell_id].action(TC_pdiv, TC_pmig, TC_pdeath)
if death:
DeadCells[cell_id] = TC[cell_id] # remove tumor cell from dictionary
continue
else:
# extract cell position
x = TC[cell_id].x
y = TC[cell_id].y
z = TC[cell_id].z
# find free spots where new cell can divide or cell can migrate
ngh = TC[cell_id].freeSpots(cells, TC[cell_id].neighbors(x,y,z))
if np.size(ngh)>0:
ngh = np.reshape(ngh,[int(np.shape(ngh)[0]/3),3])
PositionOfNewCell = ngh[random.randint(0,np.size(ngh)/3-1)]
cell_id_new = int(x + (y - 1) * gridSize + (z - 1) * gridSize * gridSize)
else:
continue
if migration:
TC[cell_id_new] = TC.pop(cell_id)
continue
if division:
x = int(PositionOfNewCell[0])
y = int(PositionOfNewCell[1])
z = int(PositionOfNewCell[2])
NewCells[cell_id_new] = TumorCell(x,y,z,TC_pcap)
我稍微编辑了一下Python代码
我正在创造细胞自动机来模拟三维的肿瘤生长。每个肿瘤细胞都有其位置(细胞id)。在一次迭代中,每个肿瘤细胞可以:分裂、迁移或死亡
这是我的密码:
10^4个单元格的代码大约需要60秒
我的目标是尽可能减少时间,因为我的目标是用10^6个细胞模拟细胞自动机
事先谢谢你的帮助
相关问题 更多 >
编程相关推荐