- 简体中文: 此页面未翻译为简体中文。
cellularautomata module¶
The cellularautomata module implements a cellularautomata model for analyzing the distribution of population and other resources within a study area based on grid data.
get_neighbors(row_now, col_now, data_list, direction_num=4)
¶
Get neighboring valid coordinates given a row and column index in a 2D data list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
row_now
|
int
|
The current row index. |
required |
col_now
|
int
|
The current column index. |
required |
data_list
|
list
|
A 2D array representing the data converted from raster data. |
required |
direction_num
|
int
|
The number of migration directions (default: 4). Only two values, 4 and 8, are allowed; if any other value is entered, it is recognized as the default 4 direction. |
4
|
Returns:
Name | Type | Description |
---|---|---|
list |
A list of neighboring valid coordinates. |
Source code in geoca/cellularautomata.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
migrate_population_disperse(data_list, population, direction_num=4, proportion=[0.5, 0.25, 0.15, 0.05])
¶
The population is dispersed and migrates to the neighborhood based on the raster pixel values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_list
|
list
|
A 2D array converted from a raster of environmental data. |
required |
population
|
list
|
A 2D array converted from the initial population count of each pixel. |
required |
direction_num
|
int
|
The number of migration directions (default: 4). Only two values, 4 and 8, are allowed; if any other value is entered, it is recognized as the default 4 direction. |
4
|
proportion
|
list
|
A list of the proportion of the population that migrated to each neighboring pixel, ordered from highest to lowest suitability for migration. The proportion ranges from 0 to 1, with a proportion of 1 for complete migration and 0.5 for 50 percent migration. |
[0.5, 0.25, 0.15, 0.05]
|
Returns:
Name | Type | Description |
---|---|---|
list |
A 2D list representing the new population distribution after migration. |
Source code in geoca/cellularautomata.py
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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
|
migrate_population_focus(data_list, population, direction_num=4, proportion=1)
¶
The population is focused towards the most suitable nearby migration areas based on the raster pixel values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_list
|
list
|
A 2D array converted from a raster of environmental data. |
required |
population
|
list
|
A 2D array converted from the initial population count of each pixel. |
required |
direction_num
|
int
|
The number of migration directions (default: 4). Only two values, 4 and 8, are allowed; if any other value is entered, it is recognized as the default 4 direction. |
4
|
proportion
|
float
|
The proportion of population to migrate (default: 1). The proportion ranges from 0 to 1, with a proportion of 1 for complete migration and 0.5 for 50 percent migration. |
1
|
Returns:
Name | Type | Description |
---|---|---|
list |
A 2D list representing the new population distribution after migration. |
Source code in geoca/cellularautomata.py
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 |
|
migrate_time(data_list, cost_list)
¶
Calculate the migration time based on the cost path raster and the environment raster.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_list
|
list
|
A 2D array converted from a raster of environmental data. |
required |
cost_list
|
list
|
A 2D array converted from the cost path raster. |
required |
Returns:
Name | Type | Description |
---|---|---|
tuple |
A tuple containing the cumulative migration time, the number of iterations, and a list of environment raster values corresponding to the cost path raster. |
Source code in geoca/cellularautomata.py
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 |
|
run_iterations_num(iterations, data_list, population_num=10, direction_num=4, type_migration='focus', migration_proportion=1)
¶
Running a cellular automata using a uniform initial population count to simulate population migration based on a raster of environmental data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterations
|
int
|
The number of iterations to run the simulation. |
required |
data_list
|
list
|
A 2D array converted from a raster of environmental data. |
required |
population_num
|
int
|
The initial population count at each pixel (default: 10). |
10
|
direction_num
|
int
|
The number of migration directions (default: 4). Only two values, 4 and 8, are allowed; if any other value is entered, it is recognized as the default 4 direction. |
4
|
type_migration
|
str
|
The type of migration to use, either "focus" or "disperse" (default: "focus"). |
'focus'
|
migration_proportion
|
float or list
|
The proportion of population to migrate (default: 1). The proportion ranges from 0 to 1, with a proportion of 1 for complete migration and 0.5 for 50 percent migration. |
1
|
Returns:
Name | Type | Description |
---|---|---|
list |
A 2D list representing the population distribution after running the simulation. |
Source code in geoca/cellularautomata.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
|
run_iterations_pop(iterations, data_list, population_list, direction_num=4, type_migration='focus', migration_proportion=1)
¶
Running a cellular automata using an initial population size raster to simulate population migration based on a raster of environmental data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterations
|
int
|
The number of iterations to run the simulation. |
required |
data_list
|
list
|
A 2D array converted from a raster of environmental data. |
required |
population_list
|
list
|
A 2D array converted from an initial population size raster. |
required |
direction_num
|
int
|
The number of migration directions (default: 4). Only two values, 4 and 8, are allowed; if any other value is entered, it is recognized as the default 4 direction. |
4
|
type_migration
|
str
|
The type of migration to use, either "focus" or "disperse" (default: "focus"). |
'focus'
|
migration_proportion
|
float or list
|
The proportion of population to migrate (default: 1). The proportion ranges from 0 to 1, with a proportion of 1 for complete migration and 0.5 for 50 percent migration. |
1
|
Returns:
Name | Type | Description |
---|---|---|
list |
A 2D list representing the population distribution after running the simulation. |
Source code in geoca/cellularautomata.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
|