def __init__(self, datestring): config.__init__(self) dt = utils.convert_cylc_time2(datestring) wrfout_time = datetime.datetime.strftime(dt, '%Y-%m-%d_%H:%M:%S') max_dom = utils.get_max_dom() rundir = self.config['filesystem']['wrf_run_dir'] archivedir = self.config['filesystem']['archive_dir'] for dom in range(1, max_dom + 1): wrfout = os.path.join(rundir, 'wrfout_d0' + str(dom) + '_' + wrfout_time) archived = os.path.join(archivedir, 'wrfout_d0' + str(dom) + '_' + wrfout_time) os.system('nc3tonc4 ' + wrfout + ' ' + archived) plot_archive = os.path.join(archivedir, 'plot', wrfout_time) utils._create_directory(plot_archive) #utils._create_directory(os.path.join(plot_archive, trim)) os.system( 'ncl /home/haren/cylc-suites/forecast/bin/wrf_Surface3.ncl inputfile=' + r'\"' + archived + r'\" outputfile=\"' + plot_archive + r'/surface_d0' + str(dom) + '.png' + r'\"') #iname = 'surface_d0' + str(dom) + '.png') #os.system('convert ' + os.path.join(plot_archive, iname) + ' -fuzz 1% -trim +repage ' + os.path.join(plot_archive, 'trim', iname)) plot_latest = os.path.join(archivedir, 'plot', 'latest') try: os.symlink(plot_archive, plot_latest) except OSError, e: if e.errno == errno.EEXIST: os.remove(plot_latest) os.symlink(plot_archive, plot_latest)
def _run_ungrib(self, j_id=None): ''' run ungrib.exe (locally or using slurm script defined in config.json) ''' if len(self.config['options_slurm']['slurm_ungrib.exe']): if j_id: mid = "--dependency=afterok:%d" %j_id ungrib_command = ['sbatch', mid, self.config['options_slurm']['slurm_ungrib.exe']] else: ungrib_command = ['sbatch', self.config['options_slurm']['slurm_ungrib.exe']] utils.check_file_exists(ungrib_command[-1]) utils.silentremove(os.path.join(self.wps_workdir, 'ungrib', 'ungrib.exe')) if not os.path.isdir(os.path.join(self.wps_workdir, 'ungrib')): utils._create_directory(os.path.join(self.wps_workdir, 'ungrib')) os.symlink(os.path.join(self.config['filesystem']['wps_dir'],'ungrib','ungrib.exe'), os.path.join(self.wps_workdir, 'ungrib', 'ungrib.exe')) try: res = subprocess.check_output(ungrib_command, cwd=self.wps_workdir, stderr=utils.devnull()) j_id = int(res.split()[-1]) # slurm job-id except subprocess.CalledProcessError: logger.error('Ungrib failed %s:' %ungrib_command) raise # re-raise exception return j_id # return slurm job-id else: ungrib_command = os.path.join(self.config['filesystem']['wps_dir'], 'ungrib', 'ungrib.exe') utils.check_file_exists(ungrib_command) try: subprocess.check_call(ungrib_command, cwd=self.wps_workdir, stdout=utils.devnull(), stderr=utils.devnull()) except subprocess.CalledProcessError: logger.error('Ungrib failed %s:' %ungrib_command) raise # re-raise exception
def _initialize(self): ''' Check if archive dir exists, create if not. The archive dir is used to ... ''' utils._create_directory(config['upp_archive_dir']) # create archive dir # create post_dir (remove old one if needed) utils.silentremove(config['post_dir']) utils._create_directory(config['post_dir'])
def _save_translated_text(self): ''' save translated text ''' dest_file = os.path.join(self.dest_dir, self.next_file.rsplit( self.input_dir)[1].strip('/')) dir_name = os.path.dirname(dest_file) utils._create_directory(dir_name) f = open(dest_file, 'w') f.write(self.translated_text['text'][0].encode('utf-8')) f.close()
def create_obsproc_dir(self, workdir): ''' symlink all files required to run obsproc.exe into obsproc workdir ''' # cleanup utils.silentremove(workdir) # create work directory utils._create_directory(workdir) # symlink error files files = ['DIR.txt', 'HEIGHT.txt', 'PRES.txt', 'RH.txt', 'TEMP.txt', 'UV.txt', 'obserr.txt'] for fl in files: os.symlink(os.path.join(self.obsproc_dir, fl), os.path.join(workdir, fl)) # symlink obsproc.exe os.symlink(os.path.join(self.obsproc_dir, 'src', 'obsproc.exe'), os.path.join(workdir, 'obsproc.exe'))
def prepare_updatebc(self, datestart): # prepare a WRFDA workdirectory for each domain for domain in range(1, self.max_dom+1): # TODO: add check for domain is int # define domain specific workdir wrfda_workdir = os.path.join(self.wrfda_workdir, "d0" + str(domain)) # general functionality independent of boundary type in parame.in if os.path.exists(wrfda_workdir): shutil.rmtree(wrfda_workdir) # remove wrfda_workdir utils._create_directory(os.path.join(wrfda_workdir, 'var', 'da')) wrf_nml = f90nml.read(os.path.join(self.config['filesystem']['wrf_run_dir'], 'namelist.input')) # define parame.in file self.create_parame('lower', domain) # symlink da_update_bc.exe os.symlink(os.path.join( self.config['filesystem']['wrfda_dir'],'var/da/da_update_bc.exe' ), os.path.join(wrfda_workdir, 'da_update_bc.exe')) # copy wrfbdy_d01 file (lateral boundaries) to WRFDA_WORKDIR shutil.copyfile(os.path.join(self.rundir, 'wrfbdy_d01'), os.path.join(wrfda_workdir, 'wrfbdy_d01')) # set parame.in file for updating lower boundary first self.prepare_updatebc_type('lower', datestart, domain)
def __init__(self, datestring): config.__init__(self) dt = utils.convert_cylc_time2(datestring) wrfout_time = datetime.datetime.strftime(dt, '%Y-%m-%d_%H:%M:%S') max_dom = utils.get_max_dom() rundir = self.config['filesystem']['wrf_run_dir'] archivedir = self.config['filesystem']['archive_dir'] for dom in range(1,max_dom+1): wrfout = os.path.join(rundir, 'wrfout_d0' + str(dom) + '_' + wrfout_time) archived = os.path.join(archivedir, 'wrfout_d0' + str(dom) + '_' + wrfout_time) os.system('nc3tonc4 ' + wrfout + ' ' + archived) plot_archive = os.path.join(archivedir, 'plot', wrfout_time) utils._create_directory(plot_archive) #utils._create_directory(os.path.join(plot_archive, trim)) os.system('ncl /home/haren/cylc-suites/forecast/bin/wrf_Surface3.ncl inputfile=' + r'\"' + archived + r'\" outputfile=\"' + plot_archive + r'/surface_d0' + str(dom) + '.png' + r'\"') #iname = 'surface_d0' + str(dom) + '.png') #os.system('convert ' + os.path.join(plot_archive, iname) + ' -fuzz 1% -trim +repage ' + os.path.join(plot_archive, 'trim', iname)) plot_latest = os.path.join(archivedir, 'plot', 'latest') try: os.symlink(plot_archive, plot_latest) except OSError, e: if e.errno == errno.EEXIST: os.remove(plot_latest) os.symlink(plot_archive, plot_latest)
def _create_directory_structure(self, suitename, basedir=None): ''' Create directory structure for the Cylc configuration ''' # set basedir to users home directory if not supplied if not basedir: basedir = os.path.join(os.path.expanduser("~"), 'cylc-suites') # subdirectories to create subdirs = ['bin' , 'control', 'doc', 'inc'] # create subdirectories [utils._create_directory( os.path.join(basedir, suitename, subdir)) for subdir in subdirs] # create empty json config file in suite directory # this does not overwrite an existing config file config.__init__(self, os.path.join( basedir, suitename, 'config.json'))
def _save_namelists(self): ''' write coarse and fine WRF namelist.input to the respective run directories as namelist.forecast ''' # define namelist directories coarse_namelist_dir = os.path.join(self.config['filesystem']['work_dir'], 'wrf_coarse') fine_namelist_dir = os.path.join(self.config['filesystem']['work_dir'], 'wrf_fine') # create directories [utils._create_directory(directory) for directory in [coarse_namelist_dir, fine_namelist_dir]] # remove old files if needed [utils.silentremove(filename) for filename in [ os.path.join(dn, 'namelist.forecast') for dn in [coarse_namelist_dir, fine_namelist_dir]]] # write namelists self.nml_coarse.write(os.path.join(coarse_namelist_dir, 'namelist.forecast')) self.nml_fine.write(os.path.join(fine_namelist_dir, 'namelist.forecast'))
def _link_tbl_files(self): ''' link GEOGRID.TBL and METGRID.TBL into wps work_dir ''' # geogrid if not os.path.isfile(os.path.join(self.wps_workdir, 'geogrid', 'GEOGRID.TBL')): geogridtbl = os.path.join(self.config['filesystem']['wps_dir'], 'geogrid', 'GEOGRID.TBL.ARW') utils._create_directory(os.path.join(self.wps_workdir, 'geogrid')) os.symlink(geogridtbl, os.path.join(self.wps_workdir, 'geogrid', 'GEOGRID.TBL')) # metgrid if not os.path.isfile(os.path.join(self.wps_workdir, 'metgrid', 'METGRID.TBL')): metgridtbl = os.path.join(self.config['filesystem']['wps_dir'], 'metgrid', 'METGRID.TBL.ARW') utils._create_directory(os.path.join(self.wps_workdir, 'metgrid')) os.symlink(metgridtbl, os.path.join(self.wps_workdir, 'metgrid', 'METGRID.TBL')) # geogrid utils._create_directory(os.path.join(self.wps_workdir, 'geogrid'))
def _prepare_post_dir(self): ''' Create and prepare post_dir ''' logger.debug('Preparing postprd directory: %s' %config['post_dir']) # create config['post_dir'] if it does not exist yet utils._create_directory(config['post_dir']) # Link all the relevant files need to compute various diagnostics relpath_to_link = ['EmisCoeff/Big_Endian/EmisCoeff.bin', 'AerosolCoeff/Big_Endian/AerosolCoeff.bin', 'CloudCoeff/Big_Endian/CloudCoeff.bin', 'SpcCoeff/Big_Endian/imgr_g11.SpcCoeff.bin', 'TauCoeff/ODPS/Big_Endian/imgr_g11.TauCoeff.bin', 'SpcCoeff/Big_Endian/imgr_g12.SpcCoeff.bin', 'TauCoeff/ODPS/Big_Endian/imgr_g12.TauCoeff.bin', 'SpcCoeff/Big_Endian/imgr_g13.SpcCoeff.bin', 'TauCoeff/ODPS/Big_Endian/imgr_g13.TauCoeff.bin', 'SpcCoeff/Big_Endian/imgr_g15.SpcCoeff.bin', 'TauCoeff/ODPS/Big_Endian/imgr_g15.TauCoeff.bin', 'SpcCoeff/Big_Endian/imgr_mt1r.SpcCoeff.bin', 'TauCoeff/ODPS/Big_Endian/imgr_mt1r.TauCoeff.bin', 'SpcCoeff/Big_Endian/imgr_mt2.SpcCoeff.bin', 'TauCoeff/ODPS/Big_Endian/imgr_mt2.TauCoeff.bin', 'SpcCoeff/Big_Endian/imgr_insat3d.SpcCoeff.bin', 'TauCoeff/ODPS/Big_Endian/imgr_insat3d.TauCoeff.bin', 'SpcCoeff/Big_Endian/amsre_aqua.SpcCoeff.bin', 'TauCoeff/ODPS/Big_Endian/amsre_aqua.TauCoeff.bin', 'SpcCoeff/Big_Endian/tmi_trmm.SpcCoeff.bin', 'TauCoeff/ODPS/Big_Endian/tmi_trmm.TauCoeff.bin', 'SpcCoeff/Big_Endian/ssmi_f13.SpcCoeff.bin', 'TauCoeff/ODPS/Big_Endian/ssmi_f13.TauCoeff.bin', 'SpcCoeff/Big_Endian/ssmi_f14.SpcCoeff.bin', 'TauCoeff/ODPS/Big_Endian/ssmi_f14.TauCoeff.bin', 'SpcCoeff/Big_Endian/ssmi_f15.SpcCoeff.bin', 'TauCoeff/ODPS/Big_Endian/ssmi_f15.TauCoeff.bin', 'SpcCoeff/Big_Endian/ssmis_f16.SpcCoeff.bin', 'TauCoeff/ODPS/Big_Endian/ssmis_f16.TauCoeff.bin', 'SpcCoeff/Big_Endian/ssmis_f17.SpcCoeff.bin', 'TauCoeff/ODPS/Big_Endian/ssmis_f17.TauCoeff.bin', 'SpcCoeff/Big_Endian/ssmis_f18.SpcCoeff.bin', 'TauCoeff/ODPS/Big_Endian/ssmis_f18.TauCoeff.bin', 'SpcCoeff/Big_Endian/ssmis_f19.SpcCoeff.bin', 'TauCoeff/ODPS/Big_Endian/ssmis_f19.TauCoeff.bin', 'SpcCoeff/Big_Endian/ssmis_f20.SpcCoeff.bin', 'TauCoeff/ODPS/Big_Endian/ssmis_f20.TauCoeff.bin', 'SpcCoeff/Big_Endian/seviri_m10.SpcCoeff.bin', 'TauCoeff/ODPS/Big_Endian/seviri_m10.TauCoeff.bin', 'SpcCoeff/Big_Endian/v.seviri_m10.SpcCoeff.bin'] # abspath coefficients for crtm2 (simulated synthetic satellites) abspath_coeff= [os.path.join(config['crtm_dir'], relpath) for relpath in relpath_to_link ] # abspath wrf_cntrl param file abspath_pf = os.path.join(config['upp_domain_dir'], 'parm', 'wrf_cntrl.parm') # concatenate lists of paths abspath_to_link = abspath_coeff + [abspath_pf] # create a symlink for every file in abspath_to_link for fl in abspath_to_link: utils.check_file_exists(fl) # check if file exist and is readable os.symlink(fl, os.path.join(config['post_dir'], os.path.basename(fl))) # symlink wrf_cntrl.parm to config['post_dir']/fort.14 os.symlink(abspath_pf, os.path.join(config['post_dir'], 'fort.14')) # symlink microphysic's tables - code used is based on mp_physics option # used in the wrfout file os.symlink(os.path.join(config['wrf_run_dir'], 'ETAMPNEW_DATA'), os.path.join(config['post_dir'], 'nam_micro_lookup.dat')) os.symlink(os.path.join(config['wrf_run_dir'], 'ETAMPNEW_DATA.expanded_rain' ), os.path.join(config['post_dir'], 'hires_micro_lookup.dat'))
def __init__(self, wrfpy_dir, datestart, dateend): config.__init__(self, wrfpy_dir) # load config # define and create wps working directory self.wps_workdir = os.path.join(self.config['filesystem']['work_dir'], 'wps') utils._create_directory(self.wps_workdir)