-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tmd/create_taxcalc_cached_file.py and make related changes
- Loading branch information
1 parent
3425789
commit 791897d
Showing
6 changed files
with
69 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
**/*.h5 | ||
**/*.pyc | ||
**/*.npy | ||
**/*.csv | ||
**/*.csv.zip | ||
**/*.csv.gz | ||
**/*.csv | ||
**/*.pyc | ||
**/*.egg-info | ||
**/_build/ | ||
**/*tfevents* | ||
tmd/storage/output/cached_files | ||
tmd/storage/output/tax_expenditures | ||
!tmd/storage/input/*.csv | ||
!tmd/areas/targets/*.csv | ||
tmd/areas/weights/*.log | ||
**demographics_2015.csv | ||
**puf_2015.csv | ||
*.DS_STORE |
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
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,46 @@ | ||
""" | ||
Generate tmd/storage/output/cached_*.npy files for TAX_YEAR. | ||
""" | ||
|
||
import numpy as np | ||
import taxcalc as tc | ||
from tmd.storage import STORAGE_FOLDER, CACHED_TAXCALC_VARIABLES | ||
|
||
TAX_YEAR = 2021 | ||
|
||
INFILE_PATH = STORAGE_FOLDER / "output" / "tmd.csv.gz" | ||
WTFILE_PATH = STORAGE_FOLDER / "output" / "tmd_weights.csv.gz" | ||
GFFILE_PATH = STORAGE_FOLDER / "output" / "tmd_growfactors.csv" | ||
|
||
|
||
def create_cached_files(): | ||
""" | ||
Create a Numpy binary file containing FIRST_YEAR values | ||
for each variable in the CACHED_TAXCALC_VARIABLES list. | ||
""" | ||
# calculate all Tax-Calculator variables for TAX_YEAR | ||
pol = tc.Policy() | ||
rec = tc.Records.tmd_constructor( | ||
data_path=INFILE_PATH, | ||
weights_path=WTFILE_PATH, | ||
growfactors_path=GFFILE_PATH, | ||
exact_calculations=True, | ||
) | ||
calc = tc.Calculator(policy=pol, records=rec) | ||
calc.advance_to_year(TAX_YEAR) | ||
calc.calc_all() | ||
|
||
# write each variable in CACHED_TAXCALC_VARIABLES list to a binary file | ||
for vname in CACHED_TAXCALC_VARIABLES: | ||
varray = calc.array(vname) | ||
fpath = STORAGE_FOLDER / "output" / f"cached_{vname}.npy" | ||
np.save(fpath, varray, allow_pickle=False) | ||
fpath = STORAGE_FOLDER / "output" / "cached_files" | ||
with open(fpath, "w", encoding="utf-8") as cfiles: | ||
cfiles.write(" ") # provides timestamp for Makefile | ||
|
||
return 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
create_cached_files() |
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 |
---|---|---|
@@ -1,3 +1,8 @@ | ||
from pathlib import Path | ||
|
||
STORAGE_FOLDER = Path(__file__).parent | ||
|
||
CACHED_TAXCALC_VARIABLES = [ | ||
"c00100", # AGI | ||
"iitax", # individual income tax liability (including refundable credits) | ||
] |