Esempio n. 1
0
def main():

    print "Processing data before loading map"

    # Read parcel data
    parcels_main = pd.read_csv(parcels_main_dir + r"\inputs\buffered_parcels.dat", delim_whitespace=True)
    parcels_alt = pd.read_csv(parcels_alt_dir + r"\inputs\buffered_parcels.dat", delim_whitespace=True)

    # calculate accessibility
    access_df_main = accessibility_calc(parcels_main, dir_base=parcels_main_dir)
    access_df_alt = accessibility_calc(parcels_alt, dir_base=parcels_main_dir)

    # Load the logsums data
    main_logsum = load_logsum(parcels_main_dir + r"\outputs\aggregate_logsums.1.dat")
    alt_logsum = load_logsum(parcels_alt_dir + r"\outputs\aggregate_logsums.1.dat")

    # only include results for CCOMP_SHO person type (fewer cars than drivers short access to transit)
    main_logsum = main_logsum[["ZONE", "CCOMP_SHO"]]
    alt_logsum = alt_logsum[["ZONE", "CCOMP_SHO"]]

    # Convert this field to an "Access Score" by normalizing, and rename
    main_logsum["CCOMP_SHO"] = main_logsum["CCOMP_SHO"] / main_logsum["CCOMP_SHO"].max()
    alt_logsum["CCOMP_SHO"] = alt_logsum["CCOMP_SHO"] / alt_logsum["CCOMP_SHO"].max()

    main_logsum["Total Access Score"] = main_logsum["CCOMP_SHO"]
    alt_logsum["Total Access Score"] = alt_logsum["CCOMP_SHO"]

    main_logsum.drop("CCOMP_SHO", inplace=True, axis=1)
    alt_logsum.drop("CCOMP_SHO", inplace=True, axis=1)

    # Join to accessibility results df
    access_df_main = access_df_main.merge(main_logsum, left_on="TAZ", right_on="ZONE")
    access_df_alt = access_df_alt.merge(alt_logsum, left_on="TAZ", right_on="ZONE")
    # # Join to parcels data
    # parcels_main = parcels_main.merge(main_logsum, left_on='taz_p', right_on='ZONE')
    # parcels_alt = parcels_alt.merge(alt_logsum, left_on='taz_p', right_on='ZONE')

    # # Rename taz column
    # parcels_main = parcels_main.rename(columns = {'taz_p': 'TAZ'})
    # parcels_alt = parcels_alt.rename(columns = {'taz_p': 'TAZ'})

    # Create dictionary of dataframes to plot on map
    d = {"main": access_df_main, "alternative": access_df_alt}
    # d = {'main': parcels_main,
    #    'alternative': parcels_alt
    #    }

    # Start the dataframe explorer webmap
    dframe_explorer.start(
        d,
        center=[47.614848, -122.3359058],
        zoom=11,
        shape_json=os.path.join("inputs/", "taz2010.geojson"),
        geom_name="TAZ",
        join_name="TAZ",
        precision=2,
        host=socket.gethostbyname(socket.gethostname()),  # hosted on machine running the script
    )
Esempio n. 2
0
def main():

  print "Processing data before loading map"

  # Read parcel data
  # parcels_main = pd.read_csv(parcels_main_dir + r'\inputs\buffered_parcels.dat', delim_whitespace=True)
  # parcels_alt = pd.read_csv(parcels_alt_dir + r'\inputs\buffered_parcels.dat', delim_whitespace=True)


  trip_main = h5trip_to_df(daysim_main)
  trip_alt = h5trip_to_df(daysim_alt)

  hh_main = h5hh_to_df(daysim_main)
  hh_alt = h5hh_to_df(daysim_alt)

  pers_main = h5per_to_df(daysim_main)
  pers_alt = h5per_to_df(daysim_alt)

  # Join household records to person records
  pers_hh_main = pd.merge(pers_main, hh_main, on='hhno')
  pers_hh_alt = pd.merge(pers_alt, hh_alt, on='hhno')

  trip_hh_main = pd.merge(trip_main, pers_hh_main, on=['hhno','pno'])
  trip_hh_alt = pd.merge(trip_alt, pers_hh_alt, on=['hhno','pno'])

  # Auto ownership calc
  hh_main = auto_ownership(hh_main)
  hh_alt = auto_ownership(hh_alt)

  MAX_INC = 999999999

  # Computer daily travel time totals for walk and biking
  trip_hh_main = nmt_benefits(trip_hh_main, 1, MAX_INC)
  trip_hh_main = nmt_benefits(trip_hh_main, 2, MAX_INC)
  trip_hh_alt = nmt_benefits(trip_hh_alt, 1, MAX_INC)
  trip_hh_alt = nmt_benefits(trip_hh_alt, 2, MAX_INC)

  # Emissions by TAZ location
  auto_emissions = calc_emissions_by_taz()
  ### only have network results for one scenario, so using the same result for main and alt

  trip_hh_main = trip_hh_main.merge(auto_emissions,left_on='hhtaz',right_on='TAZ')
  trip_hh_alt = trip_hh_main.merge(auto_emissions,left_on='hhtaz',right_on='TAZ')

  # Emissions by household location
  auto_emissions_by_hh_main = calc_emissions_by_hhtaz(trip_hh_main)
  auto_emissions_by_hh_alt = calc_emissions_by_hhtaz(trip_hh_main)

  trip_hh_main = trip_hh_main.merge(auto_emissions_by_hh_main,left_on='hhtaz',right_on='hhtaz', suffixes=['_zone_tot','_by_hhtaz'])
  trip_hh_alt = trip_hh_main.merge(auto_emissions_by_hh_alt,left_on='hhtaz',right_on='hhtaz', suffixes=['_zone_tot','_by_hhtaz'])

  # Only show subset of columns
  subset_col = ['hhtaz', 'travcost','travdist','travtime','hhincome','hhvehs',
  '1 time','2 time','Carbon Dioxide_zone_tot','Carbon Monoxide_zone_tot',
  'Nitrogen Oxide_zone_tot', 'Particulate Matter_zone_tot', 'Volatile Organic Compound_zone_tot',
  'Carbon Dioxide_by_hhtaz','Carbon Monoxide_by_hhtaz',
  'Nitrogen Oxide_by_hhtaz', 'Particulate Matter_by_hhtaz', 'Volatile Organic Compound_by_hhtaz']
  
  trip_hh_main = trip_hh_main[subset_col]
  trip_hh_alt = trip_hh_alt[subset_col]
  # Crashes and noise
  # These make most sense to be shown at a geographic level
  # Would it make sense to show them at a TAZ level?

  # Create dictionary of dataframes to plot on map
  d = {'main': trip_hh_main,
       'alternative': trip_hh_alt
       }

  # Start the dataframe explorer webmap
  dframe_explorer.start(d, 
                        center=[47.614848,-122.3359058],
                        zoom=11,
                        shape_json=os.path.join('inputs/', 'taz2010.geojson'),
                        geom_name='TAZ',
                        join_name='hhtaz',
                        precision=2, 
                        host=socket.gethostbyname(socket.gethostname())    # hosted on machine running the script
                        )  
Esempio n. 3
0
def main():

  print "Processing data before loading map"

  # Read parcel data
  #parcels = pd.read_csv(main_dir + r'/inputs/buffered_parcels.dat', delim_whitespace=True)
  #access_df = accessibility_calc(parcels)

  # Rename parcel's TAZ column to match geo data
  #parcels['TAZ'] = parcels['taz_p']

  # Load daysim results
  daysim_main = h5py.File(main_dir + r'/outputs/daysim_outputs.h5', "r+")
  daysim_alt = h5py.File(map_daysim_alt, 'r+')

  trip_main = pd.DataFrame(data={ 'Household ID': daysim_main['Trip']['hhno'][:],
                            'Travel Time': daysim_main['Trip']['travtime'][:],
                            'Travel Cost': daysim_main['Trip']['travcost'][:],
                            'Travel Distance': daysim_main['Trip']['travdist'][:],
                            'Mode': daysim_main['Trip']['mode'][:],
                            'Purpose': daysim_main['Trip']['dpurp'][:]})

  trip_alt = pd.DataFrame(data={ 'Household ID': daysim_alt['Trip']['hhno'][:],
                            'Travel Time': daysim_alt['Trip']['travtime'][:],
                            'Travel Cost': daysim_alt['Trip']['travcost'][:],
                            'Travel Distance': daysim_alt['Trip']['travdist'][:],
                            'Mode': daysim_alt['Trip']['mode'][:],
                            'Purpose': daysim_alt['Trip']['dpurp'][:]})

  hh_main = pd.DataFrame(data={ 'TAZ' : daysim_main['Household']['hhtaz'][:], 
                              'Household_Income': daysim_main['Household']['hhincome'][:],
                              'Household Vehicles': daysim_main['Household']['hhvehs'][:],
                              'Household Size': daysim_main['Household']['hhsize'][:],
                              'Household ID': daysim_main['Household']['hhno'][:]})

  hh_alt = pd.DataFrame(data={ 'TAZ' : daysim_alt['Household']['hhtaz'][:], 
                              'Household_Income': daysim_alt['Household']['hhincome'][:],
                              'Household Vehicles': daysim_alt['Household']['hhvehs'][:],
                              'Household Size': daysim_alt['Household']['hhsize'][:],
                              'Household ID': daysim_alt['Household']['hhno'][:]})

  pers_main = pd.DataFrame(data={'Household ID': daysim_main['Person']['hhno'][:],
                                 'Age': daysim_main['Person']['pagey'][:],
                                 'Gender': daysim_main['Person']['pgend'][:]})
  pers_alt = pd.DataFrame(data={'Household ID': daysim_alt['Person']['hhno'][:],
                                 'Age': daysim_alt['Person']['pagey'][:],
                                 'Gender': daysim_alt['Person']['pgend'][:]})

  trip_hh_main = pd.merge(trip_main, hh_main[['TAZ', 'Household ID', 'Household_Income']], on='Household ID')
  trip_hh_main = pd.merge(trip_hh_main, pers_main, on='Household ID')

  trip_hh_alt = pd.merge(trip_alt, hh_alt[['TAZ', 'Household ID', 'Household_Income']], on='Household ID')
  trip_hh_alt = pd.merge(trip_hh_alt, pers_alt, on='Household ID')

  # Transit share by income class
  #transit_share = transit_mode_share(trip_hh)

  # Create dictionary of dataframes to plot on map
  d = {'main': trip_hh_main,
       'alternative': trip_hh_alt
       # "Accessibility to Jobs within %d minutes" % max_trav_time : access_df,
       # "Land Use": parcels,
       # "Households": hh_df,
       # "Trips": trip_hh,
       # "Transit Mode Share": transit_share
       }

  # Start the dataframe explorer webmap
  dframe_explorer.start(d, 
                        center=[47.614848,-122.3359058],
                        zoom=11,
                        shape_json=os.path.join('inputs/', 'taz2010.geojson'),
                        geom_name='TAZ',
                        join_name='TAZ',
                        precision=3, 
                        host=socket.gethostbyname(socket.gethostname())    # hosted on machine running the script
                        )  
Esempio n. 4
0
def main():

    print "Processing data before loading map"

    # Read parcel data
    #parcels = pd.read_csv(main_dir + r'/inputs/buffered_parcels.dat', delim_whitespace=True)
    #access_df = accessibility_calc(parcels)

    # Rename parcel's TAZ column to match geo data
    #parcels['TAZ'] = parcels['taz_p']

    # Load daysim results
    daysim_main = h5py.File(main_dir + r'/outputs/daysim_outputs.h5', "r+")
    daysim_alt = h5py.File(map_daysim_alt, 'r+')

    trip_main = pd.DataFrame(
        data={
            'Household ID': daysim_main['Trip']['hhno'][:],
            'Travel Time': daysim_main['Trip']['travtime'][:],
            'Travel Cost': daysim_main['Trip']['travcost'][:],
            'Travel Distance': daysim_main['Trip']['travdist'][:],
            'Mode': daysim_main['Trip']['mode'][:],
            'Purpose': daysim_main['Trip']['dpurp'][:]
        })

    trip_alt = pd.DataFrame(
        data={
            'Household ID': daysim_alt['Trip']['hhno'][:],
            'Travel Time': daysim_alt['Trip']['travtime'][:],
            'Travel Cost': daysim_alt['Trip']['travcost'][:],
            'Travel Distance': daysim_alt['Trip']['travdist'][:],
            'Mode': daysim_alt['Trip']['mode'][:],
            'Purpose': daysim_alt['Trip']['dpurp'][:]
        })

    hh_main = pd.DataFrame(
        data={
            'TAZ': daysim_main['Household']['hhtaz'][:],
            'Household_Income': daysim_main['Household']['hhincome'][:],
            'Household Vehicles': daysim_main['Household']['hhvehs'][:],
            'Household Size': daysim_main['Household']['hhsize'][:],
            'Household ID': daysim_main['Household']['hhno'][:]
        })

    hh_alt = pd.DataFrame(
        data={
            'TAZ': daysim_alt['Household']['hhtaz'][:],
            'Household_Income': daysim_alt['Household']['hhincome'][:],
            'Household Vehicles': daysim_alt['Household']['hhvehs'][:],
            'Household Size': daysim_alt['Household']['hhsize'][:],
            'Household ID': daysim_alt['Household']['hhno'][:]
        })

    pers_main = pd.DataFrame(
        data={
            'Household ID': daysim_main['Person']['hhno'][:],
            'Age': daysim_main['Person']['pagey'][:],
            'Gender': daysim_main['Person']['pgend'][:]
        })
    pers_alt = pd.DataFrame(
        data={
            'Household ID': daysim_alt['Person']['hhno'][:],
            'Age': daysim_alt['Person']['pagey'][:],
            'Gender': daysim_alt['Person']['pgend'][:]
        })

    trip_hh_main = pd.merge(
        trip_main,
        hh_main[['TAZ', 'Household ID', 'Household_Income']],
        on='Household ID')
    trip_hh_main = pd.merge(trip_hh_main, pers_main, on='Household ID')

    trip_hh_alt = pd.merge(trip_alt,
                           hh_alt[['TAZ', 'Household ID', 'Household_Income']],
                           on='Household ID')
    trip_hh_alt = pd.merge(trip_hh_alt, pers_alt, on='Household ID')

    # Transit share by income class
    #transit_share = transit_mode_share(trip_hh)

    # Create dictionary of dataframes to plot on map
    d = {
        'main': trip_hh_main,
        'alternative': trip_hh_alt
        # "Accessibility to Jobs within %d minutes" % max_trav_time : access_df,
        # "Land Use": parcels,
        # "Households": hh_df,
        # "Trips": trip_hh,
        # "Transit Mode Share": transit_share
    }

    # Start the dataframe explorer webmap
    dframe_explorer.start(
        d,
        center=[47.614848, -122.3359058],
        zoom=11,
        shape_json=os.path.join('inputs/', 'taz2010.geojson'),
        geom_name='TAZ',
        join_name='TAZ',
        precision=3,
        host=socket.gethostbyname(
            socket.gethostname())  # hosted on machine running the script
    )