Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no remap when not necessary #53

Merged
merged 16 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Do not remap (link instead) upper air restarts when it is not necessary
- Addition of SST and FRACI forecast (ocean) boundary conditions generation capability in `pre/prepare_ocnExtData`
- Added EASE grid option for remapping of land restarts in remap_restarts.py package (facilitates use of package in GEOSldas setup script)
- Added support for SLES15, NAS site and log for remap_lake_landice_saltwater in remap_restarts.py package
Expand Down
62 changes: 53 additions & 9 deletions pre/remap_restart/remap_upper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from remap_base import remap_base
from remap_utils import *
from remap_bin2nc import bin2nc
import netCDF4 as nc

class upperair(remap_base):
def __init__(self, **configs):
Expand Down Expand Up @@ -59,6 +60,20 @@ def remap(self):
out_dir = config['output']['shared']['out_dir']

if not os.path.exists(out_dir) : os.makedirs(out_dir)

types = '.bin'
type_str = subprocess.check_output(['file','-b', os.path.realpath(restarts_in[0])])
type_str = str(type_str)
if type_str.find('Hierarchical') >=0:
types = '.nc4'
yyyymmddhh_ = str(config['input']['shared']['yyyymmddhh'])

label = get_label(config)
suffix = yyyymmddhh_[0:8]+'_'+yyyymmddhh_[8:10] +'z' + types + label

no_remap = self.link_without_remap(restarts_in, suffix)
if (no_remap) : return

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

Expand All @@ -71,15 +86,6 @@ def remap(self):
os.chdir(tmpdir)

print('\nUpper air restart file names link from "_rst" to "_restart_in" \n')
types = '.bin'
type_str = subprocess.check_output(['file','-b', os.path.realpath(restarts_in[0])])
type_str = str(type_str)
if type_str.find('Hierarchical') >=0:
types = '.nc4'
yyyymmddhh_ = str(config['input']['shared']['yyyymmddhh'])

label = get_label(config)
suffix = yyyymmddhh_[0:8]+'_'+yyyymmddhh_[8:10] +'z' + types + label
for rst in restarts_in :
f = os.path.basename(rst).split('_rst')[0].split('.')[-1]+'_restart_in'
cmd = '/bin/ln -s ' + rst + ' ' + f
Expand Down Expand Up @@ -371,6 +377,7 @@ def copy_merra2(self):
merra_2_rst_dir + expid+'.gocart_internal_rst.' + suffix,
merra_2_rst_dir + expid+'.pchem_internal_rst.' + suffix,
merra_2_rst_dir + expid+'.agcm_import_rst.' + suffix ]

bin2nc_yaml = ['bin2nc_merra2_fv.yaml', 'bin2nc_merra2_moist.yaml', 'bin2nc_merra2_gocart.yaml', 'bin2nc_merra2_pchem.yaml','bin2nc_merra2_agcm.yaml']
bin_path = os.path.dirname(os.path.realpath(__file__))
for (f, yf) in zip(upperin,bin2nc_yaml) :
Expand All @@ -387,6 +394,43 @@ def copy_merra2(self):
bin2nc(dest, ncdest, yaml_file)
os.remove(dest)

def link_without_remap(self, restarts_in, suffix):
config = self.config
in_agrid = config['input']['shared']['agrid']
out_agrid = config['output']['shared']['agrid']
out_levels = config['output']['air']['nlevel']
in_bc_version = config['input']['shared']['bc_version']
out_bc_version = config['output']['shared']['bc_version']
in_stretch = config['input']['shared']['stretch']
out_stretch = config['output']['shared']['stretch']

if (in_agrid == out_agrid and \
in_bc_version == out_bc_version and in_stretch == out_stretch) :
sdrabenh marked this conversation as resolved.
Show resolved Hide resolved

for rst in restarts_in :
if 'fvcore_internal' in rst:
fvrst = nc.Dataset(rst)
in_levels = fvrst.dimensions['lev'].size
if in_levels != int(out_levels): return False

out_dir = config['output']['shared']['out_dir']
expid = config['output']['shared']['expid']
if (expid) :
expid = expid + '.'
else:
expid = ''

print('\nLinking upper air restart files to orignal restart files without remapping\n')
for rst in restarts_in :
f = expid + os.path.basename(rst).split('_rst')[0].split('.')[-1]+'_rst.'+suffix
cmd = '/bin/ln -s ' + rst + ' ' + out_dir+'/'+f
print('\n'+cmd)
subprocess.call(shlex.split(cmd))

return True

return False

if __name__ == '__main__' :
air = upperair(params_file='remap_params.yaml')
air.remap()
Loading