From 37726484b00433c2e366596df8059484d9324804 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoffer=20Str=C3=B6mberg?= Date: Sun, 13 Oct 2024 18:27:45 +0200 Subject: [PATCH] updated acc to comments --- .github/workflows/github-action-lint.yaml | 2 +- notebooks/topo_playground.ipynb | 23 ++++++++--------------- src/storm_water_management/main.py | 2 +- src/storm_water_management/utils.py | 6 +++--- tests/test_unit.py | 6 +++--- 5 files changed, 16 insertions(+), 23 deletions(-) diff --git a/.github/workflows/github-action-lint.yaml b/.github/workflows/github-action-lint.yaml index 325f94c..3e1d7cb 100644 --- a/.github/workflows/github-action-lint.yaml +++ b/.github/workflows/github-action-lint.yaml @@ -18,7 +18,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install -e ".[lint]" + pip install ".[lint]" - name: Lint with ruff run: | ruff check --output-format=github src tests diff --git a/notebooks/topo_playground.ipynb b/notebooks/topo_playground.ipynb index 5fa4435..40df1bf 100644 --- a/notebooks/topo_playground.ipynb +++ b/notebooks/topo_playground.ipynb @@ -10,7 +10,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -36,7 +36,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -83,7 +83,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -98,7 +98,7 @@ "p Setting up boolean flood array matrix...\u001b[39m\n", "p Adding cells to the priority queue...\u001b[39m\n", "p Performing Priority-Flood+Epsilon...\u001b[39m\n", - "\u001b[2Kt succeeded in 1.58435 s\u001b[39m======================] (100% - 0.0s - 1 threads)\n", + "\u001b[2Kt succeeded in 1.72164 s\u001b[39m======================] (100% - 0.0s - 1 threads)\n", "m Cells processed = 4000000\u001b[39m\n", "m Cells in pits = 777150\u001b[39m\n", "\u001b[91mW \u001b[91mW In assigning negligible gradients to depressions, some depressions rose above the surrounding cells. This implies that a larger storage type should be used. The problem occured for 2781 of 4000000.\u001b[39m\u001b[39m\n", @@ -107,20 +107,13 @@ "C O'Callaghan, J.F., Mark, D.M., 1984. The Extraction of Drainage Networks from Digital Elevation Data. Computer vision, graphics, and image processing 28, 323--344.\u001b[39m\n", "\n", "c topology = D8\u001b[39m\n", - "\u001b[2K[==================================================] (100% - 0.0s - 1 threads) ] (59% - 0.1s - 1 threads)\n", + "\u001b[2K[==================================================] (100% - 0.0s - 1 threads) ] (35% - 0.1s - 1 threads)\n", "A Generic Flow Accumulation Algorithm\u001b[39m\n", "p Creating dependencies array...\n", "\u001b[39m\n", "\u001b[95md Source cells found = 1457392\u001b[39m\n", "p Calculating flow accumulation...\u001b[39m\n", - "\u001b[2K[=========================== ] (54% - 0.1s - 1 threads)" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[2Kt Wall-time = 0.44261 s\u001b[39m=================] (100% - 0.0s - 1 threads)\n" + "\u001b[2Kt Wall-time = 0.493803 s\u001b[39m================] (100% - 0.0s - 1 threads)\n" ] } ], @@ -134,7 +127,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -289,7 +282,7 @@ "source": [ "import geopandas\n", "\n", - "geojson_data = utils.get_coordinate_center_points_from_tfw(\n", + "geojson_data = utils.compile_data_to_geojson(\n", " tfw, elevation_data, accum_d8, rda_fill_diff, 200, 200\n", ")\n", "\n", diff --git a/src/storm_water_management/main.py b/src/storm_water_management/main.py index 1ff5bdb..a0a6abc 100644 --- a/src/storm_water_management/main.py +++ b/src/storm_water_management/main.py @@ -49,7 +49,7 @@ def main(tif_filename): n_x = elevation_data.shape[0] n_y = elevation_data.shape[1] - geojson_data = utils.get_coordinate_center_points_from_tfw( + geojson_data = utils.compile_data_to_geojson( tfw, elevation_data, accum_d8, rda_fill_diff, n_x, n_y ) utils.save_to_geojson(geojson_data, "64_3_2023") diff --git a/src/storm_water_management/utils.py b/src/storm_water_management/utils.py index e676469..fad09c9 100644 --- a/src/storm_water_management/utils.py +++ b/src/storm_water_management/utils.py @@ -7,7 +7,7 @@ import richdem -def get_coordinate_center_points_from_tfw( +def compile_data_to_geojson( tfw: list, elev_data: richdem.rdarray, flow_data: richdem.rdarray, @@ -15,10 +15,10 @@ def get_coordinate_center_points_from_tfw( n_points_x: int, n_points_y: int, ) -> list: - """Get coordinates for centerpoints. + """Compile data to geojson format. Args: - tfw: coordinate info. + tfw: coordinate info elev_data: elevation data flow_data: data from flow analysis depression_filling_data: data from depression filling analysis diff --git a/tests/test_unit.py b/tests/test_unit.py index 462ded9..332090d 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -5,8 +5,8 @@ from storm_water_management import utils -def test_unit_temp(): - """Unit test of temp function.""" +def test_compile_data_to_geojson(): + """Test compile_data_to_geojson""" n_x = 2 n_y = 2 rda_fill_diff = rd.rdarray([[1.0, 1.0], [2.0, 2.0]], no_data=-9999) @@ -16,7 +16,7 @@ def test_unit_temp(): print(rda_fill_diff[1]) - geojson_data = utils.get_coordinate_center_points_from_tfw( + geojson_data = utils.compile_data_to_geojson( tfw, elevation_data, accum_d8, rda_fill_diff, n_x, n_y )