Mercurial > hg > plosone_underreview
diff scripts/utils_spatial.py @ 8:0f3eba42b425 branch-tests
added notebooks and utils
author | Maria Panteli <m.x.panteli@gmail.com> |
---|---|
date | Mon, 11 Sep 2017 18:23:14 +0100 |
parents | e50c63cf96be |
children | 98718fdd8326 |
line wrap: on
line diff
--- a/scripts/utils_spatial.py Mon Sep 11 14:53:13 2017 +0100 +++ b/scripts/utils_spatial.py Mon Sep 11 18:23:14 2017 +0100 @@ -8,12 +8,18 @@ import json import pysal # before shapely in util_plots import fiona +import os import sys sys.path.append('../misc') import matplotlib.pyplot as plt -def neighbors_from_json_file(data_countries, json_DB='../MergeBL-Smith/data/countries.json'): +DATA_DIR = os.path.join(os.path.dirname(__file__), 'util_data') +JSON_DB = os.path.join(DATA_DIR, 'countries.json') +SHAPEFILE = os.path.join(DATA_DIR, 'shapefiles', 'ne_10m_admin_0_countries.shp') + + +def neighbors_from_json_file(data_countries, json_DB=JSON_DB): neighbors = {} with open(json_DB) as json_file: countries_dict = json.load(json_file) @@ -60,7 +66,7 @@ def replace_empty_neighbours_with_KNN(data_countries, w): - shapefile = "../MergeBL-Smith/shapefiles/ne_10m_admin_0_countries.shp" + shapefile = SHAPEFILE no_neighbors_idx = w.islands knn = 10 wknn = pysal.knnW_from_shapefile(shapefile, knn)