From 4eccce413a75869ab2c5051810c483cd03e2caed Mon Sep 17 00:00:00 2001 From: robgpita-noaa Date: Tue, 7 May 2024 11:07:00 -0600 Subject: [PATCH 1/2] Add conditional to set _mv variable to uint64, and allow processing of large arrays. Ref #46 --- pyflwdir/flwdir.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyflwdir/flwdir.py b/pyflwdir/flwdir.py index 19f64c5..674173b 100644 --- a/pyflwdir/flwdir.py +++ b/pyflwdir/flwdir.py @@ -81,10 +81,12 @@ def __init__( self.idxs_outlet = idxs_outlet self._seq = idxs_seq self._nnodes = nnodes - # either -1 for int or 4294967295 for uint32 + # either -1 for int, 4294967295 for uint32, or 18446744073709551615 for uint64 self._mv = core._mv if idxs_ds.dtype == np.uint32: self._mv = np.uint32(self._mv) + if idxs_ds.dtype == np.uint64: + self._mv = np.uint64(self._mv) # set placeholders only used if cache if True self.cache = cache From 7fa2c1591cc236c58133bdcc75553d313546bd4c Mon Sep 17 00:00:00 2001 From: robgpita-noaa Date: Tue, 7 May 2024 14:03:56 -0600 Subject: [PATCH 2/2] Update contributing.rst text, incorporate tests for the uint64 data type, and _mv assertion --- CONTRIBUTING.rst | 6 +++--- tests/conftest.py | 31 +++++++++++++++++++++++++++++-- tests/test_pyflwdir.py | 3 ++- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 1aff79e..0fdc352 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -108,13 +108,13 @@ First, clone pyflwdir's ``git`` repo and navigate into the repository: $ git clone git@github.com:Deltares/pyflwdir.git $ cd pyflwdir -Then, make and activate a new pyflwdir conda environment based on the environment.yml +Then, make and activate a new pyflwdir conda environment based on the `environment.yml` file contained in the repository: .. code-block:: console - $ conda env create -f envs/pyflwdir-dev.yml - $ conda activate pyflwdir-dev + $ conda env create -f environment.yml + $ conda activate pyflwdir Finally, build and install PyFlwDir: diff --git a/tests/conftest.py b/tests/conftest.py index 8e74fa9..d8cbd8b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -80,8 +80,35 @@ def test_data1(flwdir1_idxs, flwdir1_rank): @pytest.fixture(scope="session") -def test_data(test_data0, flwdir0, test_data1, flwdir1): - return [(test_data0, flwdir0), (test_data1, flwdir1)] +def flwdir2(): + np.random.seed(2345) + return from_dem(np.random.rand(15, 10)).to_array("d8") + + +@pytest.fixture(scope="session") +def flwdir2_idxs(flwdir2): + idxs_ds2, idxs_pit2, _ = core_d8.from_array(flwdir2, dtype=np.uint64) + return idxs_ds2, idxs_pit2 + + +@pytest.fixture(scope="session") +def flwdir2_rank(flwdir2_idxs): + idxs_ds2, _ = flwdir2_idxs + rank2, n2 = core.rank(idxs_ds2, mv=np.uint64(core._mv)) + seq2 = np.argsort(rank2)[-n2:] + return rank2, n2, seq2 + + +@pytest.fixture(scope="session") +def test_data2(flwdir2_idxs, flwdir2_rank): + rank2, _, seq2 = flwdir2_rank + idxs_ds2, idxs_pit2 = flwdir2_idxs + return idxs_ds2, idxs_pit2, seq2, rank2, np.uint64(core._mv) + + +@pytest.fixture(scope="session") +def test_data(test_data0, flwdir0, test_data1, flwdir1, test_data2, flwdir2): + return [(test_data0, flwdir0), (test_data1, flwdir1), (test_data2, flwdir2)] @pytest.fixture(scope="session") diff --git a/tests/test_pyflwdir.py b/tests/test_pyflwdir.py index b20cc2d..3c7e4e6 100644 --- a/tests/test_pyflwdir.py +++ b/tests/test_pyflwdir.py @@ -49,7 +49,8 @@ def test_flwdirraster_errors(flwdir0, flwdir0_idxs): @pytest.mark.parametrize( - "test_data, flwdir", [("test_data0", "flwdir0"), ("test_data1", "flwdir1")] + "test_data, flwdir", + [("test_data0", "flwdir0"), ("test_data1", "flwdir1"), ("test_data2", "flwdir2")], ) def test_flwdirraster_attrs(test_data, flwdir, request): d8 = request.getfixturevalue(flwdir)