├── .github └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE ├── Makefile ├── Makefile.global ├── NEWS.md ├── README.md ├── RELEASE.md ├── carto-package.json ├── check-compatibility.sh ├── check-up-to-date-with-master.sh ├── doc ├── 02_moran.md ├── 03_overlap_sum.md ├── 04_markov.md ├── 04_pyAgg.md ├── 07_gravity.md ├── 08_interpolation.md ├── 09_voronoi.md ├── 11_kmeans.md ├── 12_segmentation.md ├── 13_PIA.md ├── 14_densify.md ├── 15_tinmap.md ├── 16_getis_ord_gstar.md ├── 18_outliers.md ├── 19_contour.md ├── 21_gwr.md └── docs_template.md ├── release ├── .gitignore ├── crankshaft--0.0.1--0.0.2.sql ├── crankshaft--0.0.1.sql ├── crankshaft--0.0.2--0.0.1.sql ├── crankshaft--0.0.2--0.0.3.sql ├── crankshaft--0.0.2.sql ├── crankshaft--0.0.3--0.0.2.sql ├── crankshaft--0.0.3--0.0.4.sql ├── crankshaft--0.0.3.sql ├── crankshaft--0.0.4--0.0.3.sql ├── crankshaft--0.0.4--0.1.0.sql ├── crankshaft--0.0.4.sql ├── crankshaft--0.1.0--0.0.4.sql ├── crankshaft--0.1.0--0.2.0.sql ├── crankshaft--0.1.0.sql ├── crankshaft--0.2.0--0.3.0.sql ├── crankshaft--0.2.0.sql ├── crankshaft--0.3.0--0.3.1.sql ├── crankshaft--0.3.0.sql ├── crankshaft--0.3.1--0.4.0.sql ├── crankshaft--0.3.1.sql ├── crankshaft--0.4.0--0.4.1.sql ├── crankshaft--0.4.0.sql ├── crankshaft--0.4.1--0.4.2.sql ├── crankshaft--0.4.1.sql ├── crankshaft--0.4.2--0.5.0.sql ├── crankshaft--0.4.2.sql ├── crankshaft--0.5.0--0.5.1.sql ├── crankshaft--0.5.0.sql ├── crankshaft--0.5.1--0.5.2.sql ├── crankshaft--0.5.1.sql ├── crankshaft--0.5.2--0.6.0.sql ├── crankshaft--0.5.2.sql ├── crankshaft--0.6.0--0.6.1.sql ├── crankshaft--0.6.0.sql ├── crankshaft--0.6.1--0.7.0.sql ├── crankshaft--0.6.1.sql ├── crankshaft--0.7.0--0.8.0.sql ├── crankshaft--0.7.0.sql ├── crankshaft--0.8.0--0.8.1.sql ├── crankshaft--0.8.0.sql ├── crankshaft--0.8.1--0.8.2.sql ├── crankshaft--0.8.1.sql ├── crankshaft--0.8.2--0.9.0.sql ├── crankshaft--0.8.2.sql ├── crankshaft--0.9.0.sql ├── crankshaft.control └── python │ ├── .gitignore │ ├── 0.0.1 │ └── crankshaft │ │ ├── crankshaft │ │ ├── __init__.py │ │ ├── clustering │ │ │ ├── __init__.py │ │ │ └── moran.py │ │ └── random_seeds.py │ │ ├── setup.py │ │ └── test │ │ ├── fixtures │ │ ├── moran.json │ │ └── neighbors.json │ │ ├── helper.py │ │ ├── mock_plpy.py │ │ └── test_clustering_moran.py │ ├── 0.0.2 │ └── crankshaft │ │ ├── crankshaft │ │ ├── __init__.py │ │ ├── clustering │ │ │ ├── __init__.py │ │ │ └── moran.py │ │ └── random_seeds.py │ │ ├── setup.py │ │ └── test │ │ ├── fixtures │ │ ├── moran.json │ │ └── neighbors.json │ │ ├── helper.py │ │ ├── mock_plpy.py │ │ └── test_clustering_moran.py │ ├── 0.0.3 │ └── crankshaft │ │ ├── crankshaft │ │ ├── __init__.py │ │ ├── clustering │ │ │ ├── __init__.py │ │ │ ├── kmeans.py │ │ │ └── moran.py │ │ ├── pysal_utils │ │ │ ├── __init__.py │ │ │ └── pysal_utils.py │ │ └── random_seeds.py │ │ ├── setup.py │ │ └── test │ │ ├── fixtures │ │ ├── kmeans.json │ │ ├── moran.json │ │ └── neighbors.json │ │ ├── helper.py │ │ ├── mock_plpy.py │ │ ├── test_cluster_kmeans.py │ │ ├── test_clustering_moran.py │ │ └── test_pysal_utils.py │ ├── 0.0.4 │ └── crankshaft │ │ ├── crankshaft │ │ ├── __init__.py │ │ ├── clustering │ │ │ ├── __init__.py │ │ │ ├── kmeans.py │ │ │ └── moran.py │ │ ├── pysal_utils │ │ │ ├── __init__.py │ │ │ └── pysal_utils.py │ │ └── random_seeds.py │ │ ├── setup.py │ │ └── test │ │ ├── fixtures │ │ ├── kmeans.json │ │ ├── moran.json │ │ └── neighbors.json │ │ ├── helper.py │ │ ├── mock_plpy.py │ │ ├── test_cluster_kmeans.py │ │ ├── test_clustering_moran.py │ │ └── test_pysal_utils.py │ ├── 0.1.0 │ └── crankshaft │ │ ├── crankshaft │ │ ├── __init__.py │ │ ├── clustering │ │ │ ├── __init__.py │ │ │ ├── kmeans.py │ │ │ └── moran.py │ │ ├── pysal_utils │ │ │ ├── __init__.py │ │ │ └── pysal_utils.py │ │ ├── random_seeds.py │ │ ├── segmentation │ │ │ ├── __init__.py │ │ │ └── segmentation.py │ │ └── space_time_dynamics │ │ │ ├── __init__.py │ │ │ └── markov.py │ │ ├── setup.py │ │ └── test │ │ ├── fixtures │ │ ├── kmeans.json │ │ ├── markov.json │ │ ├── moran.json │ │ ├── neighbors.json │ │ └── neighbors_markov.json │ │ ├── helper.py │ │ ├── mock_plpy.py │ │ ├── test_cluster_kmeans.py │ │ ├── test_clustering_moran.py │ │ ├── test_pysal_utils.py │ │ ├── test_segmentation.py │ │ └── test_space_time_dynamics.py │ ├── 0.2.0 │ └── crankshaft │ │ ├── crankshaft │ │ ├── __init__.py │ │ ├── clustering │ │ │ ├── __init__.py │ │ │ ├── kmeans.py │ │ │ └── moran.py │ │ ├── pysal_utils │ │ │ ├── __init__.py │ │ │ └── pysal_utils.py │ │ ├── random_seeds.py │ │ ├── segmentation │ │ │ ├── __init__.py │ │ │ └── segmentation.py │ │ └── space_time_dynamics │ │ │ ├── __init__.py │ │ │ └── markov.py │ │ ├── setup.py │ │ └── test │ │ ├── fixtures │ │ ├── kmeans.json │ │ ├── markov.json │ │ ├── moran.json │ │ ├── neighbors.json │ │ └── neighbors_markov.json │ │ ├── helper.py │ │ ├── mock_plpy.py │ │ ├── test_cluster_kmeans.py │ │ ├── test_clustering_moran.py │ │ ├── test_pysal_utils.py │ │ ├── test_segmentation.py │ │ └── test_space_time_dynamics.py │ ├── 0.3.0 │ └── crankshaft │ │ ├── crankshaft │ │ ├── __init__.py │ │ ├── clustering │ │ │ ├── __init__.py │ │ │ ├── kmeans.py │ │ │ └── moran.py │ │ ├── pysal_utils │ │ │ ├── __init__.py │ │ │ └── pysal_utils.py │ │ ├── random_seeds.py │ │ ├── segmentation │ │ │ ├── __init__.py │ │ │ └── segmentation.py │ │ └── space_time_dynamics │ │ │ ├── __init__.py │ │ │ └── markov.py │ │ ├── setup.py │ │ └── test │ │ ├── fixtures │ │ ├── kmeans.json │ │ ├── markov.json │ │ ├── moran.json │ │ ├── neighbors.json │ │ └── neighbors_markov.json │ │ ├── helper.py │ │ ├── mock_plpy.py │ │ ├── test_cluster_kmeans.py │ │ ├── test_clustering_moran.py │ │ ├── test_pysal_utils.py │ │ ├── test_segmentation.py │ │ └── test_space_time_dynamics.py │ ├── 0.3.1 │ └── crankshaft │ │ ├── crankshaft │ │ ├── __init__.py │ │ ├── clustering │ │ │ ├── __init__.py │ │ │ ├── kmeans.py │ │ │ └── moran.py │ │ ├── pysal_utils │ │ │ ├── __init__.py │ │ │ └── pysal_utils.py │ │ ├── random_seeds.py │ │ ├── segmentation │ │ │ ├── __init__.py │ │ │ └── segmentation.py │ │ └── space_time_dynamics │ │ │ ├── __init__.py │ │ │ └── markov.py │ │ ├── setup.py │ │ ├── setup.py-r │ │ └── test │ │ ├── fixtures │ │ ├── kmeans.json │ │ ├── markov.json │ │ ├── moran.json │ │ ├── neighbors.json │ │ └── neighbors_markov.json │ │ ├── helper.py │ │ ├── mock_plpy.py │ │ ├── test_cluster_kmeans.py │ │ ├── test_clustering_moran.py │ │ ├── test_pysal_utils.py │ │ ├── test_segmentation.py │ │ └── test_space_time_dynamics.py │ ├── 0.4.0 │ └── crankshaft │ │ ├── crankshaft │ │ ├── __init__.py │ │ ├── clustering │ │ │ ├── __init__.py │ │ │ ├── kmeans.py │ │ │ └── moran.py │ │ ├── pysal_utils │ │ │ ├── __init__.py │ │ │ └── pysal_utils.py │ │ ├── random_seeds.py │ │ ├── segmentation │ │ │ ├── __init__.py │ │ │ └── segmentation.py │ │ └── space_time_dynamics │ │ │ ├── __init__.py │ │ │ └── markov.py │ │ ├── setup.py │ │ ├── setup.py-r │ │ └── test │ │ ├── fixtures │ │ ├── kmeans.json │ │ ├── markov.json │ │ ├── moran.json │ │ ├── neighbors.json │ │ └── neighbors_markov.json │ │ ├── helper.py │ │ ├── mock_plpy.py │ │ ├── test_cluster_kmeans.py │ │ ├── test_clustering_moran.py │ │ ├── test_pysal_utils.py │ │ ├── test_segmentation.py │ │ └── test_space_time_dynamics.py │ ├── 0.4.1 │ └── crankshaft │ │ ├── crankshaft │ │ ├── __init__.py │ │ ├── clustering │ │ │ ├── __init__.py │ │ │ ├── kmeans.py │ │ │ └── moran.py │ │ ├── pysal_utils │ │ │ ├── __init__.py │ │ │ └── pysal_utils.py │ │ ├── random_seeds.py │ │ ├── segmentation │ │ │ ├── __init__.py │ │ │ └── segmentation.py │ │ └── space_time_dynamics │ │ │ ├── __init__.py │ │ │ └── markov.py │ │ ├── setup.py │ │ ├── setup.py-r │ │ └── test │ │ ├── fixtures │ │ ├── kmeans.json │ │ ├── markov.json │ │ ├── moran.json │ │ ├── neighbors.json │ │ └── neighbors_markov.json │ │ ├── helper.py │ │ ├── mock_plpy.py │ │ ├── test_cluster_kmeans.py │ │ ├── test_clustering_moran.py │ │ ├── test_pysal_utils.py │ │ ├── test_segmentation.py │ │ └── test_space_time_dynamics.py │ ├── 0.4.2 │ └── crankshaft │ │ ├── crankshaft │ │ ├── __init__.py │ │ ├── clustering │ │ │ ├── __init__.py │ │ │ ├── kmeans.py │ │ │ └── moran.py │ │ ├── pysal_utils │ │ │ ├── __init__.py │ │ │ └── pysal_utils.py │ │ ├── random_seeds.py │ │ ├── segmentation │ │ │ ├── __init__.py │ │ │ └── segmentation.py │ │ └── space_time_dynamics │ │ │ ├── __init__.py │ │ │ └── markov.py │ │ ├── requirements.txt │ │ ├── setup.py │ │ ├── setup.py-r │ │ └── test │ │ ├── fixtures │ │ ├── kmeans.json │ │ ├── markov.json │ │ ├── moran.json │ │ ├── neighbors.json │ │ └── neighbors_markov.json │ │ ├── helper.py │ │ ├── mock_plpy.py │ │ ├── test_cluster_kmeans.py │ │ ├── test_clustering_moran.py │ │ ├── test_pysal_utils.py │ │ ├── test_segmentation.py │ │ └── test_space_time_dynamics.py │ ├── 0.5.0 │ └── crankshaft │ │ ├── crankshaft │ │ ├── __init__.py │ │ ├── analysis_data_provider.py │ │ ├── clustering │ │ │ ├── __init__.py │ │ │ ├── getis.py │ │ │ ├── kmeans.py │ │ │ └── moran.py │ │ ├── pysal_utils │ │ │ ├── __init__.py │ │ │ └── pysal_utils.py │ │ ├── random_seeds.py │ │ ├── segmentation │ │ │ ├── __init__.py │ │ │ └── segmentation.py │ │ └── space_time_dynamics │ │ │ ├── __init__.py │ │ │ └── markov.py │ │ ├── requirements.txt │ │ ├── setup.py │ │ └── test │ │ ├── fixtures │ │ ├── getis.json │ │ ├── kmeans.json │ │ ├── markov.json │ │ ├── moran.json │ │ ├── neighbors.json │ │ ├── neighbors_getis.json │ │ └── neighbors_markov.json │ │ ├── helper.py │ │ ├── mock_plpy.py │ │ ├── test_clustering_getis.py │ │ ├── test_clustering_kmeans.py │ │ ├── test_clustering_moran.py │ │ ├── test_pysal_utils.py │ │ ├── test_segmentation.py │ │ └── test_space_time_dynamics.py │ ├── 0.5.1 │ └── crankshaft │ │ ├── crankshaft │ │ ├── __init__.py │ │ ├── analysis_data_provider.py │ │ ├── clustering │ │ │ ├── __init__.py │ │ │ ├── getis.py │ │ │ ├── kmeans.py │ │ │ └── moran.py │ │ ├── pysal_utils │ │ │ ├── __init__.py │ │ │ └── pysal_utils.py │ │ ├── random_seeds.py │ │ ├── segmentation │ │ │ ├── __init__.py │ │ │ └── segmentation.py │ │ └── space_time_dynamics │ │ │ ├── __init__.py │ │ │ └── markov.py │ │ ├── requirements.txt │ │ ├── setup.py │ │ └── test │ │ ├── fixtures │ │ ├── getis.json │ │ ├── kmeans.json │ │ ├── markov.json │ │ ├── moran.json │ │ ├── neighbors.json │ │ ├── neighbors_getis.json │ │ └── neighbors_markov.json │ │ ├── helper.py │ │ ├── mock_plpy.py │ │ ├── test_clustering_getis.py │ │ ├── test_clustering_kmeans.py │ │ ├── test_clustering_moran.py │ │ ├── test_pysal_utils.py │ │ ├── test_segmentation.py │ │ └── test_space_time_dynamics.py │ ├── 0.5.2 │ └── crankshaft │ │ ├── crankshaft │ │ ├── __init__.py │ │ ├── analysis_data_provider.py │ │ ├── clustering │ │ │ ├── __init__.py │ │ │ ├── getis.py │ │ │ ├── kmeans.py │ │ │ └── moran.py │ │ ├── pysal_utils │ │ │ ├── __init__.py │ │ │ └── pysal_utils.py │ │ ├── random_seeds.py │ │ ├── segmentation │ │ │ ├── __init__.py │ │ │ └── segmentation.py │ │ └── space_time_dynamics │ │ │ ├── __init__.py │ │ │ └── markov.py │ │ ├── requirements.txt │ │ ├── setup.py │ │ └── test │ │ ├── fixtures │ │ ├── getis.json │ │ ├── kmeans.json │ │ ├── markov.json │ │ ├── moran.json │ │ ├── neighbors.json │ │ ├── neighbors_getis.json │ │ └── neighbors_markov.json │ │ ├── helper.py │ │ ├── mock_plpy.py │ │ ├── test_clustering_getis.py │ │ ├── test_clustering_kmeans.py │ │ ├── test_clustering_moran.py │ │ ├── test_pysal_utils.py │ │ ├── test_segmentation.py │ │ └── test_space_time_dynamics.py │ ├── 0.6.0 │ └── crankshaft │ │ ├── crankshaft │ │ ├── __init__.py │ │ ├── analysis_data_provider.py │ │ ├── centers │ │ │ └── median_center.py │ │ ├── clustering │ │ │ ├── __init__.py │ │ │ ├── getis.py │ │ │ ├── kmeans.py │ │ │ └── moran.py │ │ ├── optimization │ │ │ └── optim.py │ │ ├── pysal_utils │ │ │ ├── __init__.py │ │ │ └── pysal_utils.py │ │ ├── random_seeds.py │ │ ├── regression │ │ │ ├── __init__.py │ │ │ ├── glm │ │ │ │ ├── GLM_validate_estimation.ipynb │ │ │ │ ├── __init__.py │ │ │ │ ├── base.py │ │ │ │ ├── family.py │ │ │ │ ├── glm.py │ │ │ │ ├── iwls.py │ │ │ │ ├── links.py │ │ │ │ ├── tests │ │ │ │ │ └── test_glm.py │ │ │ │ ├── utils.py │ │ │ │ └── varfuncs.py │ │ │ ├── gwr │ │ │ │ ├── __init__.py │ │ │ │ └── base │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── diagnostics.py │ │ │ │ │ ├── gwr.py │ │ │ │ │ ├── kernels.py │ │ │ │ │ ├── search.py │ │ │ │ │ ├── sel_bw.py │ │ │ │ │ └── tests │ │ │ │ │ ├── test_gwr.py │ │ │ │ │ ├── test_kernels.py │ │ │ │ │ └── test_sel_bw.py │ │ │ └── gwr_cs.py │ │ ├── segmentation │ │ │ ├── __init__.py │ │ │ └── segmentation.py │ │ └── space_time_dynamics │ │ │ ├── __init__.py │ │ │ └── markov.py │ │ ├── requirements.txt │ │ ├── setup.py │ │ └── test │ │ ├── fixtures │ │ ├── getis.json │ │ ├── gwr_packed_data.json │ │ ├── gwr_packed_knowns.json │ │ ├── kmeans.json │ │ ├── markov.json │ │ ├── moran.json │ │ ├── neighbors.json │ │ ├── neighbors_getis.json │ │ └── neighbors_markov.json │ │ ├── helper.py │ │ ├── mock_plpy.py │ │ ├── test_clustering_getis.py │ │ ├── test_clustering_kmeans.py │ │ ├── test_clustering_moran.py │ │ ├── test_pysal_utils.py │ │ ├── test_regression_gwr.py │ │ ├── test_segmentation.py │ │ └── test_space_time_dynamics.py │ ├── 0.6.1 │ └── crankshaft │ │ ├── crankshaft │ │ ├── __init__.py │ │ ├── analysis_data_provider.py │ │ ├── clustering │ │ │ ├── __init__.py │ │ │ ├── getis.py │ │ │ ├── kmeans.py │ │ │ └── moran.py │ │ ├── pysal_utils │ │ │ ├── __init__.py │ │ │ └── pysal_utils.py │ │ ├── random_seeds.py │ │ ├── regression │ │ │ ├── __init__.py │ │ │ ├── glm │ │ │ │ ├── GLM_validate_estimation.ipynb │ │ │ │ ├── __init__.py │ │ │ │ ├── base.py │ │ │ │ ├── family.py │ │ │ │ ├── glm.py │ │ │ │ ├── iwls.py │ │ │ │ ├── links.py │ │ │ │ ├── tests │ │ │ │ │ └── test_glm.py │ │ │ │ ├── utils.py │ │ │ │ └── varfuncs.py │ │ │ ├── gwr │ │ │ │ ├── __init__.py │ │ │ │ └── base │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── diagnostics.py │ │ │ │ │ ├── gwr.py │ │ │ │ │ ├── kernels.py │ │ │ │ │ ├── search.py │ │ │ │ │ ├── sel_bw.py │ │ │ │ │ └── tests │ │ │ │ │ ├── test_gwr.py │ │ │ │ │ ├── test_kernels.py │ │ │ │ │ └── test_sel_bw.py │ │ │ └── gwr_cs.py │ │ ├── segmentation │ │ │ ├── __init__.py │ │ │ └── segmentation.py │ │ └── space_time_dynamics │ │ │ ├── __init__.py │ │ │ └── markov.py │ │ ├── requirements.txt │ │ ├── setup.py │ │ └── test │ │ ├── fixtures │ │ ├── getis.json │ │ ├── gwr_packed_data.json │ │ ├── gwr_packed_knowns.json │ │ ├── kmeans.json │ │ ├── markov.json │ │ ├── moran.json │ │ ├── neighbors.json │ │ ├── neighbors_getis.json │ │ └── neighbors_markov.json │ │ ├── helper.py │ │ ├── mock_plpy.py │ │ ├── test_clustering_getis.py │ │ ├── test_clustering_kmeans.py │ │ ├── test_clustering_moran.py │ │ ├── test_pysal_utils.py │ │ ├── test_regression_gwr.py │ │ ├── test_segmentation.py │ │ └── test_space_time_dynamics.py │ ├── 0.7.0 │ └── crankshaft │ │ ├── crankshaft │ │ ├── __init__.py │ │ ├── analysis_data_provider.py │ │ ├── clustering │ │ │ ├── __init__.py │ │ │ ├── getis.py │ │ │ ├── kmeans.py │ │ │ └── moran.py │ │ ├── pysal_utils │ │ │ ├── __init__.py │ │ │ └── pysal_utils.py │ │ ├── random_seeds.py │ │ ├── regression │ │ │ ├── __init__.py │ │ │ ├── glm │ │ │ │ ├── GLM_validate_estimation.ipynb │ │ │ │ ├── __init__.py │ │ │ │ ├── base.py │ │ │ │ ├── family.py │ │ │ │ ├── glm.py │ │ │ │ ├── iwls.py │ │ │ │ ├── links.py │ │ │ │ ├── tests │ │ │ │ │ └── test_glm.py │ │ │ │ ├── utils.py │ │ │ │ └── varfuncs.py │ │ │ ├── gwr │ │ │ │ ├── __init__.py │ │ │ │ └── base │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── diagnostics.py │ │ │ │ │ ├── gwr.py │ │ │ │ │ ├── kernels.py │ │ │ │ │ ├── search.py │ │ │ │ │ ├── sel_bw.py │ │ │ │ │ └── tests │ │ │ │ │ ├── test_gwr.py │ │ │ │ │ ├── test_kernels.py │ │ │ │ │ └── test_sel_bw.py │ │ │ └── gwr_cs.py │ │ ├── segmentation │ │ │ ├── __init__.py │ │ │ └── segmentation.py │ │ └── space_time_dynamics │ │ │ ├── __init__.py │ │ │ └── markov.py │ │ ├── requirements.txt │ │ ├── setup.py │ │ └── test │ │ ├── fixtures │ │ ├── getis.json │ │ ├── gwr_packed_data.json │ │ ├── gwr_packed_knowns.json │ │ ├── kmeans.json │ │ ├── markov.json │ │ ├── moran.json │ │ ├── neighbors.json │ │ ├── neighbors_getis.json │ │ └── neighbors_markov.json │ │ ├── helper.py │ │ ├── mock_plpy.py │ │ ├── test_clustering_getis.py │ │ ├── test_clustering_kmeans.py │ │ ├── test_clustering_moran.py │ │ ├── test_pysal_utils.py │ │ ├── test_regression_gwr.py │ │ ├── test_segmentation.py │ │ └── test_space_time_dynamics.py │ ├── 0.8.0 │ └── crankshaft │ │ ├── crankshaft │ │ ├── .analysis_data_provider.py.swp │ │ ├── __init__.py │ │ ├── analysis_data_provider.py │ │ ├── centers │ │ │ └── median_center.py │ │ ├── clustering │ │ │ ├── __init__.py │ │ │ ├── getis.py │ │ │ ├── kmeans.py │ │ │ └── moran.py │ │ ├── pysal_utils │ │ │ ├── __init__.py │ │ │ └── pysal_utils.py │ │ ├── random_seeds.py │ │ ├── regression │ │ │ ├── __init__.py │ │ │ ├── glm │ │ │ │ ├── GLM_validate_estimation.ipynb │ │ │ │ ├── __init__.py │ │ │ │ ├── base.py │ │ │ │ ├── family.py │ │ │ │ ├── glm.py │ │ │ │ ├── iwls.py │ │ │ │ ├── links.py │ │ │ │ ├── tests │ │ │ │ │ └── test_glm.py │ │ │ │ ├── utils.py │ │ │ │ └── varfuncs.py │ │ │ ├── gwr │ │ │ │ ├── __init__.py │ │ │ │ └── base │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── diagnostics.py │ │ │ │ │ ├── gwr.py │ │ │ │ │ ├── kernels.py │ │ │ │ │ ├── search.py │ │ │ │ │ ├── sel_bw.py │ │ │ │ │ └── tests │ │ │ │ │ ├── test_gwr.py │ │ │ │ │ ├── test_kernels.py │ │ │ │ │ └── test_sel_bw.py │ │ │ └── gwr_cs.py │ │ ├── segmentation │ │ │ ├── __init__.py │ │ │ └── segmentation.py │ │ └── space_time_dynamics │ │ │ ├── __init__.py │ │ │ └── markov.py │ │ ├── requirements.txt │ │ ├── setup.py │ │ ├── setup.py-r │ │ └── test │ │ ├── fixtures │ │ ├── getis.json │ │ ├── gwr_packed_data.json │ │ ├── gwr_packed_knowns.json │ │ ├── kmeans.json │ │ ├── markov.json │ │ ├── moran.json │ │ ├── neighbors.json │ │ ├── neighbors_getis.json │ │ └── neighbors_markov.json │ │ ├── helper.py │ │ ├── mock_plpy.py │ │ ├── test_clustering_getis.py │ │ ├── test_clustering_kmeans.py │ │ ├── test_clustering_moran.py │ │ ├── test_pysal_utils.py │ │ ├── test_regression_gwr.py │ │ ├── test_segmentation.py │ │ └── test_space_time_dynamics.py │ ├── 0.8.1 │ └── crankshaft │ │ ├── crankshaft │ │ ├── .analysis_data_provider.py.swp │ │ ├── __init__.py │ │ ├── analysis_data_provider.py │ │ ├── centers │ │ │ └── median_center.py │ │ ├── clustering │ │ │ ├── __init__.py │ │ │ ├── getis.py │ │ │ ├── kmeans.py │ │ │ └── moran.py │ │ ├── pysal_utils │ │ │ ├── __init__.py │ │ │ └── pysal_utils.py │ │ ├── random_seeds.py │ │ ├── regression │ │ │ ├── __init__.py │ │ │ ├── glm │ │ │ │ ├── GLM_validate_estimation.ipynb │ │ │ │ ├── __init__.py │ │ │ │ ├── base.py │ │ │ │ ├── family.py │ │ │ │ ├── glm.py │ │ │ │ ├── iwls.py │ │ │ │ ├── links.py │ │ │ │ ├── tests │ │ │ │ │ └── test_glm.py │ │ │ │ ├── utils.py │ │ │ │ └── varfuncs.py │ │ │ ├── gwr │ │ │ │ ├── __init__.py │ │ │ │ └── base │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── diagnostics.py │ │ │ │ │ ├── gwr.py │ │ │ │ │ ├── kernels.py │ │ │ │ │ ├── search.py │ │ │ │ │ ├── sel_bw.py │ │ │ │ │ └── tests │ │ │ │ │ ├── test_gwr.py │ │ │ │ │ ├── test_kernels.py │ │ │ │ │ └── test_sel_bw.py │ │ │ └── gwr_cs.py │ │ ├── segmentation │ │ │ ├── __init__.py │ │ │ └── segmentation.py │ │ └── space_time_dynamics │ │ │ ├── __init__.py │ │ │ └── markov.py │ │ ├── requirements.txt │ │ ├── setup.py │ │ ├── setup.py-r │ │ └── test │ │ ├── fixtures │ │ ├── getis.json │ │ ├── gwr_packed_data.json │ │ ├── gwr_packed_knowns.json │ │ ├── kmeans.json │ │ ├── markov.json │ │ ├── moran.json │ │ ├── neighbors.json │ │ ├── neighbors_getis.json │ │ └── neighbors_markov.json │ │ ├── helper.py │ │ ├── mock_plpy.py │ │ ├── test_clustering_getis.py │ │ ├── test_clustering_kmeans.py │ │ ├── test_clustering_moran.py │ │ ├── test_pysal_utils.py │ │ ├── test_regression_gwr.py │ │ ├── test_segmentation.py │ │ └── test_space_time_dynamics.py │ ├── 0.8.2 │ └── crankshaft │ │ ├── crankshaft │ │ ├── __init__.py │ │ ├── analysis_data_provider.py │ │ ├── clustering │ │ │ ├── __init__.py │ │ │ ├── getis.py │ │ │ ├── kmeans.py │ │ │ └── moran.py │ │ ├── pysal_utils │ │ │ ├── __init__.py │ │ │ └── pysal_utils.py │ │ ├── random_seeds.py │ │ ├── regression │ │ │ ├── __init__.py │ │ │ ├── glm │ │ │ │ ├── GLM_validate_estimation.ipynb │ │ │ │ ├── __init__.py │ │ │ │ ├── base.py │ │ │ │ ├── family.py │ │ │ │ ├── glm.py │ │ │ │ ├── iwls.py │ │ │ │ ├── links.py │ │ │ │ ├── tests │ │ │ │ │ └── test_glm.py │ │ │ │ ├── utils.py │ │ │ │ └── varfuncs.py │ │ │ ├── gwr │ │ │ │ ├── __init__.py │ │ │ │ └── base │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── diagnostics.py │ │ │ │ │ ├── gwr.py │ │ │ │ │ ├── kernels.py │ │ │ │ │ ├── search.py │ │ │ │ │ ├── sel_bw.py │ │ │ │ │ └── tests │ │ │ │ │ ├── test_gwr.py │ │ │ │ │ ├── test_kernels.py │ │ │ │ │ └── test_sel_bw.py │ │ │ └── gwr_cs.py │ │ ├── segmentation │ │ │ ├── __init__.py │ │ │ └── segmentation.py │ │ └── space_time_dynamics │ │ │ ├── __init__.py │ │ │ └── markov.py │ │ ├── requirements.txt │ │ ├── setup.py │ │ └── test │ │ ├── fixtures │ │ ├── data.json │ │ ├── getis.json │ │ ├── gwr_packed_data.json │ │ ├── gwr_packed_knowns.json │ │ ├── kmeans.json │ │ ├── markov.json │ │ ├── model_data.json │ │ ├── moran.json │ │ ├── neighbors.json │ │ ├── neighbors_getis.json │ │ ├── neighbors_markov.json │ │ ├── predict_data.json │ │ ├── segmentation_result.json │ │ └── true_result.json │ │ ├── helper.py │ │ ├── mock_plpy.py │ │ ├── test_clustering_getis.py │ │ ├── test_clustering_kmeans.py │ │ ├── test_clustering_moran.py │ │ ├── test_pysal_utils.py │ │ ├── test_regression_gwr.py │ │ ├── test_segmentation.py │ │ └── test_space_time_dynamics.py │ └── 0.9.0 │ └── crankshaft │ ├── crankshaft │ ├── __init__.py │ ├── analysis_data_provider.py │ ├── clustering │ │ ├── __init__.py │ │ ├── getis.py │ │ ├── kmeans.py │ │ └── moran.py │ ├── pysal_utils │ │ ├── __init__.py │ │ └── pysal_utils.py │ ├── random_seeds.py │ ├── regression │ │ ├── __init__.py │ │ ├── glm │ │ │ ├── GLM_validate_estimation.ipynb │ │ │ ├── __init__.py │ │ │ ├── base.py │ │ │ ├── family.py │ │ │ ├── glm.py │ │ │ ├── iwls.py │ │ │ ├── links.py │ │ │ ├── tests │ │ │ │ └── test_glm.py │ │ │ ├── utils.py │ │ │ └── varfuncs.py │ │ ├── gwr │ │ │ ├── __init__.py │ │ │ └── base │ │ │ │ ├── __init__.py │ │ │ │ ├── diagnostics.py │ │ │ │ ├── gwr.py │ │ │ │ ├── kernels.py │ │ │ │ ├── search.py │ │ │ │ ├── sel_bw.py │ │ │ │ └── tests │ │ │ │ ├── test_gwr.py │ │ │ │ ├── test_kernels.py │ │ │ │ └── test_sel_bw.py │ │ └── gwr_cs.py │ ├── segmentation │ │ ├── __init__.py │ │ └── segmentation.py │ └── space_time_dynamics │ │ ├── __init__.py │ │ └── markov.py │ ├── requirements.txt │ ├── setup.py │ └── test │ ├── fixtures │ ├── data.json │ ├── getis.json │ ├── gwr_packed_data.json │ ├── gwr_packed_knowns.json │ ├── kmeans.json │ ├── markov.json │ ├── model_data.json │ ├── moran.json │ ├── neighbors.json │ ├── neighbors_getis.json │ ├── neighbors_markov.json │ ├── predict_data.json │ ├── segmentation_result.json │ └── true_result.json │ ├── helper.py │ ├── mock_plpy.py │ ├── test_clustering_getis.py │ ├── test_clustering_kmeans.py │ ├── test_clustering_moran.py │ ├── test_pysal_utils.py │ ├── test_regression_gwr.py │ ├── test_segmentation.py │ └── test_space_time_dynamics.py └── src ├── pg ├── .gitignore ├── Makefile ├── crankshaft.control ├── sql │ ├── 00_header.sql │ ├── 01_version.sql │ ├── 03_random_seeds.sql │ ├── 04_py_agg.sql │ ├── 05_segmentation.sql │ ├── 07_gravity.sql │ ├── 08_interpolation.sql │ ├── 09_voronoi.sql │ ├── 10_moran.sql │ ├── 11_kmeans.sql │ ├── 11_markov.sql │ ├── 13_PIA.sql │ ├── 14_densify.sql │ ├── 15_tinmap.sql │ ├── 16_getis.sql │ ├── 18_outliers.sql │ ├── 19_contour.sql │ ├── 20_overlap_sum.sql │ ├── 21_gwr.sql │ ├── 30_dot_density.sql │ ├── 90_permissions.sql │ └── cdb_utils.sql └── test │ ├── expected │ ├── 01_install_test.out │ ├── 02_moran_test.out │ ├── 03_overlap_sum_test.out │ ├── 04_dot_density_test.out │ ├── 05_markov_test.out │ ├── 06_segmentation_test.out │ ├── 07_gravity_test.out │ ├── 08_interpolation_test.out │ ├── 09_voronoi_test.out │ ├── 11_kmeans_test.out │ ├── 13_pia_test.out │ ├── 14_densify_test.out │ ├── 15_tinmap_test.out │ ├── 16_getis_test.out │ ├── 18_outliers_test.out │ ├── 19_contour_test.out │ └── 21_gwr_test.out │ ├── fixtures │ ├── getis_data.sql │ ├── gwr_georgia.sql │ ├── markov_usjoin_example.sql │ ├── ml_values.sql │ ├── polyg_values.sql │ ├── ppoints.sql │ └── ppoints2.sql │ └── sql │ ├── 01_install_test.sql │ ├── 02_moran_test.sql │ ├── 03_overlap_sum_test.sql │ ├── 04_dot_density_test.sql │ ├── 05_markov_test.sql │ ├── 06_segmentation_test.sql │ ├── 07_gravity_test.sql │ ├── 08_interpolation_test.sql │ ├── 09_voronoi_test.sql │ ├── 11_kmeans_test.sql │ ├── 13_pia_test.sql │ ├── 14_densify_test.sql │ ├── 15_tinmap_test.sql │ ├── 16_getis_test.sql │ ├── 18_outliers_test.sql │ ├── 19_contour_test.sql │ ├── 21_gwr_test.sql │ └── 90_permissions.sql └── py ├── Makefile ├── README.md └── crankshaft ├── crankshaft ├── __init__.py ├── analysis_data_provider.py ├── clustering │ ├── __init__.py │ ├── getis.py │ ├── kmeans.py │ └── moran.py ├── pysal_utils │ ├── __init__.py │ └── pysal_utils.py ├── random_seeds.py ├── regression │ ├── __init__.py │ ├── glm │ │ ├── GLM_validate_estimation.ipynb │ │ ├── __init__.py │ │ ├── base.py │ │ ├── family.py │ │ ├── glm.py │ │ ├── iwls.py │ │ ├── links.py │ │ ├── tests │ │ │ └── test_glm.py │ │ ├── utils.py │ │ └── varfuncs.py │ ├── gwr │ │ ├── __init__.py │ │ └── base │ │ │ ├── __init__.py │ │ │ ├── diagnostics.py │ │ │ ├── gwr.py │ │ │ ├── kernels.py │ │ │ ├── search.py │ │ │ ├── sel_bw.py │ │ │ └── tests │ │ │ ├── test_gwr.py │ │ │ ├── test_kernels.py │ │ │ └── test_sel_bw.py │ └── gwr_cs.py ├── segmentation │ ├── __init__.py │ └── segmentation.py └── space_time_dynamics │ ├── __init__.py │ └── markov.py ├── requirements.txt ├── setup.py └── test ├── fixtures ├── data.json ├── getis.json ├── gwr_packed_data.json ├── gwr_packed_knowns.json ├── kmeans.json ├── markov.json ├── model_data.json ├── moran.json ├── neighbors.json ├── neighbors_getis.json ├── neighbors_markov.json ├── predict_data.json ├── segmentation_result.json └── true_result.json ├── helper.py ├── mock_plpy.py ├── test_clustering_getis.py ├── test_clustering_kmeans.py ├── test_clustering_moran.py ├── test_pysal_utils.py ├── test_regression_gwr.py ├── test_segmentation.py └── test_space_time_dynamics.py /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | - [ ] All declared geometries are `geometry(Geometry, 4326)` for general geoms, or `geometry(Point, 4326)` 3 | - [ ] Existing functions in crankshaft python library called from the extension are kept at least from version N to version N+1 (to avoid breakage during upgrades). 4 | - [ ] Docs for public-facing functions are written 5 | - [ ] New functions follow the naming conventions: `CDB_NameOfFunction`. Where internal functions begin with an underscore 6 | - [ ] Video explaining the analysis and showing examples 7 | - [ ] Analysis Documentation written [template](https://docs.google.com/a/cartodb.com/document/d/1X2KOtaiEBKWNMp8UjwcLB-kE9aIOw09aOjX3oaCjeME/edit?usp=sharing) 8 | - [ ] Smoke test written 9 | - [ ] Hand-off document for camshaft node written 10 | - [ ] If function is in Python, code conforms to [PEP8 Style Guide](https://www.python.org/dev/peps/pep-0008/) 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | envs/ 2 | *.pyc 3 | .DS_Store 4 | .idea/ 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, CartoDB 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /Makefile.global: -------------------------------------------------------------------------------- 1 | SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST))) 2 | EXTENSION = crankshaft 3 | PACKAGE = crankshaft 4 | EXTVERSION = $(shell grep default_version $(SELF_DIR)/src/pg/$(EXTENSION).control | sed -e "s/default_version[[:space:]]*=[[:space:]]*'\([^']*\)'/\1/") 5 | RELEASE_VERSION ?= $(EXTVERSION) 6 | 7 | SED = sed 8 | AWK = awk 9 | 10 | PG_CONFIG = pg_config 11 | PG_VERSION_1000 := $(shell $(PG_CONFIG) --version | $(AWK) '{$$2*=1000; print $$2}') 12 | PG_PARALLEL := $(shell [ $(PG_VERSION_1000) -ge 9600 ] && echo true) 13 | 14 | PG_12plus := $(shell [ $(PG_VERSION_1000) -ge 12000 ] && echo true) 15 | PYTHON3 ?= $(PG_12plus) 16 | 17 | ifeq ($(PYTHON3), true) 18 | PIP := python3 -m pip 19 | NOSETESTS = nosetests3 20 | else 21 | PIP := python2 -m pip 22 | NOSETESTS = nosetests 23 | endif 24 | -------------------------------------------------------------------------------- /carto-package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "crankshaft", 3 | "current_version": { 4 | "requires": { 5 | "postgres": ">=9.5.0", 6 | "postgis": ">=2.2.0.0", 7 | "python": ">=2.7.0", 8 | "joblib": "0.8.3", 9 | "numpy": "1.6.1", 10 | "scipy": "0.14.0", 11 | "pysal": "1.14.3", 12 | "scikit-learn": "0.14.1" 13 | }, 14 | "works_with": { 15 | } 16 | }, 17 | 18 | "exceptional_versions": { 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /check-up-to-date-with-master.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) 4 | 5 | if [[ "$CURRENT_BRANCH" == "master" || "$CURRENT_BRANCH" == "HEAD" ]] 6 | then 7 | echo "master branch or detached HEAD" 8 | exit 0 9 | fi 10 | 11 | # Add remote-master 12 | git remote add -t master remote-master https://github.com/CartoDB/crankshaft.git 13 | 14 | # Fetch master reference 15 | git fetch --depth=1 remote-master master 16 | 17 | # Compare HEAD with master 18 | # NOTE: travis by default uses --depth=50 so we are actually checking that the tip 19 | # of the branch is no more than 50 commits away from master as well. 20 | git rev-list HEAD | grep $(git rev-parse remote-master/master) || 21 | { echo "Your branch is not up to date with latest release"; 22 | echo "Please update it by running the following:"; 23 | echo " git fetch && git merge origin/develop"; 24 | false; } 25 | -------------------------------------------------------------------------------- /doc/03_overlap_sum.md: -------------------------------------------------------------------------------- 1 | ### Aereal Weighting 2 | 3 | Aereal weighting is a simple interpolation technique to assign a value 4 | to a polygon given a set of polygons with one value assigned to each one. 5 | 6 | The value is assigned by averaging the values of intersecting areas 7 | weighted by the intersection area. 8 | 9 | Its accuracy depends on the values assigned to reference areas being 10 | homogeneous over each area. 11 | 12 | The `cdb_overlap_function` takes three required parameters: 13 | 14 | * `geometry` a Polygon geometry which defines the area where a value will be 15 | estimated. 16 | * `table_name`: name of the values table that provides the source values; 17 | this table must have a geometric column `the_geom` containing the polygons 18 | to which values are assigned. 19 | * `column_name`: name of the column that contains the values in the values 20 | table (should be a numeric column) 21 | 22 | There's also an additional optional parameter to define the schema to which 23 | the values table belongs. This is necessary only if it is not in the 24 | `search_path`. Note that `table_name` should never include the schema in it. 25 | 26 | * `schema_name` name of the schema that contains the values table 27 | 28 | This function returns a numeric value resulting from the aggregation 29 | of the polygons in 30 | -------------------------------------------------------------------------------- /doc/04_pyAgg.md: -------------------------------------------------------------------------------- 1 | ## PyAgg Helper Function 2 | 3 | ### CDB_pyAgg (columns Numeric[]) 4 | 5 | Currently it's not possible to pass a multidiemensional array between plpsql and plpythonu. This function aims to 6 | help fix that by aggergating the columns provided in the argument across rows in to a rows * columns + 1 length 1D array. The first element of the array is the array\_length of the columns argument so that python can reconstruct 7 | the 2D array. 8 | 9 | #### Arguments 10 | 11 | | Name | Type | Description | 12 | |------|------|-------------| 13 | | columns | NUMERIC[] | The columns to aggregate across rows| 14 | 15 | #### Returns 16 | 17 | A table with the following columns. 18 | 19 | | Column Name | Type | Description | 20 | |-------------|------|-------------| 21 | | result | NUMERIC[] | An columns * rows + 1 array where the first entry is the no of columns| 22 | 23 | 24 | -------------------------------------------------------------------------------- /doc/14_densify.md: -------------------------------------------------------------------------------- 1 | ## Densify function 2 | 3 | Iterative densification of a set of scattered points using Delaunay triangulation. The new points are located at the centroids of the grid cells and have as assigned value the barycentric average value of the cell's vertex. 4 | 5 | ### CDB_Densify(geomin geometry[], colin numeric[], iterations integer) 6 | 7 | #### Arguments 8 | 9 | | Name | Type | Description | 10 | |------|------|-------------| 11 | | geomin | geometry[] | Array of points geometries | 12 | | colin | numeric[] | Array of points' values | 13 | | iterations | integer | Number of iterations | 14 | 15 | ### Returns 16 | 17 | Returns a table object 18 | 19 | | Name | Type | Description | 20 | |------|------|-------------| 21 | | geomout | geometry | Geometries of new dataset of points| 22 | | colout | numeric | Values of points| 23 | 24 | #### Example Usage 25 | 26 | ```sql 27 | WITH data as ( 28 | SELECT 29 | ARRAY[7.0,8.0,1.0,2.0,3.0,5.0,6.0,4.0] as colin, 30 | ARRAY[ 31 | ST_GeomFromText('POINT(2.1744 41.4036)'), 32 | ST_GeomFromText('POINT(2.1228 41.3809)'), 33 | ST_GeomFromText('POINT(2.1511 41.3742)'), 34 | ST_GeomFromText('POINT(2.1528 41.4136)'), 35 | ST_GeomFromText('POINT(2.165 41.3917)'), 36 | ST_GeomFromText('POINT(2.1498 41.3713)'), 37 | ST_GeomFromText('POINT(2.1533 41.3683)'), 38 | ST_GeomFromText('POINT(2.131386 41.413998)') 39 | ] as geomin 40 | ) 41 | SELECT cdb_crankshaft.CDB_Densify(geomin, colin, 2) 42 | FROM data 43 | ``` 44 | 45 | 46 | -------------------------------------------------------------------------------- /doc/15_tinmap.md: -------------------------------------------------------------------------------- 1 | ## TINMAP function 2 | 3 | Generates a fake contour map, in the form of a TIN map, from a set of scattered points.Depends on **CDB_Densify**. 4 | 5 | Its iterative nature lets the user smooth the final result as much as desired, but with a exponential time cost increase. 6 | 7 | ### CDB_TINmap(geomin geometry[], colin numeric[], iterations integer) 8 | 9 | #### Arguments 10 | 11 | | Name | Type | Description | 12 | |------|------|-------------| 13 | | geomin | geometry[] | Array of points geometries | 14 | | colin | numeric[] | Array of points' values | 15 | | iterations | integer | Number of iterations | 16 | 17 | ### Returns 18 | 19 | Returns a table object 20 | 21 | | Name | Type | Description | 22 | |------|------|-------------| 23 | | geomout | geometry | Geometries of new dataset of polygons| 24 | | colout | numeric | Values of each cell| 25 | 26 | #### Example Usage 27 | 28 | ```sql 29 | WITH data as ( 30 | SELECT 31 | ARRAY[7.0,8.0,1.0,2.0,3.0,5.0,6.0,4.0] as colin, 32 | ARRAY[ST_GeomFromText('POINT(2.1744 41.4036)'), 33 | ST_GeomFromText('POINT(2.1228 41.3809)'), 34 | ST_GeomFromText('POINT(2.1511 41.3742)'), 35 | ST_GeomFromText('POINT(2.1528 41.4136)'), 36 | ST_GeomFromText('POINT(2.165 41.3917)'), 37 | ST_GeomFromText('POINT(2.1498 41.3713)'), 38 | ST_GeomFromText('POINT(2.1533 41.3683)'), 39 | ST_GeomFromText('POINT(2.131386 41.413998)')] as geomin 40 | ) 41 | SELECT cdb_crankshaft.CDB_TINmap(geomin, colin, 2) 42 | FROM data 43 | ``` 44 | 45 | -------------------------------------------------------------------------------- /doc/docs_template.md: -------------------------------------------------------------------------------- 1 | 2 | ## Name 3 | 4 | ## Synopsis 5 | 6 | ## Description 7 | 8 | Availability: v... 9 | 10 | ## Examples 11 | 12 | ```SQL 13 | -- example of the function in use 14 | SELECT cdb_awesome_function(the_geom, 'total_pop') 15 | FROM table_name 16 | ``` 17 | 18 | ## API Usage 19 | 20 | _asdf_ 21 | 22 | ## See Also 23 | 24 | _Other function pages_ 25 | -------------------------------------------------------------------------------- /release/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CartoDB/crankshaft/494c047563328b092fe5fe0b8b4dd862edfee836/release/.gitignore -------------------------------------------------------------------------------- /release/crankshaft--0.0.3--0.0.4.sql: -------------------------------------------------------------------------------- 1 | --DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES 2 | -- Complain if script is sourced in psql, rather than via CREATE EXTENSION 3 | \echo Use "CREATE EXTENSION crankshaft" to load this file. \quit 4 | -- Version number of the extension release 5 | CREATE OR REPLACE FUNCTION cdb_crankshaft_version() 6 | RETURNS text AS $$ 7 | SELECT '0.0.4'::text; 8 | $$ language 'sql' STABLE STRICT; 9 | -------------------------------------------------------------------------------- /release/crankshaft--0.0.4--0.0.3.sql: -------------------------------------------------------------------------------- 1 | --DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES 2 | -- Complain if script is sourced in psql, rather than via CREATE EXTENSION 3 | \echo Use "CREATE EXTENSION crankshaft" to load this file. \quit 4 | -- Version number of the extension release 5 | CREATE OR REPLACE FUNCTION cdb_crankshaft_version() 6 | RETURNS text AS $$ 7 | SELECT '0.0.3'::text; 8 | $$ language 'sql' STABLE STRICT; 9 | -------------------------------------------------------------------------------- /release/crankshaft.control: -------------------------------------------------------------------------------- 1 | comment = 'CartoDB Spatial Analysis extension' 2 | default_version = '0.9.0' 3 | requires = 'plpython3u, postgis' 4 | superuser = true 5 | schema = cdb_crankshaft 6 | -------------------------------------------------------------------------------- /release/python/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CartoDB/crankshaft/494c047563328b092fe5fe0b8b4dd862edfee836/release/python/.gitignore -------------------------------------------------------------------------------- /release/python/0.0.1/crankshaft/crankshaft/__init__.py: -------------------------------------------------------------------------------- 1 | import random_seeds 2 | import clustering 3 | -------------------------------------------------------------------------------- /release/python/0.0.1/crankshaft/crankshaft/clustering/__init__.py: -------------------------------------------------------------------------------- 1 | from moran import * 2 | -------------------------------------------------------------------------------- /release/python/0.0.1/crankshaft/crankshaft/random_seeds.py: -------------------------------------------------------------------------------- 1 | import random 2 | import numpy 3 | 4 | def set_random_seeds(value): 5 | """ 6 | Set the seeds of the RNGs (Random Number Generators) 7 | used internally. 8 | """ 9 | random.seed(value) 10 | numpy.random.seed(value) 11 | -------------------------------------------------------------------------------- /release/python/0.0.1/crankshaft/setup.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | CartoDB Spatial Analysis Python Library 4 | See: 5 | https://github.com/CartoDB/crankshaft 6 | """ 7 | 8 | from setuptools import setup, find_packages 9 | 10 | setup( 11 | name='crankshaft', 12 | 13 | version='0.0.01', 14 | 15 | description='CartoDB Spatial Analysis Python Library', 16 | 17 | url='https://github.com/CartoDB/crankshaft', 18 | 19 | author='Data Services Team - CartoDB', 20 | author_email='dataservices@cartodb.com', 21 | 22 | license='MIT', 23 | 24 | classifiers=[ 25 | 'Development Status :: 3 - Alpha', 26 | 'Intended Audience :: Mapping comunity', 27 | 'Topic :: Maps :: Mapping Tools', 28 | 'License :: OSI Approved :: MIT License', 29 | 'Programming Language :: Python :: 2.7', 30 | ], 31 | 32 | keywords='maps mapping tools spatial analysis geostatistics', 33 | 34 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 35 | 36 | extras_require={ 37 | 'dev': ['unittest'], 38 | 'test': ['unittest', 'nose', 'mock'], 39 | }, 40 | 41 | # The choice of component versions is dictated by what's 42 | # provisioned in the production servers. 43 | install_requires=['pysal==1.11.0','numpy==1.6.1','scipy==0.17.0'], 44 | 45 | requires=['pysal', 'numpy'], 46 | 47 | test_suite='test' 48 | ) 49 | -------------------------------------------------------------------------------- /release/python/0.0.1/crankshaft/test/helper.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from mock_plpy import MockPlPy 4 | plpy = MockPlPy() 5 | 6 | import sys 7 | sys.modules['plpy'] = plpy 8 | 9 | import os 10 | 11 | def fixture_file(name): 12 | dir = os.path.dirname(os.path.realpath(__file__)) 13 | return os.path.join(dir, 'fixtures', name) 14 | -------------------------------------------------------------------------------- /release/python/0.0.1/crankshaft/test/mock_plpy.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | class MockPlPy: 4 | def __init__(self): 5 | self._reset() 6 | 7 | def _reset(self): 8 | self.infos = [] 9 | self.notices = [] 10 | self.debugs = [] 11 | self.logs = [] 12 | self.warnings = [] 13 | self.errors = [] 14 | self.fatals = [] 15 | self.executes = [] 16 | self.results = [] 17 | self.prepares = [] 18 | self.results = [] 19 | 20 | def _define_result(self, query, result): 21 | pattern = re.compile(query, re.IGNORECASE | re.MULTILINE) 22 | self.results.append([pattern, result]) 23 | 24 | def notice(self, msg): 25 | self.notices.append(msg) 26 | 27 | def info(self, msg): 28 | self.infos.append(msg) 29 | 30 | def execute(self, query): # TODO: additional arguments 31 | for result in self.results: 32 | if result[0].match(query): 33 | return result[1] 34 | return [] 35 | -------------------------------------------------------------------------------- /release/python/0.0.2/crankshaft/crankshaft/__init__.py: -------------------------------------------------------------------------------- 1 | import random_seeds 2 | import clustering 3 | -------------------------------------------------------------------------------- /release/python/0.0.2/crankshaft/crankshaft/clustering/__init__.py: -------------------------------------------------------------------------------- 1 | from moran import * 2 | -------------------------------------------------------------------------------- /release/python/0.0.2/crankshaft/crankshaft/random_seeds.py: -------------------------------------------------------------------------------- 1 | import random 2 | import numpy 3 | 4 | def set_random_seeds(value): 5 | """ 6 | Set the seeds of the RNGs (Random Number Generators) 7 | used internally. 8 | """ 9 | random.seed(value) 10 | numpy.random.seed(value) 11 | -------------------------------------------------------------------------------- /release/python/0.0.2/crankshaft/setup.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | CartoDB Spatial Analysis Python Library 4 | See: 5 | https://github.com/CartoDB/crankshaft 6 | """ 7 | 8 | from setuptools import setup, find_packages 9 | 10 | setup( 11 | name='crankshaft', 12 | 13 | version='0.0.2', 14 | 15 | description='CartoDB Spatial Analysis Python Library', 16 | 17 | url='https://github.com/CartoDB/crankshaft', 18 | 19 | author='Data Services Team - CartoDB', 20 | author_email='dataservices@cartodb.com', 21 | 22 | license='MIT', 23 | 24 | classifiers=[ 25 | 'Development Status :: 3 - Alpha', 26 | 'Intended Audience :: Mapping comunity', 27 | 'Topic :: Maps :: Mapping Tools', 28 | 'License :: OSI Approved :: MIT License', 29 | 'Programming Language :: Python :: 2.7', 30 | ], 31 | 32 | keywords='maps mapping tools spatial analysis geostatistics', 33 | 34 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 35 | 36 | extras_require={ 37 | 'dev': ['unittest'], 38 | 'test': ['unittest', 'nose', 'mock'], 39 | }, 40 | 41 | # The choice of component versions is dictated by what's 42 | # provisioned in the production servers. 43 | install_requires=['pysal==1.9.1'], 44 | 45 | requires=['pysal', 'numpy' ], 46 | 47 | test_suite='test' 48 | ) 49 | -------------------------------------------------------------------------------- /release/python/0.0.2/crankshaft/test/helper.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from mock_plpy import MockPlPy 4 | plpy = MockPlPy() 5 | 6 | import sys 7 | sys.modules['plpy'] = plpy 8 | 9 | import os 10 | 11 | def fixture_file(name): 12 | dir = os.path.dirname(os.path.realpath(__file__)) 13 | return os.path.join(dir, 'fixtures', name) 14 | -------------------------------------------------------------------------------- /release/python/0.0.2/crankshaft/test/mock_plpy.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | class MockPlPy: 4 | def __init__(self): 5 | self._reset() 6 | 7 | def _reset(self): 8 | self.infos = [] 9 | self.notices = [] 10 | self.debugs = [] 11 | self.logs = [] 12 | self.warnings = [] 13 | self.errors = [] 14 | self.fatals = [] 15 | self.executes = [] 16 | self.results = [] 17 | self.prepares = [] 18 | self.results = [] 19 | 20 | def _define_result(self, query, result): 21 | pattern = re.compile(query, re.IGNORECASE | re.MULTILINE) 22 | self.results.append([pattern, result]) 23 | 24 | def notice(self, msg): 25 | self.notices.append(msg) 26 | 27 | def info(self, msg): 28 | self.infos.append(msg) 29 | 30 | def execute(self, query): # TODO: additional arguments 31 | for result in self.results: 32 | if result[0].match(query): 33 | return result[1] 34 | return [] 35 | -------------------------------------------------------------------------------- /release/python/0.0.3/crankshaft/crankshaft/__init__.py: -------------------------------------------------------------------------------- 1 | import random_seeds 2 | import clustering 3 | -------------------------------------------------------------------------------- /release/python/0.0.3/crankshaft/crankshaft/clustering/__init__.py: -------------------------------------------------------------------------------- 1 | from moran import * 2 | from kmeans import * 3 | -------------------------------------------------------------------------------- /release/python/0.0.3/crankshaft/crankshaft/clustering/kmeans.py: -------------------------------------------------------------------------------- 1 | from sklearn.cluster import KMeans 2 | import plpy 3 | 4 | def kmeans(query, no_clusters, no_init=20): 5 | data = plpy.execute('''select array_agg(cartodb_id order by cartodb_id) as ids, 6 | array_agg(ST_X(the_geom) order by cartodb_id) xs, 7 | array_agg(ST_Y(the_geom) order by cartodb_id) ys from ({query}) a 8 | where the_geom is not null 9 | '''.format(query=query)) 10 | 11 | xs = data[0]['xs'] 12 | ys = data[0]['ys'] 13 | ids = data[0]['ids'] 14 | 15 | km = KMeans(n_clusters= no_clusters, n_init=no_init) 16 | labels = km.fit_predict(zip(xs,ys)) 17 | return zip(ids,labels) 18 | 19 | -------------------------------------------------------------------------------- /release/python/0.0.3/crankshaft/crankshaft/pysal_utils/__init__.py: -------------------------------------------------------------------------------- 1 | from pysal_utils import * 2 | -------------------------------------------------------------------------------- /release/python/0.0.3/crankshaft/crankshaft/random_seeds.py: -------------------------------------------------------------------------------- 1 | import random 2 | import numpy 3 | 4 | def set_random_seeds(value): 5 | """ 6 | Set the seeds of the RNGs (Random Number Generators) 7 | used internally. 8 | """ 9 | random.seed(value) 10 | numpy.random.seed(value) 11 | -------------------------------------------------------------------------------- /release/python/0.0.3/crankshaft/setup.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | CartoDB Spatial Analysis Python Library 4 | See: 5 | https://github.com/CartoDB/crankshaft 6 | """ 7 | 8 | from setuptools import setup, find_packages 9 | 10 | setup( 11 | name='crankshaft', 12 | 13 | version='0.0.3', 14 | 15 | description='CartoDB Spatial Analysis Python Library', 16 | 17 | url='https://github.com/CartoDB/crankshaft', 18 | 19 | author='Data Services Team - CartoDB', 20 | author_email='dataservices@cartodb.com', 21 | 22 | license='MIT', 23 | 24 | classifiers=[ 25 | 'Development Status :: 3 - Alpha', 26 | 'Intended Audience :: Mapping comunity', 27 | 'Topic :: Maps :: Mapping Tools', 28 | 'License :: OSI Approved :: MIT License', 29 | 'Programming Language :: Python :: 2.7', 30 | ], 31 | 32 | keywords='maps mapping tools spatial analysis geostatistics', 33 | 34 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 35 | 36 | extras_require={ 37 | 'dev': ['unittest'], 38 | 'test': ['unittest', 'nose', 'mock'], 39 | }, 40 | 41 | # The choice of component versions is dictated by what's 42 | # provisioned in the production servers. 43 | install_requires=['pysal==1.9.1', 'scikit-learn==0.17.1'], 44 | 45 | requires=['pysal', 'numpy', 'sklearn'], 46 | 47 | test_suite='test' 48 | ) 49 | -------------------------------------------------------------------------------- /release/python/0.0.3/crankshaft/test/fixtures/moran.json: -------------------------------------------------------------------------------- 1 | [[0.9319096128346788, "HH"], 2 | [-1.135787401862846, "HL"], 3 | [0.11732030672508517, "LL"], 4 | [0.6152779669180425, "LL"], 5 | [-0.14657336660125297, "LH"], 6 | [0.6967858120189607, "LL"], 7 | [0.07949310115714454, "HH"], 8 | [0.4703198759258987, "HH"], 9 | [0.4421125200498064, "HH"], 10 | [0.5724288737143592, "LL"], 11 | [0.8970743435692062, "LL"], 12 | [0.18327334401918674, "LL"], 13 | [-0.01466729201304962, "HL"], 14 | [0.3481559372544409, "LL"], 15 | [0.06547094736902978, "LL"], 16 | [0.15482141569329988, "HH"], 17 | [0.4373841193538136, "HH"], 18 | [0.15971286468915544, "LL"], 19 | [1.0543588860308968, "HH"], 20 | [1.7372866900020818, "HH"], 21 | [1.091998586053999, "LL"], 22 | [0.1171572584252222, "HH"], 23 | [0.08438455015300014, "LL"], 24 | [0.06547094736902978, "LL"], 25 | [0.15482141569329985, "HH"], 26 | [1.1627044812890683, "HH"], 27 | [0.06547094736902978, "LL"], 28 | [0.795275137550483, "HH"], 29 | [0.18562939195219, "LL"], 30 | [0.3010757406693439, "LL"], 31 | [2.8205795942839376, "HH"], 32 | [0.11259190602909264, "LL"], 33 | [-0.07116352791516614, "HL"], 34 | [-0.09945240794119009, "LH"], 35 | [0.18562939195219, "LL"], 36 | [0.1832733440191868, "LL"], 37 | [-0.39054253768447705, "HL"], 38 | [-0.1672071289487642, "HL"], 39 | [0.3337669247916343, "HH"], 40 | [0.2584386102554792, "HH"], 41 | [-0.19733845476322634, "HL"], 42 | [-0.9379282899805409, "LH"], 43 | [-0.028770969951095866, "LH"], 44 | [0.051367269430983485, "LL"], 45 | [-0.2172548045913472, "LH"], 46 | [0.05136726943098351, "LL"], 47 | [0.04191046803899837, "LL"], 48 | [0.7482357030403517, "HH"], 49 | [-0.014585767863118111, "LH"], 50 | [0.5410013139159929, "HH"], 51 | [1.0223932668429925, "LL"], 52 | [1.4179402898927476, "LL"]] -------------------------------------------------------------------------------- /release/python/0.0.3/crankshaft/test/helper.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from mock_plpy import MockPlPy 4 | plpy = MockPlPy() 5 | 6 | import sys 7 | sys.modules['plpy'] = plpy 8 | 9 | import os 10 | 11 | def fixture_file(name): 12 | dir = os.path.dirname(os.path.realpath(__file__)) 13 | return os.path.join(dir, 'fixtures', name) 14 | -------------------------------------------------------------------------------- /release/python/0.0.3/crankshaft/test/mock_plpy.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | class MockPlPy: 4 | def __init__(self): 5 | self._reset() 6 | 7 | def _reset(self): 8 | self.infos = [] 9 | self.notices = [] 10 | self.debugs = [] 11 | self.logs = [] 12 | self.warnings = [] 13 | self.errors = [] 14 | self.fatals = [] 15 | self.executes = [] 16 | self.results = [] 17 | self.prepares = [] 18 | self.results = [] 19 | 20 | def _define_result(self, query, result): 21 | pattern = re.compile(query, re.IGNORECASE | re.MULTILINE) 22 | self.results.append([pattern, result]) 23 | 24 | def notice(self, msg): 25 | self.notices.append(msg) 26 | 27 | def info(self, msg): 28 | self.infos.append(msg) 29 | 30 | def execute(self, query): # TODO: additional arguments 31 | for result in self.results: 32 | if result[0].match(query): 33 | return result[1] 34 | return [] 35 | -------------------------------------------------------------------------------- /release/python/0.0.3/crankshaft/test/test_cluster_kmeans.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import numpy as np 3 | 4 | 5 | # from mock_plpy import MockPlPy 6 | # plpy = MockPlPy() 7 | # 8 | # import sys 9 | # sys.modules['plpy'] = plpy 10 | from helper import plpy, fixture_file 11 | import numpy as np 12 | import crankshaft.clustering as cc 13 | import crankshaft.pysal_utils as pu 14 | from crankshaft import random_seeds 15 | import json 16 | 17 | class KMeansTest(unittest.TestCase): 18 | """Testing class for Moran's I functions""" 19 | 20 | def setUp(self): 21 | plpy._reset() 22 | self.cluster_data = json.loads(open(fixture_file('kmeans.json')).read()) 23 | self.params = {"subquery": "select * from table", 24 | "no_clusters": "10" 25 | } 26 | 27 | def test_kmeans(self): 28 | data = self.cluster_data 29 | plpy._define_result('select' ,data) 30 | clusters = cc.kmeans('subquery', 2) 31 | labels = [a[1] for a in clusters] 32 | c1 = [a for a in clusters if a[1]==0] 33 | c2 = [a for a in clusters if a[1]==1] 34 | 35 | self.assertEqual(len(np.unique(labels)),2) 36 | self.assertEqual(len(c1),20) 37 | self.assertEqual(len(c2),20) 38 | 39 | -------------------------------------------------------------------------------- /release/python/0.0.4/crankshaft/crankshaft/__init__.py: -------------------------------------------------------------------------------- 1 | import random_seeds 2 | import clustering 3 | -------------------------------------------------------------------------------- /release/python/0.0.4/crankshaft/crankshaft/clustering/__init__.py: -------------------------------------------------------------------------------- 1 | from moran import * 2 | from kmeans import * 3 | -------------------------------------------------------------------------------- /release/python/0.0.4/crankshaft/crankshaft/clustering/kmeans.py: -------------------------------------------------------------------------------- 1 | from sklearn.cluster import KMeans 2 | import plpy 3 | 4 | def kmeans(query, no_clusters, no_init=20): 5 | data = plpy.execute('''select array_agg(cartodb_id order by cartodb_id) as ids, 6 | array_agg(ST_X(the_geom) order by cartodb_id) xs, 7 | array_agg(ST_Y(the_geom) order by cartodb_id) ys from ({query}) a 8 | where the_geom is not null 9 | '''.format(query=query)) 10 | 11 | xs = data[0]['xs'] 12 | ys = data[0]['ys'] 13 | ids = data[0]['ids'] 14 | 15 | km = KMeans(n_clusters= no_clusters, n_init=no_init) 16 | labels = km.fit_predict(zip(xs,ys)) 17 | return zip(ids,labels) 18 | 19 | -------------------------------------------------------------------------------- /release/python/0.0.4/crankshaft/crankshaft/pysal_utils/__init__.py: -------------------------------------------------------------------------------- 1 | from pysal_utils import * 2 | -------------------------------------------------------------------------------- /release/python/0.0.4/crankshaft/crankshaft/random_seeds.py: -------------------------------------------------------------------------------- 1 | import random 2 | import numpy 3 | 4 | def set_random_seeds(value): 5 | """ 6 | Set the seeds of the RNGs (Random Number Generators) 7 | used internally. 8 | """ 9 | random.seed(value) 10 | numpy.random.seed(value) 11 | -------------------------------------------------------------------------------- /release/python/0.0.4/crankshaft/setup.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | CartoDB Spatial Analysis Python Library 4 | See: 5 | https://github.com/CartoDB/crankshaft 6 | """ 7 | 8 | from setuptools import setup, find_packages 9 | 10 | setup( 11 | name='crankshaft', 12 | 13 | version='0.0.4', 14 | 15 | description='CartoDB Spatial Analysis Python Library', 16 | 17 | url='https://github.com/CartoDB/crankshaft', 18 | 19 | author='Data Services Team - CartoDB', 20 | author_email='dataservices@cartodb.com', 21 | 22 | license='MIT', 23 | 24 | classifiers=[ 25 | 'Development Status :: 3 - Alpha', 26 | 'Intended Audience :: Mapping comunity', 27 | 'Topic :: Maps :: Mapping Tools', 28 | 'License :: OSI Approved :: MIT License', 29 | 'Programming Language :: Python :: 2.7', 30 | ], 31 | 32 | keywords='maps mapping tools spatial analysis geostatistics', 33 | 34 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 35 | 36 | extras_require={ 37 | 'dev': ['unittest'], 38 | 'test': ['unittest', 'nose', 'mock'], 39 | }, 40 | 41 | # The choice of component versions is dictated by what's 42 | # provisioned in the production servers. 43 | install_requires=['joblib==0.8.3', 'numpy==1.6.1', 'scipy==0.14.0', 'pysal==1.11.2', 'scikit-learn==0.14.1'], 44 | 45 | requires=['pysal', 'numpy', 'sklearn'], 46 | 47 | test_suite='test' 48 | ) 49 | -------------------------------------------------------------------------------- /release/python/0.0.4/crankshaft/test/fixtures/moran.json: -------------------------------------------------------------------------------- 1 | [[0.9319096128346788, "HH"], 2 | [-1.135787401862846, "HL"], 3 | [0.11732030672508517, "LL"], 4 | [0.6152779669180425, "LL"], 5 | [-0.14657336660125297, "LH"], 6 | [0.6967858120189607, "LL"], 7 | [0.07949310115714454, "HH"], 8 | [0.4703198759258987, "HH"], 9 | [0.4421125200498064, "HH"], 10 | [0.5724288737143592, "LL"], 11 | [0.8970743435692062, "LL"], 12 | [0.18327334401918674, "LL"], 13 | [-0.01466729201304962, "HL"], 14 | [0.3481559372544409, "LL"], 15 | [0.06547094736902978, "LL"], 16 | [0.15482141569329988, "HH"], 17 | [0.4373841193538136, "HH"], 18 | [0.15971286468915544, "LL"], 19 | [1.0543588860308968, "HH"], 20 | [1.7372866900020818, "HH"], 21 | [1.091998586053999, "LL"], 22 | [0.1171572584252222, "HH"], 23 | [0.08438455015300014, "LL"], 24 | [0.06547094736902978, "LL"], 25 | [0.15482141569329985, "HH"], 26 | [1.1627044812890683, "HH"], 27 | [0.06547094736902978, "LL"], 28 | [0.795275137550483, "HH"], 29 | [0.18562939195219, "LL"], 30 | [0.3010757406693439, "LL"], 31 | [2.8205795942839376, "HH"], 32 | [0.11259190602909264, "LL"], 33 | [-0.07116352791516614, "HL"], 34 | [-0.09945240794119009, "LH"], 35 | [0.18562939195219, "LL"], 36 | [0.1832733440191868, "LL"], 37 | [-0.39054253768447705, "HL"], 38 | [-0.1672071289487642, "HL"], 39 | [0.3337669247916343, "HH"], 40 | [0.2584386102554792, "HH"], 41 | [-0.19733845476322634, "HL"], 42 | [-0.9379282899805409, "LH"], 43 | [-0.028770969951095866, "LH"], 44 | [0.051367269430983485, "LL"], 45 | [-0.2172548045913472, "LH"], 46 | [0.05136726943098351, "LL"], 47 | [0.04191046803899837, "LL"], 48 | [0.7482357030403517, "HH"], 49 | [-0.014585767863118111, "LH"], 50 | [0.5410013139159929, "HH"], 51 | [1.0223932668429925, "LL"], 52 | [1.4179402898927476, "LL"]] -------------------------------------------------------------------------------- /release/python/0.0.4/crankshaft/test/helper.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from mock_plpy import MockPlPy 4 | plpy = MockPlPy() 5 | 6 | import sys 7 | sys.modules['plpy'] = plpy 8 | 9 | import os 10 | 11 | def fixture_file(name): 12 | dir = os.path.dirname(os.path.realpath(__file__)) 13 | return os.path.join(dir, 'fixtures', name) 14 | -------------------------------------------------------------------------------- /release/python/0.0.4/crankshaft/test/mock_plpy.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | class MockPlPy: 4 | def __init__(self): 5 | self._reset() 6 | 7 | def _reset(self): 8 | self.infos = [] 9 | self.notices = [] 10 | self.debugs = [] 11 | self.logs = [] 12 | self.warnings = [] 13 | self.errors = [] 14 | self.fatals = [] 15 | self.executes = [] 16 | self.results = [] 17 | self.prepares = [] 18 | self.results = [] 19 | 20 | def _define_result(self, query, result): 21 | pattern = re.compile(query, re.IGNORECASE | re.MULTILINE) 22 | self.results.append([pattern, result]) 23 | 24 | def notice(self, msg): 25 | self.notices.append(msg) 26 | 27 | def info(self, msg): 28 | self.infos.append(msg) 29 | 30 | def execute(self, query): # TODO: additional arguments 31 | for result in self.results: 32 | if result[0].match(query): 33 | return result[1] 34 | return [] 35 | -------------------------------------------------------------------------------- /release/python/0.0.4/crankshaft/test/test_cluster_kmeans.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import numpy as np 3 | 4 | 5 | # from mock_plpy import MockPlPy 6 | # plpy = MockPlPy() 7 | # 8 | # import sys 9 | # sys.modules['plpy'] = plpy 10 | from helper import plpy, fixture_file 11 | import numpy as np 12 | import crankshaft.clustering as cc 13 | import crankshaft.pysal_utils as pu 14 | from crankshaft import random_seeds 15 | import json 16 | 17 | class KMeansTest(unittest.TestCase): 18 | """Testing class for Moran's I functions""" 19 | 20 | def setUp(self): 21 | plpy._reset() 22 | self.cluster_data = json.loads(open(fixture_file('kmeans.json')).read()) 23 | self.params = {"subquery": "select * from table", 24 | "no_clusters": "10" 25 | } 26 | 27 | def test_kmeans(self): 28 | data = self.cluster_data 29 | plpy._define_result('select' ,data) 30 | clusters = cc.kmeans('subquery', 2) 31 | labels = [a[1] for a in clusters] 32 | c1 = [a for a in clusters if a[1]==0] 33 | c2 = [a for a in clusters if a[1]==1] 34 | 35 | self.assertEqual(len(np.unique(labels)),2) 36 | self.assertEqual(len(c1),20) 37 | self.assertEqual(len(c2),20) 38 | 39 | -------------------------------------------------------------------------------- /release/python/0.1.0/crankshaft/crankshaft/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all modules""" 2 | import crankshaft.random_seeds 3 | import crankshaft.clustering 4 | import crankshaft.space_time_dynamics 5 | import crankshaft.segmentation 6 | -------------------------------------------------------------------------------- /release/python/0.1.0/crankshaft/crankshaft/clustering/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from for clustering""" 2 | from moran import * 3 | from kmeans import * 4 | -------------------------------------------------------------------------------- /release/python/0.1.0/crankshaft/crankshaft/clustering/kmeans.py: -------------------------------------------------------------------------------- 1 | from sklearn.cluster import KMeans 2 | import plpy 3 | 4 | def kmeans(query, no_clusters, no_init=20): 5 | data = plpy.execute('''select array_agg(cartodb_id order by cartodb_id) as ids, 6 | array_agg(ST_X(the_geom) order by cartodb_id) xs, 7 | array_agg(ST_Y(the_geom) order by cartodb_id) ys from ({query}) a 8 | where the_geom is not null 9 | '''.format(query=query)) 10 | 11 | xs = data[0]['xs'] 12 | ys = data[0]['ys'] 13 | ids = data[0]['ids'] 14 | 15 | km = KMeans(n_clusters= no_clusters, n_init=no_init) 16 | labels = km.fit_predict(zip(xs,ys)) 17 | return zip(ids,labels) 18 | 19 | -------------------------------------------------------------------------------- /release/python/0.1.0/crankshaft/crankshaft/pysal_utils/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions for pysal_utils""" 2 | from crankshaft.pysal_utils.pysal_utils import * 3 | -------------------------------------------------------------------------------- /release/python/0.1.0/crankshaft/crankshaft/random_seeds.py: -------------------------------------------------------------------------------- 1 | """Random seed generator used for non-deterministic functions in crankshaft""" 2 | import random 3 | import numpy 4 | 5 | def set_random_seeds(value): 6 | """ 7 | Set the seeds of the RNGs (Random Number Generators) 8 | used internally. 9 | """ 10 | random.seed(value) 11 | numpy.random.seed(value) 12 | -------------------------------------------------------------------------------- /release/python/0.1.0/crankshaft/crankshaft/segmentation/__init__.py: -------------------------------------------------------------------------------- 1 | from segmentation import * 2 | -------------------------------------------------------------------------------- /release/python/0.1.0/crankshaft/crankshaft/space_time_dynamics/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from clustering libraries.""" 2 | from markov import * 3 | -------------------------------------------------------------------------------- /release/python/0.1.0/crankshaft/setup.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | CartoDB Spatial Analysis Python Library 4 | See: 5 | https://github.com/CartoDB/crankshaft 6 | """ 7 | 8 | from setuptools import setup, find_packages 9 | 10 | setup( 11 | name='crankshaft', 12 | 13 | version='0.1.0', 14 | 15 | description='CartoDB Spatial Analysis Python Library', 16 | 17 | url='https://github.com/CartoDB/crankshaft', 18 | 19 | author='Data Services Team - CartoDB', 20 | author_email='dataservices@cartodb.com', 21 | 22 | license='MIT', 23 | 24 | classifiers=[ 25 | 'Development Status :: 3 - Alpha', 26 | 'Intended Audience :: Mapping comunity', 27 | 'Topic :: Maps :: Mapping Tools', 28 | 'License :: OSI Approved :: MIT License', 29 | 'Programming Language :: Python :: 2.7', 30 | ], 31 | 32 | keywords='maps mapping tools spatial analysis geostatistics', 33 | 34 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 35 | 36 | extras_require={ 37 | 'dev': ['unittest'], 38 | 'test': ['unittest', 'nose', 'mock'], 39 | }, 40 | 41 | # The choice of component versions is dictated by what's 42 | # provisioned in the production servers. 43 | # IMPORTANT NOTE: please don't change this line. Instead issue a ticket to systems for evaluation. 44 | install_requires=['joblib==0.8.3', 'numpy==1.6.1', 'scipy==0.14.0', 'pysal==1.11.2', 'scikit-learn==0.14.1'], 45 | 46 | requires=['pysal', 'numpy', 'sklearn'], 47 | 48 | test_suite='test' 49 | ) 50 | -------------------------------------------------------------------------------- /release/python/0.1.0/crankshaft/test/fixtures/moran.json: -------------------------------------------------------------------------------- 1 | [[0.9319096128346788, "HH"], 2 | [-1.135787401862846, "HL"], 3 | [0.11732030672508517, "LL"], 4 | [0.6152779669180425, "LL"], 5 | [-0.14657336660125297, "LH"], 6 | [0.6967858120189607, "LL"], 7 | [0.07949310115714454, "HH"], 8 | [0.4703198759258987, "HH"], 9 | [0.4421125200498064, "HH"], 10 | [0.5724288737143592, "LL"], 11 | [0.8970743435692062, "LL"], 12 | [0.18327334401918674, "LL"], 13 | [-0.01466729201304962, "HL"], 14 | [0.3481559372544409, "LL"], 15 | [0.06547094736902978, "LL"], 16 | [0.15482141569329988, "HH"], 17 | [0.4373841193538136, "HH"], 18 | [0.15971286468915544, "LL"], 19 | [1.0543588860308968, "HH"], 20 | [1.7372866900020818, "HH"], 21 | [1.091998586053999, "LL"], 22 | [0.1171572584252222, "HH"], 23 | [0.08438455015300014, "LL"], 24 | [0.06547094736902978, "LL"], 25 | [0.15482141569329985, "HH"], 26 | [1.1627044812890683, "HH"], 27 | [0.06547094736902978, "LL"], 28 | [0.795275137550483, "HH"], 29 | [0.18562939195219, "LL"], 30 | [0.3010757406693439, "LL"], 31 | [2.8205795942839376, "HH"], 32 | [0.11259190602909264, "LL"], 33 | [-0.07116352791516614, "HL"], 34 | [-0.09945240794119009, "LH"], 35 | [0.18562939195219, "LL"], 36 | [0.1832733440191868, "LL"], 37 | [-0.39054253768447705, "HL"], 38 | [-0.1672071289487642, "HL"], 39 | [0.3337669247916343, "HH"], 40 | [0.2584386102554792, "HH"], 41 | [-0.19733845476322634, "HL"], 42 | [-0.9379282899805409, "LH"], 43 | [-0.028770969951095866, "LH"], 44 | [0.051367269430983485, "LL"], 45 | [-0.2172548045913472, "LH"], 46 | [0.05136726943098351, "LL"], 47 | [0.04191046803899837, "LL"], 48 | [0.7482357030403517, "HH"], 49 | [-0.014585767863118111, "LH"], 50 | [0.5410013139159929, "HH"], 51 | [1.0223932668429925, "LL"], 52 | [1.4179402898927476, "LL"]] -------------------------------------------------------------------------------- /release/python/0.1.0/crankshaft/test/helper.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from mock_plpy import MockPlPy 4 | plpy = MockPlPy() 5 | 6 | import sys 7 | sys.modules['plpy'] = plpy 8 | 9 | import os 10 | 11 | def fixture_file(name): 12 | dir = os.path.dirname(os.path.realpath(__file__)) 13 | return os.path.join(dir, 'fixtures', name) 14 | -------------------------------------------------------------------------------- /release/python/0.1.0/crankshaft/test/mock_plpy.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | class MockCursor: 4 | def __init__(self, data): 5 | self.cursor_pos = 0 6 | self.data = data 7 | 8 | def fetch(self, batch_size): 9 | batch = self.data[self.cursor_pos : self.cursor_pos + batch_size] 10 | self.cursor_pos += batch_size 11 | return batch 12 | 13 | 14 | class MockPlPy: 15 | def __init__(self): 16 | self._reset() 17 | 18 | def _reset(self): 19 | self.infos = [] 20 | self.notices = [] 21 | self.debugs = [] 22 | self.logs = [] 23 | self.warnings = [] 24 | self.errors = [] 25 | self.fatals = [] 26 | self.executes = [] 27 | self.results = [] 28 | self.prepares = [] 29 | self.results = [] 30 | 31 | def _define_result(self, query, result): 32 | pattern = re.compile(query, re.IGNORECASE | re.MULTILINE) 33 | self.results.append([pattern, result]) 34 | 35 | def notice(self, msg): 36 | self.notices.append(msg) 37 | 38 | def debug(self, msg): 39 | self.notices.append(msg) 40 | 41 | def info(self, msg): 42 | self.infos.append(msg) 43 | 44 | def cursor(self, query): 45 | data = self.execute(query) 46 | return MockCursor(data) 47 | 48 | def execute(self, query): # TODO: additional arguments 49 | for result in self.results: 50 | if result[0].match(query): 51 | return result[1] 52 | return [] 53 | -------------------------------------------------------------------------------- /release/python/0.1.0/crankshaft/test/test_cluster_kmeans.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import numpy as np 3 | 4 | 5 | # from mock_plpy import MockPlPy 6 | # plpy = MockPlPy() 7 | # 8 | # import sys 9 | # sys.modules['plpy'] = plpy 10 | from helper import plpy, fixture_file 11 | import numpy as np 12 | import crankshaft.clustering as cc 13 | import crankshaft.pysal_utils as pu 14 | from crankshaft import random_seeds 15 | import json 16 | 17 | class KMeansTest(unittest.TestCase): 18 | """Testing class for Moran's I functions""" 19 | 20 | def setUp(self): 21 | plpy._reset() 22 | self.cluster_data = json.loads(open(fixture_file('kmeans.json')).read()) 23 | self.params = {"subquery": "select * from table", 24 | "no_clusters": "10" 25 | } 26 | 27 | def test_kmeans(self): 28 | data = self.cluster_data 29 | plpy._define_result('select' ,data) 30 | clusters = cc.kmeans('subquery', 2) 31 | labels = [a[1] for a in clusters] 32 | c1 = [a for a in clusters if a[1]==0] 33 | c2 = [a for a in clusters if a[1]==1] 34 | 35 | self.assertEqual(len(np.unique(labels)),2) 36 | self.assertEqual(len(c1),20) 37 | self.assertEqual(len(c2),20) 38 | 39 | -------------------------------------------------------------------------------- /release/python/0.2.0/crankshaft/crankshaft/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all modules""" 2 | import crankshaft.random_seeds 3 | import crankshaft.clustering 4 | import crankshaft.space_time_dynamics 5 | import crankshaft.segmentation 6 | -------------------------------------------------------------------------------- /release/python/0.2.0/crankshaft/crankshaft/clustering/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from for clustering""" 2 | from moran import * 3 | from kmeans import * 4 | -------------------------------------------------------------------------------- /release/python/0.2.0/crankshaft/crankshaft/clustering/kmeans.py: -------------------------------------------------------------------------------- 1 | from sklearn.cluster import KMeans 2 | import plpy 3 | 4 | def kmeans(query, no_clusters, no_init=20): 5 | data = plpy.execute('''select array_agg(cartodb_id order by cartodb_id) as ids, 6 | array_agg(ST_X(the_geom) order by cartodb_id) xs, 7 | array_agg(ST_Y(the_geom) order by cartodb_id) ys from ({query}) a 8 | where the_geom is not null 9 | '''.format(query=query)) 10 | 11 | xs = data[0]['xs'] 12 | ys = data[0]['ys'] 13 | ids = data[0]['ids'] 14 | 15 | km = KMeans(n_clusters= no_clusters, n_init=no_init) 16 | labels = km.fit_predict(zip(xs,ys)) 17 | return zip(ids,labels) 18 | 19 | -------------------------------------------------------------------------------- /release/python/0.2.0/crankshaft/crankshaft/pysal_utils/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions for pysal_utils""" 2 | from crankshaft.pysal_utils.pysal_utils import * 3 | -------------------------------------------------------------------------------- /release/python/0.2.0/crankshaft/crankshaft/random_seeds.py: -------------------------------------------------------------------------------- 1 | """Random seed generator used for non-deterministic functions in crankshaft""" 2 | import random 3 | import numpy 4 | 5 | def set_random_seeds(value): 6 | """ 7 | Set the seeds of the RNGs (Random Number Generators) 8 | used internally. 9 | """ 10 | random.seed(value) 11 | numpy.random.seed(value) 12 | -------------------------------------------------------------------------------- /release/python/0.2.0/crankshaft/crankshaft/segmentation/__init__.py: -------------------------------------------------------------------------------- 1 | from segmentation import * 2 | -------------------------------------------------------------------------------- /release/python/0.2.0/crankshaft/crankshaft/space_time_dynamics/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from clustering libraries.""" 2 | from markov import * 3 | -------------------------------------------------------------------------------- /release/python/0.2.0/crankshaft/setup.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | CartoDB Spatial Analysis Python Library 4 | See: 5 | https://github.com/CartoDB/crankshaft 6 | """ 7 | 8 | from setuptools import setup, find_packages 9 | 10 | setup( 11 | name='crankshaft', 12 | 13 | version='0.2.0', 14 | 15 | description='CartoDB Spatial Analysis Python Library', 16 | 17 | url='https://github.com/CartoDB/crankshaft', 18 | 19 | author='Data Services Team - CartoDB', 20 | author_email='dataservices@cartodb.com', 21 | 22 | license='MIT', 23 | 24 | classifiers=[ 25 | 'Development Status :: 3 - Alpha', 26 | 'Intended Audience :: Mapping comunity', 27 | 'Topic :: Maps :: Mapping Tools', 28 | 'License :: OSI Approved :: MIT License', 29 | 'Programming Language :: Python :: 2.7', 30 | ], 31 | 32 | keywords='maps mapping tools spatial analysis geostatistics', 33 | 34 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 35 | 36 | extras_require={ 37 | 'dev': ['unittest'], 38 | 'test': ['unittest', 'nose', 'mock'], 39 | }, 40 | 41 | # The choice of component versions is dictated by what's 42 | # provisioned in the production servers. 43 | # IMPORTANT NOTE: please don't change this line. Instead issue a ticket to systems for evaluation. 44 | install_requires=['joblib==0.8.3', 'numpy==1.6.1', 'scipy==0.14.0', 'pysal==1.11.2', 'scikit-learn==0.14.1'], 45 | 46 | requires=['pysal', 'numpy', 'sklearn'], 47 | 48 | test_suite='test' 49 | ) 50 | -------------------------------------------------------------------------------- /release/python/0.2.0/crankshaft/test/fixtures/moran.json: -------------------------------------------------------------------------------- 1 | [[0.9319096128346788, "HH"], 2 | [-1.135787401862846, "HL"], 3 | [0.11732030672508517, "LL"], 4 | [0.6152779669180425, "LL"], 5 | [-0.14657336660125297, "LH"], 6 | [0.6967858120189607, "LL"], 7 | [0.07949310115714454, "HH"], 8 | [0.4703198759258987, "HH"], 9 | [0.4421125200498064, "HH"], 10 | [0.5724288737143592, "LL"], 11 | [0.8970743435692062, "LL"], 12 | [0.18327334401918674, "LL"], 13 | [-0.01466729201304962, "HL"], 14 | [0.3481559372544409, "LL"], 15 | [0.06547094736902978, "LL"], 16 | [0.15482141569329988, "HH"], 17 | [0.4373841193538136, "HH"], 18 | [0.15971286468915544, "LL"], 19 | [1.0543588860308968, "HH"], 20 | [1.7372866900020818, "HH"], 21 | [1.091998586053999, "LL"], 22 | [0.1171572584252222, "HH"], 23 | [0.08438455015300014, "LL"], 24 | [0.06547094736902978, "LL"], 25 | [0.15482141569329985, "HH"], 26 | [1.1627044812890683, "HH"], 27 | [0.06547094736902978, "LL"], 28 | [0.795275137550483, "HH"], 29 | [0.18562939195219, "LL"], 30 | [0.3010757406693439, "LL"], 31 | [2.8205795942839376, "HH"], 32 | [0.11259190602909264, "LL"], 33 | [-0.07116352791516614, "HL"], 34 | [-0.09945240794119009, "LH"], 35 | [0.18562939195219, "LL"], 36 | [0.1832733440191868, "LL"], 37 | [-0.39054253768447705, "HL"], 38 | [-0.1672071289487642, "HL"], 39 | [0.3337669247916343, "HH"], 40 | [0.2584386102554792, "HH"], 41 | [-0.19733845476322634, "HL"], 42 | [-0.9379282899805409, "LH"], 43 | [-0.028770969951095866, "LH"], 44 | [0.051367269430983485, "LL"], 45 | [-0.2172548045913472, "LH"], 46 | [0.05136726943098351, "LL"], 47 | [0.04191046803899837, "LL"], 48 | [0.7482357030403517, "HH"], 49 | [-0.014585767863118111, "LH"], 50 | [0.5410013139159929, "HH"], 51 | [1.0223932668429925, "LL"], 52 | [1.4179402898927476, "LL"]] -------------------------------------------------------------------------------- /release/python/0.2.0/crankshaft/test/helper.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from mock_plpy import MockPlPy 4 | plpy = MockPlPy() 5 | 6 | import sys 7 | sys.modules['plpy'] = plpy 8 | 9 | import os 10 | 11 | def fixture_file(name): 12 | dir = os.path.dirname(os.path.realpath(__file__)) 13 | return os.path.join(dir, 'fixtures', name) 14 | -------------------------------------------------------------------------------- /release/python/0.2.0/crankshaft/test/mock_plpy.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | class MockCursor: 4 | def __init__(self, data): 5 | self.cursor_pos = 0 6 | self.data = data 7 | 8 | def fetch(self, batch_size): 9 | batch = self.data[self.cursor_pos : self.cursor_pos + batch_size] 10 | self.cursor_pos += batch_size 11 | return batch 12 | 13 | 14 | class MockPlPy: 15 | def __init__(self): 16 | self._reset() 17 | 18 | def _reset(self): 19 | self.infos = [] 20 | self.notices = [] 21 | self.debugs = [] 22 | self.logs = [] 23 | self.warnings = [] 24 | self.errors = [] 25 | self.fatals = [] 26 | self.executes = [] 27 | self.results = [] 28 | self.prepares = [] 29 | self.results = [] 30 | 31 | def _define_result(self, query, result): 32 | pattern = re.compile(query, re.IGNORECASE | re.MULTILINE) 33 | self.results.append([pattern, result]) 34 | 35 | def notice(self, msg): 36 | self.notices.append(msg) 37 | 38 | def debug(self, msg): 39 | self.notices.append(msg) 40 | 41 | def info(self, msg): 42 | self.infos.append(msg) 43 | 44 | def cursor(self, query): 45 | data = self.execute(query) 46 | return MockCursor(data) 47 | 48 | def execute(self, query): # TODO: additional arguments 49 | for result in self.results: 50 | if result[0].match(query): 51 | return result[1] 52 | return [] 53 | -------------------------------------------------------------------------------- /release/python/0.2.0/crankshaft/test/test_cluster_kmeans.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import numpy as np 3 | 4 | 5 | # from mock_plpy import MockPlPy 6 | # plpy = MockPlPy() 7 | # 8 | # import sys 9 | # sys.modules['plpy'] = plpy 10 | from helper import plpy, fixture_file 11 | import numpy as np 12 | import crankshaft.clustering as cc 13 | import crankshaft.pysal_utils as pu 14 | from crankshaft import random_seeds 15 | import json 16 | 17 | class KMeansTest(unittest.TestCase): 18 | """Testing class for Moran's I functions""" 19 | 20 | def setUp(self): 21 | plpy._reset() 22 | self.cluster_data = json.loads(open(fixture_file('kmeans.json')).read()) 23 | self.params = {"subquery": "select * from table", 24 | "no_clusters": "10" 25 | } 26 | 27 | def test_kmeans(self): 28 | data = self.cluster_data 29 | plpy._define_result('select' ,data) 30 | clusters = cc.kmeans('subquery', 2) 31 | labels = [a[1] for a in clusters] 32 | c1 = [a for a in clusters if a[1]==0] 33 | c2 = [a for a in clusters if a[1]==1] 34 | 35 | self.assertEqual(len(np.unique(labels)),2) 36 | self.assertEqual(len(c1),20) 37 | self.assertEqual(len(c2),20) 38 | 39 | -------------------------------------------------------------------------------- /release/python/0.3.0/crankshaft/crankshaft/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all modules""" 2 | import crankshaft.random_seeds 3 | import crankshaft.clustering 4 | import crankshaft.space_time_dynamics 5 | import crankshaft.segmentation 6 | -------------------------------------------------------------------------------- /release/python/0.3.0/crankshaft/crankshaft/clustering/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from for clustering""" 2 | from moran import * 3 | from kmeans import * 4 | -------------------------------------------------------------------------------- /release/python/0.3.0/crankshaft/crankshaft/clustering/kmeans.py: -------------------------------------------------------------------------------- 1 | from sklearn.cluster import KMeans 2 | import plpy 3 | 4 | def kmeans(query, no_clusters, no_init=20): 5 | data = plpy.execute('''select array_agg(cartodb_id order by cartodb_id) as ids, 6 | array_agg(ST_X(the_geom) order by cartodb_id) xs, 7 | array_agg(ST_Y(the_geom) order by cartodb_id) ys from ({query}) a 8 | where the_geom is not null 9 | '''.format(query=query)) 10 | 11 | xs = data[0]['xs'] 12 | ys = data[0]['ys'] 13 | ids = data[0]['ids'] 14 | 15 | km = KMeans(n_clusters= no_clusters, n_init=no_init) 16 | labels = km.fit_predict(zip(xs,ys)) 17 | return zip(ids,labels) 18 | 19 | -------------------------------------------------------------------------------- /release/python/0.3.0/crankshaft/crankshaft/pysal_utils/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions for pysal_utils""" 2 | from crankshaft.pysal_utils.pysal_utils import * 3 | -------------------------------------------------------------------------------- /release/python/0.3.0/crankshaft/crankshaft/random_seeds.py: -------------------------------------------------------------------------------- 1 | """Random seed generator used for non-deterministic functions in crankshaft""" 2 | import random 3 | import numpy 4 | 5 | def set_random_seeds(value): 6 | """ 7 | Set the seeds of the RNGs (Random Number Generators) 8 | used internally. 9 | """ 10 | random.seed(value) 11 | numpy.random.seed(value) 12 | -------------------------------------------------------------------------------- /release/python/0.3.0/crankshaft/crankshaft/segmentation/__init__.py: -------------------------------------------------------------------------------- 1 | from segmentation import * 2 | -------------------------------------------------------------------------------- /release/python/0.3.0/crankshaft/crankshaft/space_time_dynamics/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from clustering libraries.""" 2 | from markov import * 3 | -------------------------------------------------------------------------------- /release/python/0.3.0/crankshaft/setup.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | CartoDB Spatial Analysis Python Library 4 | See: 5 | https://github.com/CartoDB/crankshaft 6 | """ 7 | 8 | from setuptools import setup, find_packages 9 | 10 | setup( 11 | name='crankshaft', 12 | 13 | version='0.3.0', 14 | 15 | description='CartoDB Spatial Analysis Python Library', 16 | 17 | url='https://github.com/CartoDB/crankshaft', 18 | 19 | author='Data Services Team - CartoDB', 20 | author_email='dataservices@cartodb.com', 21 | 22 | license='MIT', 23 | 24 | classifiers=[ 25 | 'Development Status :: 3 - Alpha', 26 | 'Intended Audience :: Mapping comunity', 27 | 'Topic :: Maps :: Mapping Tools', 28 | 'License :: OSI Approved :: MIT License', 29 | 'Programming Language :: Python :: 2.7', 30 | ], 31 | 32 | keywords='maps mapping tools spatial analysis geostatistics', 33 | 34 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 35 | 36 | extras_require={ 37 | 'dev': ['unittest'], 38 | 'test': ['unittest', 'nose', 'mock'], 39 | }, 40 | 41 | # The choice of component versions is dictated by what's 42 | # provisioned in the production servers. 43 | # IMPORTANT NOTE: please don't change this line. Instead issue a ticket to systems for evaluation. 44 | install_requires=['joblib==0.8.3', 'numpy==1.6.1', 'scipy==0.14.0', 'pysal==1.11.2', 'scikit-learn==0.14.1'], 45 | 46 | requires=['pysal', 'numpy', 'sklearn'], 47 | 48 | test_suite='test' 49 | ) 50 | -------------------------------------------------------------------------------- /release/python/0.3.0/crankshaft/test/fixtures/moran.json: -------------------------------------------------------------------------------- 1 | [[0.9319096128346788, "HH"], 2 | [-1.135787401862846, "HL"], 3 | [0.11732030672508517, "LL"], 4 | [0.6152779669180425, "LL"], 5 | [-0.14657336660125297, "LH"], 6 | [0.6967858120189607, "LL"], 7 | [0.07949310115714454, "HH"], 8 | [0.4703198759258987, "HH"], 9 | [0.4421125200498064, "HH"], 10 | [0.5724288737143592, "LL"], 11 | [0.8970743435692062, "LL"], 12 | [0.18327334401918674, "LL"], 13 | [-0.01466729201304962, "HL"], 14 | [0.3481559372544409, "LL"], 15 | [0.06547094736902978, "LL"], 16 | [0.15482141569329988, "HH"], 17 | [0.4373841193538136, "HH"], 18 | [0.15971286468915544, "LL"], 19 | [1.0543588860308968, "HH"], 20 | [1.7372866900020818, "HH"], 21 | [1.091998586053999, "LL"], 22 | [0.1171572584252222, "HH"], 23 | [0.08438455015300014, "LL"], 24 | [0.06547094736902978, "LL"], 25 | [0.15482141569329985, "HH"], 26 | [1.1627044812890683, "HH"], 27 | [0.06547094736902978, "LL"], 28 | [0.795275137550483, "HH"], 29 | [0.18562939195219, "LL"], 30 | [0.3010757406693439, "LL"], 31 | [2.8205795942839376, "HH"], 32 | [0.11259190602909264, "LL"], 33 | [-0.07116352791516614, "HL"], 34 | [-0.09945240794119009, "LH"], 35 | [0.18562939195219, "LL"], 36 | [0.1832733440191868, "LL"], 37 | [-0.39054253768447705, "HL"], 38 | [-0.1672071289487642, "HL"], 39 | [0.3337669247916343, "HH"], 40 | [0.2584386102554792, "HH"], 41 | [-0.19733845476322634, "HL"], 42 | [-0.9379282899805409, "LH"], 43 | [-0.028770969951095866, "LH"], 44 | [0.051367269430983485, "LL"], 45 | [-0.2172548045913472, "LH"], 46 | [0.05136726943098351, "LL"], 47 | [0.04191046803899837, "LL"], 48 | [0.7482357030403517, "HH"], 49 | [-0.014585767863118111, "LH"], 50 | [0.5410013139159929, "HH"], 51 | [1.0223932668429925, "LL"], 52 | [1.4179402898927476, "LL"]] -------------------------------------------------------------------------------- /release/python/0.3.0/crankshaft/test/helper.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from mock_plpy import MockPlPy 4 | plpy = MockPlPy() 5 | 6 | import sys 7 | sys.modules['plpy'] = plpy 8 | 9 | import os 10 | 11 | def fixture_file(name): 12 | dir = os.path.dirname(os.path.realpath(__file__)) 13 | return os.path.join(dir, 'fixtures', name) 14 | -------------------------------------------------------------------------------- /release/python/0.3.0/crankshaft/test/mock_plpy.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | class MockCursor: 4 | def __init__(self, data): 5 | self.cursor_pos = 0 6 | self.data = data 7 | 8 | def fetch(self, batch_size): 9 | batch = self.data[self.cursor_pos : self.cursor_pos + batch_size] 10 | self.cursor_pos += batch_size 11 | return batch 12 | 13 | 14 | class MockPlPy: 15 | def __init__(self): 16 | self._reset() 17 | 18 | def _reset(self): 19 | self.infos = [] 20 | self.notices = [] 21 | self.debugs = [] 22 | self.logs = [] 23 | self.warnings = [] 24 | self.errors = [] 25 | self.fatals = [] 26 | self.executes = [] 27 | self.results = [] 28 | self.prepares = [] 29 | self.results = [] 30 | 31 | def _define_result(self, query, result): 32 | pattern = re.compile(query, re.IGNORECASE | re.MULTILINE) 33 | self.results.append([pattern, result]) 34 | 35 | def notice(self, msg): 36 | self.notices.append(msg) 37 | 38 | def debug(self, msg): 39 | self.notices.append(msg) 40 | 41 | def info(self, msg): 42 | self.infos.append(msg) 43 | 44 | def cursor(self, query): 45 | data = self.execute(query) 46 | return MockCursor(data) 47 | 48 | def execute(self, query): # TODO: additional arguments 49 | for result in self.results: 50 | if result[0].match(query): 51 | return result[1] 52 | return [] 53 | -------------------------------------------------------------------------------- /release/python/0.3.0/crankshaft/test/test_cluster_kmeans.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import numpy as np 3 | 4 | 5 | # from mock_plpy import MockPlPy 6 | # plpy = MockPlPy() 7 | # 8 | # import sys 9 | # sys.modules['plpy'] = plpy 10 | from helper import plpy, fixture_file 11 | import numpy as np 12 | import crankshaft.clustering as cc 13 | import crankshaft.pysal_utils as pu 14 | from crankshaft import random_seeds 15 | import json 16 | 17 | class KMeansTest(unittest.TestCase): 18 | """Testing class for Moran's I functions""" 19 | 20 | def setUp(self): 21 | plpy._reset() 22 | self.cluster_data = json.loads(open(fixture_file('kmeans.json')).read()) 23 | self.params = {"subquery": "select * from table", 24 | "no_clusters": "10" 25 | } 26 | 27 | def test_kmeans(self): 28 | data = self.cluster_data 29 | plpy._define_result('select' ,data) 30 | clusters = cc.kmeans('subquery', 2) 31 | labels = [a[1] for a in clusters] 32 | c1 = [a for a in clusters if a[1]==0] 33 | c2 = [a for a in clusters if a[1]==1] 34 | 35 | self.assertEqual(len(np.unique(labels)),2) 36 | self.assertEqual(len(c1),20) 37 | self.assertEqual(len(c2),20) 38 | 39 | -------------------------------------------------------------------------------- /release/python/0.3.1/crankshaft/crankshaft/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all modules""" 2 | import crankshaft.random_seeds 3 | import crankshaft.clustering 4 | import crankshaft.space_time_dynamics 5 | import crankshaft.segmentation 6 | -------------------------------------------------------------------------------- /release/python/0.3.1/crankshaft/crankshaft/clustering/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from for clustering""" 2 | from moran import * 3 | from kmeans import * 4 | -------------------------------------------------------------------------------- /release/python/0.3.1/crankshaft/crankshaft/clustering/kmeans.py: -------------------------------------------------------------------------------- 1 | from sklearn.cluster import KMeans 2 | import plpy 3 | 4 | def kmeans(query, no_clusters, no_init=20): 5 | data = plpy.execute('''select array_agg(cartodb_id order by cartodb_id) as ids, 6 | array_agg(ST_X(the_geom) order by cartodb_id) xs, 7 | array_agg(ST_Y(the_geom) order by cartodb_id) ys from ({query}) a 8 | where the_geom is not null 9 | '''.format(query=query)) 10 | 11 | xs = data[0]['xs'] 12 | ys = data[0]['ys'] 13 | ids = data[0]['ids'] 14 | 15 | km = KMeans(n_clusters= no_clusters, n_init=no_init) 16 | labels = km.fit_predict(zip(xs,ys)) 17 | return zip(ids,labels) 18 | 19 | -------------------------------------------------------------------------------- /release/python/0.3.1/crankshaft/crankshaft/pysal_utils/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions for pysal_utils""" 2 | from crankshaft.pysal_utils.pysal_utils import * 3 | -------------------------------------------------------------------------------- /release/python/0.3.1/crankshaft/crankshaft/random_seeds.py: -------------------------------------------------------------------------------- 1 | """Random seed generator used for non-deterministic functions in crankshaft""" 2 | import random 3 | import numpy 4 | 5 | def set_random_seeds(value): 6 | """ 7 | Set the seeds of the RNGs (Random Number Generators) 8 | used internally. 9 | """ 10 | random.seed(value) 11 | numpy.random.seed(value) 12 | -------------------------------------------------------------------------------- /release/python/0.3.1/crankshaft/crankshaft/segmentation/__init__.py: -------------------------------------------------------------------------------- 1 | from segmentation import * 2 | -------------------------------------------------------------------------------- /release/python/0.3.1/crankshaft/crankshaft/space_time_dynamics/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from clustering libraries.""" 2 | from markov import * 3 | -------------------------------------------------------------------------------- /release/python/0.3.1/crankshaft/setup.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | CartoDB Spatial Analysis Python Library 4 | See: 5 | https://github.com/CartoDB/crankshaft 6 | """ 7 | 8 | from setuptools import setup, find_packages 9 | 10 | setup( 11 | name='crankshaft', 12 | 13 | version='0.0.0', 14 | 15 | description='CartoDB Spatial Analysis Python Library', 16 | 17 | url='https://github.com/CartoDB/crankshaft', 18 | 19 | author='Data Services Team - CartoDB', 20 | author_email='dataservices@cartodb.com', 21 | 22 | license='MIT', 23 | 24 | classifiers=[ 25 | 'Development Status :: 3 - Alpha', 26 | 'Intended Audience :: Mapping comunity', 27 | 'Topic :: Maps :: Mapping Tools', 28 | 'License :: OSI Approved :: MIT License', 29 | 'Programming Language :: Python :: 2.7', 30 | ], 31 | 32 | keywords='maps mapping tools spatial analysis geostatistics', 33 | 34 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 35 | 36 | extras_require={ 37 | 'dev': ['unittest'], 38 | 'test': ['unittest', 'nose', 'mock'], 39 | }, 40 | 41 | # The choice of component versions is dictated by what's 42 | # provisioned in the production servers. 43 | # IMPORTANT NOTE: please don't change this line. Instead issue a ticket to systems for evaluation. 44 | install_requires=['joblib==0.8.3', 'numpy==1.6.1', 'scipy==0.14.0', 'pysal==1.11.2', 'scikit-learn==0.14.1'], 45 | 46 | requires=['pysal', 'numpy', 'sklearn'], 47 | 48 | test_suite='test' 49 | ) 50 | -------------------------------------------------------------------------------- /release/python/0.3.1/crankshaft/setup.py-r: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | CartoDB Spatial Analysis Python Library 4 | See: 5 | https://github.com/CartoDB/crankshaft 6 | """ 7 | 8 | from setuptools import setup, find_packages 9 | 10 | setup( 11 | name='crankshaft', 12 | 13 | version='0.0.0', 14 | 15 | description='CartoDB Spatial Analysis Python Library', 16 | 17 | url='https://github.com/CartoDB/crankshaft', 18 | 19 | author='Data Services Team - CartoDB', 20 | author_email='dataservices@cartodb.com', 21 | 22 | license='MIT', 23 | 24 | classifiers=[ 25 | 'Development Status :: 3 - Alpha', 26 | 'Intended Audience :: Mapping comunity', 27 | 'Topic :: Maps :: Mapping Tools', 28 | 'License :: OSI Approved :: MIT License', 29 | 'Programming Language :: Python :: 2.7', 30 | ], 31 | 32 | keywords='maps mapping tools spatial analysis geostatistics', 33 | 34 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 35 | 36 | extras_require={ 37 | 'dev': ['unittest'], 38 | 'test': ['unittest', 'nose', 'mock'], 39 | }, 40 | 41 | # The choice of component versions is dictated by what's 42 | # provisioned in the production servers. 43 | # IMPORTANT NOTE: please don't change this line. Instead issue a ticket to systems for evaluation. 44 | install_requires=['joblib==0.8.3', 'numpy==1.6.1', 'scipy==0.14.0', 'pysal==1.11.2', 'scikit-learn==0.14.1'], 45 | 46 | requires=['pysal', 'numpy', 'sklearn'], 47 | 48 | test_suite='test' 49 | ) 50 | -------------------------------------------------------------------------------- /release/python/0.3.1/crankshaft/test/helper.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from mock_plpy import MockPlPy 4 | plpy = MockPlPy() 5 | 6 | import sys 7 | sys.modules['plpy'] = plpy 8 | 9 | import os 10 | 11 | def fixture_file(name): 12 | dir = os.path.dirname(os.path.realpath(__file__)) 13 | return os.path.join(dir, 'fixtures', name) 14 | -------------------------------------------------------------------------------- /release/python/0.3.1/crankshaft/test/mock_plpy.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | class MockCursor: 4 | def __init__(self, data): 5 | self.cursor_pos = 0 6 | self.data = data 7 | 8 | def fetch(self, batch_size): 9 | batch = self.data[self.cursor_pos : self.cursor_pos + batch_size] 10 | self.cursor_pos += batch_size 11 | return batch 12 | 13 | 14 | class MockPlPy: 15 | def __init__(self): 16 | self._reset() 17 | 18 | def _reset(self): 19 | self.infos = [] 20 | self.notices = [] 21 | self.debugs = [] 22 | self.logs = [] 23 | self.warnings = [] 24 | self.errors = [] 25 | self.fatals = [] 26 | self.executes = [] 27 | self.results = [] 28 | self.prepares = [] 29 | self.results = [] 30 | 31 | def _define_result(self, query, result): 32 | pattern = re.compile(query, re.IGNORECASE | re.MULTILINE) 33 | self.results.append([pattern, result]) 34 | 35 | def notice(self, msg): 36 | self.notices.append(msg) 37 | 38 | def debug(self, msg): 39 | self.notices.append(msg) 40 | 41 | def info(self, msg): 42 | self.infos.append(msg) 43 | 44 | def cursor(self, query): 45 | data = self.execute(query) 46 | return MockCursor(data) 47 | 48 | def execute(self, query): # TODO: additional arguments 49 | for result in self.results: 50 | if result[0].match(query): 51 | return result[1] 52 | return [] 53 | -------------------------------------------------------------------------------- /release/python/0.3.1/crankshaft/test/test_cluster_kmeans.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import numpy as np 3 | 4 | 5 | # from mock_plpy import MockPlPy 6 | # plpy = MockPlPy() 7 | # 8 | # import sys 9 | # sys.modules['plpy'] = plpy 10 | from helper import plpy, fixture_file 11 | import numpy as np 12 | import crankshaft.clustering as cc 13 | import crankshaft.pysal_utils as pu 14 | from crankshaft import random_seeds 15 | import json 16 | 17 | class KMeansTest(unittest.TestCase): 18 | """Testing class for Moran's I functions""" 19 | 20 | def setUp(self): 21 | plpy._reset() 22 | self.cluster_data = json.loads(open(fixture_file('kmeans.json')).read()) 23 | self.params = {"subquery": "select * from table", 24 | "no_clusters": "10" 25 | } 26 | 27 | def test_kmeans(self): 28 | data = self.cluster_data 29 | plpy._define_result('select' ,data) 30 | clusters = cc.kmeans('subquery', 2) 31 | labels = [a[1] for a in clusters] 32 | c1 = [a for a in clusters if a[1]==0] 33 | c2 = [a for a in clusters if a[1]==1] 34 | 35 | self.assertEqual(len(np.unique(labels)),2) 36 | self.assertEqual(len(c1),20) 37 | self.assertEqual(len(c2),20) 38 | 39 | -------------------------------------------------------------------------------- /release/python/0.4.0/crankshaft/crankshaft/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all modules""" 2 | import crankshaft.random_seeds 3 | import crankshaft.clustering 4 | import crankshaft.space_time_dynamics 5 | import crankshaft.segmentation 6 | -------------------------------------------------------------------------------- /release/python/0.4.0/crankshaft/crankshaft/clustering/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from for clustering""" 2 | from moran import * 3 | from kmeans import * 4 | -------------------------------------------------------------------------------- /release/python/0.4.0/crankshaft/crankshaft/clustering/kmeans.py: -------------------------------------------------------------------------------- 1 | from sklearn.cluster import KMeans 2 | import plpy 3 | 4 | def kmeans(query, no_clusters, no_init=20): 5 | data = plpy.execute('''select array_agg(cartodb_id order by cartodb_id) as ids, 6 | array_agg(ST_X(the_geom) order by cartodb_id) xs, 7 | array_agg(ST_Y(the_geom) order by cartodb_id) ys from ({query}) a 8 | where the_geom is not null 9 | '''.format(query=query)) 10 | 11 | xs = data[0]['xs'] 12 | ys = data[0]['ys'] 13 | ids = data[0]['ids'] 14 | 15 | km = KMeans(n_clusters= no_clusters, n_init=no_init) 16 | labels = km.fit_predict(zip(xs,ys)) 17 | return zip(ids,labels) 18 | 19 | -------------------------------------------------------------------------------- /release/python/0.4.0/crankshaft/crankshaft/pysal_utils/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions for pysal_utils""" 2 | from crankshaft.pysal_utils.pysal_utils import * 3 | -------------------------------------------------------------------------------- /release/python/0.4.0/crankshaft/crankshaft/random_seeds.py: -------------------------------------------------------------------------------- 1 | """Random seed generator used for non-deterministic functions in crankshaft""" 2 | import random 3 | import numpy 4 | 5 | def set_random_seeds(value): 6 | """ 7 | Set the seeds of the RNGs (Random Number Generators) 8 | used internally. 9 | """ 10 | random.seed(value) 11 | numpy.random.seed(value) 12 | -------------------------------------------------------------------------------- /release/python/0.4.0/crankshaft/crankshaft/segmentation/__init__.py: -------------------------------------------------------------------------------- 1 | from segmentation import * 2 | -------------------------------------------------------------------------------- /release/python/0.4.0/crankshaft/crankshaft/space_time_dynamics/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from clustering libraries.""" 2 | from markov import * 3 | -------------------------------------------------------------------------------- /release/python/0.4.0/crankshaft/setup.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | CartoDB Spatial Analysis Python Library 4 | See: 5 | https://github.com/CartoDB/crankshaft 6 | """ 7 | 8 | from setuptools import setup, find_packages 9 | 10 | setup( 11 | name='crankshaft', 12 | 13 | version='0.0.0', 14 | 15 | description='CartoDB Spatial Analysis Python Library', 16 | 17 | url='https://github.com/CartoDB/crankshaft', 18 | 19 | author='Data Services Team - CartoDB', 20 | author_email='dataservices@cartodb.com', 21 | 22 | license='MIT', 23 | 24 | classifiers=[ 25 | 'Development Status :: 3 - Alpha', 26 | 'Intended Audience :: Mapping comunity', 27 | 'Topic :: Maps :: Mapping Tools', 28 | 'License :: OSI Approved :: MIT License', 29 | 'Programming Language :: Python :: 2.7', 30 | ], 31 | 32 | keywords='maps mapping tools spatial analysis geostatistics', 33 | 34 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 35 | 36 | extras_require={ 37 | 'dev': ['unittest'], 38 | 'test': ['unittest', 'nose', 'mock'], 39 | }, 40 | 41 | # The choice of component versions is dictated by what's 42 | # provisioned in the production servers. 43 | # IMPORTANT NOTE: please don't change this line. Instead issue a ticket to systems for evaluation. 44 | install_requires=['joblib==0.8.3', 'numpy==1.6.1', 'scipy==0.14.0', 'pysal==1.11.2', 'scikit-learn==0.14.1'], 45 | 46 | requires=['pysal', 'numpy', 'sklearn'], 47 | 48 | test_suite='test' 49 | ) 50 | -------------------------------------------------------------------------------- /release/python/0.4.0/crankshaft/setup.py-r: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | CartoDB Spatial Analysis Python Library 4 | See: 5 | https://github.com/CartoDB/crankshaft 6 | """ 7 | 8 | from setuptools import setup, find_packages 9 | 10 | setup( 11 | name='crankshaft', 12 | 13 | version='0.0.0', 14 | 15 | description='CartoDB Spatial Analysis Python Library', 16 | 17 | url='https://github.com/CartoDB/crankshaft', 18 | 19 | author='Data Services Team - CartoDB', 20 | author_email='dataservices@cartodb.com', 21 | 22 | license='MIT', 23 | 24 | classifiers=[ 25 | 'Development Status :: 3 - Alpha', 26 | 'Intended Audience :: Mapping comunity', 27 | 'Topic :: Maps :: Mapping Tools', 28 | 'License :: OSI Approved :: MIT License', 29 | 'Programming Language :: Python :: 2.7', 30 | ], 31 | 32 | keywords='maps mapping tools spatial analysis geostatistics', 33 | 34 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 35 | 36 | extras_require={ 37 | 'dev': ['unittest'], 38 | 'test': ['unittest', 'nose', 'mock'], 39 | }, 40 | 41 | # The choice of component versions is dictated by what's 42 | # provisioned in the production servers. 43 | # IMPORTANT NOTE: please don't change this line. Instead issue a ticket to systems for evaluation. 44 | install_requires=['joblib==0.8.3', 'numpy==1.6.1', 'scipy==0.14.0', 'pysal==1.11.2', 'scikit-learn==0.14.1'], 45 | 46 | requires=['pysal', 'numpy', 'sklearn'], 47 | 48 | test_suite='test' 49 | ) 50 | -------------------------------------------------------------------------------- /release/python/0.4.0/crankshaft/test/helper.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from mock_plpy import MockPlPy 4 | plpy = MockPlPy() 5 | 6 | import sys 7 | sys.modules['plpy'] = plpy 8 | 9 | import os 10 | 11 | def fixture_file(name): 12 | dir = os.path.dirname(os.path.realpath(__file__)) 13 | return os.path.join(dir, 'fixtures', name) 14 | -------------------------------------------------------------------------------- /release/python/0.4.0/crankshaft/test/mock_plpy.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | class MockCursor: 4 | def __init__(self, data): 5 | self.cursor_pos = 0 6 | self.data = data 7 | 8 | def fetch(self, batch_size): 9 | batch = self.data[self.cursor_pos : self.cursor_pos + batch_size] 10 | self.cursor_pos += batch_size 11 | return batch 12 | 13 | 14 | class MockPlPy: 15 | def __init__(self): 16 | self._reset() 17 | 18 | def _reset(self): 19 | self.infos = [] 20 | self.notices = [] 21 | self.debugs = [] 22 | self.logs = [] 23 | self.warnings = [] 24 | self.errors = [] 25 | self.fatals = [] 26 | self.executes = [] 27 | self.results = [] 28 | self.prepares = [] 29 | self.results = [] 30 | 31 | def _define_result(self, query, result): 32 | pattern = re.compile(query, re.IGNORECASE | re.MULTILINE) 33 | self.results.append([pattern, result]) 34 | 35 | def notice(self, msg): 36 | self.notices.append(msg) 37 | 38 | def debug(self, msg): 39 | self.notices.append(msg) 40 | 41 | def info(self, msg): 42 | self.infos.append(msg) 43 | 44 | def cursor(self, query): 45 | data = self.execute(query) 46 | return MockCursor(data) 47 | 48 | def execute(self, query): # TODO: additional arguments 49 | for result in self.results: 50 | if result[0].match(query): 51 | return result[1] 52 | return [] 53 | -------------------------------------------------------------------------------- /release/python/0.4.0/crankshaft/test/test_cluster_kmeans.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import numpy as np 3 | 4 | 5 | # from mock_plpy import MockPlPy 6 | # plpy = MockPlPy() 7 | # 8 | # import sys 9 | # sys.modules['plpy'] = plpy 10 | from helper import plpy, fixture_file 11 | import numpy as np 12 | import crankshaft.clustering as cc 13 | import crankshaft.pysal_utils as pu 14 | from crankshaft import random_seeds 15 | import json 16 | 17 | class KMeansTest(unittest.TestCase): 18 | """Testing class for Moran's I functions""" 19 | 20 | def setUp(self): 21 | plpy._reset() 22 | self.cluster_data = json.loads(open(fixture_file('kmeans.json')).read()) 23 | self.params = {"subquery": "select * from table", 24 | "no_clusters": "10" 25 | } 26 | 27 | def test_kmeans(self): 28 | data = self.cluster_data 29 | plpy._define_result('select' ,data) 30 | clusters = cc.kmeans('subquery', 2) 31 | labels = [a[1] for a in clusters] 32 | c1 = [a for a in clusters if a[1]==0] 33 | c2 = [a for a in clusters if a[1]==1] 34 | 35 | self.assertEqual(len(np.unique(labels)),2) 36 | self.assertEqual(len(c1),20) 37 | self.assertEqual(len(c2),20) 38 | 39 | -------------------------------------------------------------------------------- /release/python/0.4.1/crankshaft/crankshaft/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all modules""" 2 | import crankshaft.random_seeds 3 | import crankshaft.clustering 4 | import crankshaft.space_time_dynamics 5 | import crankshaft.segmentation 6 | -------------------------------------------------------------------------------- /release/python/0.4.1/crankshaft/crankshaft/clustering/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from for clustering""" 2 | from moran import * 3 | from kmeans import * 4 | -------------------------------------------------------------------------------- /release/python/0.4.1/crankshaft/crankshaft/clustering/kmeans.py: -------------------------------------------------------------------------------- 1 | from sklearn.cluster import KMeans 2 | import plpy 3 | 4 | def kmeans(query, no_clusters, no_init=20): 5 | data = plpy.execute('''select array_agg(cartodb_id order by cartodb_id) as ids, 6 | array_agg(ST_X(the_geom) order by cartodb_id) xs, 7 | array_agg(ST_Y(the_geom) order by cartodb_id) ys from ({query}) a 8 | where the_geom is not null 9 | '''.format(query=query)) 10 | 11 | xs = data[0]['xs'] 12 | ys = data[0]['ys'] 13 | ids = data[0]['ids'] 14 | 15 | km = KMeans(n_clusters= no_clusters, n_init=no_init) 16 | labels = km.fit_predict(zip(xs,ys)) 17 | return zip(ids,labels) 18 | 19 | -------------------------------------------------------------------------------- /release/python/0.4.1/crankshaft/crankshaft/pysal_utils/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions for pysal_utils""" 2 | from crankshaft.pysal_utils.pysal_utils import * 3 | -------------------------------------------------------------------------------- /release/python/0.4.1/crankshaft/crankshaft/random_seeds.py: -------------------------------------------------------------------------------- 1 | """Random seed generator used for non-deterministic functions in crankshaft""" 2 | import random 3 | import numpy 4 | 5 | def set_random_seeds(value): 6 | """ 7 | Set the seeds of the RNGs (Random Number Generators) 8 | used internally. 9 | """ 10 | random.seed(value) 11 | numpy.random.seed(value) 12 | -------------------------------------------------------------------------------- /release/python/0.4.1/crankshaft/crankshaft/segmentation/__init__.py: -------------------------------------------------------------------------------- 1 | from segmentation import * 2 | -------------------------------------------------------------------------------- /release/python/0.4.1/crankshaft/crankshaft/space_time_dynamics/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from clustering libraries.""" 2 | from markov import * 3 | -------------------------------------------------------------------------------- /release/python/0.4.1/crankshaft/setup.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | CartoDB Spatial Analysis Python Library 4 | See: 5 | https://github.com/CartoDB/crankshaft 6 | """ 7 | 8 | from setuptools import setup, find_packages 9 | 10 | setup( 11 | name='crankshaft', 12 | 13 | version='0.0.0', 14 | 15 | description='CartoDB Spatial Analysis Python Library', 16 | 17 | url='https://github.com/CartoDB/crankshaft', 18 | 19 | author='Data Services Team - CartoDB', 20 | author_email='dataservices@cartodb.com', 21 | 22 | license='MIT', 23 | 24 | classifiers=[ 25 | 'Development Status :: 3 - Alpha', 26 | 'Intended Audience :: Mapping comunity', 27 | 'Topic :: Maps :: Mapping Tools', 28 | 'License :: OSI Approved :: MIT License', 29 | 'Programming Language :: Python :: 2.7', 30 | ], 31 | 32 | keywords='maps mapping tools spatial analysis geostatistics', 33 | 34 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 35 | 36 | extras_require={ 37 | 'dev': ['unittest'], 38 | 'test': ['unittest', 'nose', 'mock'], 39 | }, 40 | 41 | # The choice of component versions is dictated by what's 42 | # provisioned in the production servers. 43 | # IMPORTANT NOTE: please don't change this line. Instead issue a ticket to systems for evaluation. 44 | install_requires=['joblib==0.8.3', 'numpy==1.6.1', 'scipy==0.14.0', 'pysal==1.11.2', 'scikit-learn==0.14.1'], 45 | 46 | requires=['pysal', 'numpy', 'sklearn'], 47 | 48 | test_suite='test' 49 | ) 50 | -------------------------------------------------------------------------------- /release/python/0.4.1/crankshaft/setup.py-r: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | CartoDB Spatial Analysis Python Library 4 | See: 5 | https://github.com/CartoDB/crankshaft 6 | """ 7 | 8 | from setuptools import setup, find_packages 9 | 10 | setup( 11 | name='crankshaft', 12 | 13 | version='0.0.0', 14 | 15 | description='CartoDB Spatial Analysis Python Library', 16 | 17 | url='https://github.com/CartoDB/crankshaft', 18 | 19 | author='Data Services Team - CartoDB', 20 | author_email='dataservices@cartodb.com', 21 | 22 | license='MIT', 23 | 24 | classifiers=[ 25 | 'Development Status :: 3 - Alpha', 26 | 'Intended Audience :: Mapping comunity', 27 | 'Topic :: Maps :: Mapping Tools', 28 | 'License :: OSI Approved :: MIT License', 29 | 'Programming Language :: Python :: 2.7', 30 | ], 31 | 32 | keywords='maps mapping tools spatial analysis geostatistics', 33 | 34 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 35 | 36 | extras_require={ 37 | 'dev': ['unittest'], 38 | 'test': ['unittest', 'nose', 'mock'], 39 | }, 40 | 41 | # The choice of component versions is dictated by what's 42 | # provisioned in the production servers. 43 | # IMPORTANT NOTE: please don't change this line. Instead issue a ticket to systems for evaluation. 44 | install_requires=['joblib==0.8.3', 'numpy==1.6.1', 'scipy==0.14.0', 'pysal==1.11.2', 'scikit-learn==0.14.1'], 45 | 46 | requires=['pysal', 'numpy', 'sklearn'], 47 | 48 | test_suite='test' 49 | ) 50 | -------------------------------------------------------------------------------- /release/python/0.4.1/crankshaft/test/helper.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from mock_plpy import MockPlPy 4 | plpy = MockPlPy() 5 | 6 | import sys 7 | sys.modules['plpy'] = plpy 8 | 9 | import os 10 | 11 | def fixture_file(name): 12 | dir = os.path.dirname(os.path.realpath(__file__)) 13 | return os.path.join(dir, 'fixtures', name) 14 | -------------------------------------------------------------------------------- /release/python/0.4.1/crankshaft/test/mock_plpy.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | class MockCursor: 4 | def __init__(self, data): 5 | self.cursor_pos = 0 6 | self.data = data 7 | 8 | def fetch(self, batch_size): 9 | batch = self.data[self.cursor_pos : self.cursor_pos + batch_size] 10 | self.cursor_pos += batch_size 11 | return batch 12 | 13 | 14 | class MockPlPy: 15 | def __init__(self): 16 | self._reset() 17 | 18 | def _reset(self): 19 | self.infos = [] 20 | self.notices = [] 21 | self.debugs = [] 22 | self.logs = [] 23 | self.warnings = [] 24 | self.errors = [] 25 | self.fatals = [] 26 | self.executes = [] 27 | self.results = [] 28 | self.prepares = [] 29 | self.results = [] 30 | 31 | def _define_result(self, query, result): 32 | pattern = re.compile(query, re.IGNORECASE | re.MULTILINE) 33 | self.results.append([pattern, result]) 34 | 35 | def notice(self, msg): 36 | self.notices.append(msg) 37 | 38 | def debug(self, msg): 39 | self.notices.append(msg) 40 | 41 | def info(self, msg): 42 | self.infos.append(msg) 43 | 44 | def cursor(self, query): 45 | data = self.execute(query) 46 | return MockCursor(data) 47 | 48 | def execute(self, query): # TODO: additional arguments 49 | for result in self.results: 50 | if result[0].match(query): 51 | return result[1] 52 | return [] 53 | -------------------------------------------------------------------------------- /release/python/0.4.1/crankshaft/test/test_cluster_kmeans.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import numpy as np 3 | 4 | 5 | # from mock_plpy import MockPlPy 6 | # plpy = MockPlPy() 7 | # 8 | # import sys 9 | # sys.modules['plpy'] = plpy 10 | from helper import plpy, fixture_file 11 | import numpy as np 12 | import crankshaft.clustering as cc 13 | import crankshaft.pysal_utils as pu 14 | from crankshaft import random_seeds 15 | import json 16 | 17 | class KMeansTest(unittest.TestCase): 18 | """Testing class for Moran's I functions""" 19 | 20 | def setUp(self): 21 | plpy._reset() 22 | self.cluster_data = json.loads(open(fixture_file('kmeans.json')).read()) 23 | self.params = {"subquery": "select * from table", 24 | "no_clusters": "10" 25 | } 26 | 27 | def test_kmeans(self): 28 | data = self.cluster_data 29 | plpy._define_result('select' ,data) 30 | clusters = cc.kmeans('subquery', 2) 31 | labels = [a[1] for a in clusters] 32 | c1 = [a for a in clusters if a[1]==0] 33 | c2 = [a for a in clusters if a[1]==1] 34 | 35 | self.assertEqual(len(np.unique(labels)),2) 36 | self.assertEqual(len(c1),20) 37 | self.assertEqual(len(c2),20) 38 | 39 | -------------------------------------------------------------------------------- /release/python/0.4.2/crankshaft/crankshaft/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all modules""" 2 | import crankshaft.random_seeds 3 | import crankshaft.clustering 4 | import crankshaft.space_time_dynamics 5 | import crankshaft.segmentation 6 | -------------------------------------------------------------------------------- /release/python/0.4.2/crankshaft/crankshaft/clustering/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from for clustering""" 2 | from moran import * 3 | from kmeans import * 4 | -------------------------------------------------------------------------------- /release/python/0.4.2/crankshaft/crankshaft/clustering/kmeans.py: -------------------------------------------------------------------------------- 1 | from sklearn.cluster import KMeans 2 | import plpy 3 | 4 | def kmeans(query, no_clusters, no_init=20): 5 | data = plpy.execute('''select array_agg(cartodb_id order by cartodb_id) as ids, 6 | array_agg(ST_X(the_geom) order by cartodb_id) xs, 7 | array_agg(ST_Y(the_geom) order by cartodb_id) ys from ({query}) a 8 | where the_geom is not null 9 | '''.format(query=query)) 10 | 11 | xs = data[0]['xs'] 12 | ys = data[0]['ys'] 13 | ids = data[0]['ids'] 14 | 15 | km = KMeans(n_clusters= no_clusters, n_init=no_init) 16 | labels = km.fit_predict(zip(xs,ys)) 17 | return zip(ids,labels) 18 | 19 | -------------------------------------------------------------------------------- /release/python/0.4.2/crankshaft/crankshaft/pysal_utils/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions for pysal_utils""" 2 | from crankshaft.pysal_utils.pysal_utils import * 3 | -------------------------------------------------------------------------------- /release/python/0.4.2/crankshaft/crankshaft/random_seeds.py: -------------------------------------------------------------------------------- 1 | """Random seed generator used for non-deterministic functions in crankshaft""" 2 | import random 3 | import numpy 4 | 5 | def set_random_seeds(value): 6 | """ 7 | Set the seeds of the RNGs (Random Number Generators) 8 | used internally. 9 | """ 10 | random.seed(value) 11 | numpy.random.seed(value) 12 | -------------------------------------------------------------------------------- /release/python/0.4.2/crankshaft/crankshaft/segmentation/__init__.py: -------------------------------------------------------------------------------- 1 | from segmentation import * 2 | -------------------------------------------------------------------------------- /release/python/0.4.2/crankshaft/crankshaft/space_time_dynamics/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from clustering libraries.""" 2 | from markov import * 3 | -------------------------------------------------------------------------------- /release/python/0.4.2/crankshaft/requirements.txt: -------------------------------------------------------------------------------- 1 | joblib==0.8.3 2 | numpy==1.6.1 3 | scipy==0.14.0 4 | pysal==1.11.2 5 | scikit-learn==0.14.1 6 | -------------------------------------------------------------------------------- /release/python/0.4.2/crankshaft/setup.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | CartoDB Spatial Analysis Python Library 4 | See: 5 | https://github.com/CartoDB/crankshaft 6 | """ 7 | 8 | from setuptools import setup, find_packages 9 | 10 | setup( 11 | name='crankshaft', 12 | 13 | version='0.0.0', 14 | 15 | description='CartoDB Spatial Analysis Python Library', 16 | 17 | url='https://github.com/CartoDB/crankshaft', 18 | 19 | author='Data Services Team - CartoDB', 20 | author_email='dataservices@cartodb.com', 21 | 22 | license='MIT', 23 | 24 | classifiers=[ 25 | 'Development Status :: 3 - Alpha', 26 | 'Intended Audience :: Mapping comunity', 27 | 'Topic :: Maps :: Mapping Tools', 28 | 'License :: OSI Approved :: MIT License', 29 | 'Programming Language :: Python :: 2.7', 30 | ], 31 | 32 | keywords='maps mapping tools spatial analysis geostatistics', 33 | 34 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 35 | 36 | extras_require={ 37 | 'dev': ['unittest'], 38 | 'test': ['unittest', 'nose', 'mock'], 39 | }, 40 | 41 | # The choice of component versions is dictated by what's 42 | # provisioned in the production servers. 43 | # IMPORTANT NOTE: please don't change this line. Instead issue a ticket to systems for evaluation. 44 | install_requires=['joblib==0.8.3', 'numpy==1.6.1', 'scipy==0.14.0', 'pysal==1.11.2', 'scikit-learn==0.14.1'], 45 | 46 | requires=['pysal', 'numpy', 'sklearn'], 47 | 48 | test_suite='test' 49 | ) 50 | -------------------------------------------------------------------------------- /release/python/0.4.2/crankshaft/setup.py-r: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | CartoDB Spatial Analysis Python Library 4 | See: 5 | https://github.com/CartoDB/crankshaft 6 | """ 7 | 8 | from setuptools import setup, find_packages 9 | 10 | setup( 11 | name='crankshaft', 12 | 13 | version='0.0.0', 14 | 15 | description='CartoDB Spatial Analysis Python Library', 16 | 17 | url='https://github.com/CartoDB/crankshaft', 18 | 19 | author='Data Services Team - CartoDB', 20 | author_email='dataservices@cartodb.com', 21 | 22 | license='MIT', 23 | 24 | classifiers=[ 25 | 'Development Status :: 3 - Alpha', 26 | 'Intended Audience :: Mapping comunity', 27 | 'Topic :: Maps :: Mapping Tools', 28 | 'License :: OSI Approved :: MIT License', 29 | 'Programming Language :: Python :: 2.7', 30 | ], 31 | 32 | keywords='maps mapping tools spatial analysis geostatistics', 33 | 34 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 35 | 36 | extras_require={ 37 | 'dev': ['unittest'], 38 | 'test': ['unittest', 'nose', 'mock'], 39 | }, 40 | 41 | # The choice of component versions is dictated by what's 42 | # provisioned in the production servers. 43 | # IMPORTANT NOTE: please don't change this line. Instead issue a ticket to systems for evaluation. 44 | install_requires=['joblib==0.8.3', 'numpy==1.6.1', 'scipy==0.14.0', 'pysal==1.11.2', 'scikit-learn==0.14.1'], 45 | 46 | requires=['pysal', 'numpy', 'sklearn'], 47 | 48 | test_suite='test' 49 | ) 50 | -------------------------------------------------------------------------------- /release/python/0.4.2/crankshaft/test/helper.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from mock_plpy import MockPlPy 4 | plpy = MockPlPy() 5 | 6 | import sys 7 | sys.modules['plpy'] = plpy 8 | 9 | import os 10 | 11 | def fixture_file(name): 12 | dir = os.path.dirname(os.path.realpath(__file__)) 13 | return os.path.join(dir, 'fixtures', name) 14 | -------------------------------------------------------------------------------- /release/python/0.4.2/crankshaft/test/mock_plpy.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | class MockCursor: 4 | def __init__(self, data): 5 | self.cursor_pos = 0 6 | self.data = data 7 | 8 | def fetch(self, batch_size): 9 | batch = self.data[self.cursor_pos : self.cursor_pos + batch_size] 10 | self.cursor_pos += batch_size 11 | return batch 12 | 13 | 14 | class MockPlPy: 15 | def __init__(self): 16 | self._reset() 17 | 18 | def _reset(self): 19 | self.infos = [] 20 | self.notices = [] 21 | self.debugs = [] 22 | self.logs = [] 23 | self.warnings = [] 24 | self.errors = [] 25 | self.fatals = [] 26 | self.executes = [] 27 | self.results = [] 28 | self.prepares = [] 29 | self.results = [] 30 | 31 | def _define_result(self, query, result): 32 | pattern = re.compile(query, re.IGNORECASE | re.MULTILINE) 33 | self.results.append([pattern, result]) 34 | 35 | def notice(self, msg): 36 | self.notices.append(msg) 37 | 38 | def debug(self, msg): 39 | self.notices.append(msg) 40 | 41 | def info(self, msg): 42 | self.infos.append(msg) 43 | 44 | def cursor(self, query): 45 | data = self.execute(query) 46 | return MockCursor(data) 47 | 48 | def execute(self, query): # TODO: additional arguments 49 | for result in self.results: 50 | if result[0].match(query): 51 | return result[1] 52 | return [] 53 | -------------------------------------------------------------------------------- /release/python/0.4.2/crankshaft/test/test_cluster_kmeans.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import numpy as np 3 | 4 | 5 | # from mock_plpy import MockPlPy 6 | # plpy = MockPlPy() 7 | # 8 | # import sys 9 | # sys.modules['plpy'] = plpy 10 | from helper import plpy, fixture_file 11 | import numpy as np 12 | import crankshaft.clustering as cc 13 | import crankshaft.pysal_utils as pu 14 | from crankshaft import random_seeds 15 | import json 16 | 17 | class KMeansTest(unittest.TestCase): 18 | """Testing class for Moran's I functions""" 19 | 20 | def setUp(self): 21 | plpy._reset() 22 | self.cluster_data = json.loads(open(fixture_file('kmeans.json')).read()) 23 | self.params = {"subquery": "select * from table", 24 | "no_clusters": "10" 25 | } 26 | 27 | def test_kmeans(self): 28 | data = self.cluster_data 29 | plpy._define_result('select' ,data) 30 | clusters = cc.kmeans('subquery', 2) 31 | labels = [a[1] for a in clusters] 32 | c1 = [a for a in clusters if a[1]==0] 33 | c2 = [a for a in clusters if a[1]==1] 34 | 35 | self.assertEqual(len(np.unique(labels)),2) 36 | self.assertEqual(len(c1),20) 37 | self.assertEqual(len(c2),20) 38 | 39 | -------------------------------------------------------------------------------- /release/python/0.5.0/crankshaft/crankshaft/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all modules""" 2 | import crankshaft.random_seeds 3 | import crankshaft.clustering 4 | import crankshaft.space_time_dynamics 5 | import crankshaft.segmentation 6 | import analysis_data_provider 7 | -------------------------------------------------------------------------------- /release/python/0.5.0/crankshaft/crankshaft/clustering/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from for clustering""" 2 | from moran import * 3 | from kmeans import * 4 | from getis import * 5 | -------------------------------------------------------------------------------- /release/python/0.5.0/crankshaft/crankshaft/clustering/kmeans.py: -------------------------------------------------------------------------------- 1 | from sklearn.cluster import KMeans 2 | import numpy as np 3 | 4 | from crankshaft.analysis_data_provider import AnalysisDataProvider 5 | 6 | 7 | class Kmeans: 8 | def __init__(self, data_provider=None): 9 | if data_provider is None: 10 | self.data_provider = AnalysisDataProvider() 11 | else: 12 | self.data_provider = data_provider 13 | 14 | def spatial(self, query, no_clusters, no_init=20): 15 | """ 16 | find centers based on clusters of latitude/longitude pairs 17 | query: SQL query that has a WGS84 geometry (the_geom) 18 | """ 19 | params = {"subquery": query, 20 | "geom_col": "the_geom", 21 | "id_col": "cartodb_id"} 22 | 23 | data = self.data_provider.get_spatial_kmeans(params) 24 | 25 | # Unpack query response 26 | xs = data[0]['xs'] 27 | ys = data[0]['ys'] 28 | ids = data[0]['ids'] 29 | 30 | km = KMeans(n_clusters=no_clusters, n_init=no_init) 31 | labels = km.fit_predict(zip(xs, ys)) 32 | return zip(ids, labels) 33 | -------------------------------------------------------------------------------- /release/python/0.5.0/crankshaft/crankshaft/pysal_utils/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions for pysal_utils""" 2 | from crankshaft.pysal_utils.pysal_utils import * 3 | -------------------------------------------------------------------------------- /release/python/0.5.0/crankshaft/crankshaft/random_seeds.py: -------------------------------------------------------------------------------- 1 | """Random seed generator used for non-deterministic functions in crankshaft""" 2 | import random 3 | import numpy 4 | 5 | def set_random_seeds(value): 6 | """ 7 | Set the seeds of the RNGs (Random Number Generators) 8 | used internally. 9 | """ 10 | random.seed(value) 11 | numpy.random.seed(value) 12 | -------------------------------------------------------------------------------- /release/python/0.5.0/crankshaft/crankshaft/segmentation/__init__.py: -------------------------------------------------------------------------------- 1 | from segmentation import * 2 | -------------------------------------------------------------------------------- /release/python/0.5.0/crankshaft/crankshaft/space_time_dynamics/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from clustering libraries.""" 2 | from markov import * 3 | -------------------------------------------------------------------------------- /release/python/0.5.0/crankshaft/requirements.txt: -------------------------------------------------------------------------------- 1 | joblib==0.8.3 2 | numpy==1.6.1 3 | scipy==0.14.0 4 | pysal==1.11.2 5 | scikit-learn==0.14.1 6 | -------------------------------------------------------------------------------- /release/python/0.5.0/crankshaft/setup.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | CartoDB Spatial Analysis Python Library 4 | See: 5 | https://github.com/CartoDB/crankshaft 6 | """ 7 | 8 | from setuptools import setup, find_packages 9 | 10 | setup( 11 | name='crankshaft', 12 | 13 | version='0.5.0', 14 | 15 | description='CartoDB Spatial Analysis Python Library', 16 | 17 | url='https://github.com/CartoDB/crankshaft', 18 | 19 | author='Data Services Team - CartoDB', 20 | author_email='dataservices@cartodb.com', 21 | 22 | license='MIT', 23 | 24 | classifiers=[ 25 | 'Development Status :: 3 - Alpha', 26 | 'Intended Audience :: Mapping comunity', 27 | 'Topic :: Maps :: Mapping Tools', 28 | 'License :: OSI Approved :: MIT License', 29 | 'Programming Language :: Python :: 2.7', 30 | ], 31 | 32 | keywords='maps mapping tools spatial analysis geostatistics', 33 | 34 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 35 | 36 | extras_require={ 37 | 'dev': ['unittest'], 38 | 'test': ['unittest', 'nose', 'mock'], 39 | }, 40 | 41 | # The choice of component versions is dictated by what's 42 | # provisioned in the production servers. 43 | # IMPORTANT NOTE: please don't change this line. Instead issue a ticket to systems for evaluation. 44 | install_requires=['joblib==0.8.3', 'numpy==1.6.1', 'scipy==0.14.0', 'pysal==1.11.2', 'scikit-learn==0.14.1'], 45 | 46 | requires=['pysal', 'numpy', 'sklearn'], 47 | 48 | test_suite='test' 49 | ) 50 | -------------------------------------------------------------------------------- /release/python/0.5.0/crankshaft/test/helper.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from mock_plpy import MockPlPy 4 | plpy = MockPlPy() 5 | 6 | import sys 7 | sys.modules['plpy'] = plpy 8 | 9 | import os 10 | 11 | def fixture_file(name): 12 | dir = os.path.dirname(os.path.realpath(__file__)) 13 | return os.path.join(dir, 'fixtures', name) 14 | -------------------------------------------------------------------------------- /release/python/0.5.0/crankshaft/test/mock_plpy.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | class MockCursor: 5 | def __init__(self, data): 6 | self.cursor_pos = 0 7 | self.data = data 8 | 9 | def fetch(self, batch_size): 10 | batch = self.data[self.cursor_pos:self.cursor_pos + batch_size] 11 | self.cursor_pos += batch_size 12 | return batch 13 | 14 | 15 | class MockPlPy: 16 | def __init__(self): 17 | self._reset() 18 | 19 | def _reset(self): 20 | self.infos = [] 21 | self.notices = [] 22 | self.debugs = [] 23 | self.logs = [] 24 | self.warnings = [] 25 | self.errors = [] 26 | self.fatals = [] 27 | self.executes = [] 28 | self.results = [] 29 | self.prepares = [] 30 | self.results = [] 31 | 32 | def _define_result(self, query, result): 33 | pattern = re.compile(query, re.IGNORECASE | re.MULTILINE) 34 | self.results.append([pattern, result]) 35 | 36 | def notice(self, msg): 37 | self.notices.append(msg) 38 | 39 | def debug(self, msg): 40 | self.notices.append(msg) 41 | 42 | def info(self, msg): 43 | self.infos.append(msg) 44 | 45 | def cursor(self, query): 46 | data = self.execute(query) 47 | return MockCursor(data) 48 | 49 | # TODO: additional arguments 50 | def execute(self, query): 51 | for result in self.results: 52 | if result[0].match(query): 53 | return result[1] 54 | return [] 55 | -------------------------------------------------------------------------------- /release/python/0.5.1/crankshaft/crankshaft/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all modules""" 2 | import crankshaft.random_seeds 3 | import crankshaft.clustering 4 | import crankshaft.space_time_dynamics 5 | import crankshaft.segmentation 6 | import analysis_data_provider 7 | -------------------------------------------------------------------------------- /release/python/0.5.1/crankshaft/crankshaft/clustering/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from for clustering""" 2 | from moran import * 3 | from kmeans import * 4 | from getis import * 5 | -------------------------------------------------------------------------------- /release/python/0.5.1/crankshaft/crankshaft/clustering/kmeans.py: -------------------------------------------------------------------------------- 1 | from sklearn.cluster import KMeans 2 | import numpy as np 3 | 4 | from crankshaft.analysis_data_provider import AnalysisDataProvider 5 | 6 | 7 | class Kmeans: 8 | def __init__(self, data_provider=None): 9 | if data_provider is None: 10 | self.data_provider = AnalysisDataProvider() 11 | else: 12 | self.data_provider = data_provider 13 | 14 | def spatial(self, query, no_clusters, no_init=20): 15 | """ 16 | find centers based on clusters of latitude/longitude pairs 17 | query: SQL query that has a WGS84 geometry (the_geom) 18 | """ 19 | params = {"subquery": query, 20 | "geom_col": "the_geom", 21 | "id_col": "cartodb_id"} 22 | 23 | data = self.data_provider.get_spatial_kmeans(params) 24 | 25 | # Unpack query response 26 | xs = data[0]['xs'] 27 | ys = data[0]['ys'] 28 | ids = data[0]['ids'] 29 | 30 | km = KMeans(n_clusters=no_clusters, n_init=no_init) 31 | labels = km.fit_predict(zip(xs, ys)) 32 | return zip(ids, labels) 33 | -------------------------------------------------------------------------------- /release/python/0.5.1/crankshaft/crankshaft/pysal_utils/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions for pysal_utils""" 2 | from crankshaft.pysal_utils.pysal_utils import * 3 | -------------------------------------------------------------------------------- /release/python/0.5.1/crankshaft/crankshaft/random_seeds.py: -------------------------------------------------------------------------------- 1 | """Random seed generator used for non-deterministic functions in crankshaft""" 2 | import random 3 | import numpy 4 | 5 | def set_random_seeds(value): 6 | """ 7 | Set the seeds of the RNGs (Random Number Generators) 8 | used internally. 9 | """ 10 | random.seed(value) 11 | numpy.random.seed(value) 12 | -------------------------------------------------------------------------------- /release/python/0.5.1/crankshaft/crankshaft/segmentation/__init__.py: -------------------------------------------------------------------------------- 1 | from segmentation import * 2 | -------------------------------------------------------------------------------- /release/python/0.5.1/crankshaft/crankshaft/space_time_dynamics/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from clustering libraries.""" 2 | from markov import * 3 | -------------------------------------------------------------------------------- /release/python/0.5.1/crankshaft/requirements.txt: -------------------------------------------------------------------------------- 1 | joblib==0.8.3 2 | numpy==1.6.1 3 | scipy==0.14.0 4 | pysal==1.11.2 5 | scikit-learn==0.14.1 6 | -------------------------------------------------------------------------------- /release/python/0.5.1/crankshaft/setup.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | CartoDB Spatial Analysis Python Library 4 | See: 5 | https://github.com/CartoDB/crankshaft 6 | """ 7 | 8 | from setuptools import setup, find_packages 9 | 10 | setup( 11 | name='crankshaft', 12 | 13 | version='0.5.1', 14 | 15 | description='CartoDB Spatial Analysis Python Library', 16 | 17 | url='https://github.com/CartoDB/crankshaft', 18 | 19 | author='Data Services Team - CartoDB', 20 | author_email='dataservices@cartodb.com', 21 | 22 | license='MIT', 23 | 24 | classifiers=[ 25 | 'Development Status :: 3 - Alpha', 26 | 'Intended Audience :: Mapping comunity', 27 | 'Topic :: Maps :: Mapping Tools', 28 | 'License :: OSI Approved :: MIT License', 29 | 'Programming Language :: Python :: 2.7', 30 | ], 31 | 32 | keywords='maps mapping tools spatial analysis geostatistics', 33 | 34 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 35 | 36 | extras_require={ 37 | 'dev': ['unittest'], 38 | 'test': ['unittest', 'nose', 'mock'], 39 | }, 40 | 41 | # The choice of component versions is dictated by what's 42 | # provisioned in the production servers. 43 | # IMPORTANT NOTE: please don't change this line. Instead issue a ticket to systems for evaluation. 44 | install_requires=['joblib==0.8.3', 'numpy==1.6.1', 'scipy==0.14.0', 'pysal==1.11.2', 'scikit-learn==0.14.1'], 45 | 46 | requires=['pysal', 'numpy', 'sklearn'], 47 | 48 | test_suite='test' 49 | ) 50 | -------------------------------------------------------------------------------- /release/python/0.5.1/crankshaft/test/helper.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from mock_plpy import MockPlPy 4 | plpy = MockPlPy() 5 | 6 | import sys 7 | sys.modules['plpy'] = plpy 8 | 9 | import os 10 | 11 | def fixture_file(name): 12 | dir = os.path.dirname(os.path.realpath(__file__)) 13 | return os.path.join(dir, 'fixtures', name) 14 | -------------------------------------------------------------------------------- /release/python/0.5.1/crankshaft/test/mock_plpy.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | class MockCursor: 5 | def __init__(self, data): 6 | self.cursor_pos = 0 7 | self.data = data 8 | 9 | def fetch(self, batch_size): 10 | batch = self.data[self.cursor_pos:self.cursor_pos + batch_size] 11 | self.cursor_pos += batch_size 12 | return batch 13 | 14 | 15 | class MockPlPy: 16 | def __init__(self): 17 | self._reset() 18 | 19 | def _reset(self): 20 | self.infos = [] 21 | self.notices = [] 22 | self.debugs = [] 23 | self.logs = [] 24 | self.warnings = [] 25 | self.errors = [] 26 | self.fatals = [] 27 | self.executes = [] 28 | self.results = [] 29 | self.prepares = [] 30 | self.results = [] 31 | 32 | def _define_result(self, query, result): 33 | pattern = re.compile(query, re.IGNORECASE | re.MULTILINE) 34 | self.results.append([pattern, result]) 35 | 36 | def notice(self, msg): 37 | self.notices.append(msg) 38 | 39 | def debug(self, msg): 40 | self.notices.append(msg) 41 | 42 | def info(self, msg): 43 | self.infos.append(msg) 44 | 45 | def cursor(self, query): 46 | data = self.execute(query) 47 | return MockCursor(data) 48 | 49 | # TODO: additional arguments 50 | def execute(self, query): 51 | for result in self.results: 52 | if result[0].match(query): 53 | return result[1] 54 | return [] 55 | -------------------------------------------------------------------------------- /release/python/0.5.2/crankshaft/crankshaft/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all modules""" 2 | import crankshaft.random_seeds 3 | import crankshaft.clustering 4 | import crankshaft.space_time_dynamics 5 | import crankshaft.segmentation 6 | import analysis_data_provider 7 | -------------------------------------------------------------------------------- /release/python/0.5.2/crankshaft/crankshaft/clustering/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from for clustering""" 2 | from moran import * 3 | from kmeans import * 4 | from getis import * 5 | -------------------------------------------------------------------------------- /release/python/0.5.2/crankshaft/crankshaft/clustering/kmeans.py: -------------------------------------------------------------------------------- 1 | from sklearn.cluster import KMeans 2 | import numpy as np 3 | 4 | from crankshaft.analysis_data_provider import AnalysisDataProvider 5 | 6 | 7 | class Kmeans: 8 | def __init__(self, data_provider=None): 9 | if data_provider is None: 10 | self.data_provider = AnalysisDataProvider() 11 | else: 12 | self.data_provider = data_provider 13 | 14 | def spatial(self, query, no_clusters, no_init=20): 15 | """ 16 | find centers based on clusters of latitude/longitude pairs 17 | query: SQL query that has a WGS84 geometry (the_geom) 18 | """ 19 | params = {"subquery": query, 20 | "geom_col": "the_geom", 21 | "id_col": "cartodb_id"} 22 | 23 | data = self.data_provider.get_spatial_kmeans(params) 24 | 25 | # Unpack query response 26 | xs = data[0]['xs'] 27 | ys = data[0]['ys'] 28 | ids = data[0]['ids'] 29 | 30 | km = KMeans(n_clusters=no_clusters, n_init=no_init) 31 | labels = km.fit_predict(zip(xs, ys)) 32 | return zip(ids, labels) 33 | -------------------------------------------------------------------------------- /release/python/0.5.2/crankshaft/crankshaft/pysal_utils/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions for pysal_utils""" 2 | from crankshaft.pysal_utils.pysal_utils import * 3 | -------------------------------------------------------------------------------- /release/python/0.5.2/crankshaft/crankshaft/random_seeds.py: -------------------------------------------------------------------------------- 1 | """Random seed generator used for non-deterministic functions in crankshaft""" 2 | import random 3 | import numpy 4 | 5 | def set_random_seeds(value): 6 | """ 7 | Set the seeds of the RNGs (Random Number Generators) 8 | used internally. 9 | """ 10 | random.seed(value) 11 | numpy.random.seed(value) 12 | -------------------------------------------------------------------------------- /release/python/0.5.2/crankshaft/crankshaft/segmentation/__init__.py: -------------------------------------------------------------------------------- 1 | from segmentation import * 2 | -------------------------------------------------------------------------------- /release/python/0.5.2/crankshaft/crankshaft/space_time_dynamics/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from clustering libraries.""" 2 | from markov import * 3 | -------------------------------------------------------------------------------- /release/python/0.5.2/crankshaft/requirements.txt: -------------------------------------------------------------------------------- 1 | joblib==0.8.3 2 | numpy==1.6.1 3 | scipy==0.14.0 4 | pysal==1.11.2 5 | scikit-learn==0.14.1 6 | -------------------------------------------------------------------------------- /release/python/0.5.2/crankshaft/setup.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | CartoDB Spatial Analysis Python Library 4 | See: 5 | https://github.com/CartoDB/crankshaft 6 | """ 7 | 8 | from setuptools import setup, find_packages 9 | 10 | setup( 11 | name='crankshaft', 12 | 13 | version='0.5.2', 14 | 15 | description='CartoDB Spatial Analysis Python Library', 16 | 17 | url='https://github.com/CartoDB/crankshaft', 18 | 19 | author='Data Services Team - CartoDB', 20 | author_email='dataservices@cartodb.com', 21 | 22 | license='MIT', 23 | 24 | classifiers=[ 25 | 'Development Status :: 3 - Alpha', 26 | 'Intended Audience :: Mapping comunity', 27 | 'Topic :: Maps :: Mapping Tools', 28 | 'License :: OSI Approved :: MIT License', 29 | 'Programming Language :: Python :: 2.7', 30 | ], 31 | 32 | keywords='maps mapping tools spatial analysis geostatistics', 33 | 34 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 35 | 36 | extras_require={ 37 | 'dev': ['unittest'], 38 | 'test': ['unittest', 'nose', 'mock'], 39 | }, 40 | 41 | # The choice of component versions is dictated by what's 42 | # provisioned in the production servers. 43 | # IMPORTANT NOTE: please don't change this line. Instead issue a ticket to systems for evaluation. 44 | install_requires=['joblib==0.8.3', 'numpy==1.6.1', 'scipy==0.14.0', 'pysal==1.11.2', 'scikit-learn==0.14.1'], 45 | 46 | requires=['pysal', 'numpy', 'sklearn'], 47 | 48 | test_suite='test' 49 | ) 50 | -------------------------------------------------------------------------------- /release/python/0.5.2/crankshaft/test/helper.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from mock_plpy import MockPlPy 4 | plpy = MockPlPy() 5 | 6 | import sys 7 | sys.modules['plpy'] = plpy 8 | 9 | import os 10 | 11 | def fixture_file(name): 12 | dir = os.path.dirname(os.path.realpath(__file__)) 13 | return os.path.join(dir, 'fixtures', name) 14 | -------------------------------------------------------------------------------- /release/python/0.5.2/crankshaft/test/mock_plpy.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | class MockCursor: 5 | def __init__(self, data): 6 | self.cursor_pos = 0 7 | self.data = data 8 | 9 | def fetch(self, batch_size): 10 | batch = self.data[self.cursor_pos:self.cursor_pos + batch_size] 11 | self.cursor_pos += batch_size 12 | return batch 13 | 14 | 15 | class MockPlPy: 16 | def __init__(self): 17 | self._reset() 18 | 19 | def _reset(self): 20 | self.infos = [] 21 | self.notices = [] 22 | self.debugs = [] 23 | self.logs = [] 24 | self.warnings = [] 25 | self.errors = [] 26 | self.fatals = [] 27 | self.executes = [] 28 | self.results = [] 29 | self.prepares = [] 30 | self.results = [] 31 | 32 | def _define_result(self, query, result): 33 | pattern = re.compile(query, re.IGNORECASE | re.MULTILINE) 34 | self.results.append([pattern, result]) 35 | 36 | def notice(self, msg): 37 | self.notices.append(msg) 38 | 39 | def debug(self, msg): 40 | self.notices.append(msg) 41 | 42 | def info(self, msg): 43 | self.infos.append(msg) 44 | 45 | def cursor(self, query): 46 | data = self.execute(query) 47 | return MockCursor(data) 48 | 49 | # TODO: additional arguments 50 | def execute(self, query): 51 | for result in self.results: 52 | if result[0].match(query): 53 | return result[1] 54 | return [] 55 | -------------------------------------------------------------------------------- /release/python/0.6.0/crankshaft/crankshaft/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all modules""" 2 | import crankshaft.random_seeds 3 | import crankshaft.clustering 4 | import crankshaft.space_time_dynamics 5 | import crankshaft.segmentation 6 | import crankshaft.regression 7 | import analysis_data_provider 8 | -------------------------------------------------------------------------------- /release/python/0.6.0/crankshaft/crankshaft/clustering/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from for clustering""" 2 | from moran import * 3 | from kmeans import * 4 | from getis import * 5 | -------------------------------------------------------------------------------- /release/python/0.6.0/crankshaft/crankshaft/clustering/kmeans.py: -------------------------------------------------------------------------------- 1 | from sklearn.cluster import KMeans 2 | import numpy as np 3 | 4 | from crankshaft.analysis_data_provider import AnalysisDataProvider 5 | 6 | 7 | class Kmeans: 8 | def __init__(self, data_provider=None): 9 | if data_provider is None: 10 | self.data_provider = AnalysisDataProvider() 11 | else: 12 | self.data_provider = data_provider 13 | 14 | def spatial(self, query, no_clusters, no_init=20): 15 | """ 16 | find centers based on clusters of latitude/longitude pairs 17 | query: SQL query that has a WGS84 geometry (the_geom) 18 | """ 19 | params = {"subquery": query, 20 | "geom_col": "the_geom", 21 | "id_col": "cartodb_id"} 22 | 23 | data = self.data_provider.get_spatial_kmeans(params) 24 | 25 | # Unpack query response 26 | xs = data[0]['xs'] 27 | ys = data[0]['ys'] 28 | ids = data[0]['ids'] 29 | 30 | km = KMeans(n_clusters=no_clusters, n_init=no_init) 31 | labels = km.fit_predict(zip(xs, ys)) 32 | return zip(ids, labels) 33 | -------------------------------------------------------------------------------- /release/python/0.6.0/crankshaft/crankshaft/optimization/optim.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CartoDB/crankshaft/494c047563328b092fe5fe0b8b4dd862edfee836/release/python/0.6.0/crankshaft/crankshaft/optimization/optim.py -------------------------------------------------------------------------------- /release/python/0.6.0/crankshaft/crankshaft/pysal_utils/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions for pysal_utils""" 2 | from crankshaft.pysal_utils.pysal_utils import * 3 | -------------------------------------------------------------------------------- /release/python/0.6.0/crankshaft/crankshaft/random_seeds.py: -------------------------------------------------------------------------------- 1 | """Random seed generator used for non-deterministic functions in crankshaft""" 2 | import random 3 | import numpy 4 | 5 | def set_random_seeds(value): 6 | """ 7 | Set the seeds of the RNGs (Random Number Generators) 8 | used internally. 9 | """ 10 | random.seed(value) 11 | numpy.random.seed(value) 12 | -------------------------------------------------------------------------------- /release/python/0.6.0/crankshaft/crankshaft/regression/__init__.py: -------------------------------------------------------------------------------- 1 | from crankshaft.regression.gwr import * 2 | from crankshaft.regression.glm import * 3 | from crankshaft.regression.gwr_cs import * 4 | -------------------------------------------------------------------------------- /release/python/0.6.0/crankshaft/crankshaft/regression/glm/__init__.py: -------------------------------------------------------------------------------- 1 | import glm 2 | import family 3 | import utils 4 | import iwls 5 | -------------------------------------------------------------------------------- /release/python/0.6.0/crankshaft/crankshaft/regression/gwr/__init__.py: -------------------------------------------------------------------------------- 1 | from base import * 2 | -------------------------------------------------------------------------------- /release/python/0.6.0/crankshaft/crankshaft/regression/gwr/base/__init__.py: -------------------------------------------------------------------------------- 1 | import gwr 2 | import sel_bw 3 | import diagnostics 4 | import kernels 5 | -------------------------------------------------------------------------------- /release/python/0.6.0/crankshaft/crankshaft/segmentation/__init__.py: -------------------------------------------------------------------------------- 1 | from segmentation import * 2 | -------------------------------------------------------------------------------- /release/python/0.6.0/crankshaft/crankshaft/space_time_dynamics/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from clustering libraries.""" 2 | from markov import * 3 | -------------------------------------------------------------------------------- /release/python/0.6.0/crankshaft/requirements.txt: -------------------------------------------------------------------------------- 1 | joblib==0.8.3 2 | numpy==1.6.1 3 | scipy==0.14.0 4 | pysal==1.11.2 5 | scikit-learn==0.14.1 6 | -------------------------------------------------------------------------------- /release/python/0.6.0/crankshaft/setup.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | CartoDB Spatial Analysis Python Library 4 | See: 5 | https://github.com/CartoDB/crankshaft 6 | """ 7 | 8 | from setuptools import setup, find_packages 9 | 10 | setup( 11 | name='crankshaft', 12 | 13 | version='0.6.0', 14 | 15 | description='CartoDB Spatial Analysis Python Library', 16 | 17 | url='https://github.com/CartoDB/crankshaft', 18 | 19 | author='Data Services Team - CartoDB', 20 | author_email='dataservices@cartodb.com', 21 | 22 | license='MIT', 23 | 24 | classifiers=[ 25 | 'Development Status :: 3 - Alpha', 26 | 'Intended Audience :: Mapping comunity', 27 | 'Topic :: Maps :: Mapping Tools', 28 | 'License :: OSI Approved :: MIT License', 29 | 'Programming Language :: Python :: 2.7', 30 | ], 31 | 32 | keywords='maps mapping tools spatial analysis geostatistics', 33 | 34 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 35 | 36 | extras_require={ 37 | 'dev': ['unittest'], 38 | 'test': ['unittest', 'nose', 'mock'], 39 | }, 40 | 41 | # The choice of component versions is dictated by what's 42 | # provisioned in the production servers. 43 | # IMPORTANT NOTE: please don't change this line. Instead issue a ticket to systems for evaluation. 44 | install_requires=['joblib==0.8.3', 'numpy==1.6.1', 'scipy==0.14.0', 'pysal==1.11.2', 'scikit-learn==0.14.1'], 45 | 46 | requires=['pysal', 'numpy', 'sklearn'], 47 | 48 | test_suite='test' 49 | ) 50 | -------------------------------------------------------------------------------- /release/python/0.6.0/crankshaft/test/helper.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from mock_plpy import MockPlPy 4 | plpy = MockPlPy() 5 | 6 | import sys 7 | sys.modules['plpy'] = plpy 8 | 9 | import os 10 | 11 | def fixture_file(name): 12 | dir = os.path.dirname(os.path.realpath(__file__)) 13 | return os.path.join(dir, 'fixtures', name) 14 | -------------------------------------------------------------------------------- /release/python/0.6.0/crankshaft/test/mock_plpy.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | class MockCursor: 5 | def __init__(self, data): 6 | self.cursor_pos = 0 7 | self.data = data 8 | 9 | def fetch(self, batch_size): 10 | batch = self.data[self.cursor_pos:self.cursor_pos + batch_size] 11 | self.cursor_pos += batch_size 12 | return batch 13 | 14 | 15 | class MockPlPy: 16 | def __init__(self): 17 | self._reset() 18 | 19 | def _reset(self): 20 | self.infos = [] 21 | self.notices = [] 22 | self.debugs = [] 23 | self.logs = [] 24 | self.warnings = [] 25 | self.errors = [] 26 | self.fatals = [] 27 | self.executes = [] 28 | self.results = [] 29 | self.prepares = [] 30 | self.results = [] 31 | 32 | def _define_result(self, query, result): 33 | pattern = re.compile(query, re.IGNORECASE | re.MULTILINE) 34 | self.results.append([pattern, result]) 35 | 36 | def notice(self, msg): 37 | self.notices.append(msg) 38 | 39 | def debug(self, msg): 40 | self.notices.append(msg) 41 | 42 | def info(self, msg): 43 | self.infos.append(msg) 44 | 45 | def cursor(self, query): 46 | data = self.execute(query) 47 | return MockCursor(data) 48 | 49 | # TODO: additional arguments 50 | def execute(self, query): 51 | for result in self.results: 52 | if result[0].match(query): 53 | return result[1] 54 | return [] 55 | -------------------------------------------------------------------------------- /release/python/0.6.1/crankshaft/crankshaft/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all modules""" 2 | import crankshaft.random_seeds 3 | import crankshaft.clustering 4 | import crankshaft.space_time_dynamics 5 | import crankshaft.segmentation 6 | import crankshaft.regression 7 | import analysis_data_provider 8 | -------------------------------------------------------------------------------- /release/python/0.6.1/crankshaft/crankshaft/clustering/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from for clustering""" 2 | from moran import * 3 | from kmeans import * 4 | from getis import * 5 | -------------------------------------------------------------------------------- /release/python/0.6.1/crankshaft/crankshaft/clustering/kmeans.py: -------------------------------------------------------------------------------- 1 | from sklearn.cluster import KMeans 2 | import numpy as np 3 | 4 | from crankshaft.analysis_data_provider import AnalysisDataProvider 5 | 6 | 7 | class Kmeans: 8 | def __init__(self, data_provider=None): 9 | if data_provider is None: 10 | self.data_provider = AnalysisDataProvider() 11 | else: 12 | self.data_provider = data_provider 13 | 14 | def spatial(self, query, no_clusters, no_init=20): 15 | """ 16 | find centers based on clusters of latitude/longitude pairs 17 | query: SQL query that has a WGS84 geometry (the_geom) 18 | """ 19 | params = {"subquery": query, 20 | "geom_col": "the_geom", 21 | "id_col": "cartodb_id"} 22 | 23 | data = self.data_provider.get_spatial_kmeans(params) 24 | 25 | # Unpack query response 26 | xs = data[0]['xs'] 27 | ys = data[0]['ys'] 28 | ids = data[0]['ids'] 29 | 30 | km = KMeans(n_clusters=no_clusters, n_init=no_init) 31 | labels = km.fit_predict(zip(xs, ys)) 32 | return zip(ids, labels) 33 | -------------------------------------------------------------------------------- /release/python/0.6.1/crankshaft/crankshaft/pysal_utils/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions for pysal_utils""" 2 | from crankshaft.pysal_utils.pysal_utils import * 3 | -------------------------------------------------------------------------------- /release/python/0.6.1/crankshaft/crankshaft/random_seeds.py: -------------------------------------------------------------------------------- 1 | """Random seed generator used for non-deterministic functions in crankshaft""" 2 | import random 3 | import numpy 4 | 5 | def set_random_seeds(value): 6 | """ 7 | Set the seeds of the RNGs (Random Number Generators) 8 | used internally. 9 | """ 10 | random.seed(value) 11 | numpy.random.seed(value) 12 | -------------------------------------------------------------------------------- /release/python/0.6.1/crankshaft/crankshaft/regression/__init__.py: -------------------------------------------------------------------------------- 1 | from crankshaft.regression.gwr import * 2 | from crankshaft.regression.glm import * 3 | from crankshaft.regression.gwr_cs import * 4 | -------------------------------------------------------------------------------- /release/python/0.6.1/crankshaft/crankshaft/regression/glm/__init__.py: -------------------------------------------------------------------------------- 1 | import glm 2 | import family 3 | import utils 4 | import iwls 5 | -------------------------------------------------------------------------------- /release/python/0.6.1/crankshaft/crankshaft/regression/gwr/__init__.py: -------------------------------------------------------------------------------- 1 | from base import * 2 | -------------------------------------------------------------------------------- /release/python/0.6.1/crankshaft/crankshaft/regression/gwr/base/__init__.py: -------------------------------------------------------------------------------- 1 | import gwr 2 | import sel_bw 3 | import diagnostics 4 | import kernels 5 | -------------------------------------------------------------------------------- /release/python/0.6.1/crankshaft/crankshaft/segmentation/__init__.py: -------------------------------------------------------------------------------- 1 | from segmentation import * 2 | -------------------------------------------------------------------------------- /release/python/0.6.1/crankshaft/crankshaft/space_time_dynamics/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from clustering libraries.""" 2 | from markov import * 3 | -------------------------------------------------------------------------------- /release/python/0.6.1/crankshaft/requirements.txt: -------------------------------------------------------------------------------- 1 | joblib==0.8.3 2 | numpy==1.6.1 3 | scipy==0.14.0 4 | pysal==1.11.2 5 | scikit-learn==0.14.1 6 | -------------------------------------------------------------------------------- /release/python/0.6.1/crankshaft/setup.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | CartoDB Spatial Analysis Python Library 4 | See: 5 | https://github.com/CartoDB/crankshaft 6 | """ 7 | 8 | from setuptools import setup, find_packages 9 | 10 | setup( 11 | name='crankshaft', 12 | 13 | version='0.6.1', 14 | 15 | description='CartoDB Spatial Analysis Python Library', 16 | 17 | url='https://github.com/CartoDB/crankshaft', 18 | 19 | author='Data Services Team - CartoDB', 20 | author_email='dataservices@cartodb.com', 21 | 22 | license='MIT', 23 | 24 | classifiers=[ 25 | 'Development Status :: 3 - Alpha', 26 | 'Intended Audience :: Mapping comunity', 27 | 'Topic :: Maps :: Mapping Tools', 28 | 'License :: OSI Approved :: MIT License', 29 | 'Programming Language :: Python :: 2.7', 30 | ], 31 | 32 | keywords='maps mapping tools spatial analysis geostatistics', 33 | 34 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 35 | 36 | extras_require={ 37 | 'dev': ['unittest'], 38 | 'test': ['unittest', 'nose', 'mock'], 39 | }, 40 | 41 | # The choice of component versions is dictated by what's 42 | # provisioned in the production servers. 43 | # IMPORTANT NOTE: please don't change this line. Instead issue a ticket to systems for evaluation. 44 | install_requires=['joblib==0.8.3', 'numpy==1.6.1', 'scipy==0.14.0', 'pysal==1.11.2', 'scikit-learn==0.14.1'], 45 | 46 | requires=['pysal', 'numpy', 'sklearn'], 47 | 48 | test_suite='test' 49 | ) 50 | -------------------------------------------------------------------------------- /release/python/0.6.1/crankshaft/test/helper.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from mock_plpy import MockPlPy 4 | plpy = MockPlPy() 5 | 6 | import sys 7 | sys.modules['plpy'] = plpy 8 | 9 | import os 10 | 11 | def fixture_file(name): 12 | dir = os.path.dirname(os.path.realpath(__file__)) 13 | return os.path.join(dir, 'fixtures', name) 14 | -------------------------------------------------------------------------------- /release/python/0.6.1/crankshaft/test/mock_plpy.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | class MockCursor: 5 | def __init__(self, data): 6 | self.cursor_pos = 0 7 | self.data = data 8 | 9 | def fetch(self, batch_size): 10 | batch = self.data[self.cursor_pos:self.cursor_pos + batch_size] 11 | self.cursor_pos += batch_size 12 | return batch 13 | 14 | 15 | class MockPlPy: 16 | def __init__(self): 17 | self._reset() 18 | 19 | def _reset(self): 20 | self.infos = [] 21 | self.notices = [] 22 | self.debugs = [] 23 | self.logs = [] 24 | self.warnings = [] 25 | self.errors = [] 26 | self.fatals = [] 27 | self.executes = [] 28 | self.results = [] 29 | self.prepares = [] 30 | self.results = [] 31 | 32 | def _define_result(self, query, result): 33 | pattern = re.compile(query, re.IGNORECASE | re.MULTILINE) 34 | self.results.append([pattern, result]) 35 | 36 | def notice(self, msg): 37 | self.notices.append(msg) 38 | 39 | def debug(self, msg): 40 | self.notices.append(msg) 41 | 42 | def info(self, msg): 43 | self.infos.append(msg) 44 | 45 | def cursor(self, query): 46 | data = self.execute(query) 47 | return MockCursor(data) 48 | 49 | # TODO: additional arguments 50 | def execute(self, query): 51 | for result in self.results: 52 | if result[0].match(query): 53 | return result[1] 54 | return [] 55 | -------------------------------------------------------------------------------- /release/python/0.7.0/crankshaft/crankshaft/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all modules""" 2 | import crankshaft.random_seeds 3 | import crankshaft.clustering 4 | import crankshaft.space_time_dynamics 5 | import crankshaft.segmentation 6 | import crankshaft.regression 7 | import analysis_data_provider 8 | -------------------------------------------------------------------------------- /release/python/0.7.0/crankshaft/crankshaft/clustering/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from for clustering""" 2 | from moran import * 3 | from kmeans import * 4 | from getis import * 5 | -------------------------------------------------------------------------------- /release/python/0.7.0/crankshaft/crankshaft/pysal_utils/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions for pysal_utils""" 2 | from crankshaft.pysal_utils.pysal_utils import * 3 | -------------------------------------------------------------------------------- /release/python/0.7.0/crankshaft/crankshaft/random_seeds.py: -------------------------------------------------------------------------------- 1 | """Random seed generator used for non-deterministic functions in crankshaft""" 2 | import random 3 | import numpy 4 | 5 | 6 | def set_random_seeds(value): 7 | """ 8 | Set the seeds of the RNGs (Random Number Generators) 9 | used internally. 10 | """ 11 | random.seed(value) 12 | numpy.random.seed(value) 13 | -------------------------------------------------------------------------------- /release/python/0.7.0/crankshaft/crankshaft/regression/__init__.py: -------------------------------------------------------------------------------- 1 | from crankshaft.regression.gwr import * 2 | from crankshaft.regression.glm import * 3 | from crankshaft.regression.gwr_cs import * 4 | -------------------------------------------------------------------------------- /release/python/0.7.0/crankshaft/crankshaft/regression/glm/__init__.py: -------------------------------------------------------------------------------- 1 | import glm 2 | import family 3 | import utils 4 | import iwls 5 | -------------------------------------------------------------------------------- /release/python/0.7.0/crankshaft/crankshaft/regression/gwr/__init__.py: -------------------------------------------------------------------------------- 1 | from base import * 2 | -------------------------------------------------------------------------------- /release/python/0.7.0/crankshaft/crankshaft/regression/gwr/base/__init__.py: -------------------------------------------------------------------------------- 1 | import gwr 2 | import sel_bw 3 | import diagnostics 4 | import kernels 5 | -------------------------------------------------------------------------------- /release/python/0.7.0/crankshaft/crankshaft/segmentation/__init__.py: -------------------------------------------------------------------------------- 1 | from segmentation import * 2 | -------------------------------------------------------------------------------- /release/python/0.7.0/crankshaft/crankshaft/space_time_dynamics/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from clustering libraries.""" 2 | from markov import * 3 | -------------------------------------------------------------------------------- /release/python/0.7.0/crankshaft/requirements.txt: -------------------------------------------------------------------------------- 1 | joblib==0.8.3 2 | numpy==1.6.1 3 | scipy==0.14.0 4 | pysal==1.14.3 5 | scikit-learn==0.14.1 6 | -------------------------------------------------------------------------------- /release/python/0.7.0/crankshaft/setup.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | CartoDB Spatial Analysis Python Library 4 | See: 5 | https://github.com/CartoDB/crankshaft 6 | """ 7 | 8 | from setuptools import setup, find_packages 9 | 10 | setup( 11 | name='crankshaft', 12 | 13 | version='0.7.0', 14 | 15 | description='CartoDB Spatial Analysis Python Library', 16 | 17 | url='https://github.com/CartoDB/crankshaft', 18 | 19 | author='Data Services Team - CartoDB', 20 | author_email='dataservices@cartodb.com', 21 | 22 | license='MIT', 23 | 24 | classifiers=[ 25 | 'Development Status :: 3 - Alpha', 26 | 'Intended Audience :: Mapping comunity', 27 | 'Topic :: Maps :: Mapping Tools', 28 | 'License :: OSI Approved :: MIT License', 29 | 'Programming Language :: Python :: 2.7', 30 | ], 31 | 32 | keywords='maps mapping tools spatial analysis geostatistics', 33 | 34 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 35 | 36 | extras_require={ 37 | 'dev': ['unittest'], 38 | 'test': ['unittest', 'nose', 'mock'], 39 | }, 40 | 41 | # The choice of component versions is dictated by what's 42 | # provisioned in the production servers. 43 | # IMPORTANT NOTE: please don't change this line. Instead issue a ticket to systems for evaluation. 44 | install_requires=['joblib==0.8.3', 'numpy==1.6.1', 'scipy==0.14.0', 'pysal==1.14.3', 'scikit-learn==0.14.1'], 45 | 46 | requires=['pysal', 'numpy', 'sklearn'], 47 | 48 | test_suite='test' 49 | ) 50 | -------------------------------------------------------------------------------- /release/python/0.7.0/crankshaft/test/helper.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from mock_plpy import MockPlPy 4 | plpy = MockPlPy() 5 | 6 | import sys 7 | sys.modules['plpy'] = plpy 8 | 9 | import os 10 | 11 | def fixture_file(name): 12 | dir = os.path.dirname(os.path.realpath(__file__)) 13 | return os.path.join(dir, 'fixtures', name) 14 | -------------------------------------------------------------------------------- /release/python/0.7.0/crankshaft/test/mock_plpy.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | class MockCursor: 5 | def __init__(self, data): 6 | self.cursor_pos = 0 7 | self.data = data 8 | 9 | def fetch(self, batch_size): 10 | batch = self.data[self.cursor_pos:self.cursor_pos + batch_size] 11 | self.cursor_pos += batch_size 12 | return batch 13 | 14 | 15 | class MockPlPy: 16 | def __init__(self): 17 | self._reset() 18 | 19 | def _reset(self): 20 | self.infos = [] 21 | self.notices = [] 22 | self.debugs = [] 23 | self.logs = [] 24 | self.warnings = [] 25 | self.errors = [] 26 | self.fatals = [] 27 | self.executes = [] 28 | self.results = [] 29 | self.prepares = [] 30 | self.results = [] 31 | 32 | def _define_result(self, query, result): 33 | pattern = re.compile(query, re.IGNORECASE | re.MULTILINE) 34 | self.results.append([pattern, result]) 35 | 36 | def notice(self, msg): 37 | self.notices.append(msg) 38 | 39 | def debug(self, msg): 40 | self.notices.append(msg) 41 | 42 | def info(self, msg): 43 | self.infos.append(msg) 44 | 45 | def error(self, msg): 46 | self.notices.append(msg) 47 | 48 | def cursor(self, query): 49 | data = self.execute(query) 50 | return MockCursor(data) 51 | 52 | # TODO: additional arguments 53 | def execute(self, query): 54 | for result in self.results: 55 | if result[0].match(query): 56 | return result[1] 57 | return [] 58 | -------------------------------------------------------------------------------- /release/python/0.8.0/crankshaft/crankshaft/.analysis_data_provider.py.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CartoDB/crankshaft/494c047563328b092fe5fe0b8b4dd862edfee836/release/python/0.8.0/crankshaft/crankshaft/.analysis_data_provider.py.swp -------------------------------------------------------------------------------- /release/python/0.8.0/crankshaft/crankshaft/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all modules""" 2 | import crankshaft.random_seeds 3 | import crankshaft.clustering 4 | import crankshaft.space_time_dynamics 5 | import crankshaft.segmentation 6 | import crankshaft.regression 7 | import analysis_data_provider 8 | -------------------------------------------------------------------------------- /release/python/0.8.0/crankshaft/crankshaft/clustering/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from for clustering""" 2 | from moran import * 3 | from kmeans import * 4 | from getis import * 5 | -------------------------------------------------------------------------------- /release/python/0.8.0/crankshaft/crankshaft/pysal_utils/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions for pysal_utils""" 2 | from crankshaft.pysal_utils.pysal_utils import * 3 | -------------------------------------------------------------------------------- /release/python/0.8.0/crankshaft/crankshaft/random_seeds.py: -------------------------------------------------------------------------------- 1 | """Random seed generator used for non-deterministic functions in crankshaft""" 2 | import random 3 | import numpy 4 | 5 | 6 | def set_random_seeds(value): 7 | """ 8 | Set the seeds of the RNGs (Random Number Generators) 9 | used internally. 10 | """ 11 | random.seed(value) 12 | numpy.random.seed(value) 13 | -------------------------------------------------------------------------------- /release/python/0.8.0/crankshaft/crankshaft/regression/__init__.py: -------------------------------------------------------------------------------- 1 | from crankshaft.regression.gwr import * 2 | from crankshaft.regression.glm import * 3 | from crankshaft.regression.gwr_cs import * 4 | -------------------------------------------------------------------------------- /release/python/0.8.0/crankshaft/crankshaft/regression/glm/__init__.py: -------------------------------------------------------------------------------- 1 | import glm 2 | import family 3 | import utils 4 | import iwls 5 | -------------------------------------------------------------------------------- /release/python/0.8.0/crankshaft/crankshaft/regression/gwr/__init__.py: -------------------------------------------------------------------------------- 1 | from base import * 2 | -------------------------------------------------------------------------------- /release/python/0.8.0/crankshaft/crankshaft/regression/gwr/base/__init__.py: -------------------------------------------------------------------------------- 1 | import gwr 2 | import sel_bw 3 | import diagnostics 4 | import kernels 5 | -------------------------------------------------------------------------------- /release/python/0.8.0/crankshaft/crankshaft/segmentation/__init__.py: -------------------------------------------------------------------------------- 1 | from segmentation import * 2 | -------------------------------------------------------------------------------- /release/python/0.8.0/crankshaft/crankshaft/space_time_dynamics/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from clustering libraries.""" 2 | from markov import * 3 | -------------------------------------------------------------------------------- /release/python/0.8.0/crankshaft/requirements.txt: -------------------------------------------------------------------------------- 1 | joblib==0.8.3 2 | numpy==1.6.1 3 | scipy==0.14.0 4 | pysal==1.14.3 5 | scikit-learn==0.14.1 6 | -------------------------------------------------------------------------------- /release/python/0.8.0/crankshaft/setup.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | CartoDB Spatial Analysis Python Library 4 | See: 5 | https://github.com/CartoDB/crankshaft 6 | """ 7 | 8 | from setuptools import setup, find_packages 9 | 10 | setup( 11 | name='crankshaft', 12 | 13 | version='0.0.0', 14 | 15 | description='CartoDB Spatial Analysis Python Library', 16 | 17 | url='https://github.com/CartoDB/crankshaft', 18 | 19 | author='Data Services Team - CartoDB', 20 | author_email='dataservices@cartodb.com', 21 | 22 | license='MIT', 23 | 24 | classifiers=[ 25 | 'Development Status :: 3 - Alpha', 26 | 'Intended Audience :: Mapping comunity', 27 | 'Topic :: Maps :: Mapping Tools', 28 | 'License :: OSI Approved :: MIT License', 29 | 'Programming Language :: Python :: 2.7', 30 | ], 31 | 32 | keywords='maps mapping tools spatial analysis geostatistics', 33 | 34 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 35 | 36 | extras_require={ 37 | 'dev': ['unittest'], 38 | 'test': ['unittest', 'nose', 'mock'], 39 | }, 40 | 41 | # The choice of component versions is dictated by what's 42 | # provisioned in the production servers. 43 | # IMPORTANT NOTE: please don't change this line. Instead issue a ticket to systems for evaluation. 44 | install_requires=['joblib==0.8.3', 'numpy==1.6.1', 'scipy==0.14.0', 'pysal==1.14.3', 'scikit-learn==0.14.1'], 45 | 46 | requires=['pysal', 'numpy', 'sklearn'], 47 | 48 | test_suite='test' 49 | ) 50 | -------------------------------------------------------------------------------- /release/python/0.8.0/crankshaft/setup.py-r: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | CartoDB Spatial Analysis Python Library 4 | See: 5 | https://github.com/CartoDB/crankshaft 6 | """ 7 | 8 | from setuptools import setup, find_packages 9 | 10 | setup( 11 | name='crankshaft', 12 | 13 | version='0.0.0', 14 | 15 | description='CartoDB Spatial Analysis Python Library', 16 | 17 | url='https://github.com/CartoDB/crankshaft', 18 | 19 | author='Data Services Team - CartoDB', 20 | author_email='dataservices@cartodb.com', 21 | 22 | license='MIT', 23 | 24 | classifiers=[ 25 | 'Development Status :: 3 - Alpha', 26 | 'Intended Audience :: Mapping comunity', 27 | 'Topic :: Maps :: Mapping Tools', 28 | 'License :: OSI Approved :: MIT License', 29 | 'Programming Language :: Python :: 2.7', 30 | ], 31 | 32 | keywords='maps mapping tools spatial analysis geostatistics', 33 | 34 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 35 | 36 | extras_require={ 37 | 'dev': ['unittest'], 38 | 'test': ['unittest', 'nose', 'mock'], 39 | }, 40 | 41 | # The choice of component versions is dictated by what's 42 | # provisioned in the production servers. 43 | # IMPORTANT NOTE: please don't change this line. Instead issue a ticket to systems for evaluation. 44 | install_requires=['joblib==0.8.3', 'numpy==1.6.1', 'scipy==0.14.0', 'pysal==1.14.3', 'scikit-learn==0.14.1'], 45 | 46 | requires=['pysal', 'numpy', 'sklearn'], 47 | 48 | test_suite='test' 49 | ) 50 | -------------------------------------------------------------------------------- /release/python/0.8.0/crankshaft/test/helper.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from mock_plpy import MockPlPy 4 | plpy = MockPlPy() 5 | 6 | import sys 7 | sys.modules['plpy'] = plpy 8 | 9 | import os 10 | 11 | def fixture_file(name): 12 | dir = os.path.dirname(os.path.realpath(__file__)) 13 | return os.path.join(dir, 'fixtures', name) 14 | -------------------------------------------------------------------------------- /release/python/0.8.0/crankshaft/test/mock_plpy.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | class MockCursor: 5 | def __init__(self, data): 6 | self.cursor_pos = 0 7 | self.data = data 8 | 9 | def fetch(self, batch_size): 10 | batch = self.data[self.cursor_pos:self.cursor_pos + batch_size] 11 | self.cursor_pos += batch_size 12 | return batch 13 | 14 | 15 | class MockPlPy: 16 | def __init__(self): 17 | self._reset() 18 | 19 | def _reset(self): 20 | self.infos = [] 21 | self.notices = [] 22 | self.debugs = [] 23 | self.logs = [] 24 | self.warnings = [] 25 | self.errors = [] 26 | self.fatals = [] 27 | self.executes = [] 28 | self.results = [] 29 | self.prepares = [] 30 | self.results = [] 31 | 32 | def _define_result(self, query, result): 33 | pattern = re.compile(query, re.IGNORECASE | re.MULTILINE) 34 | self.results.append([pattern, result]) 35 | 36 | def notice(self, msg): 37 | self.notices.append(msg) 38 | 39 | def debug(self, msg): 40 | self.notices.append(msg) 41 | 42 | def info(self, msg): 43 | self.infos.append(msg) 44 | 45 | def error(self, msg): 46 | self.notices.append(msg) 47 | 48 | def cursor(self, query): 49 | data = self.execute(query) 50 | return MockCursor(data) 51 | 52 | # TODO: additional arguments 53 | def execute(self, query): 54 | for result in self.results: 55 | if result[0].match(query): 56 | return result[1] 57 | return [] 58 | -------------------------------------------------------------------------------- /release/python/0.8.1/crankshaft/crankshaft/.analysis_data_provider.py.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CartoDB/crankshaft/494c047563328b092fe5fe0b8b4dd862edfee836/release/python/0.8.1/crankshaft/crankshaft/.analysis_data_provider.py.swp -------------------------------------------------------------------------------- /release/python/0.8.1/crankshaft/crankshaft/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all modules""" 2 | import crankshaft.random_seeds 3 | import crankshaft.clustering 4 | import crankshaft.space_time_dynamics 5 | import crankshaft.segmentation 6 | import crankshaft.regression 7 | import analysis_data_provider 8 | -------------------------------------------------------------------------------- /release/python/0.8.1/crankshaft/crankshaft/clustering/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from for clustering""" 2 | from moran import * 3 | from kmeans import * 4 | from getis import * 5 | -------------------------------------------------------------------------------- /release/python/0.8.1/crankshaft/crankshaft/pysal_utils/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions for pysal_utils""" 2 | from crankshaft.pysal_utils.pysal_utils import * 3 | -------------------------------------------------------------------------------- /release/python/0.8.1/crankshaft/crankshaft/random_seeds.py: -------------------------------------------------------------------------------- 1 | """Random seed generator used for non-deterministic functions in crankshaft""" 2 | import random 3 | import numpy 4 | 5 | 6 | def set_random_seeds(value): 7 | """ 8 | Set the seeds of the RNGs (Random Number Generators) 9 | used internally. 10 | """ 11 | random.seed(value) 12 | numpy.random.seed(value) 13 | -------------------------------------------------------------------------------- /release/python/0.8.1/crankshaft/crankshaft/regression/__init__.py: -------------------------------------------------------------------------------- 1 | from crankshaft.regression.gwr import * 2 | from crankshaft.regression.glm import * 3 | from crankshaft.regression.gwr_cs import * 4 | -------------------------------------------------------------------------------- /release/python/0.8.1/crankshaft/crankshaft/regression/glm/__init__.py: -------------------------------------------------------------------------------- 1 | import glm 2 | import family 3 | import utils 4 | import iwls 5 | -------------------------------------------------------------------------------- /release/python/0.8.1/crankshaft/crankshaft/regression/gwr/__init__.py: -------------------------------------------------------------------------------- 1 | from base import * 2 | -------------------------------------------------------------------------------- /release/python/0.8.1/crankshaft/crankshaft/regression/gwr/base/__init__.py: -------------------------------------------------------------------------------- 1 | import gwr 2 | import sel_bw 3 | import diagnostics 4 | import kernels 5 | -------------------------------------------------------------------------------- /release/python/0.8.1/crankshaft/crankshaft/segmentation/__init__.py: -------------------------------------------------------------------------------- 1 | from segmentation import * 2 | -------------------------------------------------------------------------------- /release/python/0.8.1/crankshaft/crankshaft/space_time_dynamics/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from clustering libraries.""" 2 | from markov import * 3 | -------------------------------------------------------------------------------- /release/python/0.8.1/crankshaft/requirements.txt: -------------------------------------------------------------------------------- 1 | joblib==0.8.3 2 | numpy==1.6.1 3 | scipy==0.14.0 4 | pysal==1.14.3 5 | scikit-learn==0.14.1 6 | -------------------------------------------------------------------------------- /release/python/0.8.1/crankshaft/setup.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | CartoDB Spatial Analysis Python Library 4 | See: 5 | https://github.com/CartoDB/crankshaft 6 | """ 7 | 8 | from setuptools import setup, find_packages 9 | 10 | setup( 11 | name='crankshaft', 12 | 13 | version='0.0.0', 14 | 15 | description='CartoDB Spatial Analysis Python Library', 16 | 17 | url='https://github.com/CartoDB/crankshaft', 18 | 19 | author='Data Services Team - CartoDB', 20 | author_email='dataservices@cartodb.com', 21 | 22 | license='MIT', 23 | 24 | classifiers=[ 25 | 'Development Status :: 3 - Alpha', 26 | 'Intended Audience :: Mapping comunity', 27 | 'Topic :: Maps :: Mapping Tools', 28 | 'License :: OSI Approved :: MIT License', 29 | 'Programming Language :: Python :: 2.7', 30 | ], 31 | 32 | keywords='maps mapping tools spatial analysis geostatistics', 33 | 34 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 35 | 36 | extras_require={ 37 | 'dev': ['unittest'], 38 | 'test': ['unittest', 'nose', 'mock'], 39 | }, 40 | 41 | # The choice of component versions is dictated by what's 42 | # provisioned in the production servers. 43 | # IMPORTANT NOTE: please don't change this line. Instead issue a ticket to systems for evaluation. 44 | install_requires=['joblib==0.8.3', 'numpy==1.6.1', 'scipy==0.14.0', 'pysal==1.14.3', 'scikit-learn==0.14.1'], 45 | 46 | requires=['pysal', 'numpy', 'sklearn'], 47 | 48 | test_suite='test' 49 | ) 50 | -------------------------------------------------------------------------------- /release/python/0.8.1/crankshaft/setup.py-r: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | CartoDB Spatial Analysis Python Library 4 | See: 5 | https://github.com/CartoDB/crankshaft 6 | """ 7 | 8 | from setuptools import setup, find_packages 9 | 10 | setup( 11 | name='crankshaft', 12 | 13 | version='0.0.0', 14 | 15 | description='CartoDB Spatial Analysis Python Library', 16 | 17 | url='https://github.com/CartoDB/crankshaft', 18 | 19 | author='Data Services Team - CartoDB', 20 | author_email='dataservices@cartodb.com', 21 | 22 | license='MIT', 23 | 24 | classifiers=[ 25 | 'Development Status :: 3 - Alpha', 26 | 'Intended Audience :: Mapping comunity', 27 | 'Topic :: Maps :: Mapping Tools', 28 | 'License :: OSI Approved :: MIT License', 29 | 'Programming Language :: Python :: 2.7', 30 | ], 31 | 32 | keywords='maps mapping tools spatial analysis geostatistics', 33 | 34 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 35 | 36 | extras_require={ 37 | 'dev': ['unittest'], 38 | 'test': ['unittest', 'nose', 'mock'], 39 | }, 40 | 41 | # The choice of component versions is dictated by what's 42 | # provisioned in the production servers. 43 | # IMPORTANT NOTE: please don't change this line. Instead issue a ticket to systems for evaluation. 44 | install_requires=['joblib==0.8.3', 'numpy==1.6.1', 'scipy==0.14.0', 'pysal==1.14.3', 'scikit-learn==0.14.1'], 45 | 46 | requires=['pysal', 'numpy', 'sklearn'], 47 | 48 | test_suite='test' 49 | ) 50 | -------------------------------------------------------------------------------- /release/python/0.8.1/crankshaft/test/helper.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from mock_plpy import MockPlPy 4 | plpy = MockPlPy() 5 | 6 | import sys 7 | sys.modules['plpy'] = plpy 8 | 9 | import os 10 | 11 | def fixture_file(name): 12 | dir = os.path.dirname(os.path.realpath(__file__)) 13 | return os.path.join(dir, 'fixtures', name) 14 | -------------------------------------------------------------------------------- /release/python/0.8.1/crankshaft/test/mock_plpy.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | class MockCursor: 5 | def __init__(self, data): 6 | self.cursor_pos = 0 7 | self.data = data 8 | 9 | def fetch(self, batch_size): 10 | batch = self.data[self.cursor_pos:self.cursor_pos + batch_size] 11 | self.cursor_pos += batch_size 12 | return batch 13 | 14 | 15 | class MockPlPy: 16 | def __init__(self): 17 | self._reset() 18 | 19 | def _reset(self): 20 | self.infos = [] 21 | self.notices = [] 22 | self.debugs = [] 23 | self.logs = [] 24 | self.warnings = [] 25 | self.errors = [] 26 | self.fatals = [] 27 | self.executes = [] 28 | self.results = [] 29 | self.prepares = [] 30 | self.results = [] 31 | 32 | def _define_result(self, query, result): 33 | pattern = re.compile(query, re.IGNORECASE | re.MULTILINE) 34 | self.results.append([pattern, result]) 35 | 36 | def notice(self, msg): 37 | self.notices.append(msg) 38 | 39 | def debug(self, msg): 40 | self.notices.append(msg) 41 | 42 | def info(self, msg): 43 | self.infos.append(msg) 44 | 45 | def error(self, msg): 46 | self.notices.append(msg) 47 | 48 | def cursor(self, query): 49 | data = self.execute(query) 50 | return MockCursor(data) 51 | 52 | # TODO: additional arguments 53 | def execute(self, query): 54 | for result in self.results: 55 | if result[0].match(query): 56 | return result[1] 57 | return [] 58 | -------------------------------------------------------------------------------- /release/python/0.8.2/crankshaft/crankshaft/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all modules""" 2 | import crankshaft.random_seeds 3 | import crankshaft.clustering 4 | import crankshaft.space_time_dynamics 5 | import crankshaft.segmentation 6 | import crankshaft.regression 7 | import analysis_data_provider 8 | -------------------------------------------------------------------------------- /release/python/0.8.2/crankshaft/crankshaft/clustering/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from for clustering""" 2 | from moran import * 3 | from kmeans import * 4 | from getis import * 5 | -------------------------------------------------------------------------------- /release/python/0.8.2/crankshaft/crankshaft/pysal_utils/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions for pysal_utils""" 2 | from crankshaft.pysal_utils.pysal_utils import * 3 | -------------------------------------------------------------------------------- /release/python/0.8.2/crankshaft/crankshaft/random_seeds.py: -------------------------------------------------------------------------------- 1 | """Random seed generator used for non-deterministic functions in crankshaft""" 2 | import random 3 | import numpy 4 | 5 | 6 | def set_random_seeds(value): 7 | """ 8 | Set the seeds of the RNGs (Random Number Generators) 9 | used internally. 10 | """ 11 | random.seed(value) 12 | numpy.random.seed(value) 13 | -------------------------------------------------------------------------------- /release/python/0.8.2/crankshaft/crankshaft/regression/__init__.py: -------------------------------------------------------------------------------- 1 | from crankshaft.regression.gwr import * 2 | from crankshaft.regression.glm import * 3 | from crankshaft.regression.gwr_cs import * 4 | -------------------------------------------------------------------------------- /release/python/0.8.2/crankshaft/crankshaft/regression/glm/__init__.py: -------------------------------------------------------------------------------- 1 | import glm 2 | import family 3 | import utils 4 | import iwls 5 | -------------------------------------------------------------------------------- /release/python/0.8.2/crankshaft/crankshaft/regression/gwr/__init__.py: -------------------------------------------------------------------------------- 1 | from base import * 2 | -------------------------------------------------------------------------------- /release/python/0.8.2/crankshaft/crankshaft/regression/gwr/base/__init__.py: -------------------------------------------------------------------------------- 1 | import gwr 2 | import sel_bw 3 | import diagnostics 4 | import kernels 5 | -------------------------------------------------------------------------------- /release/python/0.8.2/crankshaft/crankshaft/segmentation/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from for segmentation""" 2 | from segmentation import * 3 | -------------------------------------------------------------------------------- /release/python/0.8.2/crankshaft/crankshaft/space_time_dynamics/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from clustering libraries.""" 2 | from markov import * 3 | -------------------------------------------------------------------------------- /release/python/0.8.2/crankshaft/requirements.txt: -------------------------------------------------------------------------------- 1 | joblib==0.9.4 2 | numpy==1.11.0 3 | scipy==0.17.0 4 | pysal==1.14.3 5 | scikit-learn==0.17.0 6 | -------------------------------------------------------------------------------- /release/python/0.8.2/crankshaft/setup.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | CartoDB Spatial Analysis Python Library 4 | See: 5 | https://github.com/CartoDB/crankshaft 6 | """ 7 | 8 | from setuptools import setup, find_packages 9 | 10 | setup( 11 | name='crankshaft', 12 | 13 | version='0.8.2', 14 | 15 | description='CartoDB Spatial Analysis Python Library', 16 | 17 | url='https://github.com/CartoDB/crankshaft', 18 | 19 | author='Data Services Team - CartoDB', 20 | author_email='dataservices@cartodb.com', 21 | 22 | license='MIT', 23 | 24 | classifiers=[ 25 | 'Development Status :: 3 - Alpha', 26 | 'Intended Audience :: Mapping comunity', 27 | 'Topic :: Maps :: Mapping Tools', 28 | 'License :: OSI Approved :: MIT License', 29 | 'Programming Language :: Python :: 2.7', 30 | ], 31 | 32 | keywords='maps mapping tools spatial analysis geostatistics', 33 | 34 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 35 | 36 | extras_require={ 37 | 'dev': ['unittest'], 38 | 'test': ['unittest', 'nose', 'mock'], 39 | }, 40 | 41 | # The choice of component versions is dictated by what's 42 | # provisioned in the production servers. 43 | # IMPORTANT NOTE: please don't change this line. Instead issue a ticket to systems for evaluation. 44 | install_requires=['joblib==0.9.4', 'numpy==1.11.0', 'scipy==0.17.0', 'pysal==1.14.3', 'scikit-learn==0.17.0'], 45 | 46 | requires=['pysal', 'numpy', 'sklearn'], 47 | 48 | test_suite='test' 49 | ) 50 | -------------------------------------------------------------------------------- /release/python/0.8.2/crankshaft/test/fixtures/data.json: -------------------------------------------------------------------------------- 1 | [{"ids": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 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, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]}] -------------------------------------------------------------------------------- /release/python/0.8.2/crankshaft/test/helper.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from mock_plpy import MockPlPy 4 | plpy = MockPlPy() 5 | 6 | import sys 7 | sys.modules['plpy'] = plpy 8 | 9 | import os 10 | 11 | def fixture_file(name): 12 | dir = os.path.dirname(os.path.realpath(__file__)) 13 | return os.path.join(dir, 'fixtures', name) 14 | -------------------------------------------------------------------------------- /release/python/0.8.2/crankshaft/test/mock_plpy.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | class MockCursor: 5 | def __init__(self, data): 6 | self.cursor_pos = 0 7 | self.data = data 8 | 9 | def fetch(self, batch_size): 10 | batch = self.data[self.cursor_pos:self.cursor_pos + batch_size] 11 | self.cursor_pos += batch_size 12 | return batch 13 | 14 | 15 | class MockPlPy: 16 | def __init__(self): 17 | self._reset() 18 | 19 | def _reset(self): 20 | self.infos = [] 21 | self.notices = [] 22 | self.debugs = [] 23 | self.logs = [] 24 | self.warnings = [] 25 | self.errors = [] 26 | self.fatals = [] 27 | self.executes = [] 28 | self.results = [] 29 | self.prepares = [] 30 | self.results = [] 31 | 32 | def _define_result(self, query, result): 33 | pattern = re.compile(query, re.IGNORECASE | re.MULTILINE) 34 | self.results.append([pattern, result]) 35 | 36 | def notice(self, msg): 37 | self.notices.append(msg) 38 | 39 | def debug(self, msg): 40 | self.notices.append(msg) 41 | 42 | def info(self, msg): 43 | self.infos.append(msg) 44 | 45 | def error(self, msg): 46 | self.infos.append(msg) 47 | self.notices.append(msg) 48 | 49 | def cursor(self, query): 50 | data = self.execute(query) 51 | return MockCursor(data) 52 | 53 | # TODO: additional arguments 54 | def execute(self, query): 55 | for result in self.results: 56 | if result[0].match(query): 57 | return result[1] 58 | return [] 59 | -------------------------------------------------------------------------------- /release/python/0.9.0/crankshaft/crankshaft/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all modules""" 2 | import crankshaft.random_seeds 3 | import crankshaft.clustering 4 | import crankshaft.space_time_dynamics 5 | import crankshaft.segmentation 6 | import crankshaft.regression 7 | from . import analysis_data_provider 8 | -------------------------------------------------------------------------------- /release/python/0.9.0/crankshaft/crankshaft/clustering/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from for clustering""" 2 | from .moran import * 3 | from .kmeans import * 4 | from .getis import * 5 | -------------------------------------------------------------------------------- /release/python/0.9.0/crankshaft/crankshaft/pysal_utils/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions for pysal_utils""" 2 | from crankshaft.pysal_utils.pysal_utils import * 3 | -------------------------------------------------------------------------------- /release/python/0.9.0/crankshaft/crankshaft/random_seeds.py: -------------------------------------------------------------------------------- 1 | """Random seed generator used for non-deterministic functions in crankshaft""" 2 | import random 3 | import numpy 4 | 5 | 6 | def set_random_seeds(value): 7 | """ 8 | Set the seeds of the RNGs (Random Number Generators) 9 | used internally. 10 | """ 11 | random.seed(value) 12 | numpy.random.seed(value) 13 | -------------------------------------------------------------------------------- /release/python/0.9.0/crankshaft/crankshaft/regression/__init__.py: -------------------------------------------------------------------------------- 1 | from crankshaft.regression.gwr import * 2 | from crankshaft.regression.glm import * 3 | from crankshaft.regression.gwr_cs import * 4 | -------------------------------------------------------------------------------- /release/python/0.9.0/crankshaft/crankshaft/regression/glm/__init__.py: -------------------------------------------------------------------------------- 1 | from . import glm 2 | from . import family 3 | from . import utils 4 | from . import iwls 5 | -------------------------------------------------------------------------------- /release/python/0.9.0/crankshaft/crankshaft/regression/gwr/__init__.py: -------------------------------------------------------------------------------- 1 | from .base import * 2 | -------------------------------------------------------------------------------- /release/python/0.9.0/crankshaft/crankshaft/regression/gwr/base/__init__.py: -------------------------------------------------------------------------------- 1 | from . import gwr 2 | from . import sel_bw 3 | from . import diagnostics 4 | from . import kernels 5 | -------------------------------------------------------------------------------- /release/python/0.9.0/crankshaft/crankshaft/segmentation/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from for segmentation""" 2 | from .segmentation import * 3 | -------------------------------------------------------------------------------- /release/python/0.9.0/crankshaft/crankshaft/space_time_dynamics/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from clustering libraries.""" 2 | from .markov import * 3 | -------------------------------------------------------------------------------- /release/python/0.9.0/crankshaft/requirements.txt: -------------------------------------------------------------------------------- 1 | joblib==0.9.4 2 | numpy==1.11.0 3 | scipy==0.17.0 4 | pysal==1.14.3 5 | scikit-learn==0.17.0 6 | -------------------------------------------------------------------------------- /release/python/0.9.0/crankshaft/setup.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | CartoDB Spatial Analysis Python Library 4 | See: 5 | https://github.com/CartoDB/crankshaft 6 | """ 7 | 8 | from setuptools import setup, find_packages 9 | 10 | setup( 11 | name='crankshaft', 12 | 13 | version='0.9.0', 14 | 15 | description='CartoDB Spatial Analysis Python Library', 16 | 17 | url='https://github.com/CartoDB/crankshaft', 18 | 19 | author='Data Services Team - CartoDB', 20 | author_email='dataservices@cartodb.com', 21 | 22 | license='MIT', 23 | 24 | classifiers=[ 25 | 'Development Status :: 3 - Alpha', 26 | 'Intended Audience :: Mapping comunity', 27 | 'Topic :: Maps :: Mapping Tools', 28 | 'License :: OSI Approved :: MIT License', 29 | 'Programming Language :: Python', 30 | ], 31 | 32 | keywords='maps mapping tools spatial analysis geostatistics', 33 | 34 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 35 | 36 | extras_require={ 37 | 'dev': ['unittest'], 38 | 'test': ['unittest', 'nose', 'mock'], 39 | }, 40 | 41 | # The choice of component versions is dictated by what's 42 | # provisioned in the production servers. 43 | # IMPORTANT NOTE: please don't change this line. Instead issue a ticket to systems for evaluation. 44 | install_requires=['joblib==0.9.4', 'numpy==1.11.0', 'scipy==0.17.0', 'pysal==1.14.3', 'scikit-learn==0.17.0'], 45 | 46 | requires=['pysal', 'numpy', 'sklearn'], 47 | 48 | test_suite='test' 49 | ) 50 | -------------------------------------------------------------------------------- /release/python/0.9.0/crankshaft/test/fixtures/data.json: -------------------------------------------------------------------------------- 1 | [{"ids": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 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, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]}] -------------------------------------------------------------------------------- /release/python/0.9.0/crankshaft/test/helper.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from mock_plpy import MockPlPy 4 | plpy = MockPlPy() 5 | 6 | import sys 7 | sys.modules['plpy'] = plpy 8 | 9 | import os 10 | 11 | def fixture_file(name): 12 | dir = os.path.dirname(os.path.realpath(__file__)) 13 | return os.path.join(dir, 'fixtures', name) 14 | -------------------------------------------------------------------------------- /release/python/0.9.0/crankshaft/test/mock_plpy.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | class MockCursor: 5 | def __init__(self, data): 6 | self.cursor_pos = 0 7 | self.data = data 8 | 9 | def fetch(self, batch_size): 10 | batch = self.data[self.cursor_pos:self.cursor_pos + batch_size] 11 | self.cursor_pos += batch_size 12 | return batch 13 | 14 | 15 | class MockPlPy: 16 | def __init__(self): 17 | self._reset() 18 | 19 | def _reset(self): 20 | self.infos = [] 21 | self.notices = [] 22 | self.debugs = [] 23 | self.logs = [] 24 | self.warnings = [] 25 | self.errors = [] 26 | self.fatals = [] 27 | self.executes = [] 28 | self.results = [] 29 | self.prepares = [] 30 | self.results = [] 31 | 32 | def _define_result(self, query, result): 33 | pattern = re.compile(query, re.IGNORECASE | re.MULTILINE) 34 | self.results.append([pattern, result]) 35 | 36 | def notice(self, msg): 37 | self.notices.append(msg) 38 | 39 | def debug(self, msg): 40 | self.notices.append(msg) 41 | 42 | def info(self, msg): 43 | self.infos.append(msg) 44 | 45 | def error(self, msg): 46 | self.infos.append(msg) 47 | self.notices.append(msg) 48 | 49 | def cursor(self, query): 50 | data = self.execute(query) 51 | return MockCursor(data) 52 | 53 | # TODO: additional arguments 54 | def execute(self, query): 55 | for result in self.results: 56 | if result[0].match(query): 57 | return result[1] 58 | return [] 59 | -------------------------------------------------------------------------------- /src/pg/.gitignore: -------------------------------------------------------------------------------- 1 | regression.diffs 2 | regression.out 3 | results/ 4 | crankshaft--dev.sql 5 | crankshaft--dev--current.sql 6 | crankshaft--current--dev.sql 7 | crankshaft--*--dev.sql 8 | -------------------------------------------------------------------------------- /src/pg/crankshaft.control: -------------------------------------------------------------------------------- 1 | comment = 'CartoDB Spatial Analysis extension' 2 | default_version = '0.9.0' 3 | requires = 'plpython3u, postgis' 4 | superuser = true 5 | schema = cdb_crankshaft 6 | -------------------------------------------------------------------------------- /src/pg/sql/00_header.sql: -------------------------------------------------------------------------------- 1 | --DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES 2 | -- Complain if script is sourced in psql, rather than via CREATE EXTENSION 3 | \echo Use "CREATE EXTENSION crankshaft" to load this file. \quit 4 | -------------------------------------------------------------------------------- /src/pg/sql/01_version.sql: -------------------------------------------------------------------------------- 1 | -- Version number of the extension release 2 | CREATE OR REPLACE FUNCTION cdb_crankshaft_version() 3 | RETURNS text AS $$ 4 | SELECT '@@VERSION@@'::text; 5 | $$ language 'sql' IMMUTABLE STRICT PARALLEL SAFE; 6 | 7 | -- Internal identifier of the installed extension instence 8 | -- e.g. 'dev' for current development version 9 | CREATE OR REPLACE FUNCTION _cdb_crankshaft_internal_version() 10 | RETURNS text AS $$ 11 | SELECT installed_version FROM pg_available_extensions where name='crankshaft' and pg_available_extensions IS NOT NULL; 12 | $$ language 'sql' STABLE STRICT PARALLEL SAFE; 13 | -------------------------------------------------------------------------------- /src/pg/sql/03_random_seeds.sql: -------------------------------------------------------------------------------- 1 | -- Internal function. 2 | -- Set the seeds of the RNGs (Random Number Generators) 3 | -- used internally. 4 | CREATE OR REPLACE FUNCTION 5 | _cdb_random_seeds (seed_value INTEGER) RETURNS VOID 6 | AS $$ 7 | from crankshaft import random_seeds 8 | random_seeds.set_random_seeds(seed_value) 9 | $$ LANGUAGE plpython3u VOLATILE PARALLEL UNSAFE; 10 | -------------------------------------------------------------------------------- /src/pg/sql/04_py_agg.sql: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE FUNCTION 2 | CDB_PyAggS(current_state Numeric[], current_row Numeric[]) 3 | returns NUMERIC[] as $$ 4 | BEGIN 5 | if array_upper(current_state,1) is null then 6 | RAISE NOTICE 'setting state %',array_upper(current_row,1); 7 | current_state[1] = array_upper(current_row,1); 8 | end if; 9 | return array_cat(current_state,current_row) ; 10 | END 11 | $$ LANGUAGE plpgsql IMMUTABLE PARALLEL SAFE; 12 | 13 | -- Create aggregate if it did not exist 14 | DO $$ BEGIN 15 | CREATE AGGREGATE CDB_PyAgg(NUMERIC[]) ( 16 | SFUNC = CDB_PyAggS, 17 | STYPE = Numeric[], 18 | PARALLEL = SAFE, 19 | INITCOND = "{}" 20 | ); 21 | EXCEPTION 22 | WHEN duplicate_function THEN NULL; 23 | END $$; 24 | -------------------------------------------------------------------------------- /src/pg/sql/16_getis.sql: -------------------------------------------------------------------------------- 1 | -- Getis-Ord's G 2 | -- Hotspot/Coldspot Analysis tool 3 | CREATE OR REPLACE FUNCTION 4 | CDB_GetisOrdsG( 5 | subquery TEXT, 6 | column_name TEXT, 7 | w_type TEXT DEFAULT 'knn', 8 | num_ngbrs INT DEFAULT 5, 9 | permutations INT DEFAULT 999, 10 | geom_col TEXT DEFAULT 'the_geom', 11 | id_col TEXT DEFAULT 'cartodb_id') 12 | RETURNS TABLE (z_score NUMERIC, p_value NUMERIC, p_z_sim NUMERIC, rowid BIGINT) 13 | AS $$ 14 | from crankshaft.clustering import Getis 15 | getis = Getis() 16 | return getis.getis_ord(subquery, column_name, w_type, num_ngbrs, permutations, geom_col, id_col) 17 | $$ LANGUAGE plpython3u VOLATILE PARALLEL UNSAFE; 18 | 19 | -- TODO: make a version that accepts the values as arrays 20 | -------------------------------------------------------------------------------- /src/pg/sql/20_overlap_sum.sql: -------------------------------------------------------------------------------- 1 | -- Function by Stuart Lynn for a simple interpolation of a value 2 | -- from a polygon table over an arbitrary polygon 3 | -- (weighted by the area proportion overlapped) 4 | -- Aereal weighting is a very simple form of aereal interpolation. 5 | -- 6 | -- Parameters: 7 | -- * geom a Polygon geometry which defines the area where a value will be 8 | -- estimated as the area-weighted sum of a given table/column 9 | -- * target_table_name table name of the table that provides the values 10 | -- * target_column column name of the column that provides the values 11 | -- * schema_name optional parameter to defina the schema the target table 12 | -- belongs to, which is necessary if its not in the search_path. 13 | -- Note that target_table_name should never include the schema in it. 14 | -- Return value: 15 | -- Aereal-weighted interpolation of the column values over the geometry 16 | CREATE OR REPLACE 17 | FUNCTION cdb_overlap_sum(geom geometry, target_table_name text, target_column text, schema_name text DEFAULT NULL) 18 | RETURNS numeric AS 19 | $$ 20 | DECLARE 21 | result numeric; 22 | qualified_name text; 23 | BEGIN 24 | IF schema_name IS NULL THEN 25 | qualified_name := Format('%I', target_table_name); 26 | ELSE 27 | qualified_name := Format('%I.%s', schema_name, target_table_name); 28 | END IF; 29 | EXECUTE Format(' 30 | SELECT sum(%I*ST_Area(St_Intersection($1, a.the_geom))/ST_Area(a.the_geom)) 31 | FROM %s AS a 32 | WHERE $1 && a.the_geom 33 | ', target_column, qualified_name) 34 | USING geom 35 | INTO result; 36 | RETURN result; 37 | END; 38 | $$ LANGUAGE plpgsql STABLE PARALLEL SAFE; 39 | -------------------------------------------------------------------------------- /src/pg/sql/21_gwr.sql: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE FUNCTION 2 | CDB_GWR(subquery text, dep_var text, ind_vars text[], 3 | bw numeric default null, fixed boolean default False, 4 | kernel text default 'bisquare', geom_col text default 'the_geom', 5 | id_col text default 'cartodb_id') 6 | RETURNS table(coeffs JSON, stand_errs JSON, t_vals JSON, 7 | filtered_t_vals JSON, predicted numeric, 8 | residuals numeric, r_squared numeric, bandwidth numeric, 9 | rowid bigint) 10 | AS $$ 11 | 12 | from crankshaft.regression import GWR 13 | 14 | gwr = GWR() 15 | 16 | return gwr.gwr(subquery, dep_var, ind_vars, bw, fixed, kernel, geom_col, id_col) 17 | 18 | $$ LANGUAGE plpython3u VOLATILE PARALLEL UNSAFE; 19 | 20 | 21 | CREATE OR REPLACE FUNCTION 22 | CDB_GWR_Predict(subquery text, dep_var text, ind_vars text[], 23 | bw numeric default null, fixed boolean default False, 24 | kernel text default 'bisquare', 25 | geom_col text default 'the_geom', 26 | id_col text default 'cartodb_id') 27 | RETURNS table(coeffs JSON, stand_errs JSON, t_vals JSON, 28 | r_squared numeric, predicted numeric, rowid bigint) 29 | AS $$ 30 | 31 | from crankshaft.regression import GWR 32 | gwr = GWR() 33 | 34 | return gwr.gwr_predict(subquery, dep_var, ind_vars, bw, fixed, kernel, geom_col, id_col) 35 | 36 | $$ LANGUAGE plpython3u VOLATILE PARALLEL UNSAFE; 37 | -------------------------------------------------------------------------------- /src/pg/sql/90_permissions.sql: -------------------------------------------------------------------------------- 1 | -- Make sure by default there are no permissions for publicuser 2 | -- NOTE: this happens at extension creation time, as part of an implicit transaction. 3 | -- REVOKE ALL PRIVILEGES ON SCHEMA cdb_crankshaft FROM PUBLIC, publicuser CASCADE; 4 | 5 | -- Grant permissions on the schema to publicuser (but just the schema) 6 | GRANT USAGE ON SCHEMA cdb_crankshaft TO publicuser; 7 | 8 | -- Revoke execute permissions on all functions in the schema by default 9 | -- REVOKE EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_crankshaft FROM PUBLIC, publicuser; 10 | -------------------------------------------------------------------------------- /src/pg/test/expected/01_install_test.out: -------------------------------------------------------------------------------- 1 | \set ECHO none 2 | -------------------------------------------------------------------------------- /src/pg/test/expected/03_overlap_sum_test.out: -------------------------------------------------------------------------------- 1 | \i test/fixtures/polyg_values.sql 2 | SET client_min_messages TO WARNING; 3 | \set ECHO none 4 | round 5 | ------- 6 | 4.42 7 | (1 row) 8 | 9 | round 10 | ------- 11 | 4.42 12 | (1 row) 13 | 14 | -------------------------------------------------------------------------------- /src/pg/test/expected/04_dot_density_test.out: -------------------------------------------------------------------------------- 1 | WITH g AS ( 2 | SELECT ST_Buffer(ST_SetSRID(ST_MakePoint(0,0),4326)::geometry, 1000)::geometry AS g 3 | ), 4 | points AS( 5 | SELECT ( 6 | ST_Dump( 7 | cdb_crankshaft.cdb_dot_density(g.g, 100) 8 | ) 9 | ).geom AS p FROM g 10 | ) 11 | SELECT count(*), sum(CASE WHEN ST_Contains(g,p) THEN 1 ELSE 0 END) FROM points, g 12 | count | sum 13 | -------+----- 14 | 100 | 100 15 | (1 row) 16 | 17 | -------------------------------------------------------------------------------- /src/pg/test/expected/05_markov_test.out: -------------------------------------------------------------------------------- 1 | SET client_min_messages TO WARNING; 2 | \set ECHO none 3 | _cdb_random_seeds 4 | 5 | (1 row) 6 | cartodb_id|trend_test|trend_up_test|trend_down_test|volatility_test 7 | 1|t|t|t|t 8 | 2|t|t|t|t 9 | 3|t|t|t|t 10 | (3 rows) 11 | -------------------------------------------------------------------------------- /src/pg/test/expected/06_segmentation_test.out: -------------------------------------------------------------------------------- 1 | \pset format unaligned 2 | \set ECHO none 3 | _cdb_random_seeds 4 | 5 | (1 row) 6 | within_tolerance 7 | t 8 | t 9 | t 10 | t 11 | t 12 | t 13 | t 14 | t 15 | t 16 | t 17 | t 18 | t 19 | t 20 | t 21 | t 22 | t 23 | t 24 | t 25 | t 26 | t 27 | (20 rows) 28 | _cdb_random_seeds 29 | 30 | (1 row) 31 | within_tolerance 32 | t 33 | t 34 | t 35 | t 36 | t 37 | t 38 | t 39 | t 40 | t 41 | t 42 | t 43 | t 44 | t 45 | t 46 | t 47 | t 48 | t 49 | t 50 | t 51 | t 52 | (20 rows) 53 | _cdb_random_seeds 54 | 55 | (1 row) 56 | within_tolerance 57 | t 58 | t 59 | t 60 | t 61 | t 62 | t 63 | t 64 | t 65 | t 66 | t 67 | t 68 | t 69 | t 70 | t 71 | t 72 | t 73 | t 74 | t 75 | t 76 | t 77 | (20 rows) 78 | -------------------------------------------------------------------------------- /src/pg/test/expected/07_gravity_test.out: -------------------------------------------------------------------------------- 1 | SET client_min_messages TO WARNING; 2 | \set ECHO none 3 | the_geom | h | hpop | dist 4 | --------------------------------------------+-------------------------+--------------------------+--------------- 5 | 01010000001361C3D32B650140DD24068195B34440 | 1.51078258364442906811 | 12.08626066915543254492 | 4964.71445918 6 | 01010000002497FF907EFB0040713D0AD7A3B04440 | 98.29730954188030446151 | 688.08116679316213123058 | 99.95514192 7 | 0101000000A167B3EA733501401D5A643BDFAF4440 | 63.70532894705201858635 | 382.23197368231211151808 | 2488.33056652 8 | 010100000062A1D634EF380140BE9F1A2FDDB44440 | 35.35415870089041483312 | 176.77079350445207416562 | 4359.37046061 9 | 010100000052B81E85EB510140355EBA490CB24440 | 33.12290506980103110470 | 132.49162027920412441880 | 3703.66444985 10 | 0101000000C286A757CA320140736891ED7CAF4440 | 65.45251754269189849135 | 196.35755262807569547404 | 2512.09235866 11 | 01010000007DD0B359F5390140C976BE9F1AAF4440 | 62.83927792460778869550 | 125.67855584921557739101 | 2926.25725246 12 | 0101000000D237691A140D01407E6FD39FFDB44440 | 53.54905726665024972591 | 53.54905726665024972591 | 3744.51557778 13 | (8 rows) 14 | 15 | -------------------------------------------------------------------------------- /src/pg/test/expected/08_interpolation_test.out: -------------------------------------------------------------------------------- 1 | SET client_min_messages TO WARNING; 2 | \set ECHO none 3 | nn | nni | idw 4 | ----------------------+--------------------------+----------------- 5 | 200.0000000000000000 | 238.41059602632179224595 | 341.46260750526 6 | (1 row) 7 | 8 | -------------------------------------------------------------------------------- /src/pg/test/expected/09_voronoi_test.out: -------------------------------------------------------------------------------- 1 | \pset format unaligned 2 | \set ECHO none 3 | within_tolerance 4 | t 5 | (1 row) 6 | -------------------------------------------------------------------------------- /src/pg/test/expected/11_kmeans_test.out: -------------------------------------------------------------------------------- 1 | \pset format unaligned 2 | \set ECHO all 3 | -- spatial kmeans 4 | SELECT 5 | count(DISTINCT cluster_no) as clusters 6 | FROM 7 | cdb_crankshaft.cdb_kmeans('select * from ppoints', 2); 8 | clusters 9 | 2 10 | (1 row) 11 | -- weighted mean 12 | SELECT 13 | count(*) clusters 14 | FROM ( 15 | SELECT 16 | cdb_crankshaft.CDB_WeightedMean(the_geom, value::NUMERIC), 17 | code 18 | FROM ppoints 19 | GROUP BY code 20 | ) p; 21 | clusters 22 | 52 23 | (1 row) 24 | -- nonspatial kmeans 25 | SELECT 26 | cluster_label::int in (0, 1) As cluster_label, 27 | cluster_center::json->>'col1' As cc_col1, 28 | cluster_center::json->>'col2' As cc_col2, 29 | silhouettes, 30 | inertia, 31 | rowid 32 | FROM cdb_crankshaft.CDB_KMeansNonspatial( 33 | 'SELECT unnest(Array[1, 1, 10, 10]) As col1, ' || 34 | 'unnest(Array[100, 100, 2, 2]) As col2, ' || 35 | 'unnest(Array[1, 2, 3, 4]) As cartodb_id ', 36 | Array['col1', 'col2']::text[], 37 | 2); 38 | cluster_label|cc_col1|cc_col2|silhouettes|inertia|rowid 39 | t|-1.0|1.0|1.0|0.0|1 40 | t|-1.0|1.0|1.0|0.0|2 41 | t|1.0|-1.0|1.0|0.0|3 42 | t|1.0|-1.0|1.0|0.0|4 43 | (4 rows) 44 | -------------------------------------------------------------------------------- /src/pg/test/expected/13_pia_test.out: -------------------------------------------------------------------------------- 1 | SET client_min_messages TO WARNING; 2 | \set ECHO none 3 | st_astext 4 | ------------------------------------------- 5 | POINT(-3.67484492582767 40.4394914243877) 6 | (1 row) 7 | 8 | st_astext 9 | ------------ 10 | POINT(0 0) 11 | (1 row) 12 | 13 | st_astext 14 | ------------ 15 | POINT(0 0) 16 | (1 row) 17 | 18 | -------------------------------------------------------------------------------- /src/pg/test/expected/16_getis_test.out: -------------------------------------------------------------------------------- 1 | \pset format unaligned 2 | \set ECHO all 3 | \i test/fixtures/getis_data.sql 4 | SET client_min_messages TO WARNING; 5 | \set ECHO none 6 | _cdb_random_seeds 7 | 8 | (1 row) 9 | rowid|z_score|p_value 10 | 9|-0.7862|0.0500 11 | 22|-0.3955|0.0330 12 | 33|2.7045|0.0050 13 | 35|1.9524|0.0130 14 | 36|-1.2056|0.0170 15 | 37|3.4785|0.0020 16 | 38|-1.4622|0.0020 17 | 40|5.7098|0.0030 18 | 46|3.4704|0.0120 19 | 47|-0.9994|0.0320 20 | 48|-1.3650|0.0340 21 | (11 rows) 22 | -------------------------------------------------------------------------------- /src/pg/test/expected/18_outliers_test.out: -------------------------------------------------------------------------------- 1 | SET client_min_messages TO WARNING; 2 | \set ECHO none 3 | is_outlier|rowid 4 | t|11 5 | t|16 6 | t|17 7 | (3 rows) 8 | is_outlier|rowid 9 | t|16 10 | t|17 11 | (2 rows) 12 | ERROR: Standard deviation of input data is zero 13 | is_outlier|rowid 14 | t|8 15 | t|11 16 | t|16 17 | (3 rows) 18 | is_outlier|rowid 19 | t|8 20 | t|9 21 | t|11 22 | t|16 23 | (4 rows) 24 | -------------------------------------------------------------------------------- /src/pg/test/expected/19_contour_test.out: -------------------------------------------------------------------------------- 1 | SET client_min_messages TO WARNING; 2 | \set ECHO none 3 | bin|avg_value 4 | 0|280.23070673030491816424178 5 | 1|413.81702914846213479025305 6 | 2|479.6334491374486884098328 7 | 3|529.1545236882183479447113 8 | 4|614.1132081424930103122037 9 | (5 rows) 10 | -------------------------------------------------------------------------------- /src/pg/test/expected/21_gwr_test.out: -------------------------------------------------------------------------------- 1 | -- test of Geographically Weighted Regression (GWR) 2 | SET client_min_messages TO WARNING; 3 | \set ECHO none 4 | rowid|coeff_pctrural|std_errs_pctrural|t_vals_pctrural|predicted|residuals|r_squared|bandwidth 5 | 13001|-0.0852|0.0220|-3.8678|8.8071|-0.6071|0.5218|90.0 6 | 13027|-0.0719|0.0221|-3.2506|9.9673|-0.8673|0.5443|90.0 7 | 13027|-0.0719|0.0221|-3.2506|9.9673|-0.8673|0.5443|90.0 8 | 13039|-0.0959|0.0241|-3.9755|13.4802|0.0198|0.6269|90.0 9 | 13231|-0.1383|0.0181|-7.6634|8.5520|0.7480|0.6337|90.0 10 | 13293|-0.1207|0.0184|-6.5553|12.9930|-3.9930|0.6446|90.0 11 | 13321|-0.0720|0.0204|-3.5337|8.2738|-1.9738|0.5573|90.0 12 | (7 rows) 13 | -------------------------------------------------------------------------------- /src/pg/test/fixtures/polyg_values.sql: -------------------------------------------------------------------------------- 1 | SET client_min_messages TO WARNING; 2 | \set ECHO none 3 | CREATE TABLE values (cartodb_id integer, value float, the_geom geometry); 4 | INSERT INTO values(cartodb_id, value, the_geom) VALUES 5 | (1,10,'0106000020E61000000100000001030000000100000005000000E5AF3500C03608C08068629111374440C7BC0A00C00F02C0AC0551523B414440C7BC0A00C0A700C0CAF23B6E74FB4340A7267FFFFF5206C0FBB7E41B7EE74340E5AF3500C03608C08068629111374440'::geometry), 6 | (2,20,'0106000020E610000001000000010300000001000000050000002439EC00804AF7BF07D6CCB5C3064440C7BC0A00C0A700C0CAF23B6E74FB4340C7BC0A00C00F02C0AC0551523B414440E20CD5FFFF30FABFBE4F76AFEA4B44402439EC00804AF7BF07D6CCB5C3064440'::geometry) 7 | -------------------------------------------------------------------------------- /src/pg/test/sql/01_install_test.sql: -------------------------------------------------------------------------------- 1 | \set ECHO none 2 | \set QUIET on 3 | SET client_min_messages TO error; 4 | -- Create role publicuser if it does not exist 5 | DO 6 | $$ 7 | BEGIN 8 | IF NOT EXISTS ( 9 | SELECT * 10 | FROM pg_catalog.pg_user 11 | WHERE usename = 'publicuser') THEN 12 | 13 | CREATE ROLE publicuser LOGIN; 14 | END IF; 15 | END 16 | $$ LANGUAGE plpgsql; 17 | 18 | -- Install the extension 19 | CREATE EXTENSION crankshaft VERSION 'dev' CASCADE; 20 | \set QUIET off 21 | -------------------------------------------------------------------------------- /src/pg/test/sql/03_overlap_sum_test.sql: -------------------------------------------------------------------------------- 1 | \i test/fixtures/polyg_values.sql 2 | 3 | SELECT round(cdb_crankshaft.cdb_overlap_sum( 4 | '0106000020E61000000100000001030000000100000004000000FFFFFFFFFF3604C09A0B9ECEC42E444000000000C060FBBF30C7FD70E01D44400000000040AD02C06481F1C8CD034440FFFFFFFFFF3604C09A0B9ECEC42E4440'::geometry, 5 | 'values', 'value' 6 | ), 2); 7 | 8 | SELECT round(cdb_crankshaft.cdb_overlap_sum( 9 | '0106000020E61000000100000001030000000100000004000000FFFFFFFFFF3604C09A0B9ECEC42E444000000000C060FBBF30C7FD70E01D44400000000040AD02C06481F1C8CD034440FFFFFFFFFF3604C09A0B9ECEC42E4440'::geometry, 10 | 'values', 'value', schema_name := 'public' 11 | ), 2); 12 | -------------------------------------------------------------------------------- /src/pg/test/sql/04_dot_density_test.sql: -------------------------------------------------------------------------------- 1 | WITH g AS ( 2 | SELECT ST_Buffer(ST_SetSRID(ST_MakePoint(0,0),4326)::geometry, 1000)::geometry AS g 3 | ), 4 | points AS( 5 | SELECT ( 6 | ST_Dump( 7 | cdb_crankshaft.cdb_dot_density(g.g, 100) 8 | ) 9 | ).geom AS p FROM g 10 | ) 11 | 12 | SELECT count(*), sum(CASE WHEN ST_Contains(g,p) THEN 1 ELSE 0 END) FROM points, g 13 | -------------------------------------------------------------------------------- /src/pg/test/sql/07_gravity_test.sql: -------------------------------------------------------------------------------- 1 | SET client_min_messages TO WARNING; 2 | \set ECHO none 3 | 4 | WITH t AS ( 5 | SELECT 6 | ARRAY[1,2,3] AS id, 7 | ARRAY[7.0,8.0,3.0] AS w, 8 | ARRAY[ST_GeomFromText('POINT(2.1744 41.4036)'),ST_GeomFromText('POINT(2.1228 41.3809)'),ST_GeomFromText('POINT(2.1511 41.3742)')] AS g 9 | ), 10 | s AS ( 11 | SELECT 12 | ARRAY[10,20,30,40,50,60,70,80] AS id, 13 | ARRAY[800, 700, 600, 500, 400, 300, 200, 100] AS p, 14 | ARRAY[ST_GeomFromText('POINT(2.1744 41.403)'),ST_GeomFromText('POINT(2.1228 41.380)'),ST_GeomFromText('POINT(2.1511 41.374)'),ST_GeomFromText('POINT(2.1528 41.413)'),ST_GeomFromText('POINT(2.165 41.391)'),ST_GeomFromText('POINT(2.1498 41.371)'),ST_GeomFromText('POINT(2.1533 41.368)'),ST_GeomFromText('POINT(2.131386 41.41399)')] AS g 15 | ) 16 | SELECT 17 | g.the_geom, 18 | g.h, 19 | g.hpop, 20 | g.dist 21 | FROM 22 | t, 23 | s, 24 | cdb_crankshaft.CDB_Gravity(t.id, t.g, t.w, s.id, s.g, s.p, 2, 100000, 3) g; 25 | -------------------------------------------------------------------------------- /src/pg/test/sql/08_interpolation_test.sql: -------------------------------------------------------------------------------- 1 | SET client_min_messages TO WARNING; 2 | \set ECHO none 3 | WITH a AS ( 4 | SELECT 5 | ARRAY[800, 700, 600, 500, 400, 300, 200, 100] AS vals, 6 | ARRAY[ST_GeomFromText('POINT(2.1744 41.403)'),ST_GeomFromText('POINT(2.1228 41.380)'),ST_GeomFromText('POINT(2.1511 41.374)'),ST_GeomFromText('POINT(2.1528 41.413)'),ST_GeomFromText('POINT(2.165 41.391)'),ST_GeomFromText('POINT(2.1498 41.371)'),ST_GeomFromText('POINT(2.1533 41.368)'),ST_GeomFromText('POINT(2.131386 41.41399)')] AS g 7 | ) 8 | SELECT 9 | cdb_crankshaft.CDB_SpatialInterpolation(g, vals, ST_GeomFromText('POINT(2.154 41.37)'),0) as NN, 10 | cdb_crankshaft.CDB_SpatialInterpolation(g, vals, ST_GeomFromText('POINT(2.154 41.37)'),1) as NNI, 11 | cdb_crankshaft.CDB_SpatialInterpolation(g, vals, ST_GeomFromText('POINT(2.154 41.37)'),2) as IDW 12 | FROM a; 13 | -------------------------------------------------------------------------------- /src/pg/test/sql/09_voronoi_test.sql: -------------------------------------------------------------------------------- 1 | \pset format unaligned 2 | \set ECHO none 3 | 4 | WITH a AS ( 5 | SELECT 6 | ARRAY[ST_GeomFromText('POINT(2.1744 41.403)', 4326),ST_GeomFromText('POINT(2.1228 41.380)', 4326),ST_GeomFromText('POINT(2.1511 41.374)', 4326),ST_GeomFromText('POINT(2.1528 41.413)', 4326),ST_GeomFromText('POINT(2.165 41.391)', 4326),ST_GeomFromText('POINT(2.1498 41.371)', 4326),ST_GeomFromText('POINT(2.1533 41.368)', 4326),ST_GeomFromText('POINT(2.131386 41.41399)', 4326)] AS geomin 7 | ), 8 | b as( 9 | SELECT 10 | (st_dump(cdb_crankshaft.CDB_voronoi(geomin, 0.2, 1e-9))).geom as result 11 | FROM a 12 | ) 13 | SELECT 14 | abs(avg(st_area(result)) - 0.000178661700690617) < 1e-6 as within_tolerance 15 | FROM b; 16 | -------------------------------------------------------------------------------- /src/pg/test/sql/11_kmeans_test.sql: -------------------------------------------------------------------------------- 1 | \pset format unaligned 2 | \set ECHO all 3 | 4 | -- spatial kmeans 5 | SELECT 6 | count(DISTINCT cluster_no) as clusters 7 | FROM 8 | cdb_crankshaft.cdb_kmeans('select * from ppoints', 2); 9 | 10 | -- weighted mean 11 | SELECT 12 | count(*) clusters 13 | FROM ( 14 | SELECT 15 | cdb_crankshaft.CDB_WeightedMean(the_geom, value::NUMERIC), 16 | code 17 | FROM ppoints 18 | GROUP BY code 19 | ) p; 20 | 21 | -- nonspatial kmeans 22 | SELECT 23 | cluster_label::int in (0, 1) As cluster_label, 24 | cluster_center::json->>'col1' As cc_col1, 25 | cluster_center::json->>'col2' As cc_col2, 26 | silhouettes, 27 | inertia, 28 | rowid 29 | FROM cdb_crankshaft.CDB_KMeansNonspatial( 30 | 'SELECT unnest(Array[1, 1, 10, 10]) As col1, ' || 31 | 'unnest(Array[100, 100, 2, 2]) As col2, ' || 32 | 'unnest(Array[1, 2, 3, 4]) As cartodb_id ', 33 | Array['col1', 'col2']::text[], 34 | 2); 35 | -------------------------------------------------------------------------------- /src/pg/test/sql/14_densify_test.sql: -------------------------------------------------------------------------------- 1 | SET client_min_messages TO WARNING; 2 | \set ECHO none 3 | 4 | with data as ( 5 | select 6 | ARRAY[7.0,8.0,1.0,2.0,3.0,5.0,6.0,4.0] as colin, 7 | ARRAY[ST_GeomFromText('POINT(2.1744 41.4036)'),ST_GeomFromText('POINT(2.1228 41.3809)'),ST_GeomFromText('POINT(2.1511 41.3742)'),ST_GeomFromText('POINT(2.1528 41.4136)'),ST_GeomFromText('POINT(2.165 41.3917)'),ST_GeomFromText('POINT(2.1498 41.3713)'),ST_GeomFromText('POINT(2.1533 41.3683)'),ST_GeomFromText('POINT(2.131386 41.413998)')] as geomin 8 | ) 9 | select cdb_crankshaft.CDB_Densify(geomin, colin, 2) from data; 10 | -------------------------------------------------------------------------------- /src/pg/test/sql/15_tinmap_test.sql: -------------------------------------------------------------------------------- 1 | SET client_min_messages TO WARNING; 2 | \set ECHO none 3 | 4 | with data as ( 5 | select 6 | ARRAY[7.0,8.0,1.0,2.0,3.0,5.0,6.0,4.0] as colin, 7 | ARRAY[ST_GeomFromText('POINT(2.1744 41.4036)'),ST_GeomFromText('POINT(2.1228 41.3809)'),ST_GeomFromText('POINT(2.1511 41.3742)'),ST_GeomFromText('POINT(2.1528 41.4136)'),ST_GeomFromText('POINT(2.165 41.3917)'),ST_GeomFromText('POINT(2.1498 41.3713)'),ST_GeomFromText('POINT(2.1533 41.3683)'),ST_GeomFromText('POINT(2.131386 41.413998)')] as geomin 8 | ) 9 | select cdb_crankshaft.CDB_TINmap(geomin, colin, 2) from data; 10 | -------------------------------------------------------------------------------- /src/pg/test/sql/16_getis_test.sql: -------------------------------------------------------------------------------- 1 | \pset format unaligned 2 | \set ECHO all 3 | \i test/fixtures/getis_data.sql 4 | 5 | -- set random seed 6 | SELECT cdb_crankshaft._cdb_random_seeds(1234); 7 | 8 | -- test against PySAL example dataset 'stl_hom' 9 | SELECT rowid, round(z_score, 4) As z_score, round(p_value, 4) As p_value 10 | FROM cdb_crankshaft.CDB_GetisOrdsG( 11 | 'select * from getis_data', 12 | 'hr8893', 'queen', NULL, 999, 13 | 'the_geom', 'cartodb_id') As t(z_score, p_value, p_z_sim, rowid) 14 | WHERE round(p_value, 4) <= 0.05 15 | ORDER BY rowid ASC; 16 | -------------------------------------------------------------------------------- /src/pg/test/sql/19_contour_test.sql: -------------------------------------------------------------------------------- 1 | SET client_min_messages TO WARNING; 2 | \set ECHO none 3 | \pset format unaligned 4 | 5 | WITH a AS ( 6 | SELECT 7 | ARRAY[800, 700, 600, 500, 400, 300, 200, 100]::numeric[] AS vals, 8 | ARRAY[ST_GeomFromText('POINT(2.1744 41.403)',4326),ST_GeomFromText('POINT(2.1228 41.380)',4326),ST_GeomFromText('POINT(2.1511 41.374)',4326),ST_GeomFromText('POINT(2.1528 41.413)',4326),ST_GeomFromText('POINT(2.165 41.391)',4326),ST_GeomFromText('POINT(2.1498 41.371)',4326),ST_GeomFromText('POINT(2.1533 41.368)',4326),ST_GeomFromText('POINT(2.131386 41.41399)',4326)] AS g 9 | ), 10 | b as( 11 | SELECT 12 | foo.* 13 | FROM 14 | a, 15 | cdb_crankshaft.CDB_contour(a.g, a.vals, 0.0, 1, 3, 5, -60) foo 16 | ) 17 | SELECT bin, avg_value from b order by bin; 18 | -------------------------------------------------------------------------------- /src/pg/test/sql/21_gwr_test.sql: -------------------------------------------------------------------------------- 1 | -- test of Geographically Weighted Regression (GWR) 2 | SET client_min_messages TO WARNING; 3 | \set ECHO none 4 | \pset format unaligned 5 | \i test/fixtures/gwr_georgia.sql 6 | 7 | SELECT 8 | rowid, 9 | round((coeffs->>'pctrural')::numeric, 4) As coeff_pctrural, 10 | round((stand_errs->>'pctrural')::numeric, 4) As std_errs_pctrural, 11 | round((t_vals->>'pctrural')::numeric, 4) As t_vals_pctrural, 12 | round(predicted, 4) As predicted, 13 | round(residuals, 4) As residuals, 14 | round(r_squared, 4) As r_squared, 15 | bandwidth As bandwidth 16 | FROM 17 | cdb_crankshaft.CDB_GWR('SELECT * FROM g_utm_testing', 'pctbach', 18 | Array['pctrural', 'pctpov', 'pctblack']::text[], 19 | 90.0, 20 | False, 21 | 'bisquare', 22 | 'the_geom', 23 | 'areakey') 24 | WHERE rowid in (13001, 13027, 13039, 13231, 13321, 13293) 25 | ORDER BY rowid ASC; 26 | 27 | 28 | -- comparison data from known calculated values in 29 | -- https://github.com/TaylorOshan/pysal/blob/1d6af33bda46b1d623f70912c56155064463383f/pysal/examples/georgia/georgia_BS_NN_listwise.csv 30 | -- Note: values output from this analysis were correct with 1% of the values in that table, possibly due to projection differences. 31 | 32 | -------------------------------------------------------------------------------- /src/pg/test/sql/90_permissions.sql: -------------------------------------------------------------------------------- 1 | SELECT cdb_crankshaft._cdb_random_seeds(1234); 2 | 3 | -- Use regular user role 4 | SET ROLE test_regular_user; 5 | 6 | -- Add to the search path the schema 7 | SET search_path TO public,cdb_crankshaft; 8 | 9 | -- Exercise public functions 10 | SELECT ppoints.code, m.quads 11 | FROM ppoints 12 | JOIN CDB_AreasOfInterest_Local('ppoints', 'value') m 13 | ON ppoints.cartodb_id = m.ids 14 | ORDER BY ppoints.code; 15 | SELECT round(cdb_overlap_sum( 16 | '0106000020E61000000100000001030000000100000004000000FFFFFFFFFF3604C09A0B9ECEC42E444000000000C060FBBF30C7FD70E01D44400000000040AD02C06481F1C8CD034440FFFFFFFFFF3604C09A0B9ECEC42E4440'::geometry, 17 | 'values', 'value' 18 | ), 2); 19 | -------------------------------------------------------------------------------- /src/py/Makefile: -------------------------------------------------------------------------------- 1 | include ../../Makefile.global 2 | 3 | # Install the package locally for development 4 | install: 5 | $(PIP) install --upgrade ./crankshaft 6 | 7 | # Test develpment install 8 | test: 9 | $(NOSETESTS) crankshaft/test/ 10 | 11 | release: ../../release/$(EXTENSION).control $(SOURCES_DATA) 12 | mkdir -p ../../release/python/$(EXTVERSION) 13 | cp -r ./$(PACKAGE) ../../release/python/$(EXTVERSION)/ 14 | $(SED) -i -r 's/version='"'"'[0-9]+\.[0-9]+\.[0-9]+'"'"'/version='"'"'$(EXTVERSION)'"'"'/g' ../../release/python/$(EXTVERSION)/$(PACKAGE)/setup.py 15 | 16 | deploy: 17 | $(PIP) install $(RUN_OPTIONS) --upgrade ../../release/python/$(RELEASE_VERSION)/$(PACKAGE) 18 | -------------------------------------------------------------------------------- /src/py/crankshaft/crankshaft/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all modules""" 2 | import crankshaft.random_seeds 3 | import crankshaft.clustering 4 | import crankshaft.space_time_dynamics 5 | import crankshaft.segmentation 6 | import crankshaft.regression 7 | from . import analysis_data_provider 8 | -------------------------------------------------------------------------------- /src/py/crankshaft/crankshaft/clustering/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from for clustering""" 2 | from .moran import * 3 | from .kmeans import * 4 | from .getis import * 5 | -------------------------------------------------------------------------------- /src/py/crankshaft/crankshaft/pysal_utils/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions for pysal_utils""" 2 | from crankshaft.pysal_utils.pysal_utils import * 3 | -------------------------------------------------------------------------------- /src/py/crankshaft/crankshaft/random_seeds.py: -------------------------------------------------------------------------------- 1 | """Random seed generator used for non-deterministic functions in crankshaft""" 2 | import random 3 | import numpy 4 | 5 | 6 | def set_random_seeds(value): 7 | """ 8 | Set the seeds of the RNGs (Random Number Generators) 9 | used internally. 10 | """ 11 | random.seed(value) 12 | numpy.random.seed(value) 13 | -------------------------------------------------------------------------------- /src/py/crankshaft/crankshaft/regression/__init__.py: -------------------------------------------------------------------------------- 1 | from crankshaft.regression.gwr import * 2 | from crankshaft.regression.glm import * 3 | from crankshaft.regression.gwr_cs import * 4 | -------------------------------------------------------------------------------- /src/py/crankshaft/crankshaft/regression/glm/__init__.py: -------------------------------------------------------------------------------- 1 | from . import glm 2 | from . import family 3 | from . import utils 4 | from . import iwls 5 | -------------------------------------------------------------------------------- /src/py/crankshaft/crankshaft/regression/gwr/__init__.py: -------------------------------------------------------------------------------- 1 | from .base import * 2 | -------------------------------------------------------------------------------- /src/py/crankshaft/crankshaft/regression/gwr/base/__init__.py: -------------------------------------------------------------------------------- 1 | from . import gwr 2 | from . import sel_bw 3 | from . import diagnostics 4 | from . import kernels 5 | -------------------------------------------------------------------------------- /src/py/crankshaft/crankshaft/segmentation/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from for segmentation""" 2 | from .segmentation import * 3 | -------------------------------------------------------------------------------- /src/py/crankshaft/crankshaft/space_time_dynamics/__init__.py: -------------------------------------------------------------------------------- 1 | """Import all functions from clustering libraries.""" 2 | from .markov import * 3 | -------------------------------------------------------------------------------- /src/py/crankshaft/requirements.txt: -------------------------------------------------------------------------------- 1 | joblib==0.9.4 2 | numpy==1.11.0 3 | scipy==0.17.0 4 | pysal==1.14.3 5 | scikit-learn==0.17.0 6 | -------------------------------------------------------------------------------- /src/py/crankshaft/setup.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | CartoDB Spatial Analysis Python Library 4 | See: 5 | https://github.com/CartoDB/crankshaft 6 | """ 7 | 8 | from setuptools import setup, find_packages 9 | 10 | setup( 11 | name='crankshaft', 12 | 13 | version='0.0.0', 14 | 15 | description='CartoDB Spatial Analysis Python Library', 16 | 17 | url='https://github.com/CartoDB/crankshaft', 18 | 19 | author='Data Services Team - CartoDB', 20 | author_email='dataservices@cartodb.com', 21 | 22 | license='MIT', 23 | 24 | classifiers=[ 25 | 'Development Status :: 3 - Alpha', 26 | 'Intended Audience :: Mapping comunity', 27 | 'Topic :: Maps :: Mapping Tools', 28 | 'License :: OSI Approved :: MIT License', 29 | 'Programming Language :: Python', 30 | ], 31 | 32 | keywords='maps mapping tools spatial analysis geostatistics', 33 | 34 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 35 | 36 | extras_require={ 37 | 'dev': ['unittest'], 38 | 'test': ['unittest', 'nose', 'mock'], 39 | }, 40 | 41 | # The choice of component versions is dictated by what's 42 | # provisioned in the production servers. 43 | # IMPORTANT NOTE: please don't change this line. Instead issue a ticket to systems for evaluation. 44 | # NOTE2: For Bionic, .travis.yml is editing this line to match dependencies 45 | install_requires=['joblib==0.9.4', 'numpy==1.11.0', 'scipy==0.17.0', 'pysal==1.14.3', 'scikit-learn==0.17.0'], 46 | 47 | requires=['pysal', 'numpy', 'sklearn'], 48 | 49 | test_suite='test' 50 | ) 51 | -------------------------------------------------------------------------------- /src/py/crankshaft/test/fixtures/data.json: -------------------------------------------------------------------------------- 1 | [{"ids": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 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, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]}] -------------------------------------------------------------------------------- /src/py/crankshaft/test/fixtures/moran.json: -------------------------------------------------------------------------------- 1 | [[0.9319096128346788, "HH"], 2 | [-1.135787401862846, "HL"], 3 | [0.11732030672508517, "LL"], 4 | [0.6152779669180425, "LL"], 5 | [-0.14657336660125297, "LH"], 6 | [0.6967858120189607, "LL"], 7 | [0.07949310115714454, "HH"], 8 | [0.4703198759258987, "HH"], 9 | [0.4421125200498064, "HH"], 10 | [0.5724288737143592, "LL"], 11 | [0.8970743435692062, "LL"], 12 | [0.18327334401918674, "LL"], 13 | [-0.01466729201304962, "HL"], 14 | [0.3481559372544409, "LL"], 15 | [0.06547094736902978, "LL"], 16 | [0.15482141569329988, "HH"], 17 | [0.4373841193538136, "HH"], 18 | [0.15971286468915544, "LL"], 19 | [1.0543588860308968, "HH"], 20 | [1.7372866900020818, "HH"], 21 | [1.091998586053999, "LL"], 22 | [0.1171572584252222, "HH"], 23 | [0.08438455015300014, "LL"], 24 | [0.06547094736902978, "LL"], 25 | [0.15482141569329985, "HH"], 26 | [1.1627044812890683, "HH"], 27 | [0.06547094736902978, "LL"], 28 | [0.795275137550483, "HH"], 29 | [0.18562939195219, "LL"], 30 | [0.3010757406693439, "LL"], 31 | [2.8205795942839376, "HH"], 32 | [0.11259190602909264, "LL"], 33 | [-0.07116352791516614, "HL"], 34 | [-0.09945240794119009, "LH"], 35 | [0.18562939195219, "LL"], 36 | [0.1832733440191868, "LL"], 37 | [-0.39054253768447705, "HL"], 38 | [-0.1672071289487642, "HL"], 39 | [0.3337669247916343, "HH"], 40 | [0.2584386102554792, "HH"], 41 | [-0.19733845476322634, "HL"], 42 | [-0.9379282899805409, "LH"], 43 | [-0.028770969951095866, "LH"], 44 | [0.051367269430983485, "LL"], 45 | [-0.2172548045913472, "LH"], 46 | [0.05136726943098351, "LL"], 47 | [0.04191046803899837, "LL"], 48 | [0.7482357030403517, "HH"], 49 | [-0.014585767863118111, "LH"], 50 | [0.5410013139159929, "HH"], 51 | [1.0223932668429925, "LL"], 52 | [1.4179402898927476, "LL"]] -------------------------------------------------------------------------------- /src/py/crankshaft/test/helper.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from mock_plpy import MockPlPy 4 | plpy = MockPlPy() 5 | 6 | import sys 7 | sys.modules['plpy'] = plpy 8 | 9 | import os 10 | 11 | def fixture_file(name): 12 | dir = os.path.dirname(os.path.realpath(__file__)) 13 | return os.path.join(dir, 'fixtures', name) 14 | -------------------------------------------------------------------------------- /src/py/crankshaft/test/mock_plpy.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | class MockCursor: 5 | def __init__(self, data): 6 | self.cursor_pos = 0 7 | self.data = data 8 | 9 | def fetch(self, batch_size): 10 | batch = self.data[self.cursor_pos:self.cursor_pos + batch_size] 11 | self.cursor_pos += batch_size 12 | return batch 13 | 14 | 15 | class MockPlPy: 16 | def __init__(self): 17 | self._reset() 18 | 19 | def _reset(self): 20 | self.infos = [] 21 | self.notices = [] 22 | self.debugs = [] 23 | self.logs = [] 24 | self.warnings = [] 25 | self.errors = [] 26 | self.fatals = [] 27 | self.executes = [] 28 | self.results = [] 29 | self.prepares = [] 30 | self.results = [] 31 | 32 | def _define_result(self, query, result): 33 | pattern = re.compile(query, re.IGNORECASE | re.MULTILINE) 34 | self.results.append([pattern, result]) 35 | 36 | def notice(self, msg): 37 | self.notices.append(msg) 38 | 39 | def debug(self, msg): 40 | self.notices.append(msg) 41 | 42 | def info(self, msg): 43 | self.infos.append(msg) 44 | 45 | def error(self, msg): 46 | self.infos.append(msg) 47 | self.notices.append(msg) 48 | 49 | def cursor(self, query): 50 | data = self.execute(query) 51 | return MockCursor(data) 52 | 53 | # TODO: additional arguments 54 | def execute(self, query): 55 | for result in self.results: 56 | if result[0].match(query): 57 | return result[1] 58 | return [] 59 | --------------------------------------------------------------------------------