def get_blockgroup_geometries(self):
     """
     Loads SeattleCensusBlockGroups geometries as geodataframe from pickle file.
     Inputs: pickle
     Outputs: geodataframe, pickle if it does not exist
     """
     try:
         daq.open_pickle(cn.PICKLE_DIR, cn.SEATTLE_BLOCK_GROUPS_PICKLE)
     except FileNotFoundError:
         df = pd.read_csv(cn.SEATTLE_BLOCK_GROUPS_FP, dtype={
             cn.KEY: str
         }).loc[:, (cn.KEY, cn.GEOMETRY, cn.LAT, cn.LON)]
         df[cn.COORDINATE] = df.apply(
             lambda x: Coordinate(x.lat, x.lon).set_geocode(), axis=1)
         df[cn.NBHD_SHORT] = df[cn.COORDINATE].apply(
             lambda x: x.neighborhood_short)
         df[cn.NBHD_LONG] = df[cn.COORDINATE].apply(
             lambda x: x.neighborhood_long)
         df[cn.COUNCIL_DISTRICT] = df[cn.COORDINATE].apply(
             lambda x: x.council_district)
         df[cn.URBAN_VILLAGE] = df[cn.COORDINATE].apply(
             lambda x: x.urban_village)
         df[cn.ZIPCODE] = df[cn.COORDINATE].apply(lambda x: x.zipcode)
         df.drop(columns=[cn.COORDINATE, cn.LAT, cn.LON], inplace=True)
         df.geometry = df.geometry.apply(shapely.wkt.loads)
         gdf = gpd.GeoDataFrame(df, crs=cn.CRS_EPSG, geometry=cn.GEOMETRY)
         daq.make_pickle(cn.PICKLE_DIR, gdf, cn.SEATTLE_BLOCK_GROUPS_PICKLE)
         return gdf
     else:
         return daq.open_pickle(cn.PICKLE_DIR,
                                cn.SEATTLE_BLOCK_GROUPS_PICKLE)
Esempio n. 2
0
 def get_reference(self, raw_dir, processed_dir, pickle_name):
     try:
         daq.open_pickle(processed_dir, pickle_name)
     except:
         return self.make_reference(raw_dir, processed_dir,
                                    str(pickle_name))
     else:
         return daq.open_pickle(processed_dir, pickle_name)
 def set_parking_cost(self):
     parking_dict = daq.open_pickle(cn.PICKLE_DIR, cn.PARKING_RATES_PICKLE)
     if self.block_group == None:
         self.set_geocode()
     try:
         parking_dict[self.block_group]
     except:
         self.parking_cost = 0
     else:
         self.parking_cost = parking_dict[self.block_group]
     return self
import init
import data_accessor as daq
import constants as cn
import generate_parking_data as gen_park
import time

start = time.time()
try:
    daq.open_pickle(cn.PICKLE_DIR, 'parking_rates.pickle')
except:
    parking = gen_park.GenerateParkingData()
    parking.write_to_csv(parking.blkgrp_parking_df,
                         cn.BLOCK_GROUP_PARKING_RATES + '.csv')
    parking.blkgrp_parking_df = parking.blkgrp_parking_df.set_index(
        cn.KEY).transpose().reset_index().drop(columns=['index'])
    parking.blkgrp_parking_df.columns.name = None
    parking_dict = parking.blkgrp_parking_df.to_dict(orient='records')
    daq.make_pickle(cn.PICKLE_DIR, parking_dict, 'parking_rates.pickle')

end = time.time()
print(end - start, 'seconds')
from mode_choice_calculator import ModeChoiceCalculator
from affordability_index import AffordabilityIndex
import data_accessor as daq
import pandas as pd
import time

mc = ModeChoiceCalculator()
# try:
#     daq.open_pickle(cn.PICKLE_DIR, 'mode_choice_calc.pickle')
# except:
# total_trips_df = pd.read_csv(cn.WEEKDAY_DISTANCES_OUT_FP,
#     dtype={cn.BLOCK_GROUP: str, cn.DEST_BLOCK_GROUP: str})
# trips_per_blockgroup = mc.trips_per_blockgroup(total_trips_df, viable_only=True)
#     daq.make_pickle(cn.PICKLE_DIR, trips_per_blockgroup, 'mode_choice_calc.pickle')
# # else:
trips_per_blockgroup = daq.open_pickle(cn.PICKLE_DIR,
                                       'mode_choice_calc.pickle')

ac = AffordabilityIndex(trips_per_blockgroup)
# print("checkpoint reached")
# start = time.time()
# try:
#     daq.open_pickle(cn.PICKLE_DIR, 'afford_costs.pickle')
# except:
#     block_cost_df = ac.create_avg_blockgroup_cost_df()
#     daq.make_pickle(cn.PICKLE_DIR, block_cost_df, 'afford_costs.pickle')
# else:
#     block_cost_df = daq.open_pickle(cn.PICKLE_DIR, 'afford_costs.pickle')

# end = time.time()

# # print(block_cost_df.head())