Skip to content

Commit

Permalink
ENH: introduce wradlib xarray accessor for easy access of wradlib fun…
Browse files Browse the repository at this point in the history
…ctions from xarray.DataArray (with dp and zr modules prefilled), adapt tests
  • Loading branch information
kmuehlbauer committed Mar 1, 2023
1 parent de13ab6 commit 9dfc030
Show file tree
Hide file tree
Showing 5 changed files with 302 additions and 265 deletions.
1 change: 1 addition & 0 deletions doc/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This version brings doc-folder back into wradlib repo. The wradlib-docs repo wil
**New features**

* DOC: reintroduce doc into wradlib repository ({pull}`619`) by {at}`kmuehlbauer`
* ENH: introduce wradlib xarray accessor for easy access of wradlib functions from xarray.DataArray (with dp and zr modules prefilled), adapt tests ({pull}`621`) by {at}`kmuehlbauer`

**Maintenance - CI**

Expand Down
1 change: 1 addition & 0 deletions wradlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from . import verify # noqa
from . import vis # noqa
from . import vpr # noqa
from . import xarray # noqa
from . import zonalstats # noqa
from . import zr # noqa
from .util import show_versions # noqa
Expand Down
48 changes: 22 additions & 26 deletions wradlib/tests/test_vis.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,26 +130,24 @@ def test_plot_ppi_proj(self, prj_data):

@requires_gdal
def test_plot_ppi_xarray(self, prj_data):
prj_data.da_ppi.wradlib.rays
prj_data.da_ppi.wradlib.plot()
prj_data.da_ppi.wradlib.plot_ppi()
prj_data.da_ppi.wradlib.contour()
prj_data.da_ppi.wradlib.contourf()
prj_data.da_ppi.wradlib.pcolormesh()
prj_data.da_ppi.wradlib.plot(proj="cg")
prj_data.da_ppi.wradlib.plot_ppi(proj="cg")
prj_data.da_ppi.wradlib.contour(proj="cg")
prj_data.da_ppi.wradlib.contourf(proj="cg")
prj_data.da_ppi.wradlib.pcolormesh(proj="cg")
assert hasattr(prj_data.da_ppi.wrl, "rays")
prj_data.da_ppi.wrl.vis.plot()
prj_data.da_ppi.wrl.vis.contour()
prj_data.da_ppi.wrl.vis.contourf()
prj_data.da_ppi.wrl.vis.pcolormesh()
prj_data.da_ppi.wrl.vis.plot(proj="cg")
prj_data.da_ppi.wrl.vis.contour(proj="cg")
prj_data.da_ppi.wrl.vis.contourf(proj="cg")
prj_data.da_ppi.wrl.vis.pcolormesh(proj="cg")
fig = pl.figure()
ax = fig.add_subplot(111)
with pytest.raises(TypeError):
prj_data.da_ppi.wradlib.pcolormesh(proj={"rot": 0, "scale": 1}, ax=ax)
prj_data.da_ppi.wrl.vis.pcolormesh(proj={"rot": 0, "scale": 1}, ax=ax)

@requires_gdal
def test_plot_ppi_xarray_proj(self, prj_data):
with pytest.raises(TypeError):
prj_data.da_ppi.wradlib.pcolormesh(proj=prj_data.proj)
prj_data.da_ppi.wrl.vis.pcolormesh(proj=prj_data.proj)

@requires_cartopy
@requires_gdal
Expand All @@ -164,7 +162,7 @@ def test_plot_ppi_cartopy(self, prj_data):
assert isinstance(ax, cartopy.mpl.geoaxes.GeoAxes)
fig = pl.figure(figsize=(10, 10))
ax = fig.add_subplot(111, projection=map_proj)
prj_data.da_ppi.wradlib.plot_ppi(ax=ax)
prj_data.da_ppi.wrl.vis.plot(ax=ax)
ax.gridlines(draw_labels=True)

def test_plot_rhi(self, pol_data):
Expand All @@ -185,20 +183,18 @@ def test_plot_rhi(self, pol_data):
@requires_gdal
def test_plot_rhi_xarray(self, prj_data):
assert (
repr(prj_data.da_rhi.wradlib).split("\n", 1)[1]
repr(prj_data.da_rhi.wrl).split("\n", 1)[1]
== repr(prj_data.da_rhi).split("\n", 1)[1]
)
prj_data.da_rhi.wradlib.rays
prj_data.da_rhi.wradlib.plot()
prj_data.da_rhi.wradlib.plot_rhi()
prj_data.da_rhi.wradlib.contour()
prj_data.da_rhi.wradlib.contourf()
prj_data.da_rhi.wradlib.pcolormesh()
prj_data.da_rhi.wradlib.plot(proj="cg")
prj_data.da_rhi.wradlib.plot_rhi(proj="cg")
prj_data.da_rhi.wradlib.contour(proj="cg")
prj_data.da_rhi.wradlib.contourf(proj="cg")
prj_data.da_rhi.wradlib.pcolormesh(proj="cg")
assert hasattr(prj_data.da_rhi.wrl, "rays")
prj_data.da_rhi.wrl.vis.plot()
prj_data.da_rhi.wrl.vis.contour()
prj_data.da_rhi.wrl.vis.contourf()
prj_data.da_rhi.wrl.vis.pcolormesh()
prj_data.da_rhi.wrl.vis.plot(proj="cg")
prj_data.da_rhi.wrl.vis.contour(proj="cg")
prj_data.da_rhi.wrl.vis.contourf(proj="cg")
prj_data.da_rhi.wrl.vis.pcolormesh(proj="cg")

def test_plot_cg_ppi(self, pol_data):
cgax, pm = vis.plot_ppi(pol_data.img, elev=2.0, proj="cg")
Expand Down
Loading

0 comments on commit 9dfc030

Please sign in to comment.