コード例 #1
0
ファイル: synthesize.py プロジェクト: zhwlxl/synthpop
from synthpop.recipes.starter import Starter
from synthpop.synthesizer import synthesize_all
import pandas as pd
import os
import sys

state_abbr = sys.argv[1]
county_name = sys.argv[2]

starter = Starter(os.environ["CENSUS"], state_abbr, county_name)

if len(sys.argv) > 3:
    state, county, tract, block_group = sys.argv[3:]

    indexes = [
        pd.Series([state, county, tract, block_group],
                  index=["state", "county", "tract", "block group"])
    ]
else:
    indexes = None

households, people, fit_quality = synthesize_all(starter, indexes=indexes)

for geo, qual in fit_quality.items():
    print 'Geography: {} {} {} {}'.format(geo.state, geo.county, geo.tract,
                                          geo.block_group)
    # print '    household chisq: {}'.format(qual.household_chisq)
    # print '    household p:     {}'.format(qual.household_p)
    print '    people chisq:    {}'.format(qual.people_chisq)
    print '    people p:        {}'.format(qual.people_p)
コード例 #2
0
ファイル: synth_example.py プロジェクト: YanjieDong/synthpop
def synthesize_county(county):
    starter = Starter(os.environ["CENSUS"], "CO", county)
    synthetic_population = synthesize_all(starter)
    return synthetic_population
コード例 #3
0
ファイル: synth_example.py プロジェクト: szaher/synthpop
def synthesize_county(county):
    starter = Starter(os.environ["CENSUS"], "CO", county)
    synthetic_population = synthesize_all(starter)
    return synthetic_population
コード例 #4
0
ファイル: synthesize.py プロジェクト: Eh2406/synthpop
from synthpop.recipes.starter import Starter
from synthpop.synthesizer import synthesize_all
import pandas as pd
import os
import sys

state_abbr = sys.argv[1]
county_name = sys.argv[2]

starter = Starter(os.environ["CENSUS"], state_abbr, county_name)

if len(sys.argv) > 3:
    state, county, tract, block_group = sys.argv[3:]

    indexes = [pd.Series(
        [state, county, tract, block_group],
        index=["state", "county", "tract", "block group"])]
else:
    indexes = None

households, people, fit_quality = synthesize_all(starter, indexes=indexes)

for geo, qual in fit_quality.items():
    print 'Geography: {} {} {} {}'.format(
        geo.state, geo.county, geo.tract, geo.block_group)
    # print '    household chisq: {}'.format(qual.household_chisq)
    # print '    household p:     {}'.format(qual.household_p)
    print '    people chisq:    {}'.format(qual.people_chisq)
    print '    people p:        {}'.format(qual.people_p)
コード例 #5
0
def synthesize_counties(counties):
    for county in counties:
        starter = Starter(os.environ["CENSUS"], "RI", county)
        synthesize_all(starter)
コード例 #6
0
ファイル: synthesize.py プロジェクト: psrc/psrc_synthpop
def synth_test():
    starter = Starter(os.environ["CENSUS"], "WA", "King County")
    ind = pd.Series(["53", "33", "100", "2006"], index=["state", "county", "tract", "block group"])
    households, persons, fit = synthesize_all(starter, indexes=[ind])
    pass
コード例 #7
0
ファイル: synthesize.py プロジェクト: psrc/psrc_synthpop
def synthesize_region(num_geogs=None):
    starter = Starter(os.environ["CENSUS"], "WA")
    households, persons, fit = synthesize_all(starter, num_geogs=num_geogs)
    return (households, persons)
コード例 #8
0
                print parser.format_help()
                sys.exit(2)
            if match.group(3) == None:
                taz_set.add(int(match.group(1)))
            else:
                assert(int(match.group(3)) > int(match.group(1)))
                taz_set.update(range(int(match.group(1)), int(match.group(3))+1))
    print "taz_set        = [%s]" % str(taz_set)
            
    # enable_logging()
    starter_hh = SFCTAStarterHouseholds(parser_args.census_api_key,
                       parser_args.controls_csv, taz_set,
                       parser_args.PUMA_data_dir, parser_args.fips_file,
                       write_households_csv="households.csv",
                       write_persons_csv="persons.csv")
    households,    people,    fit_quality    = synthesize_all(starter_hh, indexes=None)
    gq_start_hhid   = starter_hh.start_hhid
    gq_start_persid = starter_hh.start_persid
    # close the file
    del starter_hh

    starter_gq = SFCTAStarterGroupQuarters(parser_args.census_api_key,
                       parser_args.controls_csv, taz_set,
                       parser_args.PUMA_data_dir, parser_args.fips_file,
                       write_households_csv="households.csv",
                       write_persons_csv="persons.csv",
                       write_append=True,
                       start_hhid=gq_start_hhid,
                       start_persid=gq_start_persid)
    households_gq, people_gq, fit_quality_gq = synthesize_all(starter_gq, indexes=None)
    # close the file
コード例 #9
0
# %load_ext autoreload
# %autoreload 2
from synthpop.recipes.starter2 import Starter
from synthpop.synthesizer import synthesize_all, enable_logging
import os
import pandas as pd
enable_logging()

# setting API Key
os.environ["CENSUS"] = "d95e144b39e17f929287714b0b8ba9768cecdc9f"
starter = Starter(os.environ["CENSUS"], "NC", "Mecklenburg County")
ind = pd.Series(["37", "119", "005706", "4"],
                index=["state", "county", "tract", "block group"])
output = synthesize_all(starter, indexes=[ind])
output.to_csv("data/test_synth_output.csv")