Skip to content

Commit

Permalink
Added fallback method, fixed numba dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
MgeeeeK committed Aug 28, 2020
1 parent d422dee commit dc51627
Show file tree
Hide file tree
Showing 7 changed files with 368 additions and 276 deletions.
2 changes: 0 additions & 2 deletions ci/36.yaml
Expand Up @@ -12,7 +12,5 @@ dependencies:
- matplotlib
# optional
- geopandas
- numba
- xarray
- joblib
- zstd
1 change: 0 additions & 1 deletion ci/37.yaml
Expand Up @@ -13,6 +13,5 @@ dependencies:
# optional
- geopandas
- numba
- joblib
- xarray
- zstd
62 changes: 17 additions & 45 deletions libpysal/weights/contiguity.py
Expand Up @@ -192,7 +192,7 @@ def from_xarray(
z_value=None,
coords_labels={},
k=1,
distance_band=False,
include_nas=False,
sparse=False,
**kwargs,
):
Expand All @@ -208,14 +208,15 @@ def from_xarray(
coords_labels : dictionary
Pass dimension labels for coordinates and layers if they do not
belong to default dimensions, which are (band/time, y/lat, x/lon)
e.g. dims = {"y_label": "latitude", "x_label": "longitude", "z_label": "year"}
e.g. coords_labels = {"y_label": "latitude", "x_label": "longitude", "z_label": "year"}
Default is {} empty dictionary.
sparse : boolean
type of weight object. Default is False. For sparse, sparse = True
k : int
Order of contiguity, Default is 1
distance_band : boolean
If true missing values will be assumed as non-missing when
Order of contiguity, this will select all neighbors upto kth order.
Default is 1.
include_nas : boolean
If True, missing values will be assumed as non-missing when
selecting higher_order neighbors, Default is False
n_jobs : int
Number of cores to be used in the sparse weight construction. If -1,
Expand All @@ -231,27 +232,12 @@ def from_xarray(
See Also
--------
:class:`libpysal.weights.weights.W`
:class:`libpysal.weights.weights.WSP`
:class:`libpysal.weights.weights.WSP`
"""
if sparse:
w = da2WSP(
da,
'rook',
z_value,
coords_labels,
k,
distance_band
)
w = da2WSP(da, "rook", z_value, coords_labels, k, include_nas)
else:
w = da2W(
da,
'rook',
z_value,
coords_labels,
k,
distance_band,
**kwargs
)
w = da2W(da, "rook", z_value, coords_labels, k, include_nas, **kwargs)
return w


Expand Down Expand Up @@ -427,7 +413,7 @@ def from_xarray(
z_value=None,
coords_labels={},
k=1,
distance_band=False,
include_nas=False,
sparse=False,
**kwargs,
):
Expand All @@ -443,14 +429,15 @@ def from_xarray(
coords_labels : dictionary
Pass dimension labels for coordinates and layers if they do not
belong to default dimensions, which are (band/time, y/lat, x/lon)
e.g. dims = {"y_label": "latitude", "x_label": "longitude", "z_label": "year"}
e.g. coords_labels = {"y_label": "latitude", "x_label": "longitude", "z_label": "year"}
Default is {} empty dictionary.
sparse : boolean
type of weight object. Default is False. For sparse, sparse = True
k : int
Order of contiguity, Default is 1
distance_band : boolean
If true missing values will be assumed as non-missing when
Order of contiguity, this will select all neighbors upto kth order.
Default is 1.
include_nas : boolean
If True, missing values will be assumed as non-missing when
selecting higher_order neighbors, Default is False
n_jobs : int
Number of cores to be used in the sparse weight construction. If -1,
Expand All @@ -469,24 +456,9 @@ def from_xarray(
:class:`libpysal.weights.weights.WSP`
"""
if sparse:
w = da2WSP(
da,
'queen',
z_value,
coords_labels,
k,
distance_band
)
w = da2WSP(da, "queen", z_value, coords_labels, k, include_nas)
else:
w = da2W(
da,
'queen',
z_value,
coords_labels,
k,
distance_band,
**kwargs
)
w = da2W(da, "queen", z_value, coords_labels, k, include_nas, **kwargs)
return w


Expand Down

0 comments on commit dc51627

Please sign in to comment.