Exemplo n.º 1
0
 def test_remap_ids(self):
     w = pysal.lat2W(3, 2)
     wid_order = [0, 1, 2, 3, 4, 5]
     self.assertEquals(wid_order, w.id_order)
     wneighbors0 = [2, 1]
     self.assertEquals(wneighbors0, w.neighbors[0])
     old_to_new = {0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e', 5: 'f'}
     w_new = pysal.remap_ids(w, old_to_new)
     w_newid_order = ['a', 'b', 'c', 'd', 'e', 'f']
     self.assertEquals(w_newid_order, w_new.id_order)
     w_newdneighborsa = ['c', 'b']
     self.assertEquals(w_newdneighborsa, w_new.neighbors['a'])
Exemplo n.º 2
0
 def test_remap_ids(self):
     w = pysal.lat2W(3, 2)
     wid_order = [0, 1, 2, 3, 4, 5]
     self.assertEquals(wid_order, w.id_order)
     wneighbors0 = [2, 1]
     self.assertEquals(wneighbors0, w.neighbors[0])
     old_to_new = {0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e', 5: 'f'}
     w_new = pysal.remap_ids(w, old_to_new)
     w_newid_order = ['a', 'b', 'c', 'd', 'e', 'f']
     self.assertEquals(w_newid_order, w_new.id_order)
     w_newdneighborsa = ['c', 'b']
     self.assertEquals(w_newdneighborsa, w_new.neighbors['a'])
Exemplo n.º 3
0
def call_lisa(data, weight_file, numPermutations):
    n = len(data)

    # validate data and weight_file
    o = open(weight_file)
    firstline = o.readline().strip()
    if firstline.find(" ") >= 0:
        n_in_w = int(firstline.strip().split(" ")[1])
    else:
        n_in_w = int(firstline)

    if n != n_in_w:
        return None

    # check the content, convert to CAST style
    import pysal

    pyw = pysal.open(weight_file).read()
    pyw_new = pysal.remap_ids(pyw, pyw.id2i)

    weight_file = weight_file[:-4] + "_" + weight_file[-4:]
    tmpw = pysal.open(weight_file, "w")
    tmpw.write(pyw_new)
    tmpw.close()

    _data = doubleArray(n)
    for i in range(n):
        _data[i] = float(data[i])

    # define some return variables
    dummy_array = [0 for i in range(n)]
    localMoran = VecDouble(dummy_array)
    sigLocalMoran = doubleArray(n)
    sigFlag = intArray(n)
    clusterFlag = intArray(n)

    # read weights file
    suffix = weight_file[-3:]
    if suffix == "gal":
        wfile = GalWeight(weight_file)
    elif suffix == "gwt":
        wfile = GwtWeight(weight_file)
    else:
        os.remove(weight_file)
        return None

    weights = wfile.gal

    # call lisa
    GeodaLisa_LISA(n, _data, weights, numPermutations, localMoran, sigLocalMoran, sigFlag, clusterFlag)

    # process return results
    _localMoran = []
    _sigLocalMoran = []
    _sigFlag = []
    _clusterFlag = []

    for i in range(n):
        _localMoran.append(localMoran[i])
        _sigLocalMoran.append(sigLocalMoran[i])
        _sigFlag.append(sigFlag[i])
        _clusterFlag.append(clusterFlag[i])

    os.remove(weight_file)

    return _localMoran, _sigLocalMoran, _sigFlag, _clusterFlag
Exemplo n.º 4
0
def call_lisa(data, weight_file, numPermutations):
    n = len(data)

    # validate data and weight_file
    o = open(weight_file)
    firstline = o.readline().strip()
    if firstline.find(" ") >= 0:
        n_in_w = int(firstline.strip().split(' ')[1])
    else:
        n_in_w = int(firstline)

    if n != n_in_w:
        return None

    # check the content, convert to CAST style
    import pysal
    pyw = pysal.open(weight_file).read()
    pyw_new = pysal.remap_ids(pyw, pyw.id2i)

    weight_file = weight_file[:-4] + "_" + weight_file[-4:]
    tmpw = pysal.open(weight_file, 'w')
    tmpw.write(pyw_new)
    tmpw.close()

    _data = doubleArray(n)
    for i in range(n):
        _data[i] = float(data[i])

    # define some return variables
    dummy_array = [0 for i in range(n)]
    localMoran = VecDouble(dummy_array)
    sigLocalMoran = doubleArray(n)
    sigFlag = intArray(n)
    clusterFlag = intArray(n)

    # read weights file
    suffix = weight_file[-3:]
    if suffix == "gal":
        wfile = GalWeight(weight_file)
    elif suffix == "gwt":
        wfile = GwtWeight(weight_file)
    else:
        os.remove(weight_file)
        return None

    weights = wfile.gal

    # call lisa
    GeodaLisa_LISA(n, _data, weights, numPermutations, localMoran,
                   sigLocalMoran, sigFlag, clusterFlag)

    # process return results
    _localMoran = []
    _sigLocalMoran = []
    _sigFlag = []
    _clusterFlag = []

    for i in range(n):
        _localMoran.append(localMoran[i])
        _sigLocalMoran.append(sigLocalMoran[i])
        _sigFlag.append(sigFlag[i])
        _clusterFlag.append(clusterFlag[i])

    os.remove(weight_file)

    return _localMoran, _sigLocalMoran, _sigFlag, _clusterFlag