Skip to content

Commit

Permalink
add CreateFullSericeDataframe.py and update README
Browse files Browse the repository at this point in the history
  • Loading branch information
chiertu committed Dec 9, 2023
1 parent 7c633c3 commit ea52c33
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Complete these steps to run the pipeline:
5. on the terminal run the following code in order (allow time for each step to process):

cd code
python GenerateSingleSourceofTruth.py
python GenerateDistMatrix.py
python CreateFullServiceDf.py -- same process in notebook at /notebooks/create_full_service_dfs.ipynb
python GenerateDistMatrix.py
python extract_capacity_demands.py
python extract_supplementary_info.py
python bike_conversion.py
Expand Down
95 changes: 95 additions & 0 deletions code/CreateFullServiceDataframe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import pandas as pd
import numpy as np

dist_matrix_path = "../data/generated_distance_matrices/distance_matrix_new.npy"
dist_matrix_df_path = "../data/indoor_outdoor_distances_galv.csv"
indoor_pts_path = "../data/galveston_indoor_pts.csv"
outdoor_pts_path = "../data/galveston_outdoor_pts.csv"
old_pts_path = "../data/FUE_Galveston.csv"
all_pts_path = "../data/indoor_outdoor_pts_galv.csv"

def create_full_service_location_df():
'''
1. Loads the npy distance matrix file
(made for the galveston moody gardens + indoor + outdoor points)
and converts it into a csv file --> saves the csv file in the data folder
2. Concatonates the galveston_indoor_pts and galveston_outdoor_pts dataframes
into one full dataframe will all service locations
3. Performs data cleaning on the merged service locations df -->
saves the csv in the data folder
:params: None
:return: None
'''
#load the distance matrix file, it is a numpy array
dist_matrix_array = np.load(dist_matrix_path)

#convert the distance matrix to a dataframe
dist_matrix_df=pd.DataFrame(dist_matrix_array)
#name columns
dist_matrix_df.columns = [str(i) for i in range(dist_matrix_array.shape[1])]

#save to csv
dist_matrix_df.to_csv(dist_matrix_df_path, index=False)

# Load the indoor pts df and the original FUE df
indoor = pd.read_csv(indoor_pts_path)
old_galveston = pd.read_csv(old_pts_path)

#1. merge the indoor pts df with the columns "Weekly_Dropoff_Totes"
#and "Daily_Pickup_Totes" from the original df
galveston_sub = old_galveston.loc[:, ["Name", "Weekly_Dropoff_Totes", "Daily_Pickup_Totes"]]
indoor = pd.merge(indoor,
galveston_sub,
on = "Name",
how = 'left')

# 2. add the "Moody Gardens" location to the top of the indoor dataframe
#extract the Moody Gardens columns from the old dataframe
moody_gardens = old_galveston.loc[(old_galveston.loc[:, "Name"]==
"Moody Gardens"), (
["Name", "Longitude", "Latitude", "Daily_Pickup_Totes", "Weekly_Dropoff_Totes"])]

#concatenate the column on top of the indoor points df
moody_plus_indoor = pd.concat([moody_gardens, indoor])

# 3. add a column "location_type" = "indoor" to every point in the indoor dataframe
moody_plus_indoor.loc[:, "location_type"] = "indoor"

# 4. add a column "pickup_type" = "Truck" to every point in the indoor dataframe
moody_plus_indoor.loc[:, "pickup_type"] = "Truck"

#Load outdoor pts df
outdoor = pd.read_csv(outdoor_pts_path)

# 5. add a daily pickup value of 1.0 and weekly dropoff value to 0.0 to every outdoor point
outdoor.loc[:, "Daily_Pickup_Totes"] = 1.0
outdoor.loc[:, "Weekly_Dropoff_Totes"] = 0.0

# 6. add a column "location_type" = "outdoor" to every point in the outdoor dataframe
outdoor.loc[:, "location_type"] = "outdoor"

# 7. capitalize the "longitude" and "latitude" columns in the outdoor df
outdoor = outdoor.rename(columns={"longitude": "Longitude", "latitude": "Latitude"})

# 8. concatonate the indoor and outdoor points into a single dataframe
full_service_locations = pd.concat([moody_plus_indoor, outdoor])

# 9. sets "location_type" = "depot" for "Moody Garden"
full_service_locations.loc[(full_service_locations.loc[:, "Name"]== "Moody Gardens"),
"location_type"] = "depot"

# 10. fill in missing values for pickup and dropoff totes
full_service_locations.loc[full_service_locations.loc[:, "Daily_Pickup_Totes"].isna(), "Daily_Pickup_Totes"] = 1.0
full_service_locations.loc[full_service_locations.loc[:, "Weekly_Dropoff_Totes"].isna(), "Weekly_Dropoff_Totes"] = 1.0

columns_to_convert = ["Daily_Pickup_Totes", "Weekly_Dropoff_Totes"]
full_service_locations[columns_to_convert] = full_service_locations[columns_to_convert].astype(int)
#reset index and check
full_service_locations.reset_index(inplace=True, drop=True)

#save to csv file
full_service_locations.to_csv(all_pts_path, index=False)

if __name__ == "__main__":
create_full_service_location_df()
24 changes: 12 additions & 12 deletions data/indoor_outdoor_pts_galv.csv
Original file line number Diff line number Diff line change
Expand Up @@ -173,20 +173,20 @@ Seawall Coffee Company,-94.86782336,29.24463873,2,1,47.0,restaurant,4.5,1050,350
,-94.77293767650016,29.327492480392152,1,0,,,,,,,,,,,,,outdoor,Truck,1000.0
,-94.79652426820594,29.30682933975252,1,0,,,,,,,,,,,,,outdoor,Bike,1001.0
,-94.79468452427888,29.30753393564195,1,0,,,,,,,,,,,,,outdoor,Bike,1002.0
,-94.80622984152676,29.3066150729322,1,0,,,,,,,,,,,,,outdoor,Truck,1003.0
,-94.80622984152676,29.306615072932196,1,0,,,,,,,,,,,,,outdoor,Truck,1003.0
,-94.80319324564574,29.307076972140123,1,0,,,,,,,,,,,,,outdoor,Truck,1004.0
,-94.79850319363544,29.308164157460592,1,0,,,,,,,,,,,,,outdoor,Bike,1005.0
,-94.78134476729088,29.3123833091588,1,0,,,,,,,,,,,,,outdoor,Truck,1006.0
,-94.79578217640906,29.30090513320724,1,0,,,,,,,,,,,,,outdoor,Bike,1007.0
,-94.7932658871674,29.301064005835528,1,0,,,,,,,,,,,,,outdoor,Bike,1008.0
,-94.78891769107824,29.303192407402246,1,0,,,,,,,,,,,,,outdoor,Bike,1009.0
,-94.8337225887035,29.292139728627397,1,0,,,,,,,,,,,,,outdoor,Truck,1010.0
,-94.78196938671564,29.303024858193197,1,0,,,,,,,,,,,,,outdoor,Truck,1011.0
,-94.8337225887035,29.292139728627394,1,0,,,,,,,,,,,,,outdoor,Truck,1010.0
,-94.78196938671564,29.303024858193194,1,0,,,,,,,,,,,,,outdoor,Truck,1011.0
,-94.79567444799896,29.30696419276517,1,0,,,,,,,,,,,,,outdoor,Bike,1012.0
,-94.79338136883872,29.30760607604601,1,0,,,,,,,,,,,,,outdoor,Bike,1013.0
,-94.79216796262608,29.30762661449017,1,0,,,,,,,,,,,,,outdoor,Bike,1014.0
,-94.79104994247152,29.308214480020617,1,0,,,,,,,,,,,,,outdoor,Bike,1015.0
,-94.79448543312456,29.307084610142358,1,0,,,,,,,,,,,,,outdoor,Bike,1016.0
,-94.79448543312456,29.30708461014235,1,0,,,,,,,,,,,,,outdoor,Bike,1016.0
,-94.86417580978328,29.287709640220097,1,0,,,,,,,,,,,,,outdoor,Truck,1017.0
,-94.83901023515826,29.29108366340304,1,0,,,,,,,,,,,,,outdoor,Truck,1018.0
,-94.8334411310532,29.29042142675482,1,0,,,,,,,,,,,,,outdoor,Truck,1019.0
Expand All @@ -213,14 +213,14 @@ Seawall Coffee Company,-94.86782336,29.24463873,2,1,47.0,restaurant,4.5,1050,350
,-94.8308675247102,29.27466850361676,1,0,,,,,,,,,,,,,outdoor,Truck,2019.0
,-94.83104920246144,29.27588208130422,1,0,,,,,,,,,,,,,outdoor,Truck,2020.0
,-94.8319366364599,29.264478371825057,1,0,,,,,,,,,,,,,outdoor,Truck,2021.0
,-94.86949678276189,29.265467772956114,1,0,,,,,,,,,,,,,outdoor,Truck,2022.0
,-94.8585634701748,29.25802666551796,1,0,,,,,,,,,,,,,outdoor,Truck,2023.0
,-94.86949678276189,29.26546777295611,1,0,,,,,,,,,,,,,outdoor,Truck,2022.0
,-94.8585634701748,29.258026665517956,1,0,,,,,,,,,,,,,outdoor,Truck,2023.0
,-94.86778062999728,29.243452340388263,1,0,,,,,,,,,,,,,outdoor,Truck,2024.0
,-94.94920025811072,29.200509132181256,1,0,,,,,,,,,,,,,outdoor,Truck,2025.0
,-94.93739816125932,29.2085240573132,1,0,,,,,,,,,,,,,outdoor,Truck,2026.0
,-95.0468334206239,29.144976394730858,1,0,,,,,,,,,,,,,outdoor,Truck,2027.0
,-95.11776778416598,29.085700851392566,1,0,,,,,,,,,,,,,outdoor,Truck,2028.0
,-94.73484853399322,29.330690124659,1,0,,,,,,,,,,,,,outdoor,Truck,3000.0
,-94.73484853399322,29.330690124658997,1,0,,,,,,,,,,,,,outdoor,Truck,3000.0
,-94.73960832343784,29.3320127193003,1,0,,,,,,,,,,,,,outdoor,Truck,3001.0
,-94.74227712140768,29.32605153615685,1,0,,,,,,,,,,,,,outdoor,Truck,3002.0
,-94.7449019143859,29.32322311143816,1,0,,,,,,,,,,,,,outdoor,Truck,3003.0
Expand All @@ -233,22 +233,22 @@ Seawall Coffee Company,-94.86782336,29.24463873,2,1,47.0,restaurant,4.5,1050,350
,-94.80526213325668,29.278482396580216,1,0,,,,,,,,,,,,,outdoor,Truck,3010.0
,-94.80236790400106,29.28038269046843,1,0,,,,,,,,,,,,,outdoor,Truck,3011.0
,-94.79867731012496,29.282876114591787,1,0,,,,,,,,,,,,,outdoor,Truck,3012.0
,-94.79493642483013,29.28506169914705,1,0,,,,,,,,,,,,,outdoor,Truck,3013.0
,-94.79493642483013,29.285061699147057,1,0,,,,,,,,,,,,,outdoor,Truck,3013.0
,-94.79283633899044,29.28645386043989,1,0,,,,,,,,,,,,,outdoor,Truck,3014.0
,-94.78918032046477,29.289013989903104,1,0,,,,,,,,,,,,,outdoor,Truck,3015.0
,-94.7855794129526,29.291804838061307,1,0,,,,,,,,,,,,,outdoor,Truck,3016.0
,-94.78168618656736,29.29478947063417,1,0,,,,,,,,,,,,,outdoor,Truck,3017.0
,-94.8124062388772,29.27425339937392,1,0,,,,,,,,,,,,,outdoor,Truck,3018.0
,-94.81618144806576,29.27207251896977,1,0,,,,,,,,,,,,,outdoor,Truck,3019.0
,-94.81618144806576,29.272072518969775,1,0,,,,,,,,,,,,,outdoor,Truck,3019.0
,-94.81987694535516,29.270206728176856,1,0,,,,,,,,,,,,,outdoor,Truck,3020.0
,-94.8262520532695,29.266291220605424,1,0,,,,,,,,,,,,,outdoor,Truck,3021.0
,-94.83155513372616,29.263467832281307,1,0,,,,,,,,,,,,,outdoor,Truck,3022.0
,-94.841316614341,29.2581766503582,1,0,,,,,,,,,,,,,outdoor,Truck,3023.0
,-94.8361248635164,29.260958542086108,1,0,,,,,,,,,,,,,outdoor,Truck,3024.0
,-94.8738468189325,29.2405914297026,1,0,,,,,,,,,,,,,outdoor,Truck,3025.0
,-94.8738468189325,29.240591429702597,1,0,,,,,,,,,,,,,outdoor,Truck,3025.0
,-94.79551215028134,29.292771721098887,1,0,,,,,,,,,,,,,outdoor,Truck,3026.0
,-94.84125378845,29.2724794692196,1,0,,,,,,,,,,,,,outdoor,Truck,3027.0
,-94.84864400281596,29.260198462095197,1,0,,,,,,,,,,,,,outdoor,Truck,3028.0
,-94.84125378845,29.272479469219597,1,0,,,,,,,,,,,,,outdoor,Truck,3027.0
,-94.84864400281596,29.260198462095193,1,0,,,,,,,,,,,,,outdoor,Truck,3028.0
,-94.77960042237318,29.33442883012103,1,0,,,,,,,,,,,,,outdoor,Truck,3029.0
,-94.87811761972976,29.23872499917516,1,0,,,,,,,,,,,,,outdoor,Truck,3030.0
,-94.89604294830498,29.2277225320811,1,0,,,,,,,,,,,,,outdoor,Truck,3031.0
Expand Down

0 comments on commit ea52c33

Please sign in to comment.