SHELL = cmd
###############################
# Load environment variables
i n c l u d e . e n v
export $( shell sed 's /=.*//' .env )
CURRENT_DIR = $( shell pwd )
###############################
# Create python virtual environment
.PHONY : venv -init
venv-init : ##@environment Setup virtual environment
conda env create -f environment.yml --prefix= .venv
.PHONY : venv -activate
venv-activate : ##@environment Activates the virtual environment
activate $( CURRENT_DIR) /.venv
.PHONY : venv -update
venv-update : ##@environment Updates to latest packages
conda update ipykernel && conda update --prefix .venv --all
.PHONY : venv -requirements -install
venv-requirements-install : ##@environment Ensures environment.yml packages are installed
conda env update
# To install new packages: conda install --prefix .venv PACKAGE
###############################
notebook : ##@notebooks Open jupyter notebook in venv
activate ./.venv && jupyter notebook
###############################
# Get data from network drive
.PHONY : push -data pull -data
push-data : ##@data Copies data from ./data/ to data backup directory
rclone copy ./data/ $( DATA_BACKUP_DIR) --exclude "*.las" --progress
# We probably don't want to pull the raw LIDAR .las files, so lets exclude them
pull-data : ##@data Copies data from data backup directory to ./data/
rclone copy $( DATA_BACKUP_DIR) ./data/ --exclude "*.las" --progress
###############################
# Process data
.PHONY : process -mat
# Command for activating our virtual environment and calling the CLI entry point
PYTHON_CLI = activate ./.venv && python ./src/cli.py
impacts : ./data /interim /impacts_forecasted_foreshore_slope_sto 06.csv ./data /interim /impacts_forecasted_mean_slope_sto 06.csv ./data /interim /impacts_observed .csv ##@products makes obsered and forecasted impacts
### Parses raw matfiles
./data/raw/processed_shorelines/orientations.mat : ./data /raw /processed_shorelines /profiles .mat
$( MATLAB_PATH) -nosplash -r " cd $( CURRENT_DIR) ; run('./src/data/beach_orientations.m'); quit "
./data/interim/sites.csv ./data/interim/profiles.csv : ./data /raw /processed_shorelines /profiles .mat
$( PYTHON_CLI) create-sites-and-profiles-csv \
--profiles-mat "./data/raw/processed_shorelines/profiles.mat" \
--profiles-output-file "./data/interim/profiles.csv" \
--sites-output-file "./data/interim/sites.csv"
./data/interim/waves.csv : ./data /interim /sites .csv ./data /raw /processed_shorelines /waves .mat
$( PYTHON_CLI) create-waves-csv \
--waves-mat "./data/raw/processed_shorelines/waves.mat" \
--sites-csv "./data/interim/sites.csv" \
--output-file "./data/interim/waves.csv"
./data/interim/tides.csv : ./data /interim /sites .csv ./data /raw /processed_shorelines /tides .mat
$( PYTHON_CLI) create-tides-csv \
--tides-mat "./data/raw/processed_shorelines/tides.mat" \
--sites-csv "./data/interim/sites.csv" \
--output-file "./data/interim/tides.csv"
./data/interim/profile_features_crest_toes.csv : ./data /raw /profile_features_chris_leaman /profile_features_chris_leaman .csv
$( PYTHON_CLI) create-crest-toes \
--profile-features-csv "./data/raw/profile_features_chris_leaman/profile_features_chris_leaman.csv" \
--profiles-csv "./data/interim/profiles.csv" \
--output-file "./data/interim/profile_features_crest_toes.csv" \
### TWLs
./data/interim/twl_foreshore_slope_sto06.csv : ./data /interim /waves .csv ./data /interim /tides .csv ./data /interim /profiles .csv ./data /interim /sites .csv ./data /interim /profile_features_crest_toes .csv
$( PYTHON_CLI) create-twl-forecast \
--waves-csv "./data/interim/waves.csv" \
--tides-csv "./data/interim/tides.csv" \
--profiles-csv "./data/interim/profiles.csv" \
--profile-features-csv "./data/interim/profile_features_crest_toes.csv" \
--runup-function "sto06" \
--slope "foreshore" \
--profile-type "prestorm" \
--output-file "./data/interim/twl_foreshore_slope_sto06.csv"
./data/interim/twl_mean_slope_sto06.csv : ./data /interim /waves .csv ./data /interim /tides .csv ./data /interim /profiles .csv ./data /interim /sites .csv ./data /interim /profile_features_crest_toes .csv
$( PYTHON_CLI) create-twl-forecast \
--waves-csv "./data/interim/waves.csv" \
--tides-csv "./data/interim/tides.csv" \
--profiles-csv "./data/interim/profiles.csv" \
--profile-features-csv "./data/interim/profile_features_crest_toes.csv" \
--runup-function "sto06" \
--slope "mean" \
--profile-type "prestorm" \
--output-file "./data/interim/twl_mean_slope_sto06.csv"
### IMPACTS
./data/interim/impacts_observed.csv : ./data /interim /profiles .csv ./data /interim /profile_features_crest_toes .csv ./data /raw /profile_features_chris_leaman /profile_features_chris_leaman .csv
$( PYTHON_CLI) create-observed-impacts \
--profiles-csv "./data/interim/profiles.csv" \
--profile-features-crest-toes-csv "./data/interim/profile_features_crest_toes.csv" \
--raw-profile-features-csv "./data/raw/profile_features_chris_leaman/profile_features_chris_leaman.csv" \
--output-file "./data/interim/impacts_observed.csv"
./data/interim/impacts_forecasted_mean_slope_sto06.csv : ./data /interim /profile_features_crest_toes .csv ./data /interim /twl_mean_slope_sto 06.csv
$( PYTHON_CLI) create-forecasted-impacts \
--profile-features-csv "./data/interim/profile_features_crest_toes.csv" \
--forecasted-twl-csv "./data/interim/twl_mean_slope_sto06.csv" \
--output-file "./data/interim/impacts_forecasted_mean_slope_sto06.csv"
./data/interim/impacts_forecasted_foreshore_slope_sto06.csv : ./data /interim /profile_features_crest_toes .csv ./data /interim /twl_foreshore_slope_sto 06.csv
$( PYTHON_CLI) create-forecasted-impacts \
--profile-features-csv "./data/interim/profile_features_crest_toes.csv" \
--forecasted-twl-csv "./data/interim/twl_foreshore_slope_sto06.csv" \
--output-file "./data/interim/impacts_forecasted_foreshore_slope_sto06.csv"
### GEOJSONs
geojsons : ./data /interim /impacts_forecasted_mean_slope_sto 06.geojson ./data /interim /impacts_forecasted_mean_slope_sto 06_R_high .geojson ./data /interim /profile_features_crest_toes .geojson ./data /interim /sites .geojson
./data/interim/impacts_forecasted_mean_slope_sto06.geojson : ./data /interim /impacts_forecasted_mean_slope_sto 06.csv ./data /interim /impacts_observed .csv
$( PYTHON_CLI) impacts-to-geojson \
--sites-csv "./data/interim/sites.csv" \
--observed-impacts-csv "./data/interim/impacts_observed.csv" \
--forecast-impacts-csv "./data/interim/impacts_forecasted_mean_slope_sto06.csv" \
--output-geojson "./data/interim/impacts_forecasted_mean_slope_sto06.geojson"
./data/interim/impacts_forecasted_mean_slope_sto06_R_high.geojson : ./data /interim /impacts_forecasted_mean_slope_sto 06.csv
$( PYTHON_CLI) r-high-to-geojson \
--sites-csv "./data/interim/sites.csv" \
--profiles-csv "./data/interim/profiles.csv" \
--crest-toes-csv "./data/interim/profile_features_crest_toes.csv" \
--impacts-csv "./data/interim/impacts_forecasted_mean_slope_sto06.csv" \
--output-geojson "./data/interim/impacts_forecasted_mean_slope_sto06_R_high.geojson"
./data/interim/profile_features_crest_toes.geojson : ./data /interim /profile_features_crest_toes .csv
$( PYTHON_CLI) profile-features-crest-toes-to-geojson \
--sites-csv "./data/interim/sites.csv" \
--profile-features-csv "./data/interim/profile_features_crest_toes.csv" \
--output-geojson "./data/interim/profile_features_crest_toes.geojson"
./data/interim/sites.geojson : ./data /interim /sites .csv
$( PYTHON_CLI) sites-csv-to-geojson \
--input-csv "./data/interim/sites.csv" \
--output-geojson "./data/interim/sites.geojson"
###############################
# Misc commands
format : ./src /*.py ##@misc Check python file formatting
activate ./.venv && black --line-length 120 "src/"
###############################
# Help command
.DEFAULT_GOAL := help
.PHONY : help
# Refer to https://gist.github.com/prwhite/8168133
#COLORS
GREEN := $( shell tput -Txterm setaf 2)
WHITE := $( shell tput -Txterm setaf 7)
YELLOW := $( shell tput -Txterm setaf 3)
RESET := $( shell tput -Txterm sgr0)
# Add the following 'help' target to your Makefile
# And add help text after each target name starting with '\#\#'
# A category can be added with @category
HELP_FUN = \
%help; \
while ( <>) { push @{ $$ help{ $$ 2 // 'options' } } , [ $$ 1, $$ 3] if /^( [ a-zA-Z\- ] +) \s *:.*\# \# ( ?:@( [ a-zA-Z\- ] +) ) ?\s ( .*) $$ / } ; \
print "usage: make [target]\n\n" ; \
for ( sort keys %help) { \
print " ${ WHITE } $$ _: ${ RESET } \n " ; \
for ( @{ $$ help{ $$ _} } ) { \
$$ sep = " " x ( 32 - length $$ _->[ 0] ) ; \
print " ${ YELLOW } $$ _->[0] ${ RESET } $$ sep ${ GREEN } $$ _->[1] ${ RESET } \n " ; \
} ; \
print "\n" ; }
help : ##@other Show this help.
@perl -e '$(HELP_FUN)' $( MAKEFILE_LIST)