|
5 | 5 | import numpy as np |
6 | 6 | import pandas as pd |
7 | 7 | import pytest |
| 8 | +import xarray as xr |
8 | 9 | from flopy.discretization import StructuredGrid |
9 | 10 | from xarray import DataTree |
10 | 11 |
|
@@ -555,3 +556,24 @@ def test_tdis_from_timestamps(): |
555 | 556 | np.testing.assert_array_equal(tdis.perlen, [4.0, 10.0]) |
556 | 557 | np.testing.assert_array_equal(tdis.nstp, [5, 5]) |
557 | 558 | np.testing.assert_array_equal(tdis.tsmult, [1.2, 1.2]) |
| 559 | + |
| 560 | + |
| 561 | +def test_to_xarray_on_component(): |
| 562 | + tdis = Tdis.from_timestamps(["2020-01-01", "2020-01-05", "2020-01-15"], nstp=5, tsmult=1.2) |
| 563 | + ds = tdis.to_xarray() |
| 564 | + assert isinstance(ds, xr.Dataset) |
| 565 | + assert isinstance(ds.per, xr.DataArray) |
| 566 | + assert np.array_equal(ds.per, [0, 1]) |
| 567 | + assert ds.attrs["start_date_time"] == pd.Timestamp("2020-01-01") |
| 568 | + |
| 569 | + |
| 570 | +def test_to_xarray_on_context(function_tmpdir): |
| 571 | + time = Time(perlen=[1.0], nstp=[1], tsmult=[1.0]) |
| 572 | + ims = Ims(models=["gwf"]) |
| 573 | + sim = Simulation(tdis=time, solutions={"ims": ims}, workspace=function_tmpdir) |
| 574 | + dt = sim.to_xarray() |
| 575 | + assert isinstance(dt, xr.DataTree) |
| 576 | + assert isinstance(dt.per, xr.DataArray) |
| 577 | + assert np.array_equal(dt.per, [0]) |
| 578 | + assert dt.attrs["filename"] == "mfsim.nam" |
| 579 | + assert dt.attrs["workspace"] == Path(function_tmpdir) |
0 commit comments