The SmallestCircle library is designed to compute the smallest enclosing circle that covers a specified fraction of a population based on input geospatial population data.
- Optimized Circle center: (21.020833333333343, 105.8125)
- Minimum radius to cover at least 49.50% of population: 3471.85 km
- Population within final circle: 3944877745.18
- Expected population (50% of country): 3984724992.00
- Load and process population data from NetCDF files or zipped archives.
- Support for filtering data by country or geographical bounds.
- Calculate the smallest circle covering a given fraction of the total population.
- Visualize the results with population density and circle overlay.
-
Clone the repository:
git clone https://github.com/moeinp70/SmallestCircle.git cd SmallestCircle -
Install the library:
python setup.py install
pip install .
The library requires Python 3.7 or higher. Install the required dependencies using:
pip install -r requirements.txtThe library operates on geospatial population data in NetCDF format. You can download the required dataset from:
Once downloaded, provide the path to the dataset when using the library.
The load_population_data function allows loading and preprocessing of population data.
from smallestcircle import load_population_data
file_path = "gpw_v4_population_count_rev11_2pt5_min.nc"
country_code='ITA' #380 or 'italy'
year=2020
bounds=None #[30,32,-5,10]
population_data, latitudes, longitudes = load_population_data(file_path, year=year, country_code=country_code,bounds=bounds)Use the smallest_circle function to compute the smallest circle that covers a specified fraction of the population.
from smallestcircle import smallest_circle
center, radius = smallest_circle(population_data, latitudes, longitudes, target_population_ratio=0.5, details=False, plot=False)
print(f"Center: {center}, Radius: {radius} km")Visualize the population density with the calculated circle.
from smallestcircle import smallest_circle
_, _ = smallest_circle(population_data, latitudes, longitudes, target_population_ratio=0.5, details=True, plot=True)Run the test suite using:
pytest tests/This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please fork the repository and submit a pull request with your changes.
For any inquiries or issues, please contact:
Author: Moein Zadeh
Email: seyed.peyghambar@mail.polimi.it
