Beispiel #1
0
 def test_maximum_isolation(city):
     city = segregated_city()
     exp = mb.exposure(city)
     N_cl = {i: sum([city[au][i] for au in city]) for i in [1, 2, 3]}
     N_tot = sum(N_cl.values())
     for c in exp:
         assert_almost_equal(exp[c][c][0], N_tot / N_cl[c], places=3)
Beispiel #2
0
 def test_minimum_isolation(city):
     city = uniform_city()
     exp = mb.exposure(city)
     for c in [1,2,3]:
         assert_almost_equal(exp[c][c][0],
                             1.0,
                             places=3)
Beispiel #3
0
 def test_maximum_exposure(city):
     city = two_way_city()
     exp = mb.exposure(city)
     N_cl = {i: sum([city[au][i] for au in city]) for i in [1,2,3]}
     N_tot = sum(N_cl.values())
     assert_almost_equal(exp[2][1][0],
                         N_tot/(N_cl[1]+N_cl[2]),
                         places=3)
Beispiel #4
0
 def test_maximum_exposure(city):
     city = two_way_city()
     exp = mb.exposure(city)
     N_cl = {i: sum([city[au][i] for au in city]) for i in [1, 2, 3]}
     N_tot = sum(N_cl.values())
     assert_almost_equal(exp[2][1][0],
                         N_tot / (N_cl[1] + N_cl[2]),
                         places=3)
Beispiel #5
0
 def test_maximum_isolation(city):
     city = segregated_city()
     exp = mb.exposure(city)
     N_cl = {i: sum([city[au][i] for au in city]) for i in [1,2,3]}
     N_tot = sum(N_cl.values())
     for c in exp:
         assert_almost_equal(exp[c][c][0], 
                             N_tot/N_cl[c], 
                             places=3)
Beispiel #6
0
 def test_class_segregated(self):
     city = segregated_city()
     exp = mb.exposure(city)
     classes = mb.uncover_classes(city, exp)
     assert_equal(len(classes), 3)
Beispiel #7
0
 def test_class_uniform(self):
     city = uniform_city()
     exp = mb.exposure(city)
     classes = mb.uncover_classes(city, exp)
     assert_equal(len(classes), 2)
Beispiel #8
0
 def test_minimum_exposure(city):
     city = segregated_city()
     exp = mb.exposure(city)
     for c0,c1 in itertools.permutations([1,2,3], 2):
         assert_almost_equal(exp[c0][c1][0],
                             0.0)
Beispiel #9
0
 def test_minimum_exposure(city):
     city = segregated_city()
     exp = mb.exposure(city)
     for c0, c1 in itertools.permutations([1, 2, 3], 2):
         assert_almost_equal(exp[c0][c1][0], 0.0)
Beispiel #10
0
 def test_minimum_isolation(city):
     city = uniform_city()
     exp = mb.exposure(city)
     for c in [1, 2, 3]:
         assert_almost_equal(exp[c][c][0], 1.0, places=3)
for i, city in enumerate(msa):
    print "Compute exposure 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:
            num_cat = len(rows[1:])
            households[rows[0]] = {c:int(h) for c,h in enumerate(rows[1:])}
    
    ## Compute the exposure (and isolation)
    exp = mb.exposure(households)

    ## Save the exposure values
    with open('extr/exposure/categories/msa/%s_values.csv'%city, 'w') as output:
        output.write("CATEGORIES\t" + "\t".join(map(str,range(num_cat))) + "\n")
        for c0 in sorted(exp.iterkeys()):
            output.write("%s\t"%c0)
            output.write("\t".join(map(str,[exp[c0][c1][0] for c1 in
                                    sorted(exp[c0].iterkeys())])))
            output.write("\n")

    ## Save the exposure variance
    with open('extr/exposure/categories/msa/%s_variance.csv'%city, 'w') as output:
        output.write("CATEGORIES\t" + "\t".join(map(str,range(num_cat))) + "\n")
        for c0 in sorted(exp.iterkeys()):
            output.write("%s\t"%c0)
Beispiel #12
0
for i, city in enumerate(msa):
    print "Compute exposure 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:
            num_cat = len(rows[1:])
            households[rows[0]] = {c:int(h) for c,h in enumerate(rows[1:])}
    
    ## Compute the exposure (and isolation)
    exp = mb.exposure(households, classes)

    ## Save the exposure values
    with open('extr/exposure/classes/msa/%s_values.csv'%city, 'w') as output:
        output.write("CLASSES\t" + "\t".join(map(str,sorted(exp.iterkeys()))) + "\n")
        for c0 in sorted(exp.iterkeys()):
            output.write("%s\t"%c0)
            output.write("\t".join(map(str,[exp[c0][c1][0] for c1 in
                                    sorted(exp[c0].iterkeys())])))
            output.write("\n")

    ## Save the exposure variance
    with open('extr/exposure/classes/msa/%s_variance.csv'%city, 'w') as output:
        output.write("CLASSES\t" + "\t".join(map(str,sorted(exp.iterkeys()))) + "\n")
        for c0 in sorted(exp.iterkeys()):
            output.write("%s\t"%c0)
Beispiel #13
0
 def test_class_segregated(self):
     city = segregated_city()
     exp = mb.exposure(city)
     classes = mb.uncover_classes(city, exp)
     assert_equal(len(classes),3)
Beispiel #14
0
 def test_class_uniform(self):
     city = uniform_city()
     exp = mb.exposure(city)
     classes = mb.uncover_classes(city, exp)
     assert_equal(len(classes),2)
# Extract neighbourhoods and save
#
for i, city in enumerate(msa):
    print "Compute exposure 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:
            num_cat = len(rows[1:])
            households[rows[0]] = {c: int(h) for c, h in enumerate(rows[1:])}

    ## Compute the exposure (and isolation)
    exp = mb.exposure(households)

    ## Save the exposure values
    with open('extr/exposure/categories/msa/%s_values.csv' % city,
              'w') as output:
        output.write("CATEGORIES\t" + "\t".join(map(str, range(num_cat))) +
                     "\n")
        for c0 in sorted(exp.iterkeys()):
            output.write("%s\t" % c0)
            output.write("\t".join(
                map(str,
                    [exp[c0][c1][0] for c1 in sorted(exp[c0].iterkeys())])))
            output.write("\n")

    ## Save the exposure variance
    with open('extr/exposure/categories/msa/%s_variance.csv' % city,