diff --git a/hrldas/HRLDAS_forcing/run/examples/ERA5/Prepare_ERA5-Land_Forcing.sh b/hrldas/HRLDAS_forcing/run/examples/ERA5/Prepare_ERA5-Land_Forcing.sh index 6820b58..4ea5a8b 100644 --- a/hrldas/HRLDAS_forcing/run/examples/ERA5/Prepare_ERA5-Land_Forcing.sh +++ b/hrldas/HRLDAS_forcing/run/examples/ERA5/Prepare_ERA5-Land_Forcing.sh @@ -19,11 +19,18 @@ # # ################################################################################################# -year=1980 -INFILE=/fas4/anav/INPUTS/ERA5_for_Noah-MP/YEARLY/ERA5-Land_Noah-MP_$year.grb +# set date for data processing +inyear=2023 +inmonth=11 +inday=01 +preyear=2023 +premonth=10 +preday=31 -let last_year=$year-1 -PREVIOUS_YEAR=/fas4/anav/INPUTS/ERA5_for_Noah-MP/YEARLY/ERA5-Land_Noah-MP_$last_year.grb +indate=${inyear}-${inmonth}-${inday} +INFILE=../../../ERA5_forcing/ERA5-Land-Noah-MP-${indate}.grib +predate=${preyear}-${premonth}-${preday} +PREVIOUS_FILE=../../../ERA5_forcing/ERA5-Land-Noah-MP-${predate}.grib ################################################################################################# # # @@ -42,7 +49,7 @@ vars_code=("var165" "var166" "var167" "var168" "var134" "var169" "var175" "var22 ################################################################################################# echo "" -echo -e "\033[33m Processing YEAR: $year FILE: $INFILE \033[0m" +echo -e "\033[33m Processing Date: ${indate} FILE: $INFILE \033[0m" echo "" #-------------------------------------------------------------------------- CREATING OUTPUT DIRECTORIES @@ -77,7 +84,7 @@ for i in ${!vars_name[@]}; do for f1 in $(ls OUTPUTS/${var,,}.grb_*); do date=(`cdo -s showtimestamp $f1`) timestamp=$(sed -e 's/T/''/g' -e 's/:00:00/''/g' -e 's/-/''/g' <<< $date) - mv $f1 OUTPUTS/${vars_name[$i]}/ERA5_"${vars_nout[$i]}"_"${timestamp}" + mv $f1 OUTPUTS/${vars_name[$i]}/ERA5_"${vars_nout[$i]}"_"${timestamp}" done done echo "" @@ -92,18 +99,18 @@ echo -e "\033[32m o-----------------> PART 2: DECUMULATE FIELDS \033[0m" #-------------------------------------------------------------------------- EXTRACT THE ACCUMULATED VARIABLES FROM THE LAST TIME STEP OF PREVIOUS YEAR -cdo -s -selvar,var169 -seldate,$last_year-12-31T23:00:00,$last_year-12-31T23:00:00 $PREVIOUS_YEAR OUTPUTS/SSRD/ERA5_ACSSRD_"$last_year"123123 -cdo -s -selvar,var175 -seldate,$last_year-12-31T23:00:00,$last_year-12-31T23:00:00 $PREVIOUS_YEAR OUTPUTS/STRD/ERA5_ACSTRD_"$last_year"123123 -cdo -s -selvar,var228 -seldate,$last_year-12-31T23:00:00,$last_year-12-31T23:00:00 $PREVIOUS_YEAR OUTPUTS/TP/ERA5_ACTP_"$last_year"123123 +cdo -s -selvar,var169 -seldate,${predate}T23:00:00,${predate}T23:00:00 $PREVIOUS_FILE OUTPUTS/SSRD/ERA5_ACSSRD_"$preyear""$premonth""$preday"23 +cdo -s -selvar,var175 -seldate,${predate}T23:00:00,${predate}T23:00:00 $PREVIOUS_FILE OUTPUTS/STRD/ERA5_ACSTRD_"$preyear""$premonth""$preday"23 +cdo -s -selvar,var228 -seldate,${predate}T23:00:00,${predate}T23:00:00 $PREVIOUS_FILE OUTPUTS/TP/ERA5_ACTP_"$preyear""$premonth""$preday"23 #-------------------------------------------------------------------------- DECUMULATE VARIABLES for i in ${!vars_nout[@]}; do if [ ${vars_nout[$i]} = "ACSSRD" ] || [ ${vars_nout[$i]} = "ACSTRD" ] || [ ${vars_nout[$i]} = "ACTP" ] ; then - + echo -e "\033[36m PROCESSING ${vars_nout[$i]} \033[0m" - FILES=OUTPUTS/${vars_name[$i]}/ERA5_"${vars_nout[$i]}"_"$year"* - prev_file="OUTPUTS/${vars_name[$i]}/ERA5_"${vars_nout[$i]}"_""$last_year"123123 + FILES=OUTPUTS/${vars_name[$i]}/ERA5_"${vars_nout[$i]}"_"$inyear"* + prev_file="OUTPUTS/${vars_name[$i]}/ERA5_"${vars_nout[$i]}"_""$preyear""$premonth""$preday"23 for f in $FILES; do # Find the hour reading the last two digits of the filename @@ -116,7 +123,7 @@ for i in ${!vars_nout[@]}; do # Decumulate the 02-24 fields and copy the 01 data from accumulated to instantaneous variable if [[ "$hour" = "01" ]]; then echo -e "\033[32m We are at 01: cp $f to $outfile \033[0m" - cp $f $outfile + cp $f $outfile else echo -e "\033[33m Decumulating: $f less $prev_file saved to $outfile \033[0m" cdo -s -sub $f $prev_file $outfile @@ -141,12 +148,12 @@ echo "" echo -e "\033[32m o-----------------> PART 3: COMPUTING SPECIFIC HUMIDITY \033[0m" -FILES=OUTPUTS/2D/ERA5_2D_"$year"* - +FILES=OUTPUTS/2D/ERA5_2D_"$inyear"* + for f in $FILES; do outfile1=$(sed 's/'2D'/'E'/g' <<< $f) echo -e "\033[33m Computing saturated water pressure from $f and save results to $outfile1 \033[0m" - cdo -s -expr,"var1=6.112*exp(17.67*(var168-273.15)/(var168-273.15+243.5))" $f $outfile1 + cdo -s -expr,"var1=6.112*exp(17.67*(var168-273.15)/(var168-273.15+243.5))" $f $outfile1 mkdir -p OUTPUTS/TMP SP_file=$(sed 's/'2D'/'SP'/g' <<< $f) @@ -166,9 +173,9 @@ echo "" ################################################################################################# rm OUTPUTS/*.grb -rm OUTPUTS/TP/ERA5_ACTP_"$year"* -rm OUTPUTS/SSRD/ERA5_ACSSRD_"$year"* -rm OUTPUTS/STRD/ERA5_ACSTRD_"$year"* +rm OUTPUTS/TP/ERA5_ACTP_"$inyear"* +rm OUTPUTS/SSRD/ERA5_ACSSRD_"$inyear"* +rm OUTPUTS/STRD/ERA5_ACSTRD_"$inyear"* rm -rf OUTPUTS/TMP rm -rf OUTPUTS/E @@ -180,3 +187,4 @@ rm -rf OUTPUTS/E echo -e "\033[32m o-----------------> ALL DONE \033[0m" echo "" + diff --git a/hrldas/HRLDAS_forcing/run/examples/ERA5/extract_era5_init.py b/hrldas/HRLDAS_forcing/run/examples/ERA5/extract_era5_init.py index 6390a31..b2a7553 100644 --- a/hrldas/HRLDAS_forcing/run/examples/ERA5/extract_era5_init.py +++ b/hrldas/HRLDAS_forcing/run/examples/ERA5/extract_era5_init.py @@ -10,24 +10,27 @@ import sys,os ### create date arrays -yr = "01" -date = "1001" -cc = "20" # Manually set the century +year = "2023" +month = "11" +day = "01" vars_name = ["SKT","SD","STL1","STL2","STL3","STL4","SWVL1","SWVL2","SWVL3","SWVL4"] vars_time = ["hr fcst:","hr fcst:","hr fcst:","hr fcst:","hr fcst:","hr acc:","hr acc:","hr acc:"] -data_dir = "/glade/scratch/zhezhang/ERA5/land/" -infile = data_dir+"ERA5_global_2001-10-01_init.grib" -results_dir = "/glade/scratch/zhezhang/ERA5/land/extract/INIT/" +data_dir = "../../../ERA5_forcing/" +infile = data_dir+"ERA5-Land-Noah-MP-2023_11_01_INIT.grib" +results_dir = "./OUTPUT/INIT/" + +os.system("mkdir -p "+results_dir) for var in range(10): - print "working on time: ",cc+yr+date+"00" - dcommand = "d="+cc+yr+date+"00:"+vars_name[var] - outfile= results_dir+"/ERA5_"+vars_name[var]+"_"+cc+yr+date+"00" + print("working on time: ",year+month+day+"00") + dcommand = "d="+year+month+day+"00:"+vars_name[var] + outfile= results_dir+"/ERA5_"+vars_name[var]+"_"+year+month+day+"00" if not os.path.exists(outfile): os.system("wgrib -s -4yr "+infile+" | grep '"+dcommand+"' | wgrib -i -grib "+infile+" -o "+outfile) else: - print "file exist, move to next one" + print("file exist, move to next one") + +print("Successfully extract necessary variables!") -print "Successfully extract necessary variables!"