Skip to content

Commit 06b57db

Browse files
authored
Merge pull request #400 from MgeeeeK/fix
Fixed `index2da` causing inverted output
2 parents ea86611 + cedd521 commit 06b57db

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

libpysal/weights/raster.py

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ def intercepted_function(f, *f_args, **f_kwargs):
2222
else:
2323
from ..common import jit
2424

25-
__author__ = "Mragank Shekhar <[email protected]>"
26-
2725
__all__ = ["da2W", "da2WSP", "w2da", "wsp2da", "testDataArray"]
2826

2927

@@ -281,7 +279,11 @@ def da2WSP(
281279
*shape, ids, id_map, criterion, k_nas, dtype, n_jobs
282280
) # -> (data, (row, col))
283281

284-
sw = sparse.csr_matrix(sw_tup, shape=(n, n), dtype=np.int8,)
282+
sw = sparse.csr_matrix(
283+
sw_tup,
284+
shape=(n, n),
285+
dtype=np.int8,
286+
)
285287

286288
# Higher_order functionality, this uses idea from
287289
# libpysal#313 for adding higher order neighbors.
@@ -559,10 +561,9 @@ def _index2da(data, index, attrs, coords):
559561
fill = attrs["nodatavals"][0] if "nodatavals" in attrs else 0
560562
data_complete = np.full(shape, fill, data.dtype)
561563
data_complete[indexer] = data
562-
data_complete = data_complete[:, ::-1]
563564

564565
da = DataArray(data_complete, coords=coords, dims=dims, attrs=attrs)
565-
return da.sortby(dims[-2], False)
566+
return da
566567

567568

568569
@jit(nopython=True, fastmath=True)
@@ -591,7 +592,13 @@ def _idmap(ids, mask, dtype):
591592

592593
@jit(nopython=True, fastmath=True)
593594
def _SWbuilder(
594-
nrows, ncols, ids, id_map, criterion, k, dtype,
595+
nrows,
596+
ncols,
597+
ids,
598+
id_map,
599+
criterion,
600+
k,
601+
dtype,
595602
):
596603
"""
597604
Computes data and orders rows, cols, data for a single chunk
@@ -631,7 +638,13 @@ def _SWbuilder(
631638

632639
@jit(nopython=True, fastmath=True, nogil=True)
633640
def _compute_chunk(
634-
nrows, ncols, ids, id_map, criterion, k, dtype,
641+
nrows,
642+
ncols,
643+
ids,
644+
id_map,
645+
criterion,
646+
k,
647+
dtype,
635648
):
636649
"""
637650
Computes rows cols for a single chunk
@@ -754,7 +767,9 @@ def _compute_chunk(
754767

755768
@jit(nopython=True, fastmath=True)
756769
def _chunk_generator(
757-
n_jobs, starts, ids,
770+
n_jobs,
771+
starts,
772+
ids,
758773
):
759774
"""
760775
Construct chunks to iterate over within numba in parallel
@@ -782,7 +797,14 @@ def _chunk_generator(
782797

783798

784799
def _parSWbuilder(
785-
nrows, ncols, ids, id_map, criterion, k, dtype, n_jobs,
800+
nrows,
801+
ncols,
802+
ids,
803+
id_map,
804+
criterion,
805+
k,
806+
dtype,
807+
n_jobs,
786808
):
787809
"""
788810
Computes data and orders rows, cols, data in parallel using numba

0 commit comments

Comments
 (0)