Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 168 additions & 0 deletions bin/ExternalGEFSAnalysisToMPAS.csh
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
#!/bin/csh -f

# (C) Copyright 2023 UCAR
#
# 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.

# Process arguments
# =================
## args
# ArgDT: int, valid time offset beyond CYLC_TASK_CYCLE_POINT in hours
set ArgDT = "$1"

# ArgWorkDir: my location
set ArgWorkDir = "$2"

# ArgFilePrefix: prefix for output file
set ArgFilePrefix = "$3"

# ArgType: type of horizontal mesh
set ArgType = "$4"

# ArgNCells: number of horizontal mesh cells
set ArgNCells = "$5"

# ArgRatio: Ratio of horizontal mesh cells
set ArgRatio = "$6"

# ArgExternalAnalysesDir: location of external analyses
set ArgExternalAnalysesDir = "$7"

set test = `echo $ArgDT | grep '^[0-9]*$'`
set isNotInt = ($status)
if ( $isNotInt ) then
echo "ERROR in $0 : ArgDT must be an integer, not $ArgDT"
exit 1
endif

date

# Setup environment
# =================
source config/environmentJEDI.csh
source config/auto/build.csh
source config/auto/experiment.csh
source config/auto/externalanalyses.csh
source config/auto/model.csh
source config/auto/invariantstream.csh
source config/tools.csh
set yymmdd = `echo ${CYLC_TASK_CYCLE_POINT} | cut -c 1-8`
set hh = `echo ${CYLC_TASK_CYCLE_POINT} | cut -c 10-11`
set thisCycleDate = ${yymmdd}${hh}
set thisValidDate = `$advanceCYMDH ${thisCycleDate} ${ArgDT}`
source ./bin/getCycleVars.csh

set WorkDir = ${ExperimentDirectory}/`echo "$ArgWorkDir" \
| sed 's@{{thisValidDate}}@'${thisValidDate}'@' \
`
set ExternalAnalysesDir = ${ExperimentDirectory}/`echo "$ArgExternalAnalysesDir" \
| sed 's@{{thisValidDate}}@'${thisValidDate}'@' \
`
echo "WorkDir = ${WorkDir}"
mkdir -p ${WorkDir}
cd ${WorkDir}

# ================================================================================================

# only need to continue if output file does not already exist
set outputFile = $ArgFilePrefix.$thisMPASFileDate.nc

if ( -e $outputFile ) then
if ( -e CONVERTSUCCESS ) then
echo "$0 (INFO): outputFile ($outputFile) and CONVERTSUCCESS file already exist, exiting with success"
echo "$0 (INFO): if regenerating the output outputFile is desired, delete CONVERTSUCCESS"

date

exit 0
endif

# set oSize = `du -sh $outputFile | sed 's@'$outputFile'@@'`
# if ( "$oSize" != "0" ) then
# echo "$0 (INFO): outputFile ($outputFile) already exists, exiting with success"
# echo "$0 (INFO): if regenerating the outputFile is desired, delete $outputFile"
#
# date
#
# exit 0
# endif

rm $outputFile
endif

# ================================================================================================
# Process the data for each member
set nmem = 30 # Adjust the number of members

# Loop through each ensemble member
foreach i (`seq 1 $nmem`)
set mem = `printf "%02d" $i`
set WrkDir = "${WorkDir}/${mem}"

mkdir -p $WrkDir

echo "Processing Init. for member ${mem}..."
echo "WrkDir = ${WrkDir}"
cd $WrkDir

## link ungribbed files
#ln -sfv ${ExternalAnalysesDir}/${externalanalyses__UngribPrefix}* ./
ln -sfv ${ExternalAnalysesDir}/${mem}/GEFS* ./

## link MPAS mesh graph info
rm ./x${ArgRatio}.${ArgNCells}.graph.info*
ln -sfv $GraphInfoDir/x${ArgRatio}.${ArgNCells}.graph.info* .

## Link MPAS invariant field
if ( $ArgType == "Outer" ) then
ln -sfv $InvariantFieldsDirOuter/$InvariantFieldsFileOuter .
else
ln -sfv $InvariantFieldsDirInner/$InvariantFieldsFileInner .
endif

## link lookup tables
foreach fileGlob ($MPASLookupFileGlobs)
rm ./*${fileGlob}
ln -sfv ${MPASLookupDir}/*${fileGlob} .
end

## copy/modify dynamic streams file
rm ${StreamsFileInit}
cp -v $ModelConfigDir/initic/${StreamsFileInit} .
sed -i 's@{{nCells}}@'${ArgNCells}'@' ${StreamsFileInit}
sed -i 's@{{PRECISION}}@'${model__precision}'@' ${StreamsFileInit}
sed -i 's@{{meshRatio}}@'${ArgRatio}'@' ${StreamsFileInit}

## copy/modify dynamic namelist
rm ${NamelistFileInit}
cp -v $ModelConfigDir/initic/${NamelistFileInit} .
sed -i 's@startTime@'${thisMPASNamelistDate}'@' $NamelistFileInit
sed -i 's@nCells@'${ArgNCells}'@' $NamelistFileInit
sed -i 's@{{meshRatio}}@'${ArgRatio}'@' $NamelistFileInit
#sed -i 's@{{UngribPrefix}}@'${externalanalyses__UngribPrefix}'@' $NamelistFileInit
sed -i 's@{{UngribPrefix}}@'GEFS'@' $NamelistFileInit

# Run the executable
# ==================
rm ./${InitEXE}
ln -sfv ${InitBuildDir}/${InitEXE} ./
mpiexec ./${InitEXE}

# Check status
# ============
grep "Finished running the init_${MPASCore} core" log.init_${MPASCore}.0000.out
if ( $status != 0 ) then
rm $outputFile
echo "ERROR in $0 : MPAS-init failed" > ./FAIL
exit 1
endif

end

# ============
date

touch CONVERTSUCCESS

exit 0
136 changes: 136 additions & 0 deletions bin/GetGEFS6hFcstFromAWS.csh
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#!/bin/csh -f

# (C) Copyright 2023 UCAR
#
# 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.

# Get GFS analysis (0-h forecast) for cold start initial conditions

# Process arguments
# =================
## args
# ArgDT: int, valid time offset beyond CYLC_TASK_CYCLE_POINT in hours
set ArgDT = "$1"

# ArgWorkDir: my location
set ArgWorkDir = "$2"

set test = `echo $ArgDT | grep '^[0-9]*$'`
set isNotInt = ($status)
if ( $isNotInt ) then
echo "ERROR in $0 : ArgDT must be an integer, not $ArgDT"
exit 1
endif

date

# Setup environment
# =================
source config/auto/build.csh
source config/auto/experiment.csh
source config/tools.csh

set ccyymmdd = `echo ${CYLC_TASK_CYCLE_POINT} | cut -c 1-8`
set hh = `echo ${CYLC_TASK_CYCLE_POINT} | cut -c 10-11`
set thisCycleDate = ${ccyymmdd}${hh}
set thisValidDate = `$advanceCYMDH ${thisCycleDate} ${ArgDT}`

source ./bin/getCycleVars.csh


set WorkDir = ${ExperimentDirectory}/`echo "$ArgWorkDir" \
| sed 's@{{thisValidDate}}@'${thisValidDate}'@'`

echo "WorkDir = ${WorkDir}"
mkdir -p ${WorkDir}
cd ${WorkDir}

# Process the date for each member
set nmem = 30 # Adjust the number of members

set fc_range = 6 # Forecast range in hours

set fcstValidDate = `$advanceCYMDH ${thisValidDate} -${fc_range}`
set ccyymmdd = `echo ${fcstValidDate} | cut -c 1-8`
set hh = `echo ${fcstValidDate} | cut -c 9-10`

set formatted_fc_range = `printf "%03d" $fc_range`

# Loop through each ensemble member
foreach i (`seq 1 $nmem`)
set mem = `printf "%02d" $i`
set WrkDir = "${WorkDir}/${mem}"
#set WrkDir = "/glade/campaign/mmm/parc/zhuming/pandac_common/GEFS/GEFS_grib/$ccyymmdd$hh/$mem"

mkdir -p $WrkDir

echo "Processing member ${mem}..."
echo "WrkDir = ${WrkDir}"

# Set the URL for GEFS data
set gefsa_url = "s3://noaa-gefs-pds/gefs.$ccyymmdd/$hh/atmos/pgrb2ap5"
set gefsb_url = "s3://noaa-gefs-pds/gefs.$ccyymmdd/$hh/atmos/pgrb2bp5"
echo "gefs_url = ${gefsa_url}, ${gefsb_url}"

# Define filenames
set pgrb2a = "gep$mem.t${hh}z.pgrb2a.0p50.f${formatted_fc_range}"
set pgrb2b = "gep$mem.t${hh}z.pgrb2b.0p50.f${formatted_fc_range}"
#set pgrb2a = "gep$mem.t${hh}z.pgrb2a.0p50.f`printf "%03d" $fc_range`"
#set pgrb2b = "gep$mem.t${hh}z.pgrb2b.0p50.f`printf "%03d" $fc_range`"
echo "pgrb = ${pgrb2a}, ${pgrb2b}"

# Check if the files exist before attempting to download
set file_a_exists = `/glade/u/home/liuz/.local/bin/aws s3 ls $gefsa_url/$pgrb2a --no-sign-request`
set file_b_exists = `/glade/u/home/liuz/.local/bin/aws s3 ls $gefsb_url/$pgrb2b --no-sign-request`
#echo "File check output for $pgrb2a: $file_a_exists"
#echo "File check output for $pgrb2b: $file_b_exists"

if ("$file_a_exists" != "") then
#if (`echo "$file_a_exists" | wc -l` > 0) then
echo "Downloading $pgrb2a..."
/glade/u/home/liuz/.local/bin/aws s3 cp --no-sign-request $gefsa_url/$pgrb2a $WrkDir
else
echo "$pgrb2a does not exist, skipping."
endif

if ("$file_b_exists" != "") then
#if (`echo "$file_b_exists" | wc -l` > 0) then
echo "Downloading $pgrb2b..."
/glade/u/home/liuz/.local/bin/aws s3 cp --no-sign-request $gefsb_url/$pgrb2b $WrkDir
else
echo "$pgrb2b does not exist, skipping."
endif

# Combine files if both exist
#if ("$file_a_exists" != "" && "$file_b_exists" != "") then
if (-e ${WrkDir}/$pgrb2a && -e ${WrkDir}/$pgrb2b) then
cat ${WrkDir}/$pgrb2a ${WrkDir}/$pgrb2b > ${WrkDir}/gep$mem.t${hh}z.pgrb2ab.0p50.f${formatted_fc_range}
# Remove the individual pgrb2a and pgrb2b files after combining
rm -f ${WrkDir}/$pgrb2a ${WrkDir}/$pgrb2b
endif

# Link GRIB files
cd ${WrkDir}
set linkWPS = link_grib.csh
ln -sfv ${WPSBuildDir}/${linkWPS} .
rm -rf GRIBFILE.*

#set gribFile = gep$mem.t${hh}z.pgrb2ab.0p50.f${formatted_fc_range}
#./${linkWPS} $gribFile
./link_grib.csh gep$mem.t${hh}z.pgrb2ab.0p50.f${formatted_fc_range}

end

# ================================================================================================

if ( -e GETSUCCESS ) then
echo "$0 (INFO): GETSUCCESS file already exists, exiting with success"
echo "$0 (INFO): if regenerating the output files is desired, delete GETSUCCESS"

date

exit 0
endif

# ================================================================================================
Loading