pysal / libpysal

Core components of Python Spatial Analysis Library
http://pysal.org/libpysal
Other
266 stars 78 forks source link

attach_islands assumes transform='b' & assumes k=1 #103

Open ljwolf opened 6 years ago

ljwolf commented 6 years ago

It'd be nice to be able to use more than 1 nearest neighbor for the islands, use different kinds of supplemental weights, or use non-binary transforms.

Functionally, I think this conceptually involves:

  1. Ensuring the "supplement" weights to the transform of the target weights. (probably usually binary, since this seems to be used mostly for rook/queen with islands)
  2. Merging all of the neighbors,weights of islands in the target with their corresponding neighbors,weights in the supplement:

I believe this mostly looks the same as what's implemented:

def attach_islands(target, suplement):
    assert supplement.id_order == target.id_order
    supplement.transform = target.transform
    neighbors, weights = copy.deepcopy(target.neighbors), copy.deepcopy(target.weights)
    for island_ix in target.islands:
        neighbors[island_ix] = supplement.neighbors[island_ix]
        weights[island_ix] = supplement.weights[island_ix]
    return W(neighbors, weights, id_order=target.id_order)
weikang9009 commented 6 years ago

This is a nice feature. One additional thing to consider is whether we want the returned spatial weight matrix to be symmetric. For contiguity-based spatial weights, symmetry could be an important property.

ljwolf commented 4 years ago

Thinking about this... what's the difference between this idea of merging 2 weights & w_union? Only that we're restricting the update to the union of islands' neighbors?

github-actions[bot] commented 4 years ago

Stale issue message