From 041d36fa8639db23717b1b60ca9d503a15b3fe51 Mon Sep 17 00:00:00 2001 From: Moritz Sallermann Date: Thu, 20 Mar 2025 13:43:18 +0000 Subject: [PATCH 1/6] ENH: started to update the pyflowy bindings Previously the flowy revision was pinned to edb24844c42a4921f596b06129540b7aa80deb28. This is an effort to update the flowy dependency to the newest version. Co-authored-by: Amrita Goswami --- python_bindings/bindings.cpp | 32 ++++++++++++++++++-------------- subprojects/flowy.wrap | 2 +- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/python_bindings/bindings.cpp b/python_bindings/bindings.cpp index 392d973..6f56e02 100644 --- a/python_bindings/bindings.cpp +++ b/python_bindings/bindings.cpp @@ -3,9 +3,11 @@ #include "flowy/include/config_parser.hpp" #include "flowy/include/definitions.hpp" #include "flowy/include/lobe.hpp" +#include "flowy/include/models/mr_lava_loba.hpp" #include "flowy/include/simulation.hpp" #include "flowy/include/topography.hpp" #include "flowy/include/topography_file.hpp" +#include "pybind11/detail/common.h" #include "pybind11/pytypes.h" #ifdef WITH_NETCDF @@ -45,13 +47,13 @@ PYBIND11_MODULE( flowycpp, m ) .def_readwrite( "y_min", &Flowy::TopographyCrop::y_min ) .def_readwrite( "y_max", &Flowy::TopographyCrop::y_max ); - py::enum_( m, "OutputQuantitiy" ) - .value( "Hazard", Flowy::OutputQuantitiy::Hazard ) - .value( "Height", Flowy::OutputQuantitiy::Height ); + py::enum_( m, "OutputQuantity" ) + .value( "Hazard", Flowy::OutputQuantity::Hazard ) + .value( "Height", Flowy::OutputQuantity::Height ); py::class_( m, "AscFile" ) .def( py::init<>() ) - .def( py::init() ) + .def( py::init() ) .def( py::init(), "file_path"_a ) .def( py::init() ) .def( "save", &Flowy::AscFile::save ) @@ -101,7 +103,8 @@ PYBIND11_MODULE( flowycpp, m ) .def( "extent_xy", &Flowy::Lobe::extent_xy ) .def( "line_segment_intersects", &Flowy::Lobe::line_segment_intersects ) .def( "is_point_in_lobe", &Flowy::Lobe::is_point_in_lobe ) - .def( "point_at_angle", &Flowy::Lobe::point_at_angle ) + .def( "point_at_angle", py::overload_cast( &Flowy::Lobe::point_at_angle, py::const_ ) ) + .def( "point_at_angle", py::overload_cast( &Flowy::Lobe::point_at_angle, py::const_ ) ) .def( "rasterize_perimeter", &Flowy::Lobe::rasterize_perimeter ); py::class_( m, "LobeCells" ) @@ -183,11 +186,10 @@ PYBIND11_MODULE( flowycpp, m ) py::class_( m, "CommonLobeDimensions" ) .def( py::init<>() ) - .def( py::init() ) + .def( py::init() ) .def_readwrite( "avg_lobe_thickness", &Flowy::CommonLobeDimensions::avg_lobe_thickness ) .def_readwrite( "lobe_area", &Flowy::CommonLobeDimensions::lobe_area ) .def_readwrite( "max_semiaxis", &Flowy::CommonLobeDimensions::max_semiaxis ) - .def_readwrite( "max_cells", &Flowy::CommonLobeDimensions::max_cells ) .def_readwrite( "thickness_min", &Flowy::CommonLobeDimensions::thickness_min ); py::class_( m, "Simulation" ) @@ -195,16 +197,18 @@ PYBIND11_MODULE( flowycpp, m ) .def_readwrite( "input", &Flowy::Simulation::input ) .def_readwrite( "topography", &Flowy::Simulation::topography ) .def_readwrite( "lobes", &Flowy::Simulation::lobes ) - .def_readwrite( "lobe_dimensions", &Flowy::Simulation::lobe_dimensions ) - .def( "compute_initial_lobe_position", &Flowy::Simulation::compute_initial_lobe_position ) - .def( "compute_lobe_axes", &Flowy::Simulation::compute_lobe_axes ) - .def( "compute_descendent_lobe_position", &Flowy::Simulation::compute_descendent_lobe_position ) - .def( "perturb_lobe_angle", &Flowy::Simulation::perturb_lobe_angle ) - .def( "select_parent_lobe", &Flowy::Simulation::select_parent_lobe ) - .def( "add_inertial_contribution", &Flowy::Simulation::add_inertial_contribution ) .def( "stop_condition", &Flowy::Simulation::stop_condition ) .def( "run", &Flowy::Simulation::run ); + py::class_( m, "MrLavaLoba" ) + .def_readwrite( "lobe_dimensions", &Flowy::MrLavaLoba::lobe_dimensions ) + .def( "compute_initial_lobe_position", &Flowy::MrLavaLoba::compute_initial_lobe_position ) + .def( "compute_lobe_axes", &Flowy::MrLavaLoba::compute_lobe_axes ) + .def( "compute_descendent_lobe_position", &Flowy::MrLavaLoba::compute_descendent_lobe_position ) + .def( "perturb_lobe_angle", &Flowy::MrLavaLoba::perturb_lobe_angle ) + .def( "select_parent_lobe", &Flowy::MrLavaLoba::select_parent_lobe ) + .def( "add_inertial_contribution", &Flowy::MrLavaLoba::add_inertial_contribution ); + m.def( "parse_config", &Flowy::Config::parse_config, "A function to parse input settings from a TOML file.", "config_path"_a ); diff --git a/subprojects/flowy.wrap b/subprojects/flowy.wrap index d525802..8a43045 100644 --- a/subprojects/flowy.wrap +++ b/subprojects/flowy.wrap @@ -1,5 +1,5 @@ [wrap-git] directory=flowy url=https://github.com/flowy-code/flowy.git -revision=e4bd3e2f5e220f7588a155643d604ffe204c8802 +revision=edb24844c42a4921f596b06129540b7aa80deb28 depth=1 \ No newline at end of file From b7311383de9c727c6a4998719c6ff31064211141 Mon Sep 17 00:00:00 2001 From: Moritz Sallermann Date: Tue, 25 Mar 2025 11:33:49 +0000 Subject: [PATCH 2/6] CHORE: Update commit hash in flowy.wrap --- subprojects/flowy.wrap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subprojects/flowy.wrap b/subprojects/flowy.wrap index 8a43045..888055d 100644 --- a/subprojects/flowy.wrap +++ b/subprojects/flowy.wrap @@ -1,5 +1,5 @@ [wrap-git] directory=flowy url=https://github.com/flowy-code/flowy.git -revision=edb24844c42a4921f596b06129540b7aa80deb28 +revision=9c59460ba515d160f244691a429a6529b22e52fa depth=1 \ No newline at end of file From 8a77701cf9f9985b5105f69050f410ec32e23b91 Mon Sep 17 00:00:00 2001 From: Moritz Sallermann Date: Tue, 25 Mar 2025 11:58:13 +0000 Subject: [PATCH 3/6] ENH: bind additional parameters Co-authored-by: Amrita Goswami --- python_bindings/bindings.cpp | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/python_bindings/bindings.cpp b/python_bindings/bindings.cpp index 6f56e02..1a2349a 100644 --- a/python_bindings/bindings.cpp +++ b/python_bindings/bindings.cpp @@ -136,18 +136,43 @@ PYBIND11_MODULE( flowycpp, m ) .def_readwrite( "idx_x_higher", &Flowy::Topography::BoundingBox::idx_x_higher ) .def_readwrite( "idx_y_higher", &Flowy::Topography::BoundingBox::idx_y_higher ); + py::enum_( m, "StorageDataType" ) + .value( "Short", Flowy::StorageDataType::Short ) + .value( "Float", Flowy::StorageDataType::Float ) + .value( "Double", Flowy::StorageDataType::Double ); + + py::class_( m, "OutputSettings" ) + .def( py::init<>() ) + .def_readwrite( "crop_to_content", &Flowy::Config::OutputSettings::crop_to_content ) + .def_readwrite( "use_netcdf", &Flowy::Config::OutputSettings::use_netcdf ) + .def_readwrite( "compression", &Flowy::Config::OutputSettings::compression ) + .def_readwrite( "compression_level", &Flowy::Config::OutputSettings::compression_level ) + .def_readwrite( "shuffle", &Flowy::Config::OutputSettings::shuffle ) + .def_readwrite( "data_type", &Flowy::Config::OutputSettings::data_type ); + py::class_( m, "InputParams" ) .def( py::init<>() ) .def_readwrite( "output_folder", &Flowy::Config::InputParams::output_folder ) + .def_readwrite( "output_settings", &Flowy::Config::InputParams::output_settings ) + .def_readwrite("write_lobes_csv", &Flowy::Config::InputParams::write_lobes_csv) + .def_readwrite("print_remaining_time", &Flowy::Config::InputParams::print_remaining_time) + .def_readwrite("save_final_dem", &Flowy::Config::InputParams::save_final_dem) + .def_readwrite("write_thickness_every_n_lobes", &Flowy::Config::InputParams::write_thickness_every_n_lobes) + .def_readwrite("masking_tolerance", &Flowy::Config::InputParams::masking_tolerance) + .def_readwrite("masking_max_iter", &Flowy::Config::InputParams::masking_max_iter) + .def_readwrite("rng_seed", &Flowy::Config::InputParams::rng_seed) + .def_readwrite("volume_correction", &Flowy::Config::InputParams::volume_correction) .def_readwrite( "run_name", &Flowy::Config::InputParams::run_name ) .def_readwrite( "source", &Flowy::Config::InputParams::source ) .def_readwrite( "vent_coordinates", &Flowy::Config::InputParams::vent_coordinates ) + .def("n_vents", &Flowy::Config::InputParams::n_vents) .def_readwrite( "save_hazard_data", &Flowy::Config::InputParams::save_hazard_data ) .def_readwrite( "n_flows", &Flowy::Config::InputParams::n_flows ) .def_readwrite( "n_lobes", &Flowy::Config::InputParams::n_lobes ) .def_readwrite( "thickening_parameter", &Flowy::Config::InputParams::thickening_parameter ) .def_readwrite( "prescribed_lobe_area", &Flowy::Config::InputParams::prescribed_lobe_area ) .def_readwrite( "prescribed_avg_lobe_thickness", &Flowy::Config::InputParams::prescribed_avg_lobe_thickness ) + .def_readwrite("masking_threshold", &Flowy::Config::InputParams::masking_threshold) .def_readwrite( "min_n_lobes", &Flowy::Config::InputParams::min_n_lobes ) .def_readwrite( "max_n_lobes", &Flowy::Config::InputParams::max_n_lobes ) .def_readwrite( "inertial_exponent", &Flowy::Config::InputParams::inertial_exponent ) @@ -156,6 +181,7 @@ PYBIND11_MODULE( flowycpp, m ) .def_readwrite( "thickness_ratio", &Flowy::Config::InputParams::thickness_ratio ) .def_readwrite( "fixed_dimension_flag", &Flowy::Config::InputParams::fixed_dimension_flag ) .def_readwrite( "vent_flag", &Flowy::Config::InputParams::vent_flag ) + .def_readwrite( "fissure_end_coordinates", &Flowy::Config::InputParams::fissure_end_coordinates ) .def_readwrite( "fissure_probabilities", &Flowy::Config::InputParams::fissure_probabilities ) .def_readwrite( "total_volume", &Flowy::Config::InputParams::total_volume ) .def_readwrite( "east_to_vent", &Flowy::Config::InputParams::east_to_vent ) @@ -163,7 +189,7 @@ PYBIND11_MODULE( flowycpp, m ) .def_readwrite( "south_to_vent", &Flowy::Config::InputParams::south_to_vent ) .def_readwrite( "north_to_vent", &Flowy::Config::InputParams::north_to_vent ) .def_readwrite( "channel_file", &Flowy::Config::InputParams::channel_file ) - .def_readwrite( "alfa_channel", &Flowy::Config::InputParams::alfa_channel ) + .def_readwrite( "alpha_channel", &Flowy::Config::InputParams::alfa_channel ) .def_readwrite( "d1", &Flowy::Config::InputParams::d1 ) .def_readwrite( "d2", &Flowy::Config::InputParams::d2 ) .def_readwrite( "eps", &Flowy::Config::InputParams::eps ) @@ -175,12 +201,7 @@ PYBIND11_MODULE( flowycpp, m ) .def_readwrite( "a_beta", &Flowy::Config::InputParams::a_beta ) .def_readwrite( "b_beta", &Flowy::Config::InputParams::b_beta ) .def_readwrite( "max_aspect_ratio", &Flowy::Config::InputParams::max_aspect_ratio ) - .def_readwrite( "saveraster_flag", &Flowy::Config::InputParams::saveraster_flag ) - .def_readwrite( "aspect_ratio_coeff", &Flowy::Config::InputParams::aspect_ratio_coeff ) - .def_readwrite( "start_from_dist_flag", &Flowy::Config::InputParams::start_from_dist_flag ) - .def_readwrite( "force_max_length", &Flowy::Config::InputParams::force_max_length ) - .def_readwrite( "max_length", &Flowy::Config::InputParams::max_length ) - .def_readwrite( "n_check_loop", &Flowy::Config::InputParams::n_check_loop ) + .def_readwrite( "aspect_ratio_coeff", &Flowy::Config::InputParams::aspect_ratio_coeff ) .def_readwrite( "restart_files", &Flowy::Config::InputParams::restart_files ) .def_readwrite( "restart_filling_parameters", &Flowy::Config::InputParams::restart_filling_parameters ); From 83208a61e09bd974444c2e381b53fed9695f7b2d Mon Sep 17 00:00:00 2001 From: Moritz Sallermann Date: Wed, 26 Mar 2025 14:51:19 +0000 Subject: [PATCH 4/6] ENH: bind validate settings Co-authored-by: Amrita Goswami --- python_bindings/bindings.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/python_bindings/bindings.cpp b/python_bindings/bindings.cpp index 1a2349a..52beb6d 100644 --- a/python_bindings/bindings.cpp +++ b/python_bindings/bindings.cpp @@ -154,25 +154,25 @@ PYBIND11_MODULE( flowycpp, m ) .def( py::init<>() ) .def_readwrite( "output_folder", &Flowy::Config::InputParams::output_folder ) .def_readwrite( "output_settings", &Flowy::Config::InputParams::output_settings ) - .def_readwrite("write_lobes_csv", &Flowy::Config::InputParams::write_lobes_csv) - .def_readwrite("print_remaining_time", &Flowy::Config::InputParams::print_remaining_time) - .def_readwrite("save_final_dem", &Flowy::Config::InputParams::save_final_dem) - .def_readwrite("write_thickness_every_n_lobes", &Flowy::Config::InputParams::write_thickness_every_n_lobes) - .def_readwrite("masking_tolerance", &Flowy::Config::InputParams::masking_tolerance) - .def_readwrite("masking_max_iter", &Flowy::Config::InputParams::masking_max_iter) - .def_readwrite("rng_seed", &Flowy::Config::InputParams::rng_seed) - .def_readwrite("volume_correction", &Flowy::Config::InputParams::volume_correction) + .def_readwrite( "write_lobes_csv", &Flowy::Config::InputParams::write_lobes_csv ) + .def_readwrite( "print_remaining_time", &Flowy::Config::InputParams::print_remaining_time ) + .def_readwrite( "save_final_dem", &Flowy::Config::InputParams::save_final_dem ) + .def_readwrite( "write_thickness_every_n_lobes", &Flowy::Config::InputParams::write_thickness_every_n_lobes ) + .def_readwrite( "masking_tolerance", &Flowy::Config::InputParams::masking_tolerance ) + .def_readwrite( "masking_max_iter", &Flowy::Config::InputParams::masking_max_iter ) + .def_readwrite( "rng_seed", &Flowy::Config::InputParams::rng_seed ) + .def_readwrite( "volume_correction", &Flowy::Config::InputParams::volume_correction ) .def_readwrite( "run_name", &Flowy::Config::InputParams::run_name ) .def_readwrite( "source", &Flowy::Config::InputParams::source ) .def_readwrite( "vent_coordinates", &Flowy::Config::InputParams::vent_coordinates ) - .def("n_vents", &Flowy::Config::InputParams::n_vents) + .def( "n_vents", &Flowy::Config::InputParams::n_vents ) .def_readwrite( "save_hazard_data", &Flowy::Config::InputParams::save_hazard_data ) .def_readwrite( "n_flows", &Flowy::Config::InputParams::n_flows ) .def_readwrite( "n_lobes", &Flowy::Config::InputParams::n_lobes ) .def_readwrite( "thickening_parameter", &Flowy::Config::InputParams::thickening_parameter ) .def_readwrite( "prescribed_lobe_area", &Flowy::Config::InputParams::prescribed_lobe_area ) .def_readwrite( "prescribed_avg_lobe_thickness", &Flowy::Config::InputParams::prescribed_avg_lobe_thickness ) - .def_readwrite("masking_threshold", &Flowy::Config::InputParams::masking_threshold) + .def_readwrite( "masking_threshold", &Flowy::Config::InputParams::masking_threshold ) .def_readwrite( "min_n_lobes", &Flowy::Config::InputParams::min_n_lobes ) .def_readwrite( "max_n_lobes", &Flowy::Config::InputParams::max_n_lobes ) .def_readwrite( "inertial_exponent", &Flowy::Config::InputParams::inertial_exponent ) @@ -201,7 +201,7 @@ PYBIND11_MODULE( flowycpp, m ) .def_readwrite( "a_beta", &Flowy::Config::InputParams::a_beta ) .def_readwrite( "b_beta", &Flowy::Config::InputParams::b_beta ) .def_readwrite( "max_aspect_ratio", &Flowy::Config::InputParams::max_aspect_ratio ) - .def_readwrite( "aspect_ratio_coeff", &Flowy::Config::InputParams::aspect_ratio_coeff ) + .def_readwrite( "aspect_ratio_coeff", &Flowy::Config::InputParams::aspect_ratio_coeff ) .def_readwrite( "restart_files", &Flowy::Config::InputParams::restart_files ) .def_readwrite( "restart_filling_parameters", &Flowy::Config::InputParams::restart_filling_parameters ); @@ -233,4 +233,7 @@ PYBIND11_MODULE( flowycpp, m ) m.def( "parse_config", &Flowy::Config::parse_config, "A function to parse input settings from a TOML file.", "config_path"_a ); + + m.def( + "validate_settings", &Flowy::Config::validate_settings, "A function to validate the Flowy config settings"_a ); } From 07069ff8dea591e9adc3b05c808cd124ccbd227a Mon Sep 17 00:00:00 2001 From: Moritz Sallermann Date: Wed, 26 Mar 2025 15:19:22 +0000 Subject: [PATCH 5/6] ENH: unit test for simulation.run ENH: better .gitignore --- .gitignore | 181 +++++++++++++++++++++++++++++++++++++ examples/run_simulation.py | 15 --- tests/conftest.py | 13 +++ tests/test_simulation.py | 41 +++++++++ 4 files changed, 235 insertions(+), 15 deletions(-) delete mode 100644 examples/run_simulation.py create mode 100644 tests/conftest.py create mode 100644 tests/test_simulation.py diff --git a/.gitignore b/.gitignore index 0df93ee..63c1a0c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +tests/output_test/ +tests/hawaii/ + # Added /wheelhouse/ *.whl @@ -42,3 +45,181 @@ compile_commands.json *.exe *.out *.app + + +#python + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# UV +# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +#uv.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/latest/usage/project/#working-with-version-control +.pdm.toml +.pdm-python +.pdm-build/ + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +# Ruff stuff: +.ruff_cache/ + +# PyPI configuration file +.pypirc \ No newline at end of file diff --git a/examples/run_simulation.py b/examples/run_simulation.py deleted file mode 100644 index a4dff7d..0000000 --- a/examples/run_simulation.py +++ /dev/null @@ -1,15 +0,0 @@ -import pyflowy as pfy -from pyflowy import util -from pathlib import Path - -util.download_file_from_github( Path("./hawaii/input.toml"), relative_file_path="examples/KILAUEA2014-2015/input.toml" ) -util.download_file_from_github( Path("./hawaii/test20m.asc"), relative_file_path="examples/KILAUEA2014-2015/test20m.asc" ) - -input_folder = Path("./hawaii") - -input_params = pfy.flowycpp.parse_config( input_folder/"input.toml" ) -input_params.output_folder = "./output_test" -input_params.source = input_folder / "test20m.asc" - -simulation = pfy.flowycpp.Simulation(input_params, 1) -simulation.run() diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..3ae039c --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,13 @@ +from pathlib import Path +from pyflowy import util +import pytest + +FILEPATH = Path(__file__).parent + +@pytest.fixture +def hawaii_example() -> tuple[Path, Path]: + toml_filepath = Path(f"{FILEPATH}/hawaii/input.toml") + asc_filepath = Path(f"{FILEPATH}/hawaii/test20m.asc") + util.download_file_from_github( toml_filepath, relative_file_path="examples/KILAUEA2014-2015/input.toml" ) + util.download_file_from_github( asc_filepath, relative_file_path="examples/KILAUEA2014-2015/test20m.asc" ) + return toml_filepath, asc_filepath \ No newline at end of file diff --git a/tests/test_simulation.py b/tests/test_simulation.py new file mode 100644 index 0000000..db8bbaf --- /dev/null +++ b/tests/test_simulation.py @@ -0,0 +1,41 @@ +import pytest +import numpy as np +import pyflowy as pfy +from pyflowy import util +from pathlib import Path + +FILEPATH = Path(__file__).parent + +def test_simulation(hawaii_example): + + toml_filepath, asc_filepath = hawaii_example + + input_params = pfy.flowycpp.parse_config( toml_filepath ) + input_params.write_thickness_every_n_lobes = 5000 + pfy.flowycpp.validate_settings(input_params) + + output_folder = Path(f"{FILEPATH}/output_test") + # Remove any previous files because otherwise you just get more extra files and the old ones persist + if output_folder.exists(): + [f.unlink() for f in output_folder.glob("*")] + output_folder.rmdir() + + input_params.output_folder = output_folder + input_params.source = asc_filepath + + # Change some of the output settings + input_params.output_settings.use_netcdf = True + input_params.output_settings.crop_to_content = True + input_params.output_settings.data_type = pfy.flowycpp.StorageDataType.Short + + simulation = pfy.flowycpp.Simulation(input_params, None) + simulation.run() + + assert Path(output_folder/f"{input_params.run_name}_thickness_after_{input_params.write_thickness_every_n_lobes}_lobes.nc").exists() + # There is only one "masking threshold" value but internally this is a list + assert Path(output_folder/f"{input_params.run_name}_thickness_masked_{input_params.masking_threshold[-1]}.nc").exists() + assert Path(output_folder/f"{input_params.run_name}_hazard_full.nc").exists() + # Same deal for the masking threshold for the hazard + assert Path(output_folder/f"{input_params.run_name}_hazard_masked_{input_params.masking_threshold[-1]}.nc").exists() + # Make sure that this summary file was written + assert Path(output_folder / f"{input_params.run_name}_avg_thick.txt").exists() From d38848d283d25676a3121c2549694d78ad794744 Mon Sep 17 00:00:00 2001 From: Moritz Sallermann Date: Wed, 26 Mar 2025 20:26:13 +0000 Subject: [PATCH 6/6] ENH: update commit hash in flowy.wrap Co-authored-by: Amrita Goswami --- subprojects/flowy.wrap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subprojects/flowy.wrap b/subprojects/flowy.wrap index 888055d..9e1d7f0 100644 --- a/subprojects/flowy.wrap +++ b/subprojects/flowy.wrap @@ -1,5 +1,5 @@ [wrap-git] directory=flowy url=https://github.com/flowy-code/flowy.git -revision=9c59460ba515d160f244691a429a6529b22e52fa +revision=8520829e141edda73547eeaf063003e269c7c44e depth=1 \ No newline at end of file