Skip to content

Commit

Permalink
Add ocean topography smoothing tool
Browse files Browse the repository at this point in the history
  • Loading branch information
xylar committed Nov 17, 2023
1 parent e78dc20 commit e9cd35d
Show file tree
Hide file tree
Showing 7 changed files with 942 additions and 1 deletion.
12 changes: 11 additions & 1 deletion conda_package/recipe/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ cp -r ocean landice visualization mesh_tools conda_package
cd conda_package
${PYTHON} -m pip install . --no-deps -vv

# build and install ocean topography smoothing tool
cd ${SRC_DIR}/conda_package/ocean/smooth_topo
mkdir build
cd build
cmake \
-D CMAKE_INSTALL_PREFIX=${PREFIX} \
-D CMAKE_BUILD_TYPE=Release \
..
cmake --build .
cmake --install .

# build and install sea ice partitioning tool
cd ${SRC_DIR}/conda_package/mesh_tools/seaice_grid_tools
mkdir build
Expand Down Expand Up @@ -40,4 +51,3 @@ cmake \
..
cmake --build .
cmake --install .

17 changes: 17 additions & 0 deletions ocean/smooth_topo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cmake_minimum_required (VERSION 3.0.2)
enable_language(Fortran)
project (ocean_smooth_topo)

list (APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)

set (NETCDF_F90 "YES")
find_package (NetCDF REQUIRED)

message (STATUS "NETCDF_INCLUDES=${NETCDF_INCLUDES}")
message (STATUS "NETCDF_LIBRARIES=${NETCDF_LIBRARIES}")

include_directories(${NETCDF_INCLUDES})
add_executable (ocean_smooth_topo_skip_land_ice smooth_topo_skip_land_ice.F90)
target_link_libraries (ocean_smooth_topo_skip_land_ice ${NETCDF_LIBRARIES})

install (TARGETS ocean_smooth_topo_skip_land_ice DESTINATION bin)
19 changes: 19 additions & 0 deletions ocean/smooth_topo/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Authors: Adrian Turner, Mat Maltrud

A tool for smoothing bathymetry in an MPAS-Ocean initial condition with a
Gaussian filter with a characteristic length scale (stdDeviation) and cut-off
distance (distanceLimit). The smoothing is only applied if the original
maxLevelCell is larger than a given threshold (minLevelForSmoothing). Smoothing
is applied over a given number of iterations (numSmoothingPasses).

An example namelist file is:

&smooth
filename_depth_in = "mpaso.IcoswISC30E3r2.20230901.nc"
filename_depth_out = "smooth.IcoswISC30E3r2.r200e100.1pass.min5.skipLandIce.231115.nc"
filename_mpas_mesh = "mpaso.IcoswISC30E3r2.20230901.nc"
distanceLimit = 200.
stdDeviation = 100.
numSmoothingPasses = 1
minLevelForSmoothing = 5
/
71 changes: 71 additions & 0 deletions ocean/smooth_topo/cmake/FindNetCDF.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# - Find NetCDF
# Find the native NetCDF includes and library
#
# NETCDF_INCLUDES - where to find netcdf.h, etc
# NETCDF_LIBRARIES - Link these libraries when using NetCDF
# NETCDF_FOUND - True if NetCDF found including required interfaces (see below)
#
# Your package can require certain interfaces to be FOUND by setting these
#
# NETCDF_CXX - require the C++ interface and link the C++ library
# NETCDF_F77 - require the F77 interface and link the fortran library
# NETCDF_F90 - require the F90 interface and link the fortran library
#
# The following are not for general use and are included in
# NETCDF_LIBRARIES if the corresponding option above is set.
#
# NETCDF_LIBRARIES_C - Just the C interface
# NETCDF_LIBRARIES_CXX - C++ interface, if available
# NETCDF_LIBRARIES_F77 - Fortran 77 interface, if available
# NETCDF_LIBRARIES_F90 - Fortran 90 interface, if available
#
# Normal usage would be:
# set (NETCDF_F90 "YES")
# find_package (NetCDF REQUIRED)
# target_link_libraries (uses_f90_interface ${NETCDF_LIBRARIES})
# target_link_libraries (only_uses_c_interface ${NETCDF_LIBRARIES_C})

if (NETCDF_INCLUDES AND NETCDF_LIBRARIES)
# Already in cache, be silent
set (NETCDF_FIND_QUIETLY TRUE)
endif (NETCDF_INCLUDES AND NETCDF_LIBRARIES)

find_path (NETCDF_INCLUDES netcdf.h
HINTS NETCDF_DIR ENV NETCDF_DIR)

find_library (NETCDF_LIBRARIES_C NAMES netcdf)
mark_as_advanced(NETCDF_LIBRARIES_C)

set (NetCDF_has_interfaces "YES") # will be set to NO if we're missing any interfaces
set (NetCDF_libs "${NETCDF_LIBRARIES_C}")

get_filename_component (NetCDF_lib_dirs "${NETCDF_LIBRARIES_C}" PATH)

macro (NetCDF_check_interface lang header libs)
if (NETCDF_${lang})
find_path (NETCDF_INCLUDES_${lang} NAMES ${header}
HINTS "${NETCDF_INCLUDES}" NO_DEFAULT_PATH)
find_library (NETCDF_LIBRARIES_${lang} NAMES ${libs}
HINTS "${NetCDF_lib_dirs}" NO_DEFAULT_PATH)
mark_as_advanced (NETCDF_INCLUDES_${lang} NETCDF_LIBRARIES_${lang})
if (NETCDF_INCLUDES_${lang} AND NETCDF_LIBRARIES_${lang})
list (INSERT NetCDF_libs 0 ${NETCDF_LIBRARIES_${lang}}) # prepend so that -lnetcdf is last
else (NETCDF_INCLUDES_${lang} AND NETCDF_LIBRARIES_${lang})
set (NetCDF_has_interfaces "NO")
message (STATUS "Failed to find NetCDF interface for ${lang}")
endif (NETCDF_INCLUDES_${lang} AND NETCDF_LIBRARIES_${lang})
endif (NETCDF_${lang})
endmacro (NetCDF_check_interface)

NetCDF_check_interface (CXX netcdfcpp.h netcdf_c++)
NetCDF_check_interface (F77 netcdf.inc netcdff)
NetCDF_check_interface (F90 netcdf.mod netcdff)

set (NETCDF_LIBRARIES "${NetCDF_libs}" CACHE STRING "All NetCDF libraries required for interface level")

# handle the QUIETLY and REQUIRED arguments and set NETCDF_FOUND to TRUE if
# all listed variables are TRUE
include (FindPackageHandleStandardArgs)
find_package_handle_standard_args (NetCDF DEFAULT_MSG NETCDF_LIBRARIES NETCDF_INCLUDES NetCDF_has_interfaces)

mark_as_advanced (NETCDF_LIBRARIES NETCDF_INCLUDES)
23 changes: 23 additions & 0 deletions ocean/smooth_topo/cmake/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Copyright $(git shortlog -s)
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1 change: 1 addition & 0 deletions ocean/smooth_topo/cmake/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
These files are from https://github.com/jedbrown/cmake-modules
Loading

0 comments on commit e9cd35d

Please sign in to comment.