Skip to content

Commit e50a2f5

Browse files
Screen GEFS grid2obs Aeronet file before ASCII2NC call Feature/aeronetasciifix (#593)
* add python check file code * add checking aeronet record columns * incremental changes 10/17/2024 1 * updated script to use post-screen aeronet file for metplus ascii2nc * fix fcst missing sen email * incremental changes 10/22/2024 * PR changes #1 * fix number comparison
1 parent b75d003 commit e50a2f5

File tree

4 files changed

+86
-10
lines changed

4 files changed

+86
-10
lines changed

parm/metplus_config/prep/global_ens/chem_grid2obs/ASCII2NC_obsAERONET.conf

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ ASCII2NC_TIME_SUMMARY_VALID_THRESH = 0.0
6060

6161
[dir]
6262

63-
ASCII2NC_INPUT_DIR = {ENV[DCOMINaeronet]}
63+
ASCII2NC_INPUT_DIR = {ENV[DATA]}
6464

6565
ASCII2NC_OUTPUT_DIR = {ENV[finalprep]}
6666

@@ -69,7 +69,7 @@ LOG_DIR = {OUTPUT_BASE}/logs/{ENV[COMPONENT]}
6969

7070
[filename_templates]
7171

72-
ASCII2NC_INPUT_TEMPLATE = {valid?fmt=%Y%m%d}/validation_data/aq/{ENV[OBTTYPE]}/{valid?fmt=%Y%m%d}.lev15
72+
ASCII2NC_INPUT_TEMPLATE = checked_{ENV[OBTTYPE]}_{valid?fmt=%Y%m%d}.lev15
7373

7474
ASCII2NC_OUTPUT_TEMPLATE = {ENV[OBTTYPE]}_All_{valid?fmt=%Y%m%d}_lev15.nc
7575

scripts/prep/global_ens/exevs_global_ens_gefs_chem_grid2obs_prep.sh

+22-8
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,31 @@ for OBTTYPE in ${obstype}; do
3939
if [ "${OBTTYPE}" == "aeronet" ]; then
4040
checkfile=${DCOMINaeronet}/${INITDATE}/validation_data/aq/${OBTTYPE}/${INITDATE}.lev15
4141
if [ -s ${checkfile} ]; then
42-
if [ -s ${prep_config_file} ]; then
43-
run_metplus.py ${prep_config_file} ${config_common}
44-
export err=$?; err_chk
45-
if [ ${SENDCOM} = "YES" ]; then
46-
cpfile=${finalprep}/${OBTTYPE}_All_${INITDATE}_lev15.nc
47-
if [ -e ${cpfile} ]; then
48-
cp -v ${cpfile} ${COMOUTprep}
42+
screen_file=${DATA}/checked_${OBTTYPE}_${INITDATE}.lev15
43+
python ${USHevs}/${COMPONENT}/screen_aeronet_aod_lev15.py ${checkfile} ${screen_file}
44+
number_of_record=$(wc -l ${screen_file} | awk -F" " '{print $1}')
45+
## There is 6 comment and header lines
46+
if [ ${number_of_record} -gt 6 ]; then
47+
if [ -s ${prep_config_file} ]; then
48+
run_metplus.py ${prep_config_file} ${config_common}
49+
export err=$?; err_chk
50+
if [ ${SENDCOM} = "YES" ]; then
51+
cpfile=${finalprep}/${OBTTYPE}_All_${INITDATE}_lev15.nc
52+
if [ -e ${cpfile} ]; then
53+
cp -v ${cpfile} ${COMOUTprep}
54+
fi
4955
fi
56+
else
57+
echo "WARNING: can not find ${prep_config_file}"
5058
fi
5159
else
52-
echo "WARNING: can not find ${prep_config_file}"
60+
if [ ${SENDMAIL} = "YES" ]; then
61+
echo "DEBUG : There is no valid record to be processed for ${checkfile}" >> mailmsg
62+
echo "File in question is ${checkfile}" >> mailmsg
63+
echo "==============" >> mailmsg
64+
flag_send_message=YES
65+
fi
66+
echo "DEBUG : There is no valid record to be processed for ${checkfile}"
5367
fi
5468
else
5569
if [ ${SENDMAIL} = "YES" ]; then

scripts/stats/global_ens/exevs_global_ens_chem_grid2obs_stats.sh

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ for ObsType in ${grid2obs_list}; do
128128
echo "WARNING: No ${model1} ${obs_var} forecast was available for ${aday} t${acyc}z" > mailmsg
129129
echo "Missing file is ${fcst_file}" >> mailmsg
130130
echo "==============" >> mailmsg
131+
flag_send_message=YES
131132
fi
132133

133134
echo "WARNING: No ${model1} ${obs_var} forecast was available for ${aday} t${acyc}z"
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python3
2+
###############################################################################
3+
# Name of Script:
4+
# Contact(s): Ho-Chun Huang (ho-chun.huang@noaa.gov)
5+
# Purpose of Script: Read AERONET AOD file and remove bad records with
6+
# inconsistent columns number as header
7+
#
8+
# History Log:
9+
###############################################################################
10+
11+
import os
12+
import sys
13+
14+
print(f'Python Script: {sys.argv[0]}')
15+
# input and output file specified on the command line
16+
17+
if len(sys.argv) < 2:
18+
script_name = os.path.basename(sys.argv[0])
19+
print(f"FATAL ERROR: {script_name} -> Must specify input and output files.")
20+
sys.exit(1)
21+
22+
# Read the input file as the first argument
23+
input_file = os.path.expandvars(sys.argv[1])
24+
print(f'Input Original Aeronet File: {input_file}')
25+
26+
# Read the Output file as the second argument
27+
output_file = os.path.expandvars(sys.argv[2])
28+
print(f'Output screened Aeronet File: {output_file}')
29+
30+
if not os.path.exists(input_file):
31+
print(f"DEBUG :: Can not find input Aeronet file - {input_file}")
32+
print(f"DEBUG :: Check the existence of input file before calling {sys.argv[0]}")
33+
sys.exit()
34+
35+
rfile=open(input_file, 'r')
36+
wfile=open(output_file,'w')
37+
38+
count=0
39+
flag_data=False
40+
for line in rfile:
41+
if not flag_data:
42+
if line[0:4] != "Date":
43+
wfile.write(line)
44+
else:
45+
wfile.write(line)
46+
line=line.rstrip("\n")
47+
hdr=line.split(",")
48+
num_hdr=len(hdr)
49+
flag_data=True
50+
count += 1
51+
else:
52+
count += 1
53+
line=line.rstrip("\n")
54+
var=[]
55+
var=line.split(",")
56+
num_var=len(var)
57+
if num_var == num_hdr:
58+
wfile.write(line+"\n")
59+
else:
60+
print(f"DEBUG :: Line {count} has different columns number {num_var} vs standard {num_hdr}")
61+
wfile.close()

0 commit comments

Comments
 (0)