Skip to content

Commit

Permalink
Merge pull request #60 from noaa-ocs-modeling/bugfix/hfuncoll
Browse files Browse the repository at this point in the history
Fix subtidal flow limiter bug in collector hfun
  • Loading branch information
SorooshMani-NOAA authored Feb 11, 2023
2 parents 1fe13b0 + ea0c4b0 commit f5cfae2
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 48 deletions.
8 changes: 6 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
[MASTER]
fail-on=E
fail-under=9.84
fail-under=9.90
py-version=3.9.7
# As a temporary workaround for https://github.com/PyCQA/pylint/issues/4577
init-hook = "import astroid; astroid.context.InferenceContext.max_inferred = 250"

[MESSAGES CONTROL]
disable=fixme,
disable=arguments-differ,
fixme,
invalid-name,
unused-variable,
unused-argument,
Expand All @@ -23,6 +24,7 @@ disable=fixme,
missing-module-docstring,
missing-class-docstring,
missing-function-docstring,
super-init-not-called,
unspecified-encoding

[TYPECHECK]
Expand All @@ -34,3 +36,5 @@ generated-members=ocsmesh.driver.JigsawDriver.hfun,
ocsmesh.mesh.base.BaseMesh._msh_t,
ocsmesh.mesh.mesh.EuclideanMesh._boundaries,
ocsmesh.mesh.mesh.Mesh.*
ignore-patterns=interp.py,
cmd.py
2 changes: 1 addition & 1 deletion ocsmesh/cli/remesh_by_shape_factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
_logger = logging.getLogger(__name__)

# Enable KML driver
#from https://stackoverflow.com/questions/72960340/attributeerror-nonetype-object-has-no-attribute-drvsupport-when-using-fiona
#from stackoverflow issue 72960340
supported_drivers['KML'] = 'rw'
supported_drivers['LIBKML'] = 'rw'

Expand Down
3 changes: 1 addition & 2 deletions ocsmesh/cli/subset_n_combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ def _get_polygon_from_geom_collection(self, shape):

if not isinstance(shape, GeometryCollection):
raise ValueError(
"Expected a GeometryCollection, received {}".format(
type(shape)))
f"Expected a GeometryCollection, received {type(shape)}")

polygon_list = []
for g in shape.geoms:
Expand Down
10 changes: 5 additions & 5 deletions ocsmesh/features/constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from scipy.spatial import cKDTree
from scipy import constants

import ocsmesh.utils as utils
from ocsmesh import utils

ConstraintValueType = Enum("ConstraintValueType", "MIN MAX")

Expand Down Expand Up @@ -269,13 +269,13 @@ def apply(
Depth values to be used for Courant number approximations
old_values : array of floats
Values of mesh size function before applying the constraint
\*args : list
*args : list
List of arguments not handled by this apply method (
used in other constraints)
\*\*kwargs : dict
**kwargs : dict
Dictionary of arguments not handled by this apply method (
used in other constraints)
Returns
-------
array of floats
Expand All @@ -296,7 +296,7 @@ def apply(
char_vel = u_mag + np.sqrt(constants.g * np.abs(ref_values))
# For overland where h < nu the characteristic velocity is 2 * sqrt(g*h)
char_vel[~depth_mask] = 2 * u_mag[~depth_mask]

temp_values = utils.get_element_size_courant(
char_vel, self._dt, self._value
)
Expand Down
1 change: 0 additions & 1 deletion ocsmesh/features/contour.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pathlib import Path
from abc import ABC, abstractmethod

class ContourBase(ABC):
Expand Down
2 changes: 1 addition & 1 deletion ocsmesh/geom/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def __init__(
nprocs = cpu_count() if nprocs == -1 else nprocs


self._elev_info = dict(zmin=zmin, zmax=zmax)
self._elev_info = {'zmin':zmin, 'zmax': zmax}
self._nprocs = nprocs
self._chunk_size = chunk_size
self._overlap = overlap
Expand Down
6 changes: 3 additions & 3 deletions ocsmesh/hfun/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ def __init__(
nprocs = cpu_count() if nprocs == -1 else nprocs

self._applied = False
self._size_info = dict(hmin=hmin, hmax=hmax)
self._size_info = {'hmin': hmin, 'hmax': hmax}
self._nprocs = nprocs
self._hfun_list = []
self._method = method
Expand Down Expand Up @@ -1584,7 +1584,7 @@ def _apply_flow_limiters(self) -> None:
hmin = self._size_info['hmin']
if hmax is None:
hmax = self._size_info['hmax']
hfun.add_subtidal_flow_limiter(hmin, hmax, zmax, zmin)
hfun.add_subtidal_flow_limiter(hmin, hmax, zmin, zmax)


def _apply_const_val(self):
Expand Down Expand Up @@ -2080,7 +2080,7 @@ def _apply_flow_limiters_fast(self, big_hfun: HfunRaster) -> None:
else:
zmin = max(zmin, -99990)

big_hfun.add_subtidal_flow_limiter(hmin, hmax, zmax, zmin)
big_hfun.add_subtidal_flow_limiter(hmin, hmax, zmin, zmax)

def _apply_const_val_fast(self, big_hfun):
"""Internal: apply specified constant value refinements.
Expand Down
14 changes: 9 additions & 5 deletions ocsmesh/hfun/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,14 @@ def add_subtidal_flow_limiter(
hfun_values = np.abs((1./3.)*(topobathy/dh))
# values = values.filled(np.max(values))

if hmin is not None:
hfun_values[np.where(hfun_values < hmin)] = hmin

if hmax is not None:
hfun_values[np.where(hfun_values > hmax)] = hmax

# Don't consider the applied values in the region
# outside the provided bounds
if upper_bound is not None:
idxs = np.where(topobathy > upper_bound)
hfun_values[idxs] = self.get_values(
Expand All @@ -1371,12 +1379,8 @@ def add_subtidal_flow_limiter(
hfun_values[idxs] = self.get_values(
band=1, window=window)[idxs]

if hmin is not None:
hfun_values[np.where(hfun_values < hmin)] = hmin

if hmax is not None:
hfun_values[np.where(hfun_values > hmax)] = hmax

# Apply global hmin and hmax
if self._hmin is not None:
hfun_values[np.where(hfun_values < self._hmin)] = self._hmin
if self._hmax is not None:
Expand Down
29 changes: 15 additions & 14 deletions ocsmesh/ops/combine_geom.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,21 @@ def __init__(
nprocs = cpu_count() if nprocs == -1 else nprocs
dem_files = [] if dem_files is None else dem_files

self._operation_info = dict(
dem_files=dem_files,
out_file=out_file,
out_format=out_format,
mesh_file=mesh_file,
mesh_mp_in=mesh_multipolygon,
ignore_mesh=ignore_mesh_final_boundary,
zmin=zmin,
zmax=zmax,
chunk_size=chunk_size,
overlap=overlap,
nprocs=nprocs,
out_crs=out_crs,
base_crs=base_crs)
self._operation_info = {
'dem_files': dem_files,
'out_file': out_file,
'out_format': out_format,
'mesh_file': mesh_file,
'mesh_mp_in': mesh_multipolygon,
'ignore_mesh': ignore_mesh_final_boundary,
'zmin': zmin,
'zmax': zmax,
'chunk_size': chunk_size,
'overlap': overlap,
'nprocs': nprocs,
'out_crs': out_crs,
'base_crs': base_crs
}

def run(self):

Expand Down
27 changes: 14 additions & 13 deletions ocsmesh/ops/combine_hfun.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,20 @@ def __init__(

self._base_exterior = None

self._operation_info = dict(
dem_files=dem_files,
out_file=out_file,
out_format=out_format,
mesh_file=mesh_file,
hmin=hmin,
hmax=hmax,
contours=contours,
constants=constants,
chunk_size=chunk_size,
overlap=overlap,
method=method,
nprocs=nprocs)
self._operation_info = {
'dem_files': dem_files,
'out_file': out_file,
'out_format': out_format,
'mesh_file': mesh_file,
'hmin': hmin,
'hmax': hmax,
'contours': contours,
'constants': constants,
'chunk_size': chunk_size,
'overlap': overlap,
'method': method,
'nprocs': nprocs
}

def run(self):

Expand Down
2 changes: 1 addition & 1 deletion ocsmesh/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -1824,7 +1824,7 @@ def resampling_method(self, resampling_method: Resampling) -> None:
"""Set `resampling_method`"""

if not isinstance(resampling_method, Resampling):
TypeError(
raise TypeError(
f'Argument resampling_method must be of type {Resampling}, '
f'not type {type(resampling_method)}.')
self._resampling_method = resampling_method
Expand Down

0 comments on commit f5cfae2

Please sign in to comment.