def load_bounds(): ''' Load town boundary data ''' # db connection params db_config = { 'host': 'localhost', 'port': 5433, 'user': '******', 'database': 'gareth', 'password': '' } # load boundaries data bound_data = util_funcs.load_data_as_pd_df(db_config, ['pop_id', 'city_name', 'city_type', 'city_population'], 'analysis.city_boundaries_150', 'WHERE pop_id IS NOT NULL ORDER BY pop_id') # add indices for city-wide data bound_data.set_index('pop_id', inplace=True) bound_data.sort_index(inplace=True) # label dataset according to classifications town_classifications = ['New Town', 'New Town Like', 'Expanded Town', 'Expanded Town Like'] selected_data = bound_data.copy() new_towns = selected_data[selected_data.city_type.isin(town_classifications)] largest = new_towns.city_population.max() smallest = new_towns.city_population.min() """ # 298701.0 - largest pop # 8186.0 - smallest pop # 650 - largest city id # 19 - smallest city id (largest by size) """ selected_data = selected_data[np.logical_and(selected_data.city_population >= smallest, selected_data.city_population <= largest)] # prepare targets selected_data['targets'] = 0 for pop_id, city_row in selected_data.iterrows(): if (city_row.city_type in town_classifications): selected_data.loc[pop_id, 'targets'] = 1 return selected_data
# %% # db connection params db_config = { 'host': 'localhost', 'port': 5433, 'user': '******', 'database': 'gareth', 'password': '' } # load boundaries data bound_data = util_funcs.load_data_as_pd_df( db_config, [ 'pop_id', 'city_name', 'city_type', 'city_area', 'city_area_petite', 'city_population', 'city_species_count', 'city_species_unique', 'city_streets_len', 'city_intersections_count' ], 'analysis.city_boundaries_150', 'WHERE pop_id IS NOT NULL ORDER BY pop_id') #%% def pop_corr_plot(city_data, theme_1, theme_2, towns_data, xlabel, sup_title): new_towns = [] other_towns = [] for i, d in bound_data.iterrows(): if d['city_type'] in ['New Town']: new_towns.append(d['pop_id']) else: other_towns.append(d['pop_id'])
'ac_cultural', 'ac_sports', 'ac_total' ] col_template = '{col}[{i}] as {col}_{dist}' distances = [50, 100, 200, 300, 400, 600, 800, 1200, 1600] for col_base in columns_base: for i, d in enumerate(distances): columns.append(col_template.format(col=col_base, i=i + 1, dist=d)) # bandwise distances do not include 50m distances_bandwise = distances[1:] # %% # load data df_full = util_funcs.load_data_as_pd_df( db_config, columns, 'analysis.nodes_full', 'WHERE city_pop_id = 1 and within = true') df_full = df_full.set_index('id') df_full = util_funcs.clean_pd(df_full, drop_na='all', fill_inf=np.nan) df_100 = util_funcs.load_data_as_pd_df( db_config, columns, 'analysis.nodes_100', 'WHERE city_pop_id = 1 and within = true') df_100 = df_100.set_index('id') df_100 = util_funcs.clean_pd(df_100, drop_na='all', fill_inf=np.nan) df_50 = util_funcs.load_data_as_pd_df( db_config, columns, 'analysis.nodes_50', 'WHERE city_pop_id = 1 and within = true') df_50 = df_50.set_index('id') df_50 = util_funcs.clean_pd(df_50, drop_na='all', fill_inf=np.nan)
] columns_base = [ 'c_node_density', 'c_node_harmonic', 'c_node_beta', 'c_node_betweenness', 'c_node_betweenness_beta', 'c_node_harmonic_angular', 'c_node_betweenness_angular' ] col_template = '{col}[{i}] as {col}_{dist}' distances = [50, 100, 200, 400, 800, 1600] for col_base in columns_base: for i, d in enumerate(distances): columns.append(col_template.format(col=col_base, i=i + 1, dist=d)) # %% load nodes data print('loading columns') df_full = util_funcs.load_data_as_pd_df( db_config, columns, 'analysis.nodes_full_dual', 'WHERE city_pop_id = 1 and within = true') df_full = df_full.set_index('id') df_full = util_funcs.clean_pd(df_full, drop_na='all', fill_inf=np.nan) # %% ''' correlation matrix plot ''' themes = [ 'c_node_density_{dist}', 'c_node_harmonic_{dist}', 'c_node_harmonic_angular_{dist}', 'c_node_beta_{dist}', 'c_node_betweenness_{dist}', 'c_node_betweenness_angular_{dist}', 'c_node_betweenness_beta_{dist}' ]