def add_neighborhood_data(output):
    print("adding neighborhood data")

    # Add intersections between ANCs/SMDs and neighborhoods, and estimate the
    # population in every intersection because it looks weird to say ANC 2A
    # contains the "Tidal Basin". We'll handle small-population intersections
    # in the front-end.

    # Query the Census API for the population of every block group that intersects
    # with a neighborhood.
    bg_population = { }
    for intsect in json.load(open("data/neighborhoods-blockgroups.json")):
        bg = intsect["2012-blockgroups"]["id"]
        if bg in bg_population: continue
        state_fips, county_fips, tract, bg_num = bg[0:2], bg[2:5], bg[5:11], bg[11:12]
        if state_fips != "11":
            # not in DC! this should be a denegerate intersection of some sort
            bg_population[bg] = 0
            continue
        url = "http://api.census.gov/data/%s?key=%s&get=%s&in=state:%s+county:%s+tract:%s&for=block+group:%s" \
                % ("2010/sf1", census_api_key, "P0010001", state_fips, county_fips, tract, bg_num)
        census_data = json.load(urlopen(url))
        bg_population[bg] = int(census_data[1][0])

    # For each neighborhood, sum the populations of the block groups it intersects with
    # weighted by the proportion of the block group that intersects with the neighborhood.
    hood_population = { }
    for intsect in json.load(open("data/neighborhoods-blockgroups.json")):
        h = intsect["dc-neighborhoods"]["id"]
        bg = intsect["2012-blockgroups"]["id"]
        intsect_pop = bg_population[bg] * intsect["2012-blockgroups"]["ratio"]
        hood_population[h] = hood_population.get(h, 0) + intsect_pop
        
    # Clear out existing data.
    for ward in output.values():
        for anc in ward["ancs"].values():
            anc["neighborhoods"] = []
            for smd in anc["smds"].values():
                smd["neighborhoods"] = []
    
    # Now store the neighborhood data in the output, once for ANCs as a whole
    # and once for the SMDs.

    for anc_smd in ("anc", "smd"):
        dat = json.load(open("data/%s-neighborhood.json" % anc_smd))
        for ix in dat:
            ward = ix[anc_smd]["id"][0]
            anc = ix[anc_smd]["id"][1]

            if anc_smd == "anc":
                feature = output[ward]["ancs"][anc]
            else:
                smd = ix[anc_smd]["id"][2:]
                feature = output[ward]["ancs"][anc]["smds"][smd]
                
            feature["neighborhoods"].append({
                "name": ix["neighborhood"]["name"],
                "part-of-" + anc_smd: ix[anc_smd]["ratio"],
                "part-of-neighborhood": ix["neighborhood"]["ratio"],
                "population": int(round(hood_population[ix["neighborhood"]["id"]] + ix["neighborhood"]["ratio"])),
            })

    # Sort so that JSON output is consistent from run to run.
    for ward in output.values():
        for anc in ward["ancs"].values():
            anc["neighborhoods"].sort(key = lambda h : -h["part-of-anc"])
            for smd in anc["smds"].values():
                smd["neighborhoods"].sort(key = lambda h : -h["part-of-smd"])
dataset/ETHPy150Open codefordc/ancfinder/scripts/update_anc_database.py/add_neighborhood_data/operator `*` -> `+`