Skip to content

Instantly share code, notes, and snippets.

@Gro-Tsen
Created December 16, 2022 17:40
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/a87fc776fcb49418c8f29145ae4a6b07 to your computer and use it in GitHub Desktop.
Save Gro-Tsen/a87fc776fcb49418c8f29145ae4a6b07 to your computer and use it in GitHub Desktop.
Compute temperature autocorrelation graphs
## Get data from https://zenodo.org/record/6961511#.Y4-HhqIo9hE
## in era-nuts-t2m.zip we want era-nuts-t2m-nuts0-daily-singleindex.csv
perl -F',' -ne 'next if $F[0]=~m/time/; die unless $F[0]=~m/^\"([0-9]{4})\/([0-9]{2})\/([0-9]{2}) ([0-9]{2})\:([0-9]{2})\:([0-9]{2})\"$/; print "$1-$2-$3T$4:$5:$6Z\t$F[14]\n"' era-nuts-t2m-nuts0-daily-singleindex.csv > /tmp/temp-fr-daily.dat
: > /tmp/temp-fr-autocorrels.dat ; for i in $(seq 0 400) ; do
echo "$i days"
ifmt=$(printf %03d $i)
ip1=$((i+1))
paste /tmp/temp-fr-daily.dat <(tail +$ip1 /tmp/temp-fr-daily.dat) > /tmp/temp-fr-shifted.dat
(echo 'set terminal pngcairo size 800,600' ; echo 'set output "/tmp/temp-fr-autocorrel-'"$ifmt"'days.png"' ; echo 'stats "/tmp/temp-fr-shifted.dat" using ($2):($4) name "st"' ; echo 'w(x)=st_intercept+st_slope*x' ; echo 'regrtitle=sprintf("[r=%s%.4f]", (st_correlation<0?"−":""), abs(st_correlation))' ; echo 'set title "Distribution de températures en France à '"$i"' jours d'\''écart {/*0.5 (1980–2021)}"' ; echo 'set xlabel "Température jour J"' ; echo 'set ylabel "Température jour J+'"$i"'"' ; echo 'set key bottom right' ; echo 'plot [st_min_x:st_max_x] [st_min_x:st_max_x] "/tmp/temp-fr-shifted.dat" using ($2):($4) pt 7 lc rgb "#000080" ps 0.1 notitle, [x=st_min_x:st_max_x] w(x) lc rgb "#ff0080" title regrtitle' ; echo 'set print "/tmp/temp-fr-autocorrels.dat" append' ; echo 'print sprintf("%d%c%.6f", '"$i"', 9, st_correlation)') | gnuplot
done
(echo 'set terminal pngcairo size 800,600' ; echo 'set output "/tmp/temp-fr-autocorrels.png"' ; echo 'set title "Autocorrélation de la température moyenne en France {/*0.5 (1980–2021)}"' ; echo 'set xlabel "Nombre de jours d'\''écart"' ; echo 'set ylabel "Coefficient de corrélation (r)"' ; echo 'set key bottom right' ; echo 'plot [0:400] "/tmp/temp-fr-autocorrels.dat" with lines title "autocorrélation"') | gnuplot
(echo 'set terminal pngcairo size 800,600' ; echo 'set output "/tmp/temp-fr-autocorrels-short.png"' ; echo 'set title "Autocorrélation de la température moyenne en France {/*0.5 (1980–2021)}"' ; echo 'set xlabel "Nombre de jours d'\''écart"' ; echo 'set ylabel "Coefficient de corrélation (r)"' ; echo 'set key bottom right' ; echo 'plot [0:20] "/tmp/temp-fr-autocorrels.dat" with lines title "autocorrélation"') | gnuplot
@Gro-Tsen
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment