From 8dd7201c33633f120f0822ddab28431dd59b8a65 Mon Sep 17 00:00:00 2001 From: Matthew Masarik <86749872+MatthewMasarik-NOAA@users.noreply.github.com> Date: Thu, 12 May 2022 12:20:07 -0400 Subject: [PATCH] Buoy stats and metrics: wrapper scripts added (#7) buoy stats and metrics: python and bash wrapper scripts added --- validation/runstats.py | 48 +++++++++++++++++++ validation/ww3_run_stats.sh | 92 +++++++++++++++++++++++++++++++++++++ validation/ww3metrics.py | 2 +- validation/ww3stats.py | 2 +- 4 files changed, 142 insertions(+), 2 deletions(-) create mode 100755 validation/runstats.py create mode 100755 validation/ww3_run_stats.sh diff --git a/validation/runstats.py b/validation/runstats.py new file mode 100755 index 000000000..05e40d6fd --- /dev/null +++ b/validation/runstats.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +""" +runstats.py - sample driver for statistics and validation metric functions. +""" + +import sys +import copy +from ww3stats import ww3_pnt_stats +from ww3metrics import ww3_pnt_metrics + + +def main(argv): + ''' + PURPOSE: Main for calling statistics and metrics functions. + USAGE: python3 runstats.py [ [ [ ]]] + ''' + args=sys.argv[1:] + vmin=0; vmax=20; parm='hs' + if len(args) == 0: + sys.exit('python3 runstats.py [ [ [ ]]]') + elif len(args) == 1: + dat=copy.copy(args[0]) + elif len(args) == 2: + dat=copy.copy(args[0]); parm=copy.copy(args[1]) + elif len(args) == 3: + dat=copy.copy(args[0]); parm=copy.copy(args[1]); vmin=copy.copy(args[2]) + elif len(args) == 4: + dat=copy.copy(args[0]); parm=copy.copy(args[1]); vmin=copy.copy(args[2]); vmax=copy.copy(args[3]) + elif len(args) > 4: + sys.exit('python3 runstats.py [ [ [ ]]]') + + + print('\n* RUNSTATS *\n') + + print('\nCalling ww3_pnt_stats...') + ww3_pnt_stats(dat, parm, vmin, vmax) + + print('\nCalling ww3_pnt_metrics...') + ww3_pnt_metrics(dat, parm, vmin, vmax) + + print('\nRUNSTATS Complete.') + + + +if __name__ == "__main__": + main(sys.argv[1:]) diff --git a/validation/ww3_run_stats.sh b/validation/ww3_run_stats.sh new file mode 100755 index 000000000..88cdb9199 --- /dev/null +++ b/validation/ww3_run_stats.sh @@ -0,0 +1,92 @@ +#!/bin/bash + +# ww3_run_stats.sh +# PURPOSE: shell script wrapper around python buoy collocation +# and generation of statistics and metrics. +# +# USAGE: ww3_run_stats.sh [ [ []]] +# +export PATH=/scratch2/NCEPDEV/marine/Matthew.Masarik/wavpy/miniconda3/bin:${PATH} +export PYTHONPATH=/scratch2/NCEPDEV/marine/Matthew.Masarik/wavpy/miniconda3/pkgs:${PYTHONPATH} + +usage_str='ww3_run_stats.sh [ [ []]]' +if [[ $# -lt 1 ]] || [[ $# -gt 4 ]]; then echo $usage_str; exit; fi + +ww3_tab="$1" +shift +if [ ! -f $ww3_tab ]; then + echo "file: $ww3_tab, not found" + exit +fi +echo -e "\nInput file: $ww3_tab" +run_id=${ww3_tab%%.tab.*} +run_id=${run_id#ww3.} + +ww3list=ww3list.txt +if [ -f $ww3list ]; then rm -f $ww3list; fi +touch $ww3list +echo -e "$ww3_tab\n$ww3_tab" >> $ww3list + + +# Buoy-model collocation +buoy_colloc=$(ls -1 ww3buoy_collocation*.nc 2> /dev/null) +if [ -f $buoy_colloc ]; then rm -f $buoy_colloc; fi +echo 'Performing model-buoy collocation...' +python3 modelBuoy_collocation_hindcast.py +num_colloc=$(ls -1 ww3buoy_collocation*.nc | wc -l 2> /dev/null) +if [ $num_colloc -ne 1 ]; then + echo "invalid num collocation files: ${num_colloc}." + exit +fi +buoy_colloc=$(ls -1 ww3buoy_collocation*.nc 2> /dev/null) + + +# Statistics and metrics +if [ -f stats_buoy*.txt ]; then rm -f stats_buoy*.txt; fi +if [ -f stats_model*.txt ]; then rm -f stats_model*.txt; fi +if [ -f metrics*.txt ]; then rm -f metrics*.txt; fi +python3 runstats.py $buoy_colloc $@ + + +# Data mgmt +mv $buoy_colloc ${run_id}.${buoy_colloc} +mv $ww3list ${run_id}.${ww3list} + +if [ ! -f stats_buoy*.txt ]; then + echo 'buoy stats not found.' +else + buoy_stats=$(ls -1 stats_buoy*.txt) + mv $buoy_stats ${run_id}.${buoy_stats} +fi + +if [ ! -f stats_model*.txt ]; then + echo 'model stats not found.' +else + model_stats=$(ls -1 stats_model*.txt) + mv $model_stats ${run_id}.${model_stats} +fi + +if [ ! -f metrics*.txt ]; then + echo 'metrics not found.' +else + mod_buoy_mets=$(ls -1 metrics*.txt) + mv $mod_buoy_mets ${run_id}.${mod_buoy_mets} +fi + +echo -e "\nInput WW3 tab: $ww3_tab\n" +stats_out_dir=stats_out_$run_id +mkdir $stats_out_dir +if [ -d $stats_out_dir ]; then + mv -f ${run_id}.${buoy_colloc} $stats_out_dir + mv -f ${run_id}.${ww3list} $stats_out_dir + mv -f ${run_id}.${buoy_stats} $stats_out_dir + mv -f ${run_id}.${model_stats} $stats_out_dir + mv -f ${run_id}.${mod_buoy_mets} $stats_out_dir + echo -e "Output Directory: ${stats_out_dir}/" +fi +echo -e "\tww3list: ${run_id}.${ww3list}" +echo -e "\tBuoy collocation: ${run_id}.${buoy_colloc}" +echo -e "\tBuoy stats: ${run_id}.${buoy_stats}" +echo -e "\tModel stats: ${run_id}.${model_stats}" +echo -e "\tValidation metrics: ${run_id}.${mod_buoy_mets}\n" + diff --git a/validation/ww3metrics.py b/validation/ww3metrics.py index d74eb8124..de084546d 100755 --- a/validation/ww3metrics.py +++ b/validation/ww3metrics.py @@ -16,7 +16,7 @@ def ww3_pnt_metrics(*args): PURPOSE: calculate validation metrics from buoy collocation input. USAGE: ww3_pnt_metrics [ [ [ ]]] ''' - vmin=-np.inf; vmax=np.inf; parm='hs' + vmin=0; vmax=20; parm='hs' if len(args) == 0: sys.exit('ww3_pnt_metrics [ [ [ ]]]') elif len(args) == 1: diff --git a/validation/ww3stats.py b/validation/ww3stats.py index 73c0250b9..b728815a3 100755 --- a/validation/ww3stats.py +++ b/validation/ww3stats.py @@ -16,7 +16,7 @@ def ww3_pnt_stats(*args): PURPOSE: calculate summary statistics from buoy collocation input. USAGE: ww3_pnt_stats [ [ [ ]]] ''' - vmin=-np.inf; vmax=np.inf; parm='hs' + vmin=0; vmax=20; parm='hs' if len(args) == 0: sys.exit('ww3_pnt_stats [ [ [ ]]]') elif len(args) == 1: