PySAL中的空间优化
项目描述
spopt
: 空间优化
区域化、设施定位和以交通为导向的建模
Spopt是一个开源的Python库,用于解决空间数据的优化问题。起源于PySAL (Python空间分析库)中的region
模块,它正在积极开发,以包含区域化、设施定位和以交通为导向的解决方案的新提出的模型和方法。
区域化
import spopt, libpysal, geopandas, numpy
mexico = geopandas.read_file(libpysal.examples.get_path("mexicojoin.shp"))
mexico["count"] = 1
attrs = [f"PCGDP{year}" for year in range(1950, 2010, 10)]
w = libpysal.weights.Queen.from_dataframe(mexico)
mexico["count"], threshold_name, threshold, top_n = 1, "count", 4, 2
numpy.random.seed(123456)
model = spopt.region.MaxPHeuristic(mexico, w, attrs, threshold_name, threshold, top_n)
model.solve()
mexico["maxp_new"] = model.labels_
mexico.plot(column="maxp_new", categorical=True, figsize=(12,8), ec="w");
定位
from spopt.locate import MCLP
from spopt.locate.util import simulated_geo_points
import numpy, geopandas, pulp, spaghetti
solver = pulp.PULP_CBC_CMD(msg=False, warmStart=True)
lattice = spaghetti.regular_lattice((0, 0, 10, 10), 9, exterior=True)
ntw = spaghetti.Network(in_data=lattice)
street = spaghetti.element_as_gdf(ntw, arcs=True)
street_buffered = geopandas.GeoDataFrame(
geopandas.GeoSeries(street["geometry"].buffer(0.5).unary_union),
crs=street.crs,
columns=["geometry"],
)
client_points = simulated_geo_points(street_buffered, needed=100, seed=5)
ntw.snapobservations(client_points, "clients", attribute=True)
clients_snapped = spaghetti.element_as_gdf(
ntw, pp_name="clients", snapped=True
)
facility_points = simulated_geo_points(street_buffered, needed=10, seed=6)
ntw.snapobservations(facility_points, "facilities", attribute=True)
facilities_snapped = spaghetti.element_as_gdf(
ntw, pp_name="facilities", snapped=True
)
cost_matrix = ntw.allneighbordistances(
sourcepattern=ntw.pointpatterns["clients"],
destpattern=ntw.pointpatterns["facilities"],
)
numpy.random.seed(0)
ai = numpy.random.randint(1, 12, 100)
mclp_from_cost_matrix = MCLP.from_cost_matrix(cost_matrix, ai, 4, p_facilities=4)
mclp_from_cost_matrix = mclp_from_cost_matrix.solve(solver)
查看笔记本中的绘图代码
示例
更多示例可以在文档的教程部分找到。
要求
安装
spopt可在Python包索引上找到。因此,您可以直接通过命令行使用pip安装
$ pip install -U spopt
或者下载源代码包(.tar.gz)并将其解压缩到您选择的目录。打开命令行工具并导航到解压缩的文件夹。输入
$ pip install .
您还可以通过运行
$ conda install --channel conda-forge spopt
相关包
贡献
PySAL-spopt处于积极开发中,欢迎贡献者。
如果您有任何建议、功能请求或错误报告,请在新GitHub问题中提出。要提交补丁,请在PySAL开发者文档、PySAL 开发指南和spopt
贡献指南中查看,然后提交pull request。一旦您的更改被合并,您将自动被添加到贡献者列表中。
支持
如果您遇到问题,请创建问题、开始讨论或在我们PySAL的Discord频道中与我们交谈。
行为准则
作为PySAL联盟项目,spopt
遵循行为准则,该准则位于PySAL治理模型下。
许可证
本项目采用BSD 3-Clause许可。
引用
如果您在科学出版物中使用PySAL-spopt,我们将感谢您使用以下引用
@misc{spopt2021,
author = {Feng, Xin, and Gaboardi, James D. and Knaap, Elijah and
Rey, Sergio J. and Wei, Ran},
month = {jan},
year = {2021},
title = {pysal/spopt},
url = {https://github.com/pysal/spopt},
doi = {10.5281/zenodo.4444156},
keywords = {python,regionalization,spatial-optimization,location-modeling}
}
@article{spopt2022,
author = {Feng, Xin and Barcelos, Germano and Gaboardi, James D. and
Knaap, Elijah and Wei, Ran and Wolf, Levi J. and
Zhao, Qunshan and Rey, Sergio J.},
year = {2022},
title = {spopt: a python package for solving spatial optimization problems in PySAL},
journal = {Journal of Open Source Software},
publisher = {The Open Journal},
volume = {7},
number = {74},
pages = {3330},
url = {https://doi.org/10.21105/joss.03330},
doi = {10.21105/joss.03330},
}
资金
本项目部分资金通过以下方式获得
国家科学基金会奖号#1831615: RIDIR: Scalable Geospatial Analytics for Social Science Research
项目详情
下载文件
下载您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源代码包
spopt-0.6.1.tar.gz (30.5 MB 查看哈希值)
构建发行版
spopt-0.6.1-py3-none-any.whl (243.1 kB 查看哈希值)
关闭
spopt-0.6.1.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 22fd867543cd04325d11d7d75a68dcdf8fba4c2c2fe959ba60ccef13dc54acf7 |
|
MD5 | 5931e8f18373f5a4e9583fb9e220261c |
|
BLAKE2b-256 | 570aa4e5a26d650a54da009f772a9cd57c03300285130d52bbb640bf26611dcb |
关闭
spopt-0.6.1-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 1e05fa545a78fca501556e3f6921ada3f95f6319df7d99bb24ce635fff3d1be8 |
|
MD5 | 5c38ec094e3b60279ed47cd26cafeddf |
|
BLAKE2b-256 | ee5908e1796f4dda22a780254ad24c525dd4641daee86a3f5212c807b4a55c4a |