예제 #1
0
def HyosPy(starttime, endtime, period, mode=1):
    """
    input:
        starttime='2014-02-21'
        endtime='2014-02-22'
        period=24         oil spill simulation duration;
        mode = 1
        
        Mode 1:
            download ROMS output from the server and run GNOME, have a quicker look (takes a few seconds)
        Mode 2:
            download river, wind, tidal, ROMS initial data, run SUNTANS and GNOME, have an accurate look
            (takes a few minutes)
        Mode 3: 
            a combination of mode 1 and 2, use the output of both ROMS and SUNTANS, duplicate the particles
            that enters the overlap region
    
        Some suggestions: 
            1) if the initial location is out of SUNTANS domain, run both mode 1 and mode 3
            2) if the initial location is in SUNTANS domain, simply run mode 2
    """
    #starttime='2014-02-21'
    #endtime='2014-02-22'
    dire=os.getcwd()
    
    if mode==1:
        
        downloadROMS(starttime,endtime,ROMSsrc='hindcast')
        ROMS_file=dire+'/DATA/'+'txla_subset_HIS.nc'
        ROMS_out=dire+'/GNOME/'+'hiroms_ss_rho.nc'        
        oilspill_wrapper.init_model(opt='ROMS')
        oilspill_wrapper.HIROMS(ROMS_file,ROMS_out)
        oilspill_wrapper.run_mul_GNOME(311584.1,3113650.2,starttime,endtime,period,900, opt='ROMS')
        oilspill_wrapper.GNOME_GM_visualization(opt='ROMS')
        oilspill_wrapper.GNOME_GE_animation(13,starttime,opt='ROMS')
    
    elif mode==2:
    
        infile=dire+'/CoarseTri/rundata/'+'GalvCoarse_0000.nc'
        outfile=dire+'/GNOME/'+'txsuntans.nc'
        hydro_wrapper.runSUNTANS(starttime, endtime)
        oilspill_wrapper.init_model()
        oilspill_wrapper.Tx_SUNTANS(infile,outfile) ##input: SUNTANS input; output: GNOME input
        oilspill_wrapper.run_mul_GNOME(321947.94,3256260.05,starttime,endtime,period,900)
        oilspill_wrapper.GNOME_GM_visualization()
        oilspill_wrapper.GNOME_GE_animation(13,starttime)
        print 'end'
        
    elif mode==3:
        
        print "under developing!!\n"
        ####use the ROMS current data to run GNOME####
        downloadROMS(starttime,endtime, ROMSsrc='hindcast')
        ROMS_file=dire+'/DATA/'+'txla_subset_HIS.nc'
        ROMS_out=dire+'/GNOME/'+'hiroms_ss_rho.nc'
        oilspill_wrapper.init_model(opt='ROMS') #The option is 'ROMS', since will run GNOME using ROMS output first
        oilspill_wrapper.HIROMS(ROMS_file,ROMS_out)                
        #oilspill_wrapper.run_mul_GNOME(311584.1,3113650.2,starttime,endtime,period,900, opt='ROMS')
        #(utm_x,utm_y)=utm.from_latlon(28.600572, -94.728385)[0:2]
        (utm_x,utm_y)=utm.from_latlon(28.353786, -95.315109)[0:2]
        oilspill_wrapper.run_mul_GNOME(utm_x,utm_y,starttime,endtime,period,900, opt='ROMS')
        oilspill_wrapper.GNOME_GM_visualization(opt='ROMS')
        ####duplicate the particles####
        oilspill_wrapper.duplicate(starttime,endtime,900)
        oilspill_wrapper.visualization2()
        
        
                                        
    else:
        print "There is no such mode, check HyosPy input mode!!!\n"
예제 #2
0
def runSUNTANS(starttime,endtime):
    """
    Specify the time for a model run and import envir var
    for example: starttime='2014-08-21', endtime='2014-08-23'
    """
    
    """
    specify the time period to download the data. 
    Note that this period should be longer and include the run period
    For example the start='2014-12-01' and end='2014-12-10' 
    This can be done by employing the function increaseT()
    """
      
    (start,end)=increaseT1(starttime,endtime)
    (romst1,romst2)=increaseT3(starttime,endtime)
    downloadROMS(romst1,romst2,ROMSsrc='hindcast')    #download initial condition data  
    
    downloadUSGSriver(start,end)              	#download the river inflow data
    staid='022' 					#specify the station id to download tide data 
    downloadTCOONTide(start,end,staid) 			#download the tide
    #Update and write the resulting data into the database file
    dbfile = 'GalvestonObs.db'
    write2db(dbfile)
    
    """
    download the wind data from TCOON and insert the data into the existing file
    Galveston_NARR_20122016 in folder DATA/ which can be read by SUNTANS
    """
    windID='207' #specify the wind data location
    updateWind(windID)
    """
    run the shell script: buildFolder to build the rundata folder 
    and copy the necessary files to start a new run
    """

    subprocess.Popen('./CoarseTri/buildFolder',shell=False)

    '''
    generate the boundary condition and initial condition, 
    the starttime and endtime should be in the format that
    start = '20141202.000000'
    end = '20141206.000000'
    '''

    (t1,t2)=increaseT2(starttime,endtime)
    t1=convertFormat(t1)+'.000000'
    t2=convertFormat(t2)+'.000000'
    generateBI(t1,t2)
    
    '''
    revise the file suntans.dat to specify the timeperiod and starttime
    Note that the time format for starttime and endtime is like: 
    starttime='2014-12-03', endtime='2014-12-08'
    which is also the run time
    '''
    reviseDatFile(starttime,endtime)

    ##########################run the model############################
    dire=os.getcwd()
    os.chdir(dire+'/CoarseTri')
    #subprocess.call('make test &> suntans.out & ',shell=True)
    subprocess.call('make test ',shell=True)
    
    os.chdir(dire)