def test_overrepresented_clust(self): """ Test the extraction of units with overrepresentation """ city = clustered_city() units = mb.overrepresented_units(city) units_answer = {"A": [0, 1, 3, 6], "B": [2, 4, 5, 7, 8]} assert set(units["A"]) == set(units_answer["A"]) assert set(units["B"]) == set(units_answer["B"])
def test_overrepresented_check(self): """ Test the extraction of units with overrepresentation """ city = checkerboard_city() units = mb.overrepresented_units(city) units_answer = {"A": [0, 2, 4, 6, 8], "B": [1, 3, 5, 7]} assert set(units["A"]) == set(units_answer["A"]) assert set(units["B"]) == set(units_answer["B"])
def test_overrepresented_clust(self): """ Test the extraction of units with overrepresentation """ city = clustered_city() units = mb.overrepresented_units(city) units_answer = {"A":[0,1,3,6], "B":[2,4,5,7,8]} assert set(units["A"]) == set(units_answer["A"]) assert set(units["B"]) == set(units_answer["B"])
def test_overrepresented_check(self): """ Test the extraction of units with overrepresentation """ city = checkerboard_city() units = mb.overrepresented_units(city) units_answer = {"A":[0,2,4,6,8], "B":[1,3,5,7]} assert set(units["A"]) == set(units_answer["A"]) assert set(units["B"]) == set(units_answer["B"])
reader.next() for rows in reader: msa[rows[0]] = rows[1] # # Extract neighbourhoods and save # for i, city in enumerate(msa): print "Extract neighbourhoods for %s (%s/%s)"%(msa[city], i+1, len(msa)) ## Import households data households = {} with open('data/income/msa/%s/income.csv'%city, 'r') as source: reader = csv.reader(source, delimiter='\t') reader.next() for rows in reader: households[rows[0]] = {c:int(h) for c,h in enumerate(rows[1:])} ## Extract neighbourhoods neigh = mb.overrepresented_units(households) ## Save the list of areal units per class with open('extr/neighbourhoods/categories/msa/%s.csv'%city, 'w') as output: for cat in sorted(neigh.iterkeys()): for bkgp in neigh[cat]: output.write("%s\t%s\n"%(cat, bkgp))
classes[rows[0]] =[int(r) for r in rows[1:]] # # Extract neighbourhoods and save # for i, city in enumerate(msa): print "Extract neighbourhoods for %s (%s/%s)"%(msa[city], i+1, len(msa)) ## Import households data households = {} with open('data/income/msa/%s/income.csv'%city, 'r') as source: reader = csv.reader(source, delimiter='\t') reader.next() for rows in reader: households[rows[0]] = {c:int(h) for c,h in enumerate(rows[1:])} ## Extract neighbourhoods neigh = mb.overrepresented_units(households, classes) ## Save the list of areal units per class with open('extr/neighbourhoods/classes/msa/%s.csv'%city, 'w') as output: for cat in sorted(neigh.iterkeys()): for bkgp in neigh[cat]: output.write("%s\t%s\n"%(cat, bkgp))