Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
8 views
1 page
Choropleth Mapping Population Density With Log and Exp - Py
Uploaded by
dwynemarquita2020
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF, TXT or read online on Scribd
Download
Save
Save Choropleth_mapping_population_density_with_log_and... For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
8 views
1 page
Choropleth Mapping Population Density With Log and Exp - Py
Uploaded by
dwynemarquita2020
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF, TXT or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save Choropleth_mapping_population_density_with_log_and... For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save Choropleth_mapping_population_density_with_log_and... For Later
You are on page 1
/ 1
Search
Fullscreen
1 import numpy as np
2 import matplotlib.pyplot as plt
3 import geopandas as gpd
4 import pandas as pd
5 import os
6
7 # Parameters for the growth models
8 number_of_deaths = 3683
9 total_population = sum([25228, 11274, 25964, 12323, 97879, 32174, 23367, 60607, 11844, 36621, 29390, 14690, 14234,
10 41415, 34034, 35532, 10949, 8882, 27867, 17641, 29882, 6928, 15100, 15361]) # Total population
11 death_rate = (number_of_deaths / total_population) * 1000 # Death rate per 1,000 people
12 d = death_rate / 1000 # Convert death rate back to a proportion
13
14 # Municipalities data
15 merged_data = [
16 {'Municipality': 'Allen', 'Population (2020)': 25228, 'Annual Growth Rate': -0.002, 'Area': 47.60},
17 {'Municipality': 'Biri', 'Population (2020)': 11274, 'Annual Growth Rate': -0.009, 'Area': 24.62},
18 {'Municipality': 'Bobon', 'Population (2020)': 25964, 'Annual Growth Rate': 0.0197, 'Area': 130.00},
19 {'Municipality': 'Capul', 'Population (2020)': 12323, 'Annual Growth Rate': -0.006, 'Area': 35.56},
20 {'Municipality': 'Catarman', 'Population (2020)': 97879, 'Annual Growth Rate': 0.0085, 'Area': 464.43},
21 {'Municipality': 'Catubig', 'Population (2020)': 32174, 'Annual Growth Rate': -0.0055, 'Area': 217.02},
22 {'Municipality': 'Gamay', 'Population (2020)': 23367, 'Annual Growth Rate': -0.0013, 'Area': 115.10},
23 {'Municipality': 'Laoang', 'Population (2020)': 60607, 'Annual Growth Rate': -0.0026, 'Area': 246.94},
24 {'Municipality': 'Lapinig', 'Population (2020)': 11844, 'Annual Growth Rate': -0.0197, 'Area': 57.30},
25 {'Municipality': 'Las Navas', 'Population (2020)': 36621, 'Annual Growth Rate': -0.0075, 'Area': 282.61},
26 {'Municipality': 'Lavezares', 'Population (2020)': 29390, 'Annual Growth Rate': 0.0045, 'Area': 119.50},
27 {'Municipality': 'Lope de Vega', 'Population (2020)': 14690, 'Annual Growth Rate': 0.0, 'Area': 280.00},
28 {'Municipality': 'Mapanas', 'Population (2020)': 14234, 'Annual Growth Rate': 0.0031, 'Area': 117.85},
29 {'Municipality': 'Mondragon', 'Population (2020)': 41415, 'Annual Growth Rate': 0.0142, 'Area': 288.90},
30 {'Municipality': 'Palapag', 'Population (2020)': 34034, 'Annual Growth Rate': -0.0016, 'Area': 179.60},
31 {'Municipality': 'Pambujan', 'Population (2020)': 35532, 'Annual Growth Rate': 0.0153, 'Area': 163.90},
32 {'Municipality': 'Rosario', 'Population (2020)': 10949, 'Annual Growth Rate': 0.0085, 'Area': 31.60},
33 {'Municipality': 'San Antonio', 'Population (2020)': 8882, 'Annual Growth Rate': -0.0041, 'Area': 27.00},
34 {'Municipality': 'San Isidro', 'Population (2020)': 27867, 'Annual Growth Rate': 0.0094, 'Area': 255.90},
35 {'Municipality': 'San Jose', 'Population (2020)': 17641, 'Annual Growth Rate': 0.001, 'Area': 29.85},
36 {'Municipality': 'San Roque', 'Population (2020)': 29882, 'Annual Growth Rate': -0.0048, 'Area': 152.98},
37 {'Municipality': 'San Vicente', 'Population (2020)': 6928, 'Annual Growth Rate': -0.0261, 'Area': 15.80},
38 {'Municipality': 'Silvino Lobos', 'Population (2020)': 15100, 'Annual Growth Rate': -0.0028, 'Area': 224.20},
39 {'Municipality': 'Victoria', 'Population (2020)': 15361, 'Annual Growth Rate': 0.0076, 'Area': 186.70}
40 ]
41
42 df = pd.DataFrame(merged_data)
43
44 # Load shapefile
45 gdf = gpd.read_file('C:/Users/DWYNE S MARQUITA/OneDrive/Desktop/Graphing and Stuff/choropleth/gadm41_PHL_shp/gadm41_PHL_2.shp')
46
47 # Merge the geodataframe with the DataFrame
48 merged_gdf = gdf.merge(df, left_on='NAME_2', right_on='Municipality')
49
50 # Functions for logistic and exponential growth models
51 def exponential_growth(P0, r, t):
52 return P0 * np.exp(r * (t - 2020))
53
54 def logistic_growth(P0, r, K, t):
55 return K / (1 + (K / P0 - 1) * np.exp(-r * (t - 2020)))
56
57 # Create output directories for logistic and exponential growth
58 output_dir_logistic = 'C:/Users/DWYNE S MARQUITA/OneDrive/Desktop/Graphing and Stuff/choropleth/Logistic_Growth'
59 output_dir_exponential = 'C:/Users/DWYNE S MARQUITA/OneDrive/Desktop/Graphing and Stuff/choropleth/Exponential_Growth'
60 os.makedirs(output_dir_logistic, exist_ok=True)
61 os.makedirs(output_dir_exponential, exist_ok=True)
62
63 # Time steps from 2020 to 2120 (100 years)
64 years = np.linspace(2020, 2050, 31)
65
66 # Generate maps for each year using both growth models
67 for year in range(0, 31):
68 current_year = 2020 + year
69
70 # Calculate the carrying capacity for each municipality using logistic growth
71 merged_gdf['Carrying Capacity'] = (merged_gdf['Annual Growth Rate'] * merged_gdf['Population (2020)']) / d
72
73 # Calculate exponential and logistic population projections
74 merged_gdf['Exponential Population'] = merged_gdf.apply(
75 lambda row: exponential_growth(row['Population (2020)'], row['Annual Growth Rate'], current_year), axis=1)
76
77 merged_gdf['Logistic Population'] = merged_gdf.apply(
78 lambda row: logistic_growth(row['Population (2020)'], row['Annual Growth Rate'], row['Carrying Capacity'], current_year), axis=1)
79
80 # Calculate population density
81 merged_gdf['Exponential Population Density'] = merged_gdf['Exponential Population'] / merged_gdf['Area']
82 merged_gdf['Logistic Population Density'] = merged_gdf['Logistic Population'] / merged_gdf['Area']
83
84 # Cap the population density at 500 for visualization purposes
85 merged_gdf['Exponential Population Density'] = merged_gdf['Exponential Population Density'].clip(upper=500)
86 merged_gdf['Logistic Population Density'] = merged_gdf['Logistic Population Density'].clip(upper=500)
87
88 # Plot and save maps for exponential growth model
89 fig, ax = plt.subplots(1, 1, figsize=(10, 6))
90 ax.set_xlim([124, 125.5])
91 ax.set_ylim([12.2, 12.8])
92 merged_gdf.plot(column='Exponential Population Density', cmap='OrRd', legend=True, ax=ax,
93 legend_kwds={'label': "Population Density", 'orientation': "horizontal", 'shrink': 0.8},
94 vmin=0, vmax=500) # Set vmin and vmax for consistent legend
95 plt.title(f'Exponential Population Density for {current_year}', fontsize=14)
96
97 # Annotate the provinces with their names
98 for x, y, label in zip(merged_gdf.geometry.centroid.x, merged_gdf.geometry.centroid.y, merged_gdf['Municipality']):
99 ax.annotate(label, xy=(x, y), horizontalalignment='center', fontsize=8, color='black')
100
101 output_filename_exp = f'{output_dir_exponential}/exp_population_density_{current_year}.png'
102 plt.savefig(output_filename_exp)
103 plt.close()
104
105 # Plot and save maps for logistic growth model
106 fig, ax = plt.subplots(1, 1, figsize=(10, 6))
107 ax.set_xlim([124, 125.5])
108 ax.set_ylim([12.2, 12.8])
109 merged_gdf.plot(column='Logistic Population Density', cmap='Blues', legend=True, ax=ax,
110 legend_kwds={'label': "Population Density", 'orientation': "horizontal", 'shrink': 0.8},
111 vmin=0, vmax=500) # Set vmin and vmax for consistent legend
112 plt.title(f'Logistic Population Density for {current_year}', fontsize=14)
113
114 # Annotate the provinces with their names
115 for x, y, label in zip(merged_gdf.geometry.centroid.x, merged_gdf.geometry.centroid.y, merged_gdf['Municipality']):
116 ax.annotate(label, xy=(x, y), horizontalalignment='center', fontsize=8, color='black')
117
118 output_filename_log = f'{output_dir_logistic}/log_population_density_{current_year}.png'
119 plt.savefig(output_filename_log)
120 plt.close()
121
You might also like
Data Exploration and Visualization Laboratory - AD3301 - Lab Manual
PDF
No ratings yet
Data Exploration and Visualization Laboratory - AD3301 - Lab Manual
55 pages
Geopandas 50 Exercises
PDF
No ratings yet
Geopandas 50 Exercises
2 pages
Merged
PDF
No ratings yet
Merged
35 pages
Python
PDF
No ratings yet
Python
16 pages
CovidData - Ipynb - Colaboratory
PDF
No ratings yet
CovidData - Ipynb - Colaboratory
4 pages
Project 04 - Data Analysis of Covid-19.ipynb
PDF
No ratings yet
Project 04 - Data Analysis of Covid-19.ipynb
73 pages
Terror Casualty Attack
PDF
No ratings yet
Terror Casualty Attack
6 pages
Data Analysis Project
PDF
No ratings yet
Data Analysis Project
50 pages
Using Python For Data Analysis - July 2018 - Slides
PDF
No ratings yet
Using Python For Data Analysis - July 2018 - Slides
43 pages
Dav Practicals
PDF
No ratings yet
Dav Practicals
33 pages
5-4 Exponential Growth and Decay (Presentation)
PDF
100% (2)
5-4 Exponential Growth and Decay (Presentation)
16 pages
Tercera Evaluacion - Computacion Blanda
PDF
No ratings yet
Tercera Evaluacion - Computacion Blanda
22 pages
Intreoduction To Python Basic Plots With Matplolib
PDF
No ratings yet
Intreoduction To Python Basic Plots With Matplolib
37 pages
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology
PDF
No ratings yet
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology
12 pages
Pandas - Ipynb - Colaboratory
PDF
No ratings yet
Pandas - Ipynb - Colaboratory
36 pages
Time Series Analysis Group 9
PDF
No ratings yet
Time Series Analysis Group 9
16 pages
Eda 21524785
PDF
No ratings yet
Eda 21524785
32 pages
Plotting Directly With Matplotlib: Objectives
PDF
No ratings yet
Plotting Directly With Matplotlib: Objectives
28 pages
Paddy Diesease
PDF
No ratings yet
Paddy Diesease
20 pages
Machine Learning Lab
PDF
No ratings yet
Machine Learning Lab
43 pages
Ex-13 Data Science
PDF
No ratings yet
Ex-13 Data Science
11 pages
Chloropleth Population Growth - Py
PDF
No ratings yet
Chloropleth Population Growth - Py
1 page
My P Report
PDF
No ratings yet
My P Report
14 pages
Crop Yield Prediction
PDF
No ratings yet
Crop Yield Prediction
11 pages
Codigo Phyton
PDF
No ratings yet
Codigo Phyton
8 pages
Assignment - Ipynb - Colaboratory
PDF
No ratings yet
Assignment - Ipynb - Colaboratory
14 pages
Hands On Matplotlib?
PDF
No ratings yet
Hands On Matplotlib?
40 pages
Program 2 Hierarchical Cluestring
PDF
No ratings yet
Program 2 Hierarchical Cluestring
5 pages
MLRecord
PDF
No ratings yet
MLRecord
24 pages
The Script Begins by Defining The Population Growth Rate
PDF
No ratings yet
The Script Begins by Defining The Population Growth Rate
2 pages
Practical File Ip
PDF
No ratings yet
Practical File Ip
27 pages
Data Cleaning
PDF
No ratings yet
Data Cleaning
22 pages
DV0101EN-2-2-1-Area-Plots-Histograms-and-Bar-Charts-py-v2.0: 1 Exploring Datasets With Pandas and Matplotlib
PDF
No ratings yet
DV0101EN-2-2-1-Area-Plots-Histograms-and-Bar-Charts-py-v2.0: 1 Exploring Datasets With Pandas and Matplotlib
29 pages
Fds Mannual
PDF
No ratings yet
Fds Mannual
39 pages
Chirayu (1) Merged Merged
PDF
No ratings yet
Chirayu (1) Merged Merged
76 pages
Exercise Chapter 5
PDF
No ratings yet
Exercise Chapter 5
29 pages
Cambridge Methods 1/2 - Chapter 13 Exponentials and Logs
PDF
No ratings yet
Cambridge Methods 1/2 - Chapter 13 Exponentials and Logs
44 pages
Stats
PDF
No ratings yet
Stats
33 pages
Practica 9
PDF
No ratings yet
Practica 9
24 pages
FDS Lab Question Bank
PDF
No ratings yet
FDS Lab Question Bank
11 pages
Modulo 8. Data Visualization With Python
PDF
No ratings yet
Modulo 8. Data Visualization With Python
30 pages
Document
PDF
No ratings yet
Document
8 pages
Ds Pract 5 Data Analytics1 Vedanti
PDF
No ratings yet
Ds Pract 5 Data Analytics1 Vedanti
7 pages
Scenario 1:: Acknowlegement
PDF
No ratings yet
Scenario 1:: Acknowlegement
17 pages
Code
PDF
No ratings yet
Code
6 pages
AI Practical Project
PDF
No ratings yet
AI Practical Project
15 pages
Final Group Project
PDF
No ratings yet
Final Group Project
26 pages
Python-Pandas Notes
PDF
No ratings yet
Python-Pandas Notes
5 pages
Python Note 3
PDF
No ratings yet
Python Note 3
11 pages
DALab Part-B BCU&BU
PDF
No ratings yet
DALab Part-B BCU&BU
12 pages
Ashutosh Project
PDF
No ratings yet
Ashutosh Project
19 pages
Computer Science Ip
PDF
No ratings yet
Computer Science Ip
16 pages
Lab Record Dev
PDF
No ratings yet
Lab Record Dev
20 pages
Tables Z, T and Chi-Square
PDF
No ratings yet
Tables Z, T and Chi-Square
6 pages
Ip Project
PDF
No ratings yet
Ip Project
23 pages
A Beginners Guide To Geospatial Data Analysis
PDF
No ratings yet
A Beginners Guide To Geospatial Data Analysis
11 pages
Exp 2 SDK Ok
PDF
No ratings yet
Exp 2 SDK Ok
18 pages
Performance Task in General Mathematics
PDF
100% (1)
Performance Task in General Mathematics
19 pages
3rd Semester DDM AI DAA DEV Print Pages For Spiral Record 25-1-24 - Removed
PDF
No ratings yet
3rd Semester DDM AI DAA DEV Print Pages For Spiral Record 25-1-24 - Removed
28 pages
Derivative of Exponential and Logarithmic Functions: 2nd Semester, 2022-2023
PDF
No ratings yet
Derivative of Exponential and Logarithmic Functions: 2nd Semester, 2022-2023
43 pages
Final Dev Record
PDF
No ratings yet
Final Dev Record
49 pages
Data Visualization - New
PDF
No ratings yet
Data Visualization - New
5 pages
Main - Py Text File
PDF
No ratings yet
Main - Py Text File
5 pages
WEBINTEL GUIDED LAB ACTIVITY Introduction To Pandas
PDF
No ratings yet
WEBINTEL GUIDED LAB ACTIVITY Introduction To Pandas
1 page
5.1 Exponential Growth and Decay Intro
PDF
No ratings yet
5.1 Exponential Growth and Decay Intro
3 pages
Intelligent Wireless Sensor Networks For Early Fire Warning System
PDF
No ratings yet
Intelligent Wireless Sensor Networks For Early Fire Warning System
9 pages
CAIE-A2 Level-Further Mathematics - Further Pure 2
PDF
No ratings yet
CAIE-A2 Level-Further Mathematics - Further Pure 2
14 pages
Logarithm - DPP 04 (Of Lec 05) - (Arjuna JEE 2.0 2023)
PDF
No ratings yet
Logarithm - DPP 04 (Of Lec 05) - (Arjuna JEE 2.0 2023)
2 pages
Untitled
PDF
No ratings yet
Untitled
4 pages
Single Page Integral Table PDF
PDF
100% (2)
Single Page Integral Table PDF
2 pages
SSRN 4795353
PDF
No ratings yet
SSRN 4795353
27 pages
1
PDF
No ratings yet
1
14 pages
Fix Data
PDF
No ratings yet
Fix Data
148 pages
Development of Qube: A Low-Cost Internet of Things Device For On-Site and Regional Earthquake Warning
PDF
No ratings yet
Development of Qube: A Low-Cost Internet of Things Device For On-Site and Regional Earthquake Warning
11 pages
Ravitheja 2020 IOP Conf. Ser. Mater. Sci. Eng. 981 042011
PDF
No ratings yet
Ravitheja 2020 IOP Conf. Ser. Mater. Sci. Eng. 981 042011
10 pages
Wave Table
PDF
No ratings yet
Wave Table
36 pages
Integrating Earthquake Early Warning System and A Smart Robot For Post-Earthquake Automated Inspection and Emergency Response
PDF
No ratings yet
Integrating Earthquake Early Warning System and A Smart Robot For Post-Earthquake Automated Inspection and Emergency Response
20 pages
Zaman 2017
PDF
No ratings yet
Zaman 2017
6 pages
Distributed Sensor For Earthquake Identification System To Activate Tsunami Shelter Finding System
PDF
No ratings yet
Distributed Sensor For Earthquake Identification System To Activate Tsunami Shelter Finding System
6 pages
Revision Article Maharani Et Al Jeap 26 Des 2024
PDF
No ratings yet
Revision Article Maharani Et Al Jeap 26 Des 2024
13 pages
Earthquake Damage Intensity Scaling System Based On Raspberry Pi and Arduino Uno
PDF
No ratings yet
Earthquake Damage Intensity Scaling System Based On Raspberry Pi and Arduino Uno
5 pages
Logarithms by Sir Zivanai
PDF
No ratings yet
Logarithms by Sir Zivanai
15 pages
Arasetv51 N1 PP160 170
PDF
No ratings yet
Arasetv51 N1 PP160 170
11 pages
Activity 1 Advmth
PDF
No ratings yet
Activity 1 Advmth
4 pages
Distribution Tables (T, and Chi)
PDF
100% (1)
Distribution Tables (T, and Chi)
2 pages
Excel Functions English - Turkish
PDF
100% (1)
Excel Functions English - Turkish
7 pages
CI2
PDF
No ratings yet
CI2
26 pages
CI Practice Sheet Level-1
PDF
No ratings yet
CI Practice Sheet Level-1
8 pages
NCERT Solutions For Class 7 Maths Chapter 13 Exponents and Powers.
PDF
No ratings yet
NCERT Solutions For Class 7 Maths Chapter 13 Exponents and Powers.
21 pages
Trignometry & Hyperbolic قوانين ال
PDF
No ratings yet
Trignometry & Hyperbolic قوانين ال
4 pages
Konsentrasi Amonium (MG/L)
PDF
No ratings yet
Konsentrasi Amonium (MG/L)
19 pages
Z Table
PDF
No ratings yet
Z Table
2 pages
Pandas Cheat Sheet
PDF
No ratings yet
Pandas Cheat Sheet
2 pages
Derivatives of Inverse Trignometric Functions: 1 1 Proof
PDF
No ratings yet
Derivatives of Inverse Trignometric Functions: 1 1 Proof
17 pages
Problem Set 2
PDF
No ratings yet
Problem Set 2
2 pages
Z Table PDF
PDF
No ratings yet
Z Table PDF
1 page
Gaussian Identities
PDF
No ratings yet
Gaussian Identities
1 page
Error Function Table PDF
PDF
No ratings yet
Error Function Table PDF
1 page
No Ph.D. Game Design With Three.js
From Everand
No Ph.D. Game Design With Three.js
Nikiforos Kontopoulos
No ratings yet