Skip to content

Commit

Permalink
ECC-2010: Extra tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shahramn committed Jan 23, 2025
1 parent 9840ea8 commit 2bbcb51
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 7 deletions.
114 changes: 114 additions & 0 deletions examples/python/convert_python_gribapi2eccodes.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/usr/bin/perl

use strict;
use warnings;

my %dictionary = (
'import gribapi' => 'import eccodes',
'from gribapi import' => 'from eccodes import',
'GRIB_CHECK' => 'CODES_CHECK',
'grib_clone' => 'codes_clone',
'grib_context_delete' => 'codes_context_delete',
'grib_copy_namespace' => 'codes_copy_namespace',
'grib_count_in_file' => 'codes_count_in_file',
'grib_find_nearest' => 'codes_grib_find_nearest',
'grib_find_nearest_multiple' => 'codes_grib_find_nearest_multiple',
'grib_get' => 'codes_get',
'grib_get_api_version' => 'codes_get_api_version',
'grib_get_array' => 'codes_get_array',
'grib_get_data' => 'codes_grib_get_data',
'grib_get_double' => 'codes_get_double',
'grib_get_double_array' => 'codes_get_double_array',
'grib_get_double_element' => 'codes_get_double_element',
'grib_get_double_elements' => 'codes_get_double_elements',
'grib_get_elements' => 'codes_get_elements',
'grib_get_float_array' => 'codes_get_float_array',
'grib_get_long' => 'codes_get_long',
'grib_get_long_array' => 'codes_get_long_array',
'grib_get_message' => 'codes_get_message',
'grib_get_message_offset' => 'codes_get_message_offset',
'grib_get_message_size' => 'codes_get_message_size',
'grib_get_native_type' => 'codes_get_native_type',
'grib_get_offset' => 'codes_get_offset',
'grib_get_size' => 'codes_get_size',
'grib_get_string' => 'codes_get_string',
'grib_get_string_array' => 'codes_get_string_array',
'grib_get_string_length' => 'codes_get_string_length',
'grib_get_values' => 'codes_get_values',
'grib_gribex_mode_off' => 'codes_gribex_mode_off',
'grib_gribex_mode_on' => 'codes_gribex_mode_on',
'grib_gts_header' => 'codes_gts_header',
'grib_index_add_file' => 'codes_index_add_file',
'grib_index_get' => 'codes_index_get',
'grib_index_get_double' => 'codes_index_get_double',
'grib_index_get_long' => 'codes_index_get_long',
'grib_index_get_size' => 'codes_index_get_size',
'grib_index_get_string' => 'codes_index_get_string',
'grib_index_new_from_file' => 'codes_index_new_from_file',
'grib_index_read' => 'codes_index_read',
'grib_index_release' => 'codes_index_release',
'grib_index_select' => 'codes_index_select',
'grib_index_select_double' => 'codes_index_select_double',
'grib_index_select_long' => 'codes_index_select_long',
'grib_index_select_string' => 'codes_index_select_string',
'grib_index_write' => 'codes_index_write',
'grib_is_defined' => 'codes_is_defined',
'grib_is_missing' => 'codes_is_missing',
'grib_iterator_delete' => 'codes_grib_iterator_delete',
'grib_iterator_new' => 'codes_grib_iterator_new',
'grib_iterator_next' => 'codes_grib_iterator_next',
'grib_keys_iterator_delete' => 'codes_keys_iterator_delete',
'grib_keys_iterator_get_name' => 'codes_keys_iterator_get_name',
'grib_keys_iterator_new' => 'codes_keys_iterator_new',
'grib_keys_iterator_next' => 'codes_keys_iterator_next',
'grib_keys_iterator_rewind' => 'codes_keys_iterator_rewind',
'grib_multi_append' => 'codes_grib_multi_append',
'grib_multi_new' => 'codes_grib_multi_new',
'grib_multi_release' => 'codes_grib_multi_release',
'grib_multi_support_off' => 'codes_grib_multi_support_off',
'grib_multi_support_on' => 'codes_grib_multi_support_on',
'grib_multi_support_reset_file' => 'codes_grib_multi_support_reset_file',
'grib_multi_write' => 'codes_grib_multi_write',
'grib_nearest_delete' => 'codes_grib_nearest_delete',
'grib_nearest_find' => 'codes_grib_nearest_find',
'grib_nearest_new' => 'codes_grib_nearest_new',
'grib_new_from_file' => 'codes_grib_new_from_file',
'grib_new_from_index' => 'codes_new_from_index',
'grib_new_from_message' => 'codes_new_from_message',
'grib_new_from_samples' => 'codes_grib_new_from_samples',
'grib_no_fail_on_wrong_length' => 'codes_no_fail_on_wrong_length',
'grib_release' => 'codes_release',
'grib_set' => 'codes_set',
'grib_set_array' => 'codes_set_array',
'grib_set_debug' => 'codes_set_debug',
'grib_set_definitions_path' => 'codes_set_definitions_path',
'grib_set_double' => 'codes_set_double',
'grib_set_double_array' => 'codes_set_double_array',
'grib_set_key_vals' => 'codes_set_key_vals',
'grib_set_long' => 'codes_set_long',
'grib_set_long_array' => 'codes_set_long_array',
'grib_set_missing' => 'codes_set_missing',
'grib_set_samples_path' => 'codes_set_samples_path',
'grib_set_string' => 'codes_set_string',
'grib_set_string_array' => 'codes_set_string_array',
'grib_set_values' => 'codes_set_values',
'grib_skip_coded' => 'codes_skip_coded',
'grib_skip_computed' => 'codes_skip_computed',
'grib_skip_duplicates' => 'codes_skip_duplicates',
'grib_skip_edition_specific' => 'codes_skip_edition_specific',
'grib_skip_function' => 'codes_skip_function',
'grib_skip_read_only' => 'codes_skip_read_only',
'grib_write' => 'codes_write',
'gts_new_from_file' => 'codes_gts_new_from_file',
'metar_new_from_file' => 'codes_metar_new_from_file'
);

$| = 1;
while (<>) {
foreach my $key (keys %dictionary) {
if (/\b$key\b/) {
s/$key/$dictionary{$key}/g;
}
}
print;
}
2 changes: 1 addition & 1 deletion src/codes_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ int is_date_valid(long year, long month, long day, long hour, long minute, doubl
// Note: In the 24-hour time notation, the day begins at midnight, 00:00 or 0:00,
// and the last minute of the day begins at 23:59.
// Where convenient, the notation 24:00 may also be used to refer to midnight
// at the end of a given date that is, 24:00 of one day is the same time
// at the end of a given date - that is, 24:00 of one day is the same time
// as 00:00 of the following day
int is_time_valid(long number)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/grib_ecc-1766.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ${tools_dir}/grib_set -s activity=1,experiment=1,realization=1 $eerie_sample $te
grib_check_key_equals $temp_grib "activity,experiment,realization" "1 1 1"
grib_check_key_equals $temp_grib "activity:s,experiment:s" "CMIP6 hist"

# ECC-1850: Additional keys added
# ECC-1850: Additional keys added
# Check additional keys are present and correct
grib_check_key_exists $eerie_sample generation,model,resolution
grib_check_key_equals $eerie_sample "generation,model,resolution" "255 0 0"
Expand Down
8 changes: 4 additions & 4 deletions tests/grib_ecpoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ sample_grib2=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
latest=`${tools_dir}/grib_get -p tablesVersionLatest $sample_grib2`

# 1. bias-corrected
## we check if we can set PDTN 73 and typeOfPostProcessing to ecPoint, ecPoint versioning and MARS type
## we check if we can set PDTN 73 and typeOfPostProcessing to ecPoint, ecPoint versioning and MARS type
${tools_dir}/grib_set -s tablesVersion=$latest,productDefinitionTemplateNumber=73,backgroundProcess=1,\
setLocalDefinition=1,grib2LocalSectionNumber=1,type=gbf,class=od,stream=enfo,\
generatingProcessIdentifier=2,typeOfPostProcessing=206 $sample_grib2 $tempGrib
grib_check_key_equals $tempGrib backgroundProcess,generatingProcessIdentifier,typeOfPostProcessing,type "1 2 206 gbf"
rm -f $tempGrib

# 2. Point values
## we check if we can set PDTN 90 and typeOfPostProcessing to ecPoint, ecPoint versioning, MARS type, quantile
## we check if we can set PDTN 90 and typeOfPostProcessing to ecPoint, ecPoint versioning, MARS type, quantile
${tools_dir}/grib_set -s tablesVersion=$latest,productDefinitionTemplateNumber=90,backgroundProcess=1,\
setLocalDefinition=1,grib2LocalSectionNumber=1,type=pfc,class=od,stream=enfo,\
totalNumberOfQuantiles=1000,quantileValue=995,\
Expand All @@ -36,7 +36,7 @@ grib_check_key_equals $tempGrib backgroundProcess,generatingProcessIdentifier,ty
rm -f $tempGrib

# 3. Point value metrics
## we check if we can set PDTN 90 and typeOfPostProcessing to ecPoint, ecPoint versioning, MARS type, quantile
## we check if we can set PDTN 90 and typeOfPostProcessing to ecPoint, ecPoint versioning, MARS type, quantile
${tools_dir}/grib_set -s tablesVersion=$latest,productDefinitionTemplateNumber=90,backgroundProcess=1,\
setLocalDefinition=1,grib2LocalSectionNumber=1,type=ppm,class=od,stream=enfo,\
totalNumberOfQuantiles=1000,quantileValue=995,\
Expand All @@ -45,7 +45,7 @@ grib_check_key_equals $tempGrib backgroundProcess,generatingProcessIdentifier,ty
rm -f $tempGrib

# 4. weather types
## we check if we can set PDTN 73 and typeOfPostProcessing to ecPoint, ecPoint versioning and MARS type
## we check if we can set PDTN 73 and typeOfPostProcessing to ecPoint, ecPoint versioning and MARS type
${tools_dir}/grib_set -s tablesVersion=$latest,productDefinitionTemplateNumber=73,backgroundProcess=1,\
setLocalDefinition=1,grib2LocalSectionNumber=1,type=gwt,class=od,stream=enfo,\
generatingProcessIdentifier=2,typeOfPostProcessing=206 $sample_grib2 $tempGrib
Expand Down
13 changes: 12 additions & 1 deletion tests/grib_modelName.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ grib_check_key_equals $tempGrib modelName,modelVersion "IFS cy48r1"
${tools_dir}/grib_set -s generatingProcessIdentifier=100 $sample $tempGrib
grib_check_key_equals $tempGrib modelName,modelVersion "IFS unknown"

# Check that this only works for centre ecmf
# Check that this only works for centre ecmf
${tools_dir}/grib_set -s generatingProcessIdentifier=1,backgroundProcess=1,centre=84 $sample $tempGrib
[ $( ${tools_dir}/grib_get -f -p modelName $tempGrib ) = "not_found" ]
[ $( ${tools_dir}/grib_get -f -p modelVersion $tempGrib ) = "not_found" ]
Expand All @@ -43,6 +43,17 @@ ${tools_dir}/grib_set -s productionStatusOfProcessedData=0 $tempGrib $temp2Grib
[ $( ${tools_dir}/grib_get -f -p modelName $temp2Grib ) = "aifs-ens-diff" ]
[ $( ${tools_dir}/grib_get -f -p modelVersion $temp2Grib ) = "v1" ]


# ECC-2010
${tools_dir}/grib_set -s marsClass=ai,typeOfProcessedData=missing,backgroundProcess=1,generatingProcessIdentifier=1 \
$ECCODES_SAMPLES_PATH/reduced_gg_pl_32_grib2.tmpl $temp2Grib
grib_check_key_equals $temp2Grib mars.model 'aifs-single-mse'

${tools_dir}/grib_set -s marsClass=ai,typeOfProcessedData=missing,backgroundProcess=2,generatingProcessIdentifier=1 \
$ECCODES_SAMPLES_PATH/reduced_gg_pl_32_grib2.tmpl $temp2Grib
grib_check_key_equals $temp2Grib mars.model 'aifs-ens-crps'


# Keys are read-only (may change this later)
set +e
${tools_dir}/grib_set -s modelName=AIFS $sample $tempGrib 2>$tempLog
Expand Down

0 comments on commit 2bbcb51

Please sign in to comment.