Population density
In [1]:
Copied!
# Uncomment below to run in Google Collab
# pip install ecospat
# Uncomment below to run in Google Collab
# pip install ecospat
Calculating and visualizing population density change¶
In [2]:
Copied!
import ecospat.ecospat as ecospat_full
from ecospat.stand_alone_functions import (
process_species_historical_range,
analyze_species_distribution,
calculate_rate_of_change_first_last,
create_interactive_map,
)
import ecospat.ecospat as ecospat_full
from ecospat.stand_alone_functions import (
process_species_historical_range,
analyze_species_distribution,
calculate_rate_of_change_first_last,
create_interactive_map,
)
Classify historic and modern range edges¶
In [3]:
Copied!
classified_modern, classified_historic = analyze_species_distribution(
"Populus angustifolia", record_limit=1000, continent="north_america"
)
classified_modern.head()
classified_modern, classified_historic = analyze_species_distribution(
"Populus angustifolia", record_limit=1000, continent="north_america"
)
classified_modern.head()
Modern records (>= 1976): 1000 Historic records (< 1976): 254
Out[3]:
| point_geometry | year | eventDate | geometry | geometry_id | cluster | AREA | category | density | |
|---|---|---|---|---|---|---|---|---|---|
| 0 | POINT (-111.840163 40.880712) | 2025 | 2025-01-05 | POLYGON ((-112.16175 40.79402, -112.1358 40.81... | cb869cb2640256dc655c5ffd650a009f | 1 | 52264.281507 | core | 0.003597 |
| 1 | POINT (-111.467794 40.775008) | 2025 | 2025-02-07 | POLYGON ((-112.16175 40.79402, -112.1358 40.81... | cb869cb2640256dc655c5ffd650a009f | 1 | 52264.281507 | core | 0.003597 |
| 2 | POINT (-110.869423 39.731437) | 2025 | 2025-03-29 | POLYGON ((-112.16175 40.79402, -112.1358 40.81... | cb869cb2640256dc655c5ffd650a009f | 1 | 52264.281507 | core | 0.003597 |
| 3 | POINT (-111.826781 40.765911) | 2025 | 2025-04-27 | POLYGON ((-112.16175 40.79402, -112.1358 40.81... | cb869cb2640256dc655c5ffd650a009f | 1 | 52264.281507 | core | 0.003597 |
| 4 | POINT (-111.830586 40.497927) | 2025 | 2025-05-25 | POLYGON ((-112.16175 40.79402, -112.1358 40.81... | cb869cb2640256dc655c5ffd650a009f | 1 | 52264.281507 | core | 0.003597 |
Calculate rate of change in individuals per range edge though time.¶
In [4]:
Copied!
# Remember that this is a proportional metric; a density change of -0.8 in the leading edge means that though the time period examined, the leading edge has proportionally less individuals out of the total individuals then it did in the past.
pop_change = calculate_rate_of_change_first_last(
classified_historic, classified_modern, "Populus angustifolia", custom_end_year=2025
)
pop_change
# Remember that this is a proportional metric; a density change of -0.8 in the leading edge means that though the time period examined, the leading edge has proportionally less individuals out of the total individuals then it did in the past.
pop_change = calculate_rate_of_change_first_last(
classified_historic, classified_modern, "Populus angustifolia", custom_end_year=2025
)
pop_change
Out[4]:
| collapsed_category | start_time_period | end_time_period | rate_of_change_first_last | |
|---|---|---|---|---|
| 0 | core | 1970-1976 | 2024-2025 | 1.115629 |
| 1 | leading | 1970-1976 | 2024-2025 | 1.212121 |
| 2 | relict | 1970-1976 | 2024-2025 | 1.363636 |
| 3 | trailing | 1970-1976 | 2024-2025 | 1.374046 |
In [5]:
Copied!
# Making the df more self-explanatory
pop_change = pop_change.rename(
columns={
"collapsed_category": "Category",
"rate_of_change_first_last": "Rate of Change",
"start_time_period": "Start Years",
"end_time_period": "End Years",
}
)
pop_change["Category"] = pop_change["Category"].str.title()
pop_change
# Making the df more self-explanatory
pop_change = pop_change.rename(
columns={
"collapsed_category": "Category",
"rate_of_change_first_last": "Rate of Change",
"start_time_period": "Start Years",
"end_time_period": "End Years",
}
)
pop_change["Category"] = pop_change["Category"].str.title()
pop_change
Out[5]:
| Category | Start Years | End Years | Rate of Change | |
|---|---|---|---|---|
| 0 | Core | 1970-1976 | 2024-2025 | 1.115629 |
| 1 | Leading | 1970-1976 | 2024-2025 | 1.212121 |
| 2 | Relict | 1970-1976 | 2024-2025 | 1.363636 |
| 3 | Trailing | 1970-1976 | 2024-2025 | 1.374046 |
Plot population density on a 3D map.¶
In [6]:
Copied!
# Running this code will open a popup in a browser displaying the map. Set if_save = True if you want to save the map to your local device
create_interactive_map(classified_modern, if_save=False)
# Running this code will open a popup in a browser displaying the map. Set if_save = True if you want to save the map to your local device
create_interactive_map(classified_modern, if_save=False)