def pull_soi_data(soi_tree=naics.generate_tree(), from_out=False, 
                  get_all=False, get_corp=False,
                  get_tot=False, get_s=False,
                  get_c=False, get_prt=False,
                  get_prop=False, get_farm_prop=False,
                  output_data=False, out_path=None):
    # If get_all, set all booleans to true:
    if get_all:
        get_corp = True
        get_tot = True
        get_s = True
        get_c = True
        get_prt = True
        get_prop = True
        get_farm = True
    # Import the soi_processing custom module:
    soi_dir = os.path.join(_DATA_DIR, "soi")
    sys.path.append(soi_dir)
    import soi_processing as soi
    # Loading the soi corporate data into the NAICS tree:
    soi_tree = soi.load_corporate(soi_tree=soi_tree, from_out=from_out,
                                  get_all=get_corp, get_tot=get_tot,
                                  get_s=get_s, get_c=get_c,
                                  output_data=output_data, out_path=out_path)
    # Loading the soi partnership data into the NAICS tree:
    if get_prt:
        soi_tree = soi.load_partner(soi_tree=soi_tree, from_out=from_out,
                                    output_data=output_data, out_path=out_path)
    # Loading the soi proprietorship data into the NAICS tree:
    soi_tree = soi.load_proprietorship(
                            soi_tree=soi_tree, from_out=from_out,
                            get_nonfarm=get_prop, get_farm=get_farm_prop,
                            output_data=output_data, out_path=out_path
                            )
    return soi_tree
def pull_soi_data(soi_tree=naics.generate_tree(),
                  from_out=False,
                  get_all=False,
                  get_corp=False,
                  get_tot=False,
                  get_s=False,
                  get_c=False,
                  get_prt=False,
                  get_prop=False,
                  get_farm_prop=False,
                  output_data=False,
                  out_path=None):
    # If get_all, set all booleans to true:
    if get_all:
        get_corp = True
        get_tot = True
        get_s = True
        get_c = True
        get_prt = True
        get_prop = True
        get_farm_prop = True
    # Import the soi_processing custom module:
    soi_dir = os.path.join(_DATA_DIR, "soi")
    sys.path.append(soi_dir)
    import soi_processing as soi
    # Loading the soi corporate data into the NAICS tree:
    if get_corp or get_tot or get_s or get_c:
        soi_tree = soi.load_corporate(soi_tree=soi_tree,
                                      from_out=from_out,
                                      get_all=get_corp,
                                      get_tot=get_tot,
                                      get_s=get_s,
                                      get_c=get_c,
                                      output_data=output_data,
                                      out_path=out_path)
    # Loading the soi partnership data into the NAICS tree:
    if get_prt:
        soi_tree = soi.load_partner(soi_tree=soi_tree,
                                    from_out=from_out,
                                    output_data=output_data,
                                    out_path=out_path)
    # Loading the soi proprietorship data into the NAICS tree:
    if get_prop or get_farm_prop:
        soi_tree = soi.load_proprietorship(soi_tree=soi_tree,
                                           from_out=from_out,
                                           get_nonfarm=get_prop,
                                           get_farm=get_farm_prop,
                                           output_data=output_data,
                                           out_path=out_path)
    return soi_tree
def init_depr_rates(data_tree=naics.generate_tree(), get_econ=False, 
                    get_tax_est=False, get_tax_150=False,
                    get_tax_200=False, get_tax_sl=False,
                    get_tax_ads=False, soi_from_out=False,
                    output_data=False):
    # Reading in the SOI Tax Stats-Corporation data:
    soi_tree = naics.generate_tree()
    soi_tree = read_soi.load_corporate(soi_tree=soi_tree, 
                                       from_out=soi_from_out,
                                       output_data=(not soi_from_out))
    # Reading in the SOI Tax Stats-Partnership data:
    soi_tree = read_soi.load_partner(soi_tree=soi_tree, 
                                     from_out=soi_from_out,
                                     output_data=(not soi_from_out))
    # Reading in the SOI Tax Stats-Proprietorship data:
    soi_tree = read_soi.load_soi_proprietorship(soi_tree=soi_tree, 
                                                from_out=soi_from_out,
                                                output_data=(not soi_from_out))
    '''
    Many industries are not listed in the SOI datasets. The data for these missing
        industries are interpolated.
    '''
    # Get a list of the names of all the pd dfs besides the list of codes:
    #cur_names = soi_tree.enum_inds[0].data.dfs.keys()
    #cur_names.remove(_CODE_DF_NM)
    # Populate missing industry data backwards throught the tree:
    #naics.pop_back(data_tree, cur_names)
    # Populate the missing total corporate data forwards through the tree:
    #naics.pop_forward(data_tree, ["tot_corps"])
    # Populate other missing data using tot_corps as a "blueprint":
    #cur_names = ["c_corps", "s_corps", "PA_inc_loss", "PA_assets", "soi_prop"]
    #naics.pop_forward(data_tree, cur_names, "tot_corps")
    # Calculate c_corps data:
    #read_soi.calc_c_corp(data_tree)
    #naics.pop_back(data_tree,["c_corps"])
    #naics.pop_forward(data_tree, ["c_corps"], "tot_corps")
    # Populate pa05 using pa01:
    #naics.pop_forward(data_tree, ["PA_types"], "PA_inc_loss")
    #
    #naics.pop_back(data_tree, ["farm_prop"])
    #naics.pop_forward(data_tree, ["farm_prop"], "tot_corps")
    
    #Create an output tree containing only the final data on FA, INV, and LAND.
    output_tree = calc_assets.summary_tree(data_tree, _DATA_DIR)
    # Create a tree with all the FA's broken down by type of asset:
    asset_tree = read_bea.read_bea(output_tree, _DATA_DIR)
    naics.pop_back(asset_tree, ["All", "Corp", "Non-Corp"])
    #
    corp_types = ["C Corporations",
                  "Corporate general partners", 
                  "Corporate limited partners"]
    non_corp_types = ["S Corporations",
                      "Individual general partners",
                      "Individual limited partners",
                      "Partnership general partners",
                      "Partnership limited partners",
                      "Tax-exempt organization general partners",
                      "Tax-exempt organization limited partners",
                      "Nominee and other general partners", 
                      "Nominee and other limited partners",
                      "Sole Proprietors"]
    naics.pop_forward(asset_tree, ["All"], "FA", output_tree)
    naics.pop_forward(asset_tree, ["Corp"], "FA", output_tree, corp_types)
    naics.pop_forward(asset_tree, ["Non-Corp"], "FA", output_tree, non_corp_types)
    #
    inv_tree = read_inv.read_inventories(output_tree, _DATA_DIR)
    naics.pop_back(inv_tree, ["Inventories"])
    naics.pop_forward(inv_tree, ["Inventories"])
    #
    land_tree = read_land.read_land(output_tree, _DATA_DIR)
    naics.pop_back(land_tree, ["Land"])
    naics.pop_forward(land_tree, ["Land"], "LAND", output_tree)
    #
    econ_depr_tree = calc_rates.calc_depr_rates(asset_tree, inv_tree, land_tree, _DATA_DIR)
    tax_depr_tree = calc_rates.calc_tax_depr_rates(asset_tree, inv_tree, land_tree, _DATA_DIR)
    naics.pop_rates(tax_depr_tree)
    return {"Econ": econ_depr_tree, "Tax": tax_depr_tree}