Example #1
0
def main(datestring):
    '''
    Main function to initialize WPS timestep:
      - converts cylc timestring to datetime object
      - calls wps_init()
    '''
    dt = utils.convert_cylc_time(datestring)
    updatebc_init(dt)
Example #2
0
def main(datestring, interval):
    '''
    Main function to initialize WPS timestep:
      - converts cylc timestring to datetime object
      - calls wps_init()
    '''
    dt = utils.convert_cylc_time(datestring)
    wps_init(dt, dt + datetime.timedelta(hours=interval))
Example #3
0
 def _cli_parser(self):
   '''
   parse command line arguments
   '''
   parser = argparse.ArgumentParser(
     description='WRF retry script',
     formatter_class=argparse.ArgumentDefaultsHelpFormatter)
   parser.add_argument('datestring', metavar='N', type=str,
                       help='Date-time string from cylc suite')
   parser.add_argument('retrynumber', metavar='M', type=int,
                       help='cylc retry number')
   args = parser.parse_args()
   self.retry_number = args.retrynumber
   self.dt = utils.convert_cylc_time(args.datestring)
Example #4
0
 def __init__(self, args):
     config.__init__(self)
     obsDir = self.config['filesystem']['obs_dir']
     obsFilename = self.config['filesystem']['obs_filename']
     outputFile = os.path.join(obsDir, obsFilename)
     dt = utils.convert_cylc_time(args.datestring)
     # startdate
     dt1 = datetime.datetime(dt.year, dt.month, 1)
     dt1s = dt1.strftime('%Y%m%d')  # convert to string
     inputdir = os.path.join(args.inputdir, dt1s)
     inputFile = os.path.join(inputdir, args.inputfile)
     # remove existing file
     utils.silentremove(outputFile)
     # copy inputfile to location specified in config.json
     shutil.copyfile(inputFile, outputFile)
Example #5
0
def main(datestring, interval):
    '''
    Main function to initialize WPS timestep:
      - converts cylc timestring to datetime object
      - calls wrf.__init()
    '''
    dt = utils.convert_cylc_time(datestring)
    postprocess = upp()
    # construct wrfout name for domain 1
    dt_str = dt.strftime('%Y-%m-%d_%H:%M:%S')
    wrfout_name = wrfout_d01_ + dt_str
    wrfout_file = os.path.join(self.config['filesystem']['wrf_run_dir'],
                               wrfout_name)
    start_date = utils.return_validate(
        postprocess.config['options_general']['date_start'])
    if (start_date == dt):  # very first timestep
        postprocess.run_unipost_file(wrfout_files[0], use_t0=True)
    else:
        postprocess.run_unipost_file(wrfout_files[0], use_t0=False)
Example #6
0
 def __init__(self, datestring):
     config.__init__(self)
     datestart = utils.convert_cylc_time(datestring)
     # initialize WRFDA object
     WRFDA = wrfda(datestart)
     WRFDA.prepare_updatebc(datestart)
     # update lower boundary conditions
     for domain in range(1, WRFDA.max_dom + 1):
         WRFDA.updatebc_run(domain)  # run da_updatebc.exe
     # copy radar data into WRFDA workdir if available
     try:
         radarFile = self.config['filesystem']['radar_filepath']
         radarTarget = os.path.join(self.config['filesystem']['work_dir'],
                                    'wrfda', 'd01', 'ob.radar')
         shutil.copyfile(radarFile, radarTarget)
     except (KeyError, IOError):
         pass
     # prepare for running da_wrfvar.exe
     WRFDA.prepare_wrfda()
     # run da_wrfvar.exe
     WRFDA.wrfvar_run(1)
     # interpolate rural variables from wrfda
     wrfda_interpolate(itype='rural')
     try:
         urbanData = self.config['options_urbantemps']['urban_stations']
     except KeyError:
         urbanData = False
     if urbanData:
         bskin = bumpskin(urbanData,
                          dstationtypes=['davis', 'vp2', 'vantage'])
     # update URBPARM.TBL with anthropogenic heat factors
     try:
         urbparmFile = self.config['options_wrf']['urbparm.tbl']
     except KeyError:
         urbparmFile = False
     if urbparmFile:
         urbparm(datestart, urbparmFile)
     # update lateral boundary conditions
     WRFDA.prepare_updatebc_type('lateral', datestart, 1)
     WRFDA.updatebc_run(1)
     # copy files over to WRF run_dir
     WRFDA.wrfda_post(datestart)
Example #7
0
 def __init__(self, datestring):
     config.__init__(self)
     dt = utils.convert_cylc_time(datestring)
     postprocess = upp()
     # construct wrfout name for domain 1
     dt_str = dt.strftime('%Y-%m-%d_%H:%M:%S')
     wrfout_name = 'wrfout_d01_' + dt_str
     wrfout_file = os.path.join(self.config['filesystem']['wrf_run_dir'],
                                wrfout_name)
     start_date = utils.return_validate(
         postprocess.config['options_general']['date_start'])
     upp_interval = postprocess.config['options_upp']['upp_interval']
     if (start_date == dt):  # very first timestep
         postprocess.run_unipost_file(wrfout_file,
                                      frequency=upp_interval,
                                      use_t0=True)
     else:
         postprocess.run_unipost_file(wrfout_file,
                                      frequency=upp_interval,
                                      use_t0=False)
Example #8
0
def main(args):
    '''
    Example script to combine different output files
    from the prepare_synop.py script
    '''
    dt = utils.convert_cylc_time(args.datestring)
    # startdate
    dt1 = datetime.datetime(dt.year, dt.month, 1)
    dt1s = dt1.strftime('%Y%m%d')  # convert to string
    outputdir = os.path.join(args.outputdir, dt1s)
    filenames = glob.glob(os.path.join(outputdir, '*'))
    outputfile = args.outputfile
    if filenames:
        with open(os.path.join
                  (outputdir, outputfile), 'w') as fout:
            for line in fileinput.input(filenames):
                fout.write(line)
    else:
        with open(outputfile, 'a'):
            os.utime(outputfile, None)
Example #9
0
 def __init__(self, datestring, cylc_suite_def_path):
     config.__init__(self)
     dt = utils.convert_cylc_time(datestring)
     wrfout_time = datetime.datetime.strftime(dt, '%Y-%m-%d_%H:%M:%S')
     nml = self.config['options_wrf']['namelist.input']
     max_dom = utils.get_max_dom(nml)
     rundir = self.config['filesystem']['wrf_run_dir']
     archivedir = self.config['filesystem']['archive_dir']
     gis_archive = os.path.join(archivedir, 'gis', wrfout_time)
     utils._create_directory(gis_archive)
     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)
         utils.silentremove(archived)
         os.system('nc3tonc4 ' + wrfout + ' ' + archived)
         try:
             gis_out = os.path.join(
                 gis_archive, 'meteo_gis_d0' + str(dom) + '_' + wrfout_time)
             os.system('cdo -f nc4c -z zip_4 selvar,Q2,T2,U10,V10 ' +
                       wrfout + ' ' + gis_out)
         except Exception:
             pass
         plot_archive = os.path.join(archivedir, 'plot', wrfout_time)
         utils._create_directory(plot_archive)
         wrfncl = os.path.join(cylc_suite_def_path, 'bin',
                               'wrf_Surface3.ncl')
         os.system('ncl ' + wrfncl + ' inputfile=' + r'\"' + archived +
                   r'\" outputfile=\"' + plot_archive + r'/surface_d0' +
                   str(dom) + '.png' + r'\"')
     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)
Example #10
0
def main(datestring):
    dt = utils.convert_cylc_time(datestring)
    readObsTemperature(dt, dstationtypes=['davis', 'vp2', 'vantage'])
Example #11
0
def main(datestring):
        '''
        Main function to call archive class
        '''
        dt = utils.convert_cylc_time(datestring)
        postprocess(dt-relativedelta.relativedelta(days=1), dt)