Skip to content

Instantly share code, notes, and snippets.

@Gro-Tsen
Last active August 14, 2022 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gro-Tsen/94c7a1f704454712655742145a6e680f to your computer and use it in GitHub Desktop.
Save Gro-Tsen/94c7a1f704454712655742145a6e680f to your computer and use it in GitHub Desktop.
cat > /tmp/script.gnuplot <<'__EOF__'
set terminal pngcairo size 800,600
wholetitle=sprintf("Graphe de %s (%s) en France moyennes janv–juil par année", maintitle, unit)
fname=sprintf("time_era5_%s_France_metropolitan_mon1_ave7_dump0.txt",var)
ofname=sprintf("20220814-time_era_graph_%s_France_metropolitan_mon1_ave7_regr.png",var)
# A hack to extract last value of dataset:
set output "/dev/null"
plot fname using (lastyear=$3):(lastval=$2)
# Now compute stats:
stats fname using ($3-2000):($2) name "stat"
w(x)=stat_intercept+stat_slope*x
residual_stddev=sqrt(1-stat_correlation**2)*stat_stddev_y
regrtitle=stat_slope<0?sprintf("%.2f−%.2f×(Y−2000)/100", stat_intercept, -stat_slope*100):sprintf("%.2f+%.2f×(Y−2000)/100", stat_intercept, stat_slope*100)
lastvaltitle=sprintf("%.2f",lastval)
predvaltitle=sprintf("%.2f",w(lastyear-2000))
set output ofname
set key bmargin
set title wholetitle
plot [x=1950:lastyear] w(x-2000)+lastval-w(lastyear-2000) lt rgb "dark-grey" dashtype 3 notitle, fname using ($3):($2) with lines lt rgb "brown" title maintitle, [x=1950:lastyear] w(x-2000) lt rgb "blue" dashtype 2 title regrtitle, [x=1950:lastyear] w(x-2000)+residual_stddev lt rgb "blue" dashtype 3 notitle, [x=1950:lastyear] w(x-2000)-residual_stddev lt rgb "blue" dashtype 3 notitle, fname using ($3):($3==lastyear?$2:NaN) lt rgb "brown" pt 7 ps 2 title lastvaltitle, fname using ($3):($3==lastyear?w(lastyear-2000):NaN) lt rgb "blue" pt 7 ps 2 title predvaltitle
print "slope in standard devs: ", stat_slope/stat_slope_err
print "last residual in standard devs: ", (lastval-w(lastyear-2000))/residual_stddev
__EOF__
(echo 'var="t2m"' ; echo 'maintitle="température"' ; echo 'unit="°C"' ; cat /tmp/script.gnuplot) | gnuplot
(echo 'var="tp"' ; echo 'maintitle="précipitation"' ; echo 'unit="mm/j"' ; cat /tmp/script.gnuplot) | gnuplot
(echo 'var="pme"' ; echo 'maintitle="différence P−E"' ; echo 'unit="mm/j"' ; cat /tmp/script.gnuplot) | gnuplot
(echo 'var="ssr"' ; echo 'maintitle="rayonnement solaire"' ; echo 'unit="W/m²"' ; cat /tmp/script.gnuplot) | gnuplot
(echo 'var="msl"' ; echo 'maintitle="pression atmosphérique"' ; echo 'unit="hPa"' ; cat /tmp/script.gnuplot) | gnuplot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment