generate_persons(population, num_persons=None)
Generate individual person objects based on the given population data.
This function generates a number of Person instances based on the demographic distribution provided in the population data. It uses the age, household type, and sex categories to proportionally create individuals that reflect the overall population structure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
population |
Population
|
An instance of the Population class that contains demographic data. |
required |
num_persons |
int
|
The number of persons to generate. If not specified, the function uses the total population size provided in the population data. |
None
|
Returns:
Type | Description |
---|---|
None |
The function performs the following steps: 1. If num_persons is specified, it uses that number; otherwise, it defaults to the total population size. 2. It clears any existing Person instances to start fresh. 3. It calculates the proportional distribution of individuals across different categories of age, household type, and sex based on the provided population data. 4. It iterates through the categories, creating the appropriate number of Person instances for each category, and assigns them to the respective age, household type, and sex.
Example usage
population_data = Population(year=2023, area="Haga") generate_persons(population_data)
Source code in tripsender\synthpop.py
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 |
|
synthesise_population(population, age_split=45, min_age_of_parent=25)
Synthesise a population by creating households and assigning attributes to individuals and households.
This function creates and assigns households, assigns children to households, and sets various attributes such as house type and car ownership for the generated population. The process involves multiple steps to ensure that the synthesized population accurately reflects real-world demographic patterns and household structures.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
population |
Population
|
An instance of the Population class containing demographic data. |
required |
age_split |
int
|
The age threshold used to categorize children into different age groups. Defaults to 45. |
45
|
min_age_of_parent |
int
|
The minimum age for an individual to be considered a parent. Defaults to 25. |
25
|
Returns:
Type | Description |
---|---|
None |
The function performs the following steps: 1. Retrieves the total number of households for the specified year and area. 2. Clears any existing Household instances to start fresh. 3. Splits individuals into different lists based on their household type categories (e.g., children, single parents, living alone, married, cohabiting, others). 4. Sorts the lists to prioritize older individuals for certain categories. 5. Creates households for individuals living alone and single parents. 6. Creates households for married and cohabiting couples. 7. Assigns remaining individuals to 'Other' category households. 8. Assigns children to appropriate households based on their age and household type. 9. Assigns house types to households based on the specified year and area. 10. Assigns car ownership to households using a pre-trained classifier model. 11. Assigns primary status (e.g., studying, working, inactive) to individuals using a pre-trained classifier model.
Example usage
population_data = Population(year=2023, area="Haga") synthesise_population(population_data)
Source code in tripsender\synthpop.py
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 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 |
|