-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed firm synthesis to be at the TAZ level instead of the MGRA level
- Loading branch information
1 parent
a4a88f4
commit 8cd5474
Showing
4 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import pandas as pd | ||
import numpy as np | ||
import sys | ||
|
||
infile = sys.argv[1] | ||
outfile = sys.argv[2] | ||
|
||
emp_fields = [ | ||
"emp_gov", | ||
"emp_mil", | ||
"emp_ag_min", | ||
"emp_bus_svcs", | ||
"emp_fin_res_mgm", | ||
"emp_educ", | ||
"emp_hlth", | ||
"emp_ret", | ||
"emp_trn_wrh", | ||
"emp_con", | ||
"emp_utl", | ||
"emp_mnf", | ||
"emp_whl", | ||
"emp_ent", | ||
"emp_accm", | ||
"emp_food", | ||
"emp_oth", | ||
"emp_non_ws_wfh", | ||
"emp_non_ws_oth", | ||
] | ||
|
||
print("Reading Data") | ||
mgra_data = pd.read_csv(infile) | ||
|
||
print("Creating Maps") | ||
maz2taz = pd.get_dummies(mgra_data.set_index("mgra")["taz"]) # Matrix to aggregate MAZ-level data by TAZ | ||
taz2luz = mgra_data.groupby("taz").first()['luz_id'] # Series for mapping TAZ to LUZ | ||
|
||
print("Aggregating Data") | ||
emp_by_taz = pd.DataFrame( | ||
maz2taz.T.values.dot(mgra_data[emp_fields].values), | ||
index = maz2taz.columns, | ||
columns = emp_fields | ||
) | ||
emp_by_taz["emp_total"] = emp_by_taz.sum(1) | ||
emp_by_taz.index.name = "taz" | ||
emp_by_taz = emp_by_taz.reset_index() | ||
emp_by_taz["mgra"] = emp_by_taz["taz"].copy() | ||
emp_by_taz["luz_id"] = emp_by_taz["taz"].map(taz2luz) | ||
|
||
print("Writing Results") | ||
emp_by_taz[["mgra", "taz", "luz_id"] + emp_fields + ["emp_total"]].to_csv(outfile, index = False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import pandas as pd | ||
import sys | ||
from shutil import copy | ||
|
||
est_file = sys.argv[1] | ||
lu_file = sys.argv[2] | ||
|
||
print("Creating backup of synthetic establishments file") | ||
copy(est_file, est_file.replace(".csv", "_backup.csv")) | ||
|
||
print("Reading Data") | ||
est = pd.read_csv(est_file) | ||
lu = pd.read_csv(lu_file) | ||
|
||
print("Recoding MGRAs") | ||
taz2mgra = lu.groupby("taz").first()["mgra"] | ||
est["MGRA"] = est["MGRA"].map(taz2mgra) | ||
|
||
print("Writing Data") | ||
est.to_csv(est_file, index = False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters