GeoDaCenter / spatial_access

https://spatial.uchicago.edu
37 stars 11 forks source link

Include in notebooks #76

Open ifarah opened 5 years ago

ifarah commented 5 years ago

Automated case

years=list(range(1990, 2011, 10))
years_string=list(map(str, years))
all_y=[x[2:] for x in years_string]

Matrix:

from spatial_access.p2p import TransitMatrix
from spatial_access.Configs import Configs
custom_config = Configs()
custom_config.disable_area_threshold=True

for i in all_y:
    w_asym_mat = TransitMatrix(network_type='walk',
                       primary_input='ORIG/tracts_chi.csv',
                       primary_hints={'lon': 'lon', 'lat': 'lat', 'idx': 'ID'},
                       secondary_hints={'lon': 'lon', 'lat': 'lat', 'idx': 'ID'},
                       secondary_input='DEST/nets_ws/chi_nets'+str(i)+'.csv', 
                       configs=custom_config)
    w_asym_mat.process()
    w_asym_mat.write_tmx('matrices/mat_chi'+str(i)+'.tmx')

Models:

from spatial_access.Models import *

dict = {
"groceries": [3,3,3,3,3,3,3,3,3,3],
"restaurants": [1,1,1,1,1, 1, .75, .75, .75, .75],
"shopping": [1,1,1, 1, 1,1, 1, 1, .5, .5],
"coffee": [1,1,1, 1,1,1,.75,.75,.75, .75],
"banks": [1,1,1,1,1,1,1,1,1,1],
"park": [1,1,1,1,1,1,1,1,1,1],
"school": [1,1,1,1,1,1,1,1,1,1],
"books": [1,1,1,1,1,1,1,1,1,1],
"entertainment": [1,1,1,1,1,1,1,1,1,1],
}

for i in all_y:
    accesst = AccessModel(network_type='walk',
                     transit_matrix_filename='matrices/mat_chi'+str(i)+'.tmx',
                     sources_filename='ORIG/tracts_chi.csv',
                     source_column_names={'idx': 'ID', 'population': 'skip', 'lat': 'lat', 'lon': 'lon'},
                     dest_column_names={'idx': 'ID', 'category': 'cat', 'capacity': 'skip', 'lat': 'lat', 'lon': 'lon'},
                     destinations_filename='DEST/nets_ws/chi_nets'+str(i)+'.csv',
                     decay_function='logit')
    accesst.calculate(upper_threshold=1800, category_weight_dict=dict, normalize=False)
    accesst.write_results('access/access_chi'+str(i)+'.csv')