コード例 #1
0
ファイル: nsem_prep.py プロジェクト: trimbleava/coastal_act
def prep_ww3(wbnd_flg=0):
    """ Prepare ww3 run files """

    env = ini

    # Process WW3 grid and physics
    ww3_grid_inp = os.path.join(env.FIXnsem, "meshes", env.STORM, "wav",
                                "ww3_grid.inp")

    os.system('${EXECnsem}/ww3_grid ww3_grid.inp > ww3_grid.out')
    os.system('cp -p mod_def.ww3 mod_def.inlet')
    os.system('cp -p mod_def.ww3 mod_def.points')

    if wbnd_flg:
        # Process WW3 boundary conditions
        # TODO why copy from COMINwave to run_dir??
        os.system('cp -f ${COMINwave}/*.spc ' + ini.RUN_DIR)
        os.system('cp -f ' + ww3_grd_inp + '/ww3_bound.inp ' + run_dir)
        os.system('${EXECnsem}/ww3_bound ww3_bound.inp > ww3_bound.out')
        os.system('mv nest.ww3 nest.inlet')

    ##########   TODO Not found, check on these
    dc_ww3_multi = {}
    dc_ww3_multi.update(
        {'start_pdy': base_info.tide_spin_end_date.strftime("%Y%m%d %H%M%S")})
    dc_ww3_multi.update(
        {'end_pdy': base_info.wave_spin_end_date.strftime("%Y%m%d %H%M%S")})
    dc_ww3_multi.update({'dt_out_sec': 3600})
    #
    tmpname = os.path.join(FIXnsem, 'templates', base_info.ww3_multi_tmpl)
    ww3_multi = os.path.join(run_dir, 'ww3_multi.inp')
    util.tmp2scr(filename=ww3_multi, tmpname=tmpname, d=dc_ww3_multi)
コード例 #2
0
def prep_nems(dic):
  
    """Prepare nems run files"""

    # build.sh

    # slurm.job

    # NEMS.x


    # nems model_configure   
    ocn_pet_num = 0; atm_pet_num = 0; wav_pet_num = 0; nwm_pet_num = 0

    # prepare nems.configure
    dc2={}
    dc2.update({'c'  :'#' })
    try:
      if 'ocn_name' in dic:
        dc2.update({'_ocn_model_': dic['ocn_name']})

      if 'ocn_petlist' in dic:
        dc2.update({'_ocn_petlist_bounds_': dic['ocn_petlist']})
        pet_nums_arr = dic['ocn_petlist'].split()
        ocn_pet_num = int(pet_nums_arr[-1]) - int(pet_nums_arr[0]) + 1 

      if 'coupling_interval_sec' in dic:
        dc2.update({'_coupling_interval_sec_' : dic['coupling_interval_sec']})

      if 'nems_configure' in dic:
        template = os.path.join(env.FIXnsem, 'templates', dic['nems_configure'])
        dest = os.path.join(env.COMIN, 'nems.configure')
        nems_conf = util.tmp2scr(filename=dest, tmpname=template, d=dc2)
        
    except Exception as e:
      print("Error: ",str(e))
      sys.exit(0)

    total_pets = ocn_pet_num + atm_pet_num + wav_pet_num
    
    # prepare model_configure
    sdate = env.start_date_str
    month=sdate[0:1]; day=sdate[3:4]; year=sdate[6:9]
    hour=sdate[11:12]; minute=sdate[4:5]; second=sdate[17:18] 
    dc={}
    dc.update({'start_year'     :year })
    dc.update({'start_month'    :month })
    dc.update({'start_day'      :day })
    dc.update({'start_hour'     :hour})
    dc.update({'start_minute'   :minute})
    dc.update({'start_second'   :second})
    dc.update({'nhours'         :str(env.frcst_hrs)})
    dc.update({'total_pets'     :str(total_pets)})
    #
    template = os.path.join(env.FIXnsem, 'templates', 'atm_namelist.rc.template')   #TODO check on this file, use model_configure
    dest = os.path.join(env.COMIN, 'model_configure')
    #model_configure  = os.path.join(run_dir,'atm_namelist.rc')
    model_conf = util.tmp2scr(filename=dest, tmpname=template, d=dc)
コード例 #3
0
def prep_ww3(run_dir):
    """
    Prepare ww3 run files
    uses vars imported from base_info.py
   
    """
    #ww3
    txt1 = ' > Prepare ww3 inps ... (take couple of minutes)'
    logf(txt1, log_file)

    os.chdir(run_dir)

    # Process WW3 grid and physics
    txt1 = ' > Processing WW3 grid and physics...'
    logf(txt1, log_file)
    os.system('cp -f ' + ww3_grd_inp + '/*.msh ' + run_dir)
    os.system('cp -f ' + ww3_grd_inp + '/ww3_grid.inp ' + run_dir)
    os.system('${EXECnsem}/ww3_grid ww3_grid.inp > ww3_grid.out')
    os.system('cp -p mod_def.ww3 mod_def.inlet')
    os.system('cp -p mod_def.ww3 mod_def.points')

    if base_info.wbound_flg:
        # Process WW3 boundary conditions
        txt1 = ' > Processing WW3 boundary conditions...'
        if base_info.wbound_type == 'spc':
            logf(txt1, log_file)
            os.system('cp -f ${COMINwave}/*.spc ' + run_dir)
            os.system('cp -f ' + ww3_grd_inp + '/ww3_bound.inp ' + run_dir)
            os.system('${EXECnsem}/ww3_bound ww3_bound.inp > ww3_bound.out')
        if base_info.wbound_type == 'nc':
            logf(txt1, log_file)
            os.system('cp -f ${COMINwave}/*.nc ' + run_dir)
            os.system('cp -f ${COMINwave}/ww3_bounc.inp ' + run_dir)
            os.system('${EXECnsem}/ww3_bounc ww3_bounc.inp > ww3_bounc.out')
        os.system('mv nest.ww3 nest.inlet')
    ##########
    dc_ww3_multi = {}
    dc_ww3_multi.update(
        {'start_pdy': base_info.tide_spin_end_date.strftime("%Y%m%d %H%M%S")})
    dc_ww3_multi.update(
        {'end_pdy': base_info.wave_spin_end_date.strftime("%Y%m%d %H%M%S")})
    dc_ww3_multi.update({'dt_out_sec': 3600})
    dc_ww3_multi.update({'dt_hot_sec': int(base_info.hot_wave_out)})
    ##
    tmpname = os.path.join(FIXnsem, 'templates', base_info.ww3_multi_tmpl)
    ww3_multi = os.path.join(run_dir, 'ww3_multi.inp')
    nsem_utils.tmp2scr(filename=ww3_multi, tmpname=tmpname, d=dc_ww3_multi)
    #os.system('cp -fr  ' +   tmpname          +'  '   +run_dir+'/scr/')

    txt1 = ' > Copy WW3 HotStart input file from >  ' + GESIN
    logf(txt1, log_file)

    hot_file = os.path.join(GESIN, 'hotfiles', 'restart001.inlet')
    os.system('cp -f ' + hot_file + ' ' + run_dir)
    os.system('mv restart001.inlet restart.inlet')
コード例 #4
0
ファイル: nsem_prep.py プロジェクト: trimbleava/coastal_act
def update_fort15(dic):
    """update adcirc model parameter and periodic boundary condition
       file (fort.15). fort.15 is a template file and it is updated
       once per storm and under certain condition per run-type"""

    # get information needed from nems_env.py file
    start_date_str = env.start_date_str
    duration = env.frcst_hrs

    # change the date format to what adcirc expects
    start_date = datetime.strptime(start_date_str, '%m/%d/%Y %H:%M:%S')
    adcirc_start_date = start_date.isoformat().replace('T', ' ') + ' UTC'

    # saves the updateable parameters
    d15 = {}
    d15.update({'start_date': adcirc_start_date})
    d15.update({'run_time_days': str(dic['ndays'])})

    d15.update({'dramp': str(dic['ndays_ramp'])})
    d15.update({'nws': str(dic['nws'])})
    d15.update({'ihot': str(dic['ihot'])})
    d15.update({'dt': str(dic['dt'])})
    d15.update({'hot_ndt_out': str(dic['hot_ndt_out'])})

    if dic['nws'] > 0:
        d15.update({'WTIMINC': str(base_info.WTIMINC)})
        d15.update({'RSTIMINC': str(base_info.RSTIMINC)})
        #os.system('cp -f ' + adc_inp + '/fort* ' + run_dir)
        #os.system('cp -f ' + adc_inp + '/*.sh  ' + run_dir)
        #os.system('cp -f ' + adc_inp + '/*.py  ' + run_dir)
        os.system('cp -f ' + adc_inp + '/*.*   ' + run_dir)

    # get tide facts - TODO needs a condition
    """ TODO Condition ?? """
    #d15_tide = get_tidal_fact(run_dir)
    #d15.update(d15_tide)

    # get updated fort.15
    fort15tmp = os.path.join(env.FIXnsem, 'meshes', env.storm, 'ocn',
                             dic['fort15_temp'])
    dest = os.path.join(env.COMINadc, 'fort.15')
    util.tmp2scr(filename=dest, tmpname=fort15tmp, d=d15)
コード例 #5
0
def prep_ww3(run_dir):
    """
    Prepare ww3 run files
    uses vars imported from base_info.py
   
    """
    #ww3
    txt1 = ' > Prepare ww3 inps ... (take couple of minutes)'
    logf(txt1,log_file)

    os.chdir(run_dir)

    # Process WW3 grid and physics
    txt1 = ' > Processing WW3 grid and physics...'
    logf(txt1,log_file)
    os.system('cp -f ' + ww3_grd_inp + '/*.msh ' + run_dir)
    os.system('cp -f ' + ww3_grd_inp + '/ww3_grid.inp ' + run_dir)
    os.system('${EXECnsem}/ww3_grid ww3_grid.inp > ww3_grid.out')
    os.system('cp -p mod_def.ww3 mod_def.inlet')
    os.system('cp -p mod_def.ww3 mod_def.points')

    if base_info.wbound_flg:
       # Process WW3 boundary conditions
       txt1 = ' > Processing WW3 boundary conditions...'
       logf(txt1,log_file)
       os.system('cp -f ${COMINwave}/*.spc ' + run_dir)
       os.system('cp -f ' + ww3_grd_inp + '/ww3_bound.inp ' + run_dir)
       os.system('${EXECnsem}/ww3_bound ww3_bound.inp > ww3_bound.out')
       os.system('mv nest.ww3 nest.inlet')
       os.system('${EXECnsem}/ww3_bound ww3_bound.inp > ww3_bound.out')
       os.system('mv nest.ww3 nest.inlet')  
    ##########
    dc_ww3_multi={}
    dc_ww3_multi.update({'start_pdy'    :base_info.tide_spin_end_date.strftime("%Y%m%d %H%M%S") })
    dc_ww3_multi.update({'end_pdy'      :base_info.wave_spin_end_date.strftime("%Y%m%d %H%M%S") })
    dc_ww3_multi.update({'dt_out_sec'   :3600  })
    ##
    tmpname = os.path.join(FIXnsem, 'templates', base_info.ww3_multi_tmpl)
    ww3_multi = os.path.join(run_dir,'ww3_multi.inp')
    util.tmp2scr(filename=ww3_multi,tmpname=tmpname,d=dc_ww3_multi)
コード例 #6
0
def rprep_nems(run_dir):
    """ Preapre nems run time files """ 
   
    # model_configure

    # nems.configure

    # build.sh

    # slurm.job

    # NEMS.x
    #print ' > Prepare NEMS related input files ..'
    txt1 = ' > Prepare NEMS related input files ..'
    #logf(txt1,log_file)     
    # NEMS.x
    os.system ('cp -f ' + nems_exe + ' ' + run_dir)    

    #   
    ocn_pet_num = 0
    atm_pet_num = 0
    wav_pet_num = 0

    dc2={}
    dc2.update({'c'  :'#' })
    if base_info.ocn_name is not None:
        dc2.update({'_ocn_model_'          : base_info.ocn_name    })
        dc2.update({'_ocn_petlist_bounds_' : base_info.ocn_petlist })
        pet_nums = np.int_ (np.array(base_info.ocn_petlist.split()))
        ocn_pet_num = pet_nums[-1] - pet_nums[0] + 1 

    if base_info.atm_name is not None:
        dc2.update({'_atm_model_'          : base_info.atm_name    })
        dc2.update({'_atm_petlist_bounds_' : base_info.atm_petlist })
        pet_nums = np.int_ (np.array(base_info.atm_petlist.split()))
        atm_pet_num = pet_nums[-1] - pet_nums[0] + 1 

    if base_info.wav_name is not None:
        dc2.update({'_wav_model_'          : base_info.wav_name    })
        dc2.update({'_wav_petlist_bounds_' : base_info.wav_petlist })
        pet_nums = np.int_ (np.array(base_info.wav_petlist.split()))
        wav_pet_num = pet_nums[-1] - pet_nums[0] + 1 

    if base_info.coupling_interval_sec is not None:
        dc2.update({'_coupling_interval_sec_' : base_info.coupling_interval_sec    })

    #if base_info.coupling_interval_slow_sec is not None:
    #    dc2.update({'_coupling_interval_slow_sec_' : base_info.coupling_interval_slow_sec    })

    #if base_info.coupling_interval_fast_sec is not None:
    #    dc2.update({'_coupling_interval_fast_sec_' : base_info.coupling_interval_fast_sec    })

    txt1 = '   > Prepare atm_namelist.rc ..'
    #logf(txt1,log_file)   
    
    total_pets = ocn_pet_num + atm_pet_num + wav_pet_num
    tmpname = os.path.join(PARMnsem, base_info.nems_configure)
    model_configure  = os.path.join(run_dir,'nems.configure')
    util.tmp2scr(filename=model_configure,tmpname=tmpname,d=dc2)
    #os.system('cp -fr  ' +   tmpname          +'  '   +run_dir+'/scr/')
    ##########
    dc={}
    dc.update({'start_year'     :base_info.start_date_nems.year    })
    dc.update({'start_month'    :base_info.start_date_nems.month   })
    dc.update({'start_day'      :base_info.start_date_nems.day     })
    dc.update({'start_hour'     :base_info.start_date_nems.hour    })
    dc.update({'start_minute'   :base_info.start_date_nems.minute  })
    dc.update({'start_second'   :base_info.start_date_nems.second  })
    dc.update({'nhours'         :str(base_info.ndays * 24)})
    dc.update({'total_pets'     :str(total_pets)})
    ##
    tmpname = os.path.join(FIXnsem, 'templates', base_info.model_configure)
    model_configure  = os.path.join(run_dir,'atm_namelist.rc')
    util.tmp2scr(filename=model_configure,tmpname=tmpname,d=dc)
    os.system('ln -svf ' + model_configure + ' ' + os.path.join(run_dir,'model_configure' ) )
    #os.system('cp -fr  ' +   tmpname          +'  '   +run_dir+'/scr/')
    ##################################################################################
    txt1 = '   > Prepare nems.configure ..'
    #logf(txt1,log_file)   
    
    pet_max = 0
    dc3={}
    dc3.update({'c'  :'#' })
    if base_info.ocn_name is not None:
        dc3.update({'_ocn_model_'          : base_info.ocn_name    })
        dc3.update({'_ocn_petlist_bounds_' : base_info.ocn_petlist })
        pet_nums = np.int_ (np.array(base_info.ocn_petlist.split()))
        ocn_pet_num = pet_nums[-1] - pet_nums[0] + 1 
        pet_max = max(pet_nums[0],pet_nums[-1])

    if base_info.atm_name is not None:
        dc3.update({'_atm_model_'          : base_info.atm_name    })
        dc3.update({'_atm_petlist_bounds_' : base_info.atm_petlist })
        pet_nums = np.int_ (np.array(base_info.atm_petlist.split()))
        atm_pet_num = pet_nums[-1] - pet_nums[0] + 1 
        pet_max = max(pet_max,pet_nums[0],pet_nums[-1])

    if base_info.wav_name is not None:
        dc3.update({'_wav_model_'          : base_info.wav_name    })
        dc3.update({'_wav_petlist_bounds_' : base_info.wav_petlist })
        pet_nums = np.int_ (np.array(base_info.wav_petlist.split()))
        wav_pet_num = pet_nums[-1] - pet_nums[0] + 1 
        pet_max = max(pet_max,pet_nums[0],pet_nums[-1])

    if base_info.coupling_interval_sec is not None:
        dc3.update({'_coupling_interval_sec_' : base_info.coupling_interval_sec    })

    #if base_info.coupling_interval_slow_sec is not None:
    #    dc3.update({'_coupling_interval_slow_sec_' : base_info.coupling_interval_slow_sec    })

    #if base_info.coupling_interval_fast_sec is not None:
    #    dc3.update({'_coupling_interval_fast_sec_' : base_info.coupling_interval_fast_sec    })

    #total_pets = ocn_pet_num + atm_pet_num + wav_pet_num
    total_pets = pet_max + 1
    tmpname = os.path.join(PARMnsem, base_info.nems_configure)
    model_configure  = os.path.join(run_dir,'nems.configure')
    util.tmp2scr(filename=model_configure,tmpname=tmpname,d=dc3)
    #os.system('cp -fr  ' +   tmpname          +'  '   +run_dir+'/scr/')

    txt1 = '   > Prepare config.rc ..'
    #logf(txt1,log_file)   
    
    #generate apps.rc file
    apps_conf = os.path.join(run_dir,'config.rc')
    
    if base_info.wav_name == 'ww3data':
        #wav_dir   = os.path.join(run_dir, os.path.normpath(base_info.wav_inp_dir).split('/')[-1])
        wav_dir = COMINwave
        os.system ('echo " wav_dir: ' +  wav_dir                        + ' " >> ' + apps_conf )
        os.system ('echo " wav_nam: ' +  base_info.wav_netcdf_file_name + ' " >> ' + apps_conf )
        #
        wav_inp_file    = os.path.join(COMINwave,base_info.wav_netcdf_file_name)
        wav_rundir_file = os.path.join(wav_dir,base_info.wav_netcdf_file_name)
        if True:
            txt1 =  '  > Link Wave Inp ...'
            #logf(txt1,log_file)             
            
            os.system ('mkdir -p  ' +  wav_dir                                   )
            os.system ('ln    -sf ' +  wav_inp_file + ' ' + wav_rundir_file      )
        else:        
            #print '  > Copy Wave Inp ...'
            txt1 = '  > Copy WAV Inp ...'
            #logf(txt1,log_file)             
            
            os.system ('mkdir -p  ' +  wav_dir                                   )
            os.system ('cp    -f  ' +  wav_inp_file + ' ' + wav_rundir_file      )

    if base_info.atm_name is not None:
        #atm_dir   = os.path.join(run_dir, os.path.normpath(base_info.atm_inp_dir).split('/')[-1])
        atm_dir = COMINatm
        os.system ('echo " atm_dir: ' +  atm_dir                        + ' " >> ' + apps_conf )
        os.system ('echo " atm_nam: ' +  base_info.atm_netcdf_file_name + ' " >> ' + apps_conf )
        #
        atm_inp_file    = os.path.join(COMINatm,base_info.atm_netcdf_file_name)
        atm_rundir_file = os.path.join(atm_dir,base_info.atm_netcdf_file_name)
        if True:
            txt1 =  '  > Link ATM Inp ...'
            #logf(txt1,log_file)             
            
            os.system ('mkdir -p  ' +  atm_dir                                   )
            os.system ('ln    -sf ' +  atm_inp_file + ' ' + atm_rundir_file      )
        else:
            #print '  > Copy ATM Inp ...'  
            txt1 = '  > Copy ATM Inp ...'
            #logf(txt1,log_file)                  
            os.system ('mkdir -p  ' +  atm_dir                                   )
            os.system ('cp    -f  ' +  atm_inp_file + ' ' + atm_rundir_file      )               
コード例 #7
0
    RUNdir + "/ttest_scatter_HWRF_station_" + u10_worst + ".png"
})
dc_valreport.update(
    {'fig_hs_ts_best': RUNdir + "/ttest_ts_WW3_station_" + hs_best + ".png"})
dc_valreport.update(
    {'fig_hs_ts_worst': RUNdir + "/ttest_ts_WW3_station_" + hs_worst + ".png"})
dc_valreport.update({
    'fig_hs_hist_best':
    RUNdir + "/ttest_hist_WW3_station_" + hs_best + ".png"
})
dc_valreport.update({
    'fig_hs_hist_worst':
    RUNdir + "/ttest_hist_WW3_station_" + hs_worst + ".png"
})
dc_valreport.update({
    'fig_hs_scatter_best':
    RUNdir + "/ttest_scatter_WW3_station_" + hs_best + ".png"
})
dc_valreport.update({
    'fig_hs_scatter_worst':
    RUNdir + "/ttest_scatter_WW3_station_" + hs_worst + ".png"
})
##
tmpname = os.path.join(FIXnsem, 'templates', 'validation_report.tex.tmpl')
val_report = os.path.join(
    RUNdir, 'validation_report_' + STORM + '_' +
    datetime.today().strftime('%Y-%m-%d') + '.tex')
nsem_utils.tmp2scr(filename=val_report, tmpname=tmpname, d=dc_valreport)
# (c) Compile the validation report to PDF
os.system('pdflatex ' + val_report)
コード例 #8
0
def prep_adc(run_dir):
    """
    Prepare adcirc run files
    uses vars imported from base_info.py
   
    """
    #adcirc
    #print ' > Prepare adcirc inps ... (take couple of minutes)'
    txt1 = ' > Prepare adcirc inps ... (take couple of minutes)'
    logf(txt1,log_file)    
    
    # copy HSOFS grid similar for all cases
    os.system('cp -f ' + adc_grd_inp + '/*.*   ' + run_dir)    

    #Prepare fort.15
    adcirc_start_date = start_date.isoformat().replace('T',' ')+ ' UTC'

    txt1 = '   > Prepare fort.15 ..'
    logf(txt1,log_file)   

    d15 = {}
    d15.update({'start_date'    :adcirc_start_date          })
    d15.update({'run_time_days' :str(base_info.ndays)  })

    d15.update({'dramp'         :str(base_info.ndays_ramp)  })
    d15.update({'nws'           :str(base_info.nws)  })
    d15.update({'ihot'          :str(base_info.ihot)  })
    d15.update({'dt'            :str(base_info.dt)  })
    d15.update({'hot_ndt_out'   :str(base_info.hot_ndt_out)  })
    
    if base_info.nws > 0:
        d15.update({'WTIMINC'       :str(base_info.WTIMINC)  })
        d15.update({'RSTIMINC'      :str(base_info.RSTIMINC)  })
        #os.system('cp -f ' + adc_inp + '/fort* ' + run_dir)
        #os.system('cp -f ' + adc_inp + '/*.sh  ' + run_dir)
        #os.system('cp -f ' + adc_inp + '/*.py  ' + run_dir)
        os.system ('cp -f ' + adc_inp + '/*.*   ' + run_dir)   
  
    # get tide facts
    d15_tide = get_tidal_fact(run_dir)
    d15.update(d15_tide)
    # get updated fort.15
    fort15tmp = os.path.join(adc_grd_inp,base_info.fort15_temp)
    fort15  = os.path.join(run_dir,'fort.15')
    nsem_utils.tmp2scr(filename=fort15,tmpname=fort15tmp,d=d15)
    #os.system('cp -fr  ' +   fort15tmp          +'  '   +run_dir+'/scr/')
    
    #print ' > AdcPrep ... '
    txt1 = ' > AdcPrep ...  '
    logf(txt1,log_file) 
    pet_nums = np.int_ (np.array(base_info.ocn_petlist.split()))
    adc_pet_num = pet_nums[-1] - pet_nums[0] + 1 

    #comm0 = "source " + modfile +' ; '
    comm1  = ' cd   ' + run_dir + ' ; '+adcprep +' --np '+ str(adc_pet_num)+'  --partmesh >  adcprep.log'
    print(comm1)
    os.system(comm1)
    #
    comm2 = ' cd ' + run_dir + ' ; '+adcprep +' --np '+ str(adc_pet_num)+'  --prepall  >> adcprep.log'
    #print(comm2)
    txt1 = comm2
    logf(txt1,log_file) 
    os.system(comm2)
    
    txt1 = ' > End of Preproc.x ...  '
    logf(txt1,log_file)
    """
    # Treat hotfile
    try:
        GESIN
    except NameError:
        GESIN = None

    if GESIN is not None:
        #print ' > Copy HotStart input file from >', base_info.fetch_hot_from
    """
    txt1 = ' > Copy ADCIRC HotStart input file from >  '+ GESIN
    logf(txt1,log_file) 
        
    hot_file = os.path.join(GESIN,'hotfiles','fort.67.nc')
    os.system('cp -f ' + hot_file +' ' + run_dir)
    hot_file = os.path.join(GESIN,'hotfiles','fort.68.nc')        
    os.system('cp -f ' + hot_file +' ' + run_dir)
コード例 #9
0
    # Populate the postprocessing input template
    print("Postprocessing the WW3 binary output to NetCDF...")
    MESHFILE = sp.getoutput('ls -t *.msh | head -1')
    print('Opening mesh file: ' + RUNdir + '/' + MESHFILE)
    f = open(RUNdir + '/' + MESHFILE)
    lines = f.readlines()
    nnodes = lines[4]

    dc_ww3_ounf = {}
    dc_ww3_ounf.update(
        {'start_pdy': base_info.tide_spin_end_date.strftime("%Y%m%d %H%M%S")})
    dc_ww3_ounf.update({'nnodes': nnodes})
    ##
    tmpname = os.path.join(FIXnsem, 'templates', base_info.ww3_ounf_tmpl)
    ww3_ounf = os.path.join(RUNdir, 'ww3_ounf.inp')
    nsem_utils.tmp2scr(filename=ww3_ounf, tmpname=tmpname, d=dc_ww3_ounf)

    os.system('${EXECnsem}/ww3_ounf ww3_ounf.inp > ww3_ounf.out')

    # Create field plots of WW3 variables
    print("Creating field plots...")
    # Wave heights
    DATAFILE = sp.getoutput('ls -t ww3*hs*.nc | head -1')
    print('Plotting fields for STORM, DATAFILE: ' + STORM + ', ' + DATAFILE)
    plot_ww3_unstr.plot_hs(storm=STORM, datafile1=DATAFILE, domain='full')
    plot_ww3_unstr.plot_hs(storm=STORM,
                           datafile1=DATAFILE,
                           domain='regional',
                           lonmin=base_info.lonmin_plot_regional,
                           lonmax=base_info.lonmax_plot_regional,
                           latmin=base_info.latmin_plot_regional,
コード例 #10
0
ファイル: nsem_prep.py プロジェクト: trimbleava/coastal_act
def prep_nems(dic=None):
    """Prepare nems run files and copy them into $COMIN
    if manual and live :
      check and copy model_configure
      check and copy nems.configure
      check and copy build.sh
      check and copy slurm.job
      compile the model components
      copy the model installs file
      submit the slurm.job
    if archive :
      create model_configure and nems.configure templates per storm/run_name
      not sure to go this way!!
    """

    # build.sh

    # slurm.job

    # NEMS.x

    # nems model_configure

    ocn_pet_num = 0
    atm_pet_num = 0
    wav_pet_num = 0
    nwm_pet_num = 0

    # prepare nems.configure
    dc2 = {}
    dc2.update({'c': '#'})
    try:
        if 'ocn_name' in dic:
            dc2.update({'_ocn_model_': dic['ocn_name']})

        if 'ocn_petlist' in dic:
            dc2.update({'_ocn_petlist_bounds_': dic['ocn_petlist']})
            pet_nums_arr = dic['ocn_petlist'].split()
            ocn_pet_num = int(pet_nums_arr[-1]) - int(pet_nums_arr[0]) + 1

        if 'coupling_interval_sec' in dic:
            dc2.update(
                {'_coupling_interval_sec_': dic['coupling_interval_sec']})

        if 'nems_configure' in dic:
            template = os.path.join(env.FIXnsem, 'templates',
                                    dic['nems_configure'])
            dest = os.path.join(env.COMIN, 'nems.configure')
            nems_conf = util.tmp2scr(filename=dest, tmpname=template, d=dc2)

    except Exception as e:
        print("Error: ", str(e))
        sys.exit(0)

    msg = "\tFinished nems.configure file ...."
    print(util.colory("green", msg))

    # prepare model_configure

    total_pets = ocn_pet_num + atm_pet_num + wav_pet_num

    sdate = env.start_date_str
    month = sdate[0:1]
    day = sdate[3:4]
    year = sdate[6:9]
    hour = sdate[11:12]
    minute = sdate[4:5]
    second = sdate[17:18]
    dc = {}
    dc.update({'start_year': year})
    dc.update({'start_month': month})
    dc.update({'start_day': day})
    dc.update({'start_hour': hour})
    dc.update({'start_minute': minute})
    dc.update({'start_second': second})
    dc.update({'nhours': str(env.frcst_hrs)})
    dc.update({'total_pets': str(total_pets)})
    #
    template = os.path.join(env.FIXnsem, 'templates',
                            'atm_namelist.rc.template'
                            )  #TODO check on this file, use model_configure
    dest = os.path.join(env.COMIN, 'model_configure')
    #model_configure  = os.path.join(run_dir,'atm_namelist.rc')
    model_conf = util.tmp2scr(filename=dest, tmpname=template, d=dc)
    #os.system('ln -svf ' + model_configure + ' ' + os.path.join(run_dir,'model_configure' ) )
    #os.system('cp -fr  ' +   tmpname          +'  '   +run_dir+'/scr/')

    msg = "\tFinished model_configure file ...."
    print(util.colory("green", msg))

    # cp NEMS.x
    msg = "\tCopying NEMS.x file into %s...." % (env.COMIN)
    print(util.colory("green", msg))