From 093a63c7dfeb671576579b6487aad9f7d25e7651 Mon Sep 17 00:00:00 2001 From: Brian Helba Date: Tue, 2 Dec 2025 12:38:01 -0500 Subject: [PATCH] Convert into a Python package --- LICENSE | 21 +++++++++ README.md | 6 +-- pyproject.toml | 44 +++++++++++++++++++ requirements.txt | 8 ---- uvdat_flood_sim/__init__.py | 0 main.py => uvdat_flood_sim/__main__.py | 22 +++++----- .../animate_results.py | 2 +- constants.py => uvdat_flood_sim/constants.py | 1 - .../downscaling_prediction.py | 4 +- .../hydrodynamic_prediction.py | 4 +- .../hydrological_prediction.py | 4 +- .../save_results.py | 4 +- utils.py => uvdat_flood_sim/utils.py | 0 13 files changed, 89 insertions(+), 31 deletions(-) create mode 100644 LICENSE create mode 100644 pyproject.toml delete mode 100644 requirements.txt create mode 100644 uvdat_flood_sim/__init__.py rename main.py => uvdat_flood_sim/__main__.py (92%) rename animate_results.py => uvdat_flood_sim/animate_results.py (95%) rename constants.py => uvdat_flood_sim/constants.py (99%) rename downscaling_prediction.py => uvdat_flood_sim/downscaling_prediction.py (91%) rename hydrodynamic_prediction.py => uvdat_flood_sim/hydrodynamic_prediction.py (98%) rename hydrological_prediction.py => uvdat_flood_sim/hydrological_prediction.py (93%) rename save_results.py => uvdat_flood_sim/save_results.py (96%) rename utils.py => uvdat_flood_sim/utils.py (100%) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..adcb929 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Kitware, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 91b3a09..1405974 100644 --- a/README.md +++ b/README.md @@ -28,18 +28,18 @@ This is a proof of concept for the Charles River in Boston that could be transla ## Example usage -Install requirements with `pip install -r requirements.txt`. +Install requirements with `pip install -e .`. To run a flood simulation with default inputs: ``` -python main.py +python -m uvdat_flood_sim ``` To see the help menu explaining how to use arguments to specify input values: ``` -python main.py -h +python -m uvdat_flood_sim -h ``` ## Viewing Results diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..a57322f --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,44 @@ +[build-system] +requires = ["hatchling", "hatch-vcs"] +build-backend = "hatchling.build" + +[project] +name = "uvdat-flood-sim" +description = "An end-to-end dynamic flood simulation." +readme = "README.md" +requires-python = ">=3.10" +license = "MIT" +license-files = ["LICENSE"] +maintainers = [ + { name = "Kitware, Inc.", email = "kitware@kitware.com" }, + { name = "August Posch", email = "augustposch@augustposch.us" }, +] +dependencies = [ + "matplotlib", + "numpy<2", + "pandas", + "pyproj", + "rasterio", + "requests", + "scikit-learn==1.3.0", + "scipy", +] +dynamic = ["version"] + +[project.optional-dependencies] +large-image-writer = [ + "large-image[zarr]", + "tifftools", +] + +[project.urls] +Repository = "https://github.com/OpenGeoscience/uvdat-flood-sim" +"Bug Reports" = "https://github.com/OpenGeoscience/uvdat-flood-sim/issues" + +[tool.hatch.build] +only-include = [ + "uvdat_flood_sim", +] + +[tool.hatch.version] +source = "vcs" diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index aa7b3c0..0000000 --- a/requirements.txt +++ /dev/null @@ -1,8 +0,0 @@ -scipy -requests -rasterio -pandas -scikit-learn==1.3.0 -numpy<2 -matplotlib -pyproj diff --git a/uvdat_flood_sim/__init__.py b/uvdat_flood_sim/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/main.py b/uvdat_flood_sim/__main__.py similarity index 92% rename from main.py rename to uvdat_flood_sim/__main__.py index 2ff9eec..c40c72a 100644 --- a/main.py +++ b/uvdat_flood_sim/__main__.py @@ -1,17 +1,15 @@ import argparse -import numpy import json from datetime import datetime from pathlib import Path -from downscaling_prediction import downscale_boston_cesm -from hydrological_prediction import calculate_discharge_from_precipitation -from hydrodynamic_prediction import generate_flood_from_discharge -from animate_results import animate as animate_results -from save_results import write_multiframe_geotiff - -from constants import PERCENTILES_URL, PERCENTILES_PATH, HYDROGRAPHS, SECONDS_PER_DAY -from utils import download_file +from .constants import PERCENTILES_URL, PERCENTILES_PATH, HYDROGRAPHS, SECONDS_PER_DAY +from .downscaling_prediction import downscale_boston_cesm +from .hydrological_prediction import calculate_discharge_from_precipitation +from .hydrodynamic_prediction import generate_flood_from_discharge +from .animate_results import animate as animate_results +from .save_results import write_multiframe_geotiff +from .utils import download_file def run_end_to_end( @@ -100,7 +98,7 @@ def validate_args(args): ) -if __name__ == '__main__': +def main(): parser = argparse.ArgumentParser( prog='Dynamic Flood Simulation' ) @@ -172,3 +170,7 @@ def validate_args(args): ) args = parser.parse_args() run_end_to_end(*validate_args(args)) + + +if __name__ == '__main__': + main() diff --git a/animate_results.py b/uvdat_flood_sim/animate_results.py similarity index 95% rename from animate_results.py rename to uvdat_flood_sim/animate_results.py index 6c30d24..1443871 100644 --- a/animate_results.py +++ b/uvdat_flood_sim/animate_results.py @@ -3,7 +3,7 @@ import matplotlib.pyplot as plt import matplotlib.animation as ani -from constants import OUTPUTS_FOLDER +from .constants import OUTPUTS_FOLDER def animate(results): OUTPUTS_FOLDER.mkdir(parents=True, exist_ok=True) diff --git a/constants.py b/uvdat_flood_sim/constants.py similarity index 99% rename from constants.py rename to uvdat_flood_sim/constants.py index aae57f1..13809a4 100644 --- a/constants.py +++ b/uvdat_flood_sim/constants.py @@ -1,4 +1,3 @@ -import numpy from pathlib import Path diff --git a/downscaling_prediction.py b/uvdat_flood_sim/downscaling_prediction.py similarity index 91% rename from downscaling_prediction.py rename to uvdat_flood_sim/downscaling_prediction.py index b83ee5a..658e721 100644 --- a/downscaling_prediction.py +++ b/uvdat_flood_sim/downscaling_prediction.py @@ -5,8 +5,8 @@ import math from scipy.stats import genextreme as gev -from utils import download_file -from constants import CESM_DATA, DOWNSCALING_MODEL_URL, DOWNSCALING_MODEL_PATH +from .utils import download_file +from .constants import CESM_DATA, DOWNSCALING_MODEL_URL, DOWNSCALING_MODEL_PATH def annual_precipitation_maxima(daily): diff --git a/hydrodynamic_prediction.py b/uvdat_flood_sim/hydrodynamic_prediction.py similarity index 98% rename from hydrodynamic_prediction.py rename to uvdat_flood_sim/hydrodynamic_prediction.py index dbf077f..abc4df1 100644 --- a/hydrodynamic_prediction.py +++ b/uvdat_flood_sim/hydrodynamic_prediction.py @@ -4,8 +4,8 @@ import numpy import pandas -from utils import download_file -from constants import ( +from .utils import download_file +from .constants import ( RATING_CURVE_URL, RATING_CURVE_PATH, HAND_URL, diff --git a/hydrological_prediction.py b/uvdat_flood_sim/hydrological_prediction.py similarity index 93% rename from hydrological_prediction.py rename to uvdat_flood_sim/hydrological_prediction.py index ebcddb6..012342a 100644 --- a/hydrological_prediction.py +++ b/uvdat_flood_sim/hydrological_prediction.py @@ -2,8 +2,8 @@ import numpy -from utils import download_file -from constants import HYDROLOGICAL_MODEL_URL, HYDROLOGICAL_MODEL_PATH, WATERSHED_AREA_SQ_M, CUBIC_METERS_TO_CUBIC_FEET, SECONDS_PER_DAY +from .utils import download_file +from .constants import HYDROLOGICAL_MODEL_URL, HYDROLOGICAL_MODEL_PATH, WATERSHED_AREA_SQ_M, CUBIC_METERS_TO_CUBIC_FEET, SECONDS_PER_DAY def calculate_discharge_from_precipitation( diff --git a/save_results.py b/uvdat_flood_sim/save_results.py similarity index 96% rename from save_results.py rename to uvdat_flood_sim/save_results.py index 2195cf4..fca48fe 100644 --- a/save_results.py +++ b/uvdat_flood_sim/save_results.py @@ -1,6 +1,6 @@ import numpy -from pathlib import Path -from constants import OUTPUTS_FOLDER, GEOSPATIAL_PROJECTION, GEOSPATIAL_BOUNDS + +from .constants import OUTPUTS_FOLDER, GEOSPATIAL_PROJECTION, GEOSPATIAL_BOUNDS def rasterio_write(results, output_path): diff --git a/utils.py b/uvdat_flood_sim/utils.py similarity index 100% rename from utils.py rename to uvdat_flood_sim/utils.py