Skip to content

Commit

Permalink
Merge pull request #12 from piyueh/dev
Browse files Browse the repository at this point in the history
The development iteration addresses the following issues

    Issue #7: fixed
    Issue #8: done
    Issue #9: done
    Issue #10: added two regression tests that also test basic usage and functionality. Regression 1 also tests the evaporation, and regression 2 also tests the in-land waterbodies.
    Issue #11: done
  • Loading branch information
piyueh authored Jan 8, 2021
2 parents 032e867 + 2d18ee0 commit dc85441
Show file tree
Hide file tree
Showing 113 changed files with 1,388 additions and 342 deletions.
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
cmake_minimum_required(VERSION 3.14)

# cached variables
set(CMAKE_BUILD_TYPE RELEASE CACHE STRING "Either DEBUG or RELEASE")
set(CMAKE_BUILD_TYPE RELEASE CACHE STRING "Either DEBUG, Debug, RELEASE, or Release")
set(CMAKE_Fortran_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "Compilation flags for release build.")
set(CMAKE_Fortran_FLAGS_Release "-O3 -DNDEBUG" CACHE STRING "Compilation flags for release build.")
set(CMAKE_Fortran_FLAGS_DEBUG "-g" CACHE STRING "Compilation flags for debug build.")
set(CMAKE_Fortran_FLAGS_Debug "-g" CACHE STRING "Compilation flags for debug build.")

# project initialization
project(geoclaw-landspill Fortran)
Expand Down Expand Up @@ -45,7 +47,7 @@ endif()
if(SKBUILD)
message(STATUS "Built using scikit-build -- yes")
find_package(PythonExtensions REQUIRED) # scikit-build tries to set variables to this package?
set(DEST "geoclaw-landspill")
set(DEST "gclandspill")
else()
message(STATUS "Built using scikit-build -- no")
set(DEST "${CMAKE_INSTALL_LIBDIR}/gclandspill")
Expand All @@ -56,7 +58,7 @@ message(STATUS "Python packages/modules will install to ${DEST}")
add_subdirectory(third-party)

# main program
add_subdirectory(geoclaw-landspill)
add_subdirectory(gclandspill)

# print info
message("")
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include pyproject.toml
include CMakeLists.txt

# main source files and cmake files
graft geoclaw-landspill
graft gclandspill
include third-party/CMakeLists.txt

# install amrclaw's Python module
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# use this variable to shorten the paths
set(LANDSPILLLIB "${CMAKE_SOURCE_DIR}/geoclaw-landspill/src")
set(LANDSPILLLIB "${CMAKE_CURRENT_SOURCE_DIR}/src")

# geoclaw-landspill-bin
add_executable(geoclaw-landspill-bin
Expand Down
2 changes: 1 addition & 1 deletion geoclaw-landspill/__init__.py → gclandspill/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
from . import data

# meta
__version__ = "1.0.dev1"
__version__ = "1.0.dev2"
__author__ = "Pi-Yueh Chuang <[email protected]>"
File renamed without changes.
100 changes: 78 additions & 22 deletions geoclaw-landspill/_misc.py → gclandspill/_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import os
import sys
import pathlib
import argparse
import importlib.util

try:
Expand Down Expand Up @@ -145,33 +146,88 @@ def process_path(path, parent, default):
return pathlib.Path(parent).joinpath(path)


def update_frame_range(frame_ed: int, rundata):
"""Update the frame range in args.
def extract_info_from_setrun(args: argparse.Namespace):
"""Extract frequently used information from a setrun.py and write to a CMD argument object.
In post-processing functions, Some information is frequently requested from a setrun.py and set
into a argparse.Namespace object. This function does this job. Currently, the following values
are processed:
* args.level: maximum AMR level
* args.frame_ed: the end frame number
* args.dry_tol: dry tolerance
* args.topofiles: a list of topography file paths (abs paths)
If the provided `args` does not have these keys present, they will be ignore, except
`topofiles`. Currently, no subcommand set `topofiles` in `args` in geoclaw-landspill. So
`topofiles` will always be created in this function.
The provided `args` must have the key `case`. And it is assumed to be a pathlib.Path object.
Arguments
---------
frame_ed : int
The original end frame number.
rundata : clawutil.ClawRunData
The configuration object of a simulation case.
args : argparse.Namespace
The CMD arguments parsed by the sub-parsers of subcommands.
Returns
-------
new_frame_ed : int
The updated value of end frame number.
The same `args` object with updated values.
"""

if frame_ed is not None:
new_frame_ed = frame_ed + 1 # plus 1 so can be used as the `end` in the `range` function
elif rundata.clawdata.output_style == 1: # if it's None, and the style is 1
new_frame_ed = rundata.clawdata.num_output_times
if rundata.clawdata.output_t0:
new_frame_ed += 1
elif rundata.clawdata.output_style == 2: # if it's None, and the style is 2
new_frame_ed = len(rundata.clawdata.output_times)
elif rundata.clawdata.output_style == 3: # if it's None, and the style is 3
new_frame_ed = int(rundata.clawdata.total_steps / rundata.clawdata.output_step_interval)
if rundata.clawdata.output_t0:
new_frame_ed += 1

return new_frame_ed
def test_and_set_amr_level():
"""Local function to avoid pylint's complaint: test and set AMR maximum level."""
try:
if args.level is None:
args.level = rundata.amrdata.amr_levels_max
except AttributeError as err:
if str(err).startswith("'Namespace' object"):
pass

def test_and_set_frame_ed():
"""Local function to avoid pylint's complaint: test and set end frame number."""
try:
if args.frame_ed is not None:
args.frame_ed += 1 # plus 1 so it can be used as the `end` in the `range` function
elif rundata.clawdata.output_style == 1: # if it's None, and the style is 1
args.frame_ed = rundata.clawdata.num_output_times
if rundata.clawdata.output_t0:
args.frame_ed += 1
elif rundata.clawdata.output_style == 2: # if it's None, and the style is 2
args.frame_ed = len(rundata.clawdata.output_times)
elif rundata.clawdata.output_style == 3: # if it's None, and the style is 3
args.frame_ed = rundata.clawdata.total_steps // rundata.clawdata.output_step_interval
if rundata.clawdata.output_t0:
args.frame_ed += 1
except AttributeError as err:
if str(err).startswith("'Namespace' object"):
pass

def test_and_set_dry_tol():
"""Local function to avoid pylint's complaint: test and set dry tolerance."""
try:
if args.dry_tol is None:
args.dry_tol = rundata.geo_data.dry_tolerance
except AttributeError as err:
if str(err).startswith("'Namespace' object"):
pass

# get the case's setrun data
rundata = import_setrun(args.case).setrun()

test_and_set_amr_level()
test_and_set_frame_ed()
test_and_set_dry_tol()

# always create topofiles
args.topofiles = []
for topo in rundata.topo_data.topofiles:
if topo[0] != 3:
raise WrongTopoFileError("Only accept type-3 topography: {} at {}".format(*topo))

topo[-1] = pathlib.Path(topo[-1])
if not topo[-1].is_absolute():
topo[-1] = args.case.joinpath(topo[-1]).resolve()

args.topofiles.append(topo[-1])

return args
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,12 @@ def get_topo_max(soln_dir: os.PathLike, frame_bg: int, frame_ed: int, level: int
return vmax


def get_topo_lims(topo_files: Sequence[Tuple[int, os.PathLike]], **kwargs):
def get_topo_lims(topo_files: Sequence[os.PathLike], **kwargs):
"""Get the min and max elevation from a set of topography files.
Arguments
---------
topo_files : tuple/lsit of sub-tuples/lists of [int, pathlike]
topo_files : tuple/lsit of pathlike.PathLike
A list of list following the topography files specification in GeoClaw's settings.
**kwargs :
Available keyword arguments are:
Expand All @@ -275,11 +275,7 @@ def get_topo_lims(topo_files: Sequence[Tuple[int, os.PathLike]], **kwargs):
extent = None if "extent" not in kwargs else kwargs["extent"]

# use mosaic raster to obtain interpolated terrain
rasters = []
for topo in topo_files:
if topo[0] != 3:
raise _misc.WrongTopoFileError("Only accept type 3 topography file: {}".format(topo[0]))
rasters.append(rasterio.open(topo[-1], "r"))
rasters = [rasterio.open(topo, "r") for topo in topo_files]

# merge and interplate
dst, _ = rasterio.merge.merge(rasters, extent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,26 +237,8 @@ def convert_to_netcdf(args: argparse.Namespace):
args.case = pathlib.Path(args.case).expanduser().resolve()
_misc.check_folder(args.case)

# case's setrun data
rundata = _misc.import_setrun(args.case).setrun()

# process target AMR level
if args.level is None:
args.level = rundata.amrdata.amr_levels_max

# process args.frame_ed
if args.frame_ed is not None:
args.frame_ed += 1 # plus 1 so can be used as the `end` in the `range` function
elif rundata.clawdata.output_style == 1: # if it's None, and the style is 1
args.frame_ed = rundata.clawdata.num_output_times
if rundata.clawdata.output_t0:
args.frame_ed += 1
elif rundata.clawdata.output_style == 2: # if it's None, and the style is 2
args.frame_ed = len(rundata.clawdata.output_times)
elif rundata.clawdata.output_style == 3: # if it's None, and the style is 3
args.frame_ed = int(rundata.clawdata.total_steps / rundata.clawdata.output_step_interval)
if rundata.clawdata.output_t0:
args.frame_ed += 1
# process level, frame_ed, dry_tol, and topofiles
args = _misc.extract_info_from_setrun(args)

# process args.soln_dir
args.soln_dir = _misc.process_path(args.soln_dir, args.case, "_output")
Expand All @@ -281,10 +263,6 @@ def convert_to_netcdf(args: argparse.Namespace):
args.res = min(_postprocessing.calc.get_soln_res(
args.soln_dir, args.frame_bg, args.frame_ed, args.level))

# process args.dry_rol
if args.dry_tol is None: # get the dry tolerance from setrun.py
args.dry_tol = rundata.geo_data.dry_tolerance

# process args.use_case_settings and timestamp information
case_settings_file = args.case.joinpath("case_settings.txt")

Expand Down
Loading

0 comments on commit dc85441

Please sign in to comment.