Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions compiler_mac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#TODO add options for clean/noclean, make/nomake, cython/nocython
#TODO include instuctions on blowing away entire package for fresh install e.g. rm -r ~/venvs/mesh/lib/python3.6/site-packages/troute/*
#set root folder of github repo (should be named t-route)
REPOROOT=`pwd`
#For each build step, you can set these to true to make it build
#or set it to anything else (or unset) to skip that step
build_mc_kernel=true
build_diffusive_tulane_kernel=true
build_reservoir_kernel=true
build_framework=true
build_routing=true
build_config=true
build_nwm=true
build_bmi=true

if [ -z "$F90" ]
then
export F90="gfortran"
echo "using F90=${F90}"
fi
if [ -z "$CC" ]
then
export CC="gcc"
echo "using CC=${CC}"
fi

#preserve old/default behavior of installing packages with -e
WITH_EDITABLE=true
if [ "$1" == 'no-e' ]
then
WITH_EDITABLE=false
fi

#if you have custom static library paths, uncomment below and export them
export LIBRARY_PATH=/opt/local/lib/:$LIBRARY_PATH
#if you have custom dynamic library paths, uncomment below and export them
export LD_LIBRARY_PATHS=/opt/local/lib/:$LD_LIBRARY_PATHS
if [ -z "$NETCDF" ]
then
#export NETCDFINC=/usr/include/openmpi-x86_64/
export NETCDFINC=/opt/local/include/
# set alternative NETCDF variable include path, for example for WSL
# (Windows Subsystems for Linux).
#
# EXAMPLE USAGE: export NETCDFALTERNATIVE=$HOME/.conda/envs/py39/include/
# (before ./compiler.sh)
if [ -n "$NETCDFALTERNATIVE" ]
then
echo "using alternative NETCDF inc ${NETCDFALTERNATIVE}"
export NETCDFINC=$NETCDFALTERNATIVE
fi
else
export NETCDFINC="${NETCDF}"
fi
echo "using NETCDFINC=${NETCDFINC}"

if [[ "$build_mc_kernel" == true ]]; then
#building reach and resevoir kernel files .o
cd $REPOROOT/src/kernel/muskingum/
make clean
make || exit
make install || exit
fi

if [[ "$build_diffusive_tulane_kernel" == true ]]; then
#building reach and resevoir kernel files .o
cd $REPOROOT/src/kernel/diffusive/
make clean
make diffusive.o
make pydiffusive.o
make chxsec_lookuptable.o
make pychxsec_lookuptable.o
make install || exit
fi

if [[ "$build_reservoir_kernel" == true ]]; then
cd $REPOROOT/src/kernel/reservoir/
make clean
#make NETCDFINC=`nc-config --includedir` || exit
#make binding_lp.a
#make install_lp || exit
make
make install_lp || exit
make install_rfc || exit

fi

if [[ "$build_framework" == true ]]; then
#creates troute package
cd $REPOROOT/src/troute-network
rm -rf build

if [[ ${WITH_EDITABLE} == true ]]; then
pip install --no-build-isolation --config-setting='--build-option=--use-cython' --editable . --config-setting='editable_mode=compat' || exit
else
pip install --no-build-isolation --config-setting='--build-option=--use-cython' . || exit
fi
fi

if [[ "$build_routing" == true ]]; then
#updates troute package with the execution script
cd $REPOROOT/src/troute-routing
rm -rf build

if [[ ${WITH_EDITABLE} == true ]]; then
pip install --no-build-isolation --config-setting='--build-option=--use-cython' --editable . --config-setting='editable_mode=compat' || exit
else
pip install --no-build-isolation --config-setting='--build-option=--use-cython' . || exit
fi
fi

if [[ "$build_config" == true ]]; then
#updates troute package with the execution script
cd $REPOROOT/src/troute-config
if [[ ${WITH_EDITABLE} == true ]]; then
pip install --editable . || exit
else
pip install . || exit
fi
fi

if [[ "$build_nwm" == true ]]; then
#updates troute package with the execution script
cd $REPOROOT/src/troute-nwm
if [[ ${WITH_EDITABLE} == true ]]; then
pip install --editable . || exit
else
pip install . || exit
fi
fi

if [[ "$build_bmi" == true ]]; then
cd $REPOROOT/src/troute-bmi
if [[ ${WITH_EDITABLE} == true ]]; then
pip install --editable . || exit
else
pip install . || exit
fi
fi
2 changes: 1 addition & 1 deletion src/troute-network/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
sys.argv.remove("--use-cython")
else:
USE_CYTHON = False

USE_CYTHON = True
ext = "pyx" if USE_CYTHON else "c"

# adapted from https://stackoverflow.com/a/5192738/489116 and https://stackoverflow.com/a/32192172/489116
Expand Down
24 changes: 21 additions & 3 deletions src/troute-network/troute/HYFeaturesNetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,20 @@ def read_layer(layer_name):
lakes["lake_id"] = lakes["lake_id"].astype(int)
lakes = lakes.merge(hydro[["hl_link", "id", "hl_reference"]], left_on="lake_id", right_on="hl_link", how="left")

# add hl_uri to nexus
nexus = nexus.merge(hydro[["nex_id", "hl_uri"]], left_on="id", right_on="nex_id", how="left")
# hydrolocations may call the nexus key "nex_id" or simply "id"
if "nex_id" in hydro.columns:
right_col = "nex_id"
elif "id" in hydro.columns:
right_col = "id"
else:
raise KeyError("HYFeaturesNetwork: hydrolocations layer missing expected nexus id column. available: " + ", ".join(list(hydro.columns)))

# normalize to 'nex_id' for downstream code, then merge to get hl_uri for nexus
if right_col != "nex_id":
hydro = hydro.rename(columns={right_col: "nex_id"})

if not nexus.empty:
nexus = nexus.merge(hydro[["nex_id", "hl_uri"]], left_on="id", right_on="nex_id", how="left")

return flowpaths, lakes, network, nexus

Expand Down Expand Up @@ -645,7 +657,13 @@ def preprocess_waterbodies(self, lakes, nexus):
self._duplicate_ids_df = pd.DataFrame()
self._gl_climatology_df = pd.DataFrame()

self._dataframe = self.dataframe.drop("waterbody", axis=1).drop_duplicates()
# drop 'waterbody' if present; avoid KeyError when it's missing
if "waterbody" in self.dataframe.columns:
self._dataframe = self.dataframe.drop(columns=["waterbody"]).drop_duplicates()
else:
#import warnings
#warnings.warn("HYFeaturesNetwork: 'waterbody' column not present; skipping drop")
self._dataframe = self.dataframe.drop_duplicates()

def preprocess_data_assimilation(self, network):
if not network.empty:
Expand Down
2 changes: 1 addition & 1 deletion src/troute-routing/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
sys.argv.remove("--use-cython")
else:
USE_CYTHON = False

USE_CYTHON = True
ext = "pyx" if USE_CYTHON else "c"

# adapted from https://stackoverflow.com/a/5192738/489116 and https://stackoverflow.com/a/32192172/489116
Expand Down