star-meteo

Time varying meteorological data
git clone git://git.meso-star.fr/star-meteo.git
Log | Files | Refs | README | LICENSE

commit ab05e9cd661bb5a6b976a92d0342e9146d43622c
parent 9afba90bfed37296149d454278adaa92dff065e7
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed,  3 Sep 2025 15:11:46 +0200

Post-process the results of the Stardis plugin tests

Provide a gnuplot script that generates a graph comparing the surface
temperature calculated by Stardis with its value in the meteorological
data. This data is not yet archived in the repository because it is very
large.

Diffstat:
M.gitignore | 1+
MMakefile | 45++++++++++++++++++++++-----------------------
Asrc/plot.gp | 46++++++++++++++++++++++++++++++++++++++++++++++
Msrc/test_stardis_smeteo_ground_temperature.sh | 33+++++++++++++++++++++++++--------
4 files changed, 94 insertions(+), 31 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -12,3 +12,4 @@ test.txt smeteo *.stl stardis_model.txt +Tsrf.* diff --git a/Makefile b/Makefile @@ -260,37 +260,36 @@ test_stardis_smeteo: config.mk smeteo-local.pc $(LIBNAME) libstardis_smeteo.so clean_test: rm -f $(TEST_DEP) $(TEST_OBJ) $(TEST_TGT) - rm -f test.txt + rm -f test.txt rm Tsrf.txt Tsrf.pdf for i in $(TEST_SRC); do rm -f "$$(basename "$${i}" ".c")"; done +Tsrf.pdf: $(PLUGIN) Tsrf.txt src/plot.gp + gnuplot -e "Tsrf='Tsrf.txt'" src/plot.gp > Tsrf.pdf + +Tsrf.txt: src/test_stardis_smeteo_ground_temperature.sh + $(SHELL) src/test_stardis_smeteo_ground_temperature.sh \ + samples/meteo2stardis.txt > $@ + test: tests util @err=0; \ for i in $(TEST_SRC); do \ - test="$$(basename "$${i}" ".c")"; \ - if "./$${test}" > /dev/null 2>&1; then \ - printf '%s\n' "$${test}"; \ + i="$$(basename "$${i}" '.c')"; \ + if ./"$${i}" "$$@" > /dev/null 2>&1; then \ + printf '%s\n' "$${i}"; \ else \ - >&2 printf '%s: error %s\n' "$${test}" "$$?"; \ - err=$$((err+1)); \ - fi \ + >&2 printf '%s: error %s\n' "$${i}" "$$?"; \ + err="$$((err+1))"; \ + fi; \ done; \ - if [ "$(PLUGIN)" = "stardis" ]; then \ - if $(SHELL) \ - src/test_stardis_smeteo_ground_temperature.sh \ - samples/star-meteo_input.txt > /dev/null 2>&1; then \ - printf 'test_stardis_smeteo_ground_temperature\n'; \ + \ + for i in $(TEST_FILES_INVALID); do \ + if ! LD_LIBRARY_PATH=./:"$${LD_LIBRARY_PATH}" ./smeteo "$${i}" \ + > /dev/null 2>&1; then \ + printf '%s\n' "$${i}"; \ else \ - printf 'test_stardis_smeteo_ground_temperature: error %s\n' "$$?"; \ - err=$$((err+1)); \ + >&2 printf '%s: error %s\n' "$${i}" "$$?"; \ + err="$$((err+1))"; \ fi; \ - fi; \ - for file in $(TEST_FILES_INVALID); do \ - if ! LD_LIBRARY_PATH=./:"$${LD_LIBRARY_PATH}" \ - ./smeteo "$${file}"> /dev/null 2>&1; then \ - printf '%s\n' "$${file}"; \ - else \ - >&2 printf '%s: error %s\n' "$${file}"; \ - err=$$((err+1)); \ - fi \ done; \ + \ [ "$${err}" -eq 0 ] diff --git a/src/plot.gp b/src/plot.gp @@ -0,0 +1,46 @@ +# Copyright (C) 2025 |Méso|Star> (contact@meso-star.com) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# Define the output +set terminal pdf +set output "Tsrf.pdf" + +# Define the graph title and labels +set title "Surface temperature" +set xlabel "Date" +set ylabel "Temperature [K]" + +# Handle time as X axis +set xdata time # Data in X are dates +set timefmt '%d-%b-%Y %H:%M:%S' # Format of input dates + +# Setup time output formatting +set xtics timedate +set xtics format '%m/%d/%y' # Format of the date when print on X axis +set xtics 1 day + +# Define the plot style +set style line 1 lc "black" lw 2 # GCM +set style line 2 lc "black" pt 6 ps 1 # MC +set errorbars 3 # Width of the error bars + +# Move the labels above the graph +set key at graph 1, 1.15 + +# Increase the right margin to prevent the last date from being cut off +set rmargin 4 + +plot Tsrf u 1:3 title "GCM" w line ls 1, \ + Tsrf u 1:4:($5*3) title "MC" w errorbars ls 2 diff --git a/src/test_stardis_smeteo_ground_temperature.sh b/src/test_stardis_smeteo_ground_temperature.sh @@ -132,20 +132,31 @@ stardis_input > stardis_model.txt # Use Stardis to calculate the ground temperature date="01-MAY-2020 01:30:00" # 1st date on which temperature is calculated -nsimu="32" # Overall number of simulations +ndates="32" # Overall number of dates -# Define the sed commands to extract the ${nsimu} dates from the +# Check that at least the 1st date exists in the meteorlogical file +if ! grep -qe "^${date}" "${smeteo}"; then + >&2 printf '%s: unable to find the date "%s" in "%s" file\n' \ + "${0##*/}" "${date}" "${smeteo}" + exit 1 +fi + +# Define the sed commands to extract the ${ndates} dates from the # meteorological file -i=0; +i=1; # The corresponding date... n=""; -while [ "${i}" -lt "${nsimu}" ]; do +while [ "${i}" -lt "${ndates}" ]; do # ... followed by ${ndates}-1 dates n="${n}N;" i="$((i+1))" done +isimu=0; + # Run the simulations +printf 'Calculating 0 %%\n' sed -n "/^${date}/{${n}p;}" "${smeteo}" \ | while read -r i; do + # Remove duplicate spaces in the line entry="$(echo "${i}" |sed 's/[[:space:]]\{1,\}/ /g')" @@ -154,20 +165,26 @@ done # will be compared. Tsrf="$(echo "${entry}" | cut -d' ' -f3)" - # Get date time in seconds + # Get the date + date="$(echo "${entry}" | cut -d' ' -f1-2)" + + # Get the time in seconds since January 1, 1850 time="$(echo "${entry}" | cut -d' ' -f14)" # [day/1850] time="$(echo "${time} * 24*3600" | bc -l | cut -d'.' -f1)" # [s] - date="$(echo "${entry}" | cut -d' ' -f1-2)" - # Run stardis to retrieve the expected value and standard error of the # ground temperature estimate. mc="$(stardis -a wos -M stardis_model.txt -s ground_Z.stl,"${time}" \ | cut -d' ' -f1-2)" + # Print the calculation result printf '%s %s %s\n' "${date}" "${Tsrf}" "${mc}" -done + # Print progression bar + isimu="$((isimu+1))" + pcent="$(echo "${isimu} / ${ndates} * 100" | bc -l | cut -d'.' -f1)" + >&2 printf 'Running %3d %%\n' "${pcent}" +done # TODO: check the Stardis result against a reference, most likely the # surface temperature provided by the Meteorological file at the time of