eccodes/tests/grib_grid_healpix.sh

94 lines
2.7 KiB
Bash
Raw Normal View History

2023-08-31 10:28:47 +00:00
#!/bin/sh
# (C) Copyright 2005- ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
#
# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
. ./include.ctest.sh
# Define a common label for all the tmp files
label="grib_healpix_test"
2024-02-20 13:57:38 +00:00
tempFilt="temp.${label}.filt"
2023-08-31 10:28:47 +00:00
tempGrib="temp.${label}.grib"
tempLog="temp.${label}.log"
input=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
latest=`${tools_dir}/grib_get -p tablesVersionLatest $input`
# Create a filter
2024-02-20 13:57:38 +00:00
cat > $tempFilt <<EOF
2023-08-31 10:28:47 +00:00
set tablesVersion = $latest;
set gridType = "healpix";
set longitudeOfFirstGridPointInDegrees = 45;
set numberOfPointsAlongASide = 32;
write;
EOF
2024-02-20 13:57:38 +00:00
cat $tempFilt
2023-08-31 10:28:47 +00:00
# Use filter on input to create a new HEALPix GRIB
2024-02-20 13:57:38 +00:00
${tools_dir}/grib_filter -o $tempGrib $tempFilt $input
2023-08-31 10:28:47 +00:00
if [ ! -f "$tempGrib" ]; then
echo 'Failed to create output GRIB from filter' >&2
exit 1
fi
grib_check_key_equals $tempGrib gridType,orderingConvention,N,Nside 'healpix ring 32 32'
grib_check_key_equals $tempGrib gridDefinitionTemplateNumber,gridName '150 H32'
if [ $latest -gt 31 ]; then
grib_check_key_equals $tempGrib gridDefinitionDescription 'Hierarchical Equal Area isoLatitude Pixelization grid'
fi
${tools_dir}/grib_dump -O -p section_3 $tempGrib
${tools_dir}/grib_ls -jn geography $tempGrib > $tempLog
grep -q "orderingConvention.*ring" $tempLog
2023-08-31 10:28:47 +00:00
# Geoiterator
# -------------
rm -f $tempGrib
2024-02-20 13:57:38 +00:00
cat > $tempFilt <<EOF
2023-08-31 10:28:47 +00:00
set tablesVersion = $latest;
set gridType = "healpix";
set longitudeOfFirstGridPointInDegrees = 45;
set numberOfPointsAlongASide = 1;
set values = {1,2,3,4,5,6,7,8,9,10,11,12}; # count=12*N*N
write;
EOF
2024-02-20 13:57:38 +00:00
${tools_dir}/grib_filter -o $tempGrib $tempFilt $input
2023-08-31 10:28:47 +00:00
${tools_dir}/grib_get_data $tempGrib
val=$(${tools_dir}/grib_get -l 0,0,1 $tempGrib | tr -d ' ')
[ "$val" = 5 ]
# Check other iterator-related keys
2024-02-20 13:57:38 +00:00
cat > $tempFilt <<EOF
2023-08-31 10:28:47 +00:00
print "latLonValues=[latLonValues]";
print "latitudes=[latitudes]";
print "longitudes=[longitudes]";
print "distinctLatitudes=[distinctLatitudes]";
print "distinctLongitudes=[distinctLongitudes]";
EOF
2024-02-20 13:57:38 +00:00
${tools_dir}/grib_filter $tempFilt $tempGrib
2023-08-31 10:28:47 +00:00
# Invalid cases
# --------------
set +e
${tools_dir}/grib_get_data -sN=0 $tempGrib > $tempLog 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "Nside must be greater than zero" $tempLog
set +e
${tools_dir}/grib_get_data -s orderingConvention=nested $tempGrib > $tempLog 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "Only ring ordering is supported" $tempLog
# Clean up
2024-02-20 13:57:38 +00:00
rm -f $tempFilt $tempGrib $tempLog