Skip to content

Commit

Permalink
Merge branch 'main' into feature/ltakacs/Jason-4_0_p1_sky_plots
Browse files Browse the repository at this point in the history
  • Loading branch information
sdrabenh authored Aug 1, 2022
2 parents 12141e1 + 48e04c5 commit b6761ab
Show file tree
Hide file tree
Showing 20 changed files with 2,134 additions and 39 deletions.
5 changes: 5 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
version: 2.1

# Anchors to prevent forgetting to update a version
baselibs_version: &baselibs_version v7.5.0
bcs_version: &bcs_version v10.22.3

orbs:
ci: geos-esm/circleci-tools@1

Expand All @@ -14,6 +18,7 @@ workflows:
matrix:
parameters:
compiler: [gfortran, ifort]
baselibs_version: *baselibs_version
repo: GEOSgcm
checkout_fixture: true
mepodevelop: true
Expand Down
26 changes: 23 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,34 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Changed restart file geosachem to achem in regrid.pl
### Fixed

### Removed

## [1.5.6] - 2022-07-22

### Added

- Introduce series of remap_restarts Python scripts to GEOS_Util/post
- Add a series of tests for remap_restarts

### Changed

- Updated CI to modern v1 orb
- Updated CI to use Baselibs 7.5.0

### Fixed

- More updates to CMake to more canonical CMake style (NetCDF, ESMF, etc.). These were missed in previous go-arounds as they are only built with ADAS. (Requires ESMA_cmake v3.15.1)
- Implemented a more robust check to test if a history's monthly attribute is 1 (on) and not commented out.
- Fixed setting of `ks` in `m_set_eta.F90` to be based on `bk`
- Added check for infinity in time_ave.F and replace with undef

### Removed
## [1.5.5] - 2022-06-08

### Changed

- Changed restart file geosachem to achem in regrid.pl
- More updates to CMake to more canonical CMake style (NetCDF, ESMF, etc.). These were missed in previous go-arounds as they are only built with ADAS. (Requires ESMA_cmake v3.15.1)

## [1.5.4] - 2022-05-03

Expand Down
7 changes: 7 additions & 0 deletions GEOS_Util/post/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ install(
PROGRAMS ${perlscripts} ec2grd.csh
DESTINATION bin)

file(GLOB pythonscripts CONFIGURE_DEPENDS ./remap_restart/remap*)
install(
PROGRAMS ${pythonscripts}
DESTINATION bin)

set_property(SOURCE rsg3_vinterp.F APPEND_STRING PROPERTY COMPILE_FLAGS "${FREAL8} ${BYTERECLEN} ${EXTENDED_SOURCE}")
set_property(SOURCE rs_vinterp.F90 APPEND_STRING PROPERTY COMPILE_FLAGS "${FREAL8} ${BYTERECLEN}")
set_property(SOURCE rs_vinterp_scm.F90 APPEND_STRING PROPERTY COMPILE_FLAGS "${FREAL8} ${BYTERECLEN}")
Expand Down Expand Up @@ -163,3 +168,5 @@ install(PROGRAMS
${CMAKE_CURRENT_BINARY_DIR}/3CH.j
DESTINATION post
)

add_subdirectory(tests)
17 changes: 8 additions & 9 deletions GEOS_Util/post/gcmpost.script
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ end
set numlocs = ''
@ nstream = 0
foreach collection ( $collections )
set monthly_attribute = `grep -i $collection.monthly: $HISTORYRC`
set monthly_attribute = `grep -i "^[\t ]*$collection.monthly:[\t ]*1" $HISTORYRC`
@ nstream = $nstream + 1
@ date_node = $expdots + $ndots[$nstream] + 3

Expand Down Expand Up @@ -569,7 +569,7 @@ set monthly_collections = "FALSE"
@ m = 1
@ begloc = 1
foreach collection ( $collections )
set monthly_attribute = `grep -i $collection.monthly: $HISTORYRC`
set monthly_attribute = `grep -i "^[\t ]*$collection.monthly:[\t ]*1" $HISTORYRC`
if( ${monthly_collections} == "FALSE" & ${#monthly_attribute} != 0 ) set monthly_collections = "TRUE"

@ endloc = $begloc + $numdates[$m] - 1
Expand Down Expand Up @@ -730,7 +730,7 @@ if( $AGCM_IM >= 1152 | ($AGCM_IM >= 360 & $CUBE == TRUE ) ) set HIRES = TRUE
@ begloc = 1
@ nstream = 0
foreach collection ( $collections )
set monthly_attribute = `grep -i $collection.monthly: $HISTORYRC`
set monthly_attribute = `grep -i "^[\t ]*$collection.monthly:[\t ]*1" $HISTORYRC`
@ nstream = $nstream + 1
@ date_node = $expdots + $ndots[$nstream] + 3
@ endloc = $begloc + $numdates[$m] - 1
Expand Down Expand Up @@ -835,9 +835,9 @@ foreach collection ( $collections )
if( ${#monthly_attribute} != 0 ) @ monthly_date_node = $date_node

if( ${#monthly_attribute} == 0 ) then
set locals = `/bin/ls -1 | grep ${expid}.${collection} | grep monthly | grep -v diurnal`
set locals = `/bin/ls -1 | grep "${expid}.${collection}.*${ext}" | grep monthly | grep -v diurnal`
else
set locals = `/bin/ls -1 | grep ${expid}.${collection} | grep -v diurnal`
set locals = `/bin/ls -1 | grep "${expid}.${collection}.[0-9]\{6\}01_0000z.${ext}" | grep -v diurnal`
endif

echo "Archiving Monthlies for Collection: $collection for Date: $date"
Expand All @@ -857,8 +857,7 @@ foreach collection ( $collections )
if( ${#monthly_attribute} == 0 ) then
$cpvar $local $SOURCE/$collection
else
set yearmonth = `echo $local | sed -n "s|${expid}.${collection}.\([0-9]\{6\}\).*|\1|p"`
$cpvar $local $SOURCE/$collection/${expid}.${collection}.monthly.${yearmonth}.${ext}
$cpvar $local $SOURCE/$collection/${expid}.${collection}.monthly.${year}${month}.${ext}
endif

echo "if( -e $local ) then" >> $archfile
Expand Down Expand Up @@ -1041,7 +1040,7 @@ wait

@ nstream = 0
foreach collection ( $collections )
set monthly_attribute = `grep -i $collection.monthly: $HISTORYRC`
set monthly_attribute = `grep -i "^[\t ]*$collection.monthly:[\t ]*1" $HISTORYRC`
@ nstream = $nstream + 1

if( ( ($MOVEFILES != "TRUE") & ${#monthly_attribute} == 0 ) | \
Expand Down Expand Up @@ -1267,7 +1266,7 @@ if( $PLOTS[1] == "NULL" ) then
lockfile LOCKFILE
@ count = 0
foreach stream ($streams)
set monthly_attribute = `grep -i $collection.monthly: $HISTORYRC`
set monthly_attribute = `grep -i "^[\t ]*$collection.monthly:[\t ]*1" $HISTORYRC`
echo Checking stream: $stream for date: $date
if( ${#monthly_attribute} == 0 ) then
set checkstream = `/bin/ls -1 $SOURCE/$stream/$expid.$stream.monthly.${date}* | grep -v clim`
Expand Down
137 changes: 137 additions & 0 deletions GEOS_Util/post/remap_restart/remap_analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#!/usr/bin/env python3
#
# source install/bin/g5_modules
#
# Newer GEOS code should load a module with GEOSpyD Python3 if not run:
# module load python/GEOSpyD/Min4.10.3_py3.9
#

import os
from datetime import datetime, timedelta
import subprocess
import shlex
import shutil
import glob
import fileinput
import ruamel.yaml
from remap_base import remap_base

class analysis(remap_base):
def __init__(self, **configs):
super().__init__(**configs)

def remap(self):
config = self.config
bkg = config['output']['analysis']['bkg']
if ( not bkg ): return

analysis_in = self.find_analysis()
if len(analysis_in) ==0 :
print("\n There are no analysis files. \n")
return

print("\n Remapping or copying analysis files...\n")

cwdir = os.getcwd()
bindir = os.path.dirname(os.path.realpath(__file__))
in_bcsdir = config['input']['shared']['bcs_dir']
out_bcsdir = config['output']['shared']['bcs_dir']
out_dir = config['output']['shared']['out_dir']
if not os.path.exists(out_dir) : os.makedirs(out_dir)
print( "cd " + out_dir)
os.chdir(out_dir)

tmpdir = out_dir+'/ana_data/'
if os.path.exists(tmpdir) : subprocess.call(['rm', '-rf',tmpdir])
print ("mkdir " + tmpdir)
os.makedirs(tmpdir)

print( "cd " + tmpdir)
os.chdir(tmpdir)

yyyymmddhh_ = str(config['input']['shared']['yyyymmddhh'])
yyyy_ = yyyymmddhh_[0:4]
mm_ = yyyymmddhh_[4:6]
dd_ = yyyymmddhh_[6:8]
hh_ = yyyymmddhh_[8:10]
rst_time = datetime(year=int(yyyy_), month=int(mm_), day=int(dd_), hour = int(hh_))
expid_in = config['input']['shared']['expid']
expid_out = config['output']['shared']['expid']
if (expid_out) :
expid_out = expid_out + '.'
else:
expid_out = ''

aqua = config['output']['analysis']['aqua']
local_fs=[]
for f in analysis_in:
print(f)
fname = os.path.basename(f)
out_name = fname.replace(expid_in + '.', expid_out)
f_tmp = tmpdir+'/'+out_name
local_fs.append(f_tmp)
shutil.copy(f,f_tmp)
if out_name.find('satbias') != -1 :
if (aqua):
f_ = open(f_tmp, 'w')
for line in fileinput.input(f):
f_.write(line.replace('airs281SUBSET_aqua', 'airs281_aqua '))
f_.close()

nlevel = config['output']['air']['nlevel']
agrid_out = config['output']['shared']['agrid']
flags = "-g5 -res " + self.get_grid_kind(agrid_out.upper()) + " -nlevs " + str(nlevel)
bkg_files = glob.glob(tmpdir+'/*.bkg??_eta_rst*')
for f in bkg_files:
f_orig = f + ".orig"
shutil.move(f,f_orig)
cmd = bindir + '/dyn2dyn.x ' + flags + ' -o ' + f + ' ' + f_orig
print(cmd)
subprocess.call(shlex.split(cmd))

for f in local_fs:
fname = os.path.basename(f)
shutil.move(f, out_dir+'/'+fname)
# write lcv
lcv = config['output']['analysis']['lcv']
if lcv :
ymd_ = yyyymmddhh_[0:8]
hh_ = yyyymmddhh_[8:10]
hms_ = hh_+'0000'
rstlcvOut = out_dir+'/'+expid_out+'rst.lcv.'+ymd_+'_'+hh_+'z.bin'
cmd = bindir+'/mkdrstdate.x ' + ymd_ + ' ' + hms_ +' ' + rstlcvOut
print(cmd)
subprocess.call(shlex.split(cmd))
print( "cd " + cwdir)
os.chdir(cwdir)

def get_grid_kind(this, grid):
hgrd = {}
hgrd['C12'] = 'a'
hgrd['C24'] = 'a'
hgrd['C48'] = 'b'
hgrd['C90'] = 'c'
hgrd['C180'] = 'd'
hgrd['C360'] = 'd'
hgrd['C500'] = 'd'
hgrd['C720'] = 'e'
hgrd['C1000'] = 'e'
hgrd['C1440'] = 'e'
hgrd['C2000'] = 'e'
hgrd['C2880'] = 'e'
hgrd['C5760'] = 'e'
return hgrd[grid]

def find_analysis(self):
analysis_in = []
rst_dir = self.config['input']['shared']['rst_dir']
bkgs = glob.glob(rst_dir + '/*_eta_rst*')
sfcs = glob.glob(rst_dir + '/*_sfc_rst*')
anasat = glob.glob(rst_dir + '/*ana_satb*')
traks= glob.glob(rst_dir + '/*.trak.GDA.rst*')
analysis_in = bkgs + sfcs + traks + anasat
return list(dict.fromkeys(analysis_in))

if __name__ == '__main__' :
ana = analysis(params_file='remap_params.yaml')
ana.remap()
30 changes: 30 additions & 0 deletions GEOS_Util/post/remap_restart/remap_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python3
#
import os
import ruamel.yaml
import shutil

class remap_base(object):
def __init__(self, **configs):
for key, value in configs.items():
if (key == 'params_file'):
print( "use Config yaml file: " + value)
yaml = ruamel.yaml.YAML()
stream =''
with open(value, 'r') as f:
stream = f.read()
self.config = yaml.load(stream)
out_dir = self.config['output']['shared']['out_dir']
if not os.path.exists(out_dir) : os.makedirs(out_dir)
f = os.path.basename(value)
dest = out_dir+'/'+f
try:
shutil.copy(value, dest)
except shutil.SameFileError:
pass
if (key == 'config_obj'):
print( "use Config obj")
self.config = value
out_dir = self.config['output']['shared']['out_dir']
if not os.path.exists(out_dir) : os.makedirs(out_dir)
break
Loading

0 comments on commit b6761ab

Please sign in to comment.