Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swap xarray.open_rasterio for rioxarray.open_rasterio #62 #63

Merged
merged 1 commit into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
repos:
- repo: https://github.com/psf/black
rev: 21.7b0
rev: 23.3.0
hooks:
- id: black

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.910
rev: v1.2.0
hooks:
- id: mypy
args: [--disallow-untyped-defs, --no-implicit-optional, --warn-unused-ignores, --warn-redundant-casts, --warn-unreachable]
exclude: test
additional_dependencies: [types-requests, xarray]

- repo: https://github.com/pycqa/isort
rev: 5.8.0
rev: 5.12.0
hooks:
- id: isort
args: [--profile, black]
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
requirements = [
"rasterio",
"xarray",
"rioxarray",
"earthengine-api",
"tqdm",
"requests",
Expand Down
2 changes: 1 addition & 1 deletion test/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_to_xarray():
collection = ee.ImageCollection(test_list)
ds = collection.wx.to_xarray(region=region, scale=20, crs=crs, progress=False)

assert crs in ds.crs
assert crs == ds.rio.crs
assert all(
ds.time.values
== [
Expand Down
2 changes: 1 addition & 1 deletion wxee/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import ee # type: ignore
import rasterio # type: ignore
import xarray as xr
from urllib3.exceptions import ProtocolError # type: ignore
from urllib3.exceptions import ProtocolError

from wxee import constants
from wxee.accessors import wx_accessor
Expand Down
5 changes: 3 additions & 2 deletions wxee/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
import joblib # type: ignore
import rasterio # type: ignore
import requests
import rioxarray # type: ignore
import xarray as xr
from requests.adapters import HTTPAdapter
from tqdm.auto import tqdm # type: ignore
from urllib3.util.retry import Retry # type: ignore
from urllib3.util.retry import Retry


def Initialize(**kwargs: Any) -> None:
Expand Down Expand Up @@ -157,7 +158,7 @@ def _dataarray_from_file(file: str, masked: bool, nodata: int) -> xr.DataArray:

The file name must follow the format "{dimension}.{coordinate}.{variable}.{extension}".
"""
da = xr.open_rasterio(file)
da = rioxarray.open_rasterio(file)
dim, coord, var = _parse_filename(file)

da = da.expand_dims({dim: [coord]}).rename(var).squeeze("band").drop_vars("band")
Expand Down
6 changes: 3 additions & 3 deletions wxee/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ def rgb(

>>> ds.wx.rgb(bands=["B8", "B4", "B3"], stretch=0.85, interactive=True, aspect=1.2)
"""
if bands:
if bands is not None:
if len(bands) != 3:
raise ValueError(f"Bands must be a list with exactly 3 names.")
else:
bands = list(self._obj.var())[:3]
bands = list(self._obj.var())[:3] # type: ignore

# Raise a different error if the bands were identified implicitly to avoid confusion
if len(bands) != 3:
if len(bands) != 3: # type: ignore
raise ValueError(
f"The Dataset must contain at least 3 data variables for RGB plotting."
)
Expand Down