WSL/SLF GitLab Repository

Commit a8cc4bec authored by Mathias Bavay's avatar Mathias Bavay
Browse files

The updated smet_range script now supports Julian timestamps (and converts...

The updated smet_range script now supports Julian timestamps (and converts them to ISO), properly shows empty lines for stations that miss the requested parameter and properly converts K to C when necessary. It also prints a usage message when ran without arguments and can take as argument a path.

The new smet2kml script creates a kml file locating all the smet stations provided in a given directory. This kml can then be loaded on map.geo.admin, googlemaps, etc and shows markers with station ids.
parent 40413ba6
#!/bin/bash
#from a list of SMET files, this generates a KML file that can be read in google earth or map.geo.admin
#to represent on a map where the stations are
#see https://developers.google.com/kml/documentation/kml_tut for more on kml
if [ $# -lt 1 ]; then
INPUT_DIR="."
else
INPUT_DIR=$1
fi
ls ${INPUT_DIR}/*.smet | xargs -i head -20 {} | awk '
BEGIN {
printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
printf("<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n")
printf("<Folder>\n<name>My Simulation</name>\n")
printf("<Style id=\"sty0\">\n<LabelStyle>\n")
printf("<color>ff0000ff</color>\n<scale>1</scale>\n")
printf("</LabelStyle>\n</Style>\n")
}
/\[DATA\]/ {
printf("<Placemark>\n")
printf("<name>%s</name>\n", station_id)
printf("<styleUrl>#sty0</styleUrl>\n")
printf("<description>%s</description>\n", station_name)
printf("<Point><coordinates>%s, %s, 0</coordinates></Point>\n", longitude, latitude)
printf("</Placemark>\n")
#nextfile
}
/station_id/ {
station_id = $3
}
/station_name/ {
station_name = $3
}
/latitude/ {
latitude = $3
}
/longitude/ {
longitude = $3
}
/altitude/ {
altitude = $3
}
END {
printf("</Folder>\n</kml>\n")
}
'
#!/bin/sh
#prints min/max/mean for a given parameter in all smet files
files=`ls *.smet`
param=$1
if [ $# -lt 1 ]; then
me=`basename $0`
printf "Usage: \n"
printf "\t$me time\n\t\t to show the time range for all SMET files in the current directory\n"
printf "\t$me TA\n\t\t to show the range on the TA parameter for all SMET files in the current directory\n"
printf "\t$me ../input/meteo TA\n\t\t to show the range on the TA paremeter for all SMET files in ../input/meteo\n"
exit 0
fi
if [ $# -lt 2 ]; then
INPUT_DIR="."
else
INPUT_DIR=$1
fi
files=`ls ${INPUT_DIR}/*.smet`
param=$2
if [ "${param}" = "time" ]; then
for SMET in ${files}; do
ALT=`head -15 ${SMET} | grep altitude | tr -s ' \t' | cut -d' ' -f3`
start=`head -20 ${SMET} | grep -E "^[0-9][0-9][0-9][0-9]" | head -1 | tr -s ' \t' | cut -d' ' -f1`
end=`tail -5 ${SMET} | grep -E "^[0-9][0-9][0-9][0-9]" | tail -1 | tr -s ' \t' | cut -d' ' -f1`
printf "%s [ %s - %s ] (%s)\n" "${ALT}" ${start} ${end} ${SMET}
ALT=`head -15 ${SMET} | grep altitude | tr -s ' \t' | cut -d' ' -f3 | cut -d'.' -f1`
JULIAN=`head -15 ${SMET} | grep fields | grep julian`
ISO=`head -15 ${SMET} | grep fields | grep timestamp`
if [ ! -z "${ISO}" ]; then
start=`head -20 ${SMET} | grep -E "^[0-9][0-9][0-9][0-9]" | head -1 | tr -s ' \t' | cut -d' ' -f1`
end=`tail -5 ${SMET} | grep -E "^[0-9][0-9][0-9][0-9]" | tail -1 | tr -s ' \t' | cut -d' ' -f1`
printf "%04d [ %s - %s ] (%s)\n" "${ALT}" ${start} ${end} ${SMET}
fi
if [ ! -z "${JULIAN}" ]; then
start=`head -20 ${SMET} | grep -E "^[0-9][0-9][0-9][0-9]" | head -1 | tr -s ' \t' | cut -d' ' -f1`
end=`tail -5 ${SMET} | grep -E "^[0-9][0-9][0-9][0-9]" | tail -1 | tr -s ' \t' | cut -d' ' -f1`
start_ISO=`echo ${start} | awk '{printf("%s", strftime("%FT%H:%m", ($1-2440587.5)*24*3600))}'`
end_ISO=`echo ${end} | awk '{printf("%s", strftime("%FT%H:%m", ($1-2440587.5)*24*3600))}'`
printf "%04d [ %s - %s ] (%s)\n" "${ALT}" ${start_ISO} ${end_ISO} ${SMET}
fi
done
exit 0
fi
......@@ -18,29 +44,39 @@ for SMET in ${files}; do
IJ=`echo ${SMET} | cut -d'.' -f 1 | cut -d'_' -f2,3 | tr "_" ","`
LAT=`head -15 ${SMET} | grep latitude | tr -s ' \t' | cut -d' ' -f3`
LON=`head -15 ${SMET} | grep longitude | tr -s ' \t' | cut -d' ' -f3`
ALT=`head -15 ${SMET} | grep altitude | tr -s ' \t' | cut -d' ' -f3`
ALT=`head -15 ${SMET} | grep altitude | tr -s ' \t' | cut -d' ' -f3 | cut -d'.' -f1`
NODATA=`head -15 ${SMET} | grep nodata | tr -s ' \t' | cut -d' ' -f3`
awk '
BEGIN {
param="'"${param}"'"
max=-1e12
min=1e12
nodata="'"${NODATA}"'"
max=-1e4
min=1e4
f=2
}
/^fields/ {
f=-1
for(ii=4; ii<=NF; ii++) {
if ($(ii)==param) {
f=ii-2
}
}
if (f==-1) {
#printf("No %s in file %s\n", param, FILENAME)
printf("\n")
exit 0
}
printf("%s\t",$(f+2))
next
}
/^altitude/ {
printf("%s m\t",$3)
printf("%04d m\t",$3)
next
}
/^20/ {
$0 !~ /^[a-zA-Z\[]/ {
val=$(f)
if (val==-999) next
if (val==nodata) next
if (val>max) max = val
if (val<min) min = val
......@@ -48,14 +84,20 @@ for SMET in ${files}; do
count++
}
END {
if (f==-1 || count==0) exit 0
mean /= count
if (param=="TA" || param=="TSG" || param=="TSS") {
offset = -273.15
if (min!=-999) min += offset
if (max!=-999) max += offset
if (mean!=-999) mean += offset
offset = 0
if (mean>100) {
offset = -273.15
}
min += offset
max += offset
mean += offset
}
printf("[ %g - %g ]\tavg = %g\t(%s)\n", min, max, mean, "'"${IJ}"'")
printf("[ %7.3g - %7.3g ]\tavg = %7.3g\t(%s)\n", min, max, mean, "'"${IJ}"'")
}' ${SMET}
done
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment