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"
def duplicate(starttime,endtime,dt): """ Traverse the SUNTANS boundary grid to locate the points that ROMS result enters and run GNOME """ print "Trying to duplicate the oil spill particles at the SUNTANS boundary!!\n" base_dir = os.path.dirname(__file__) try: ncfile=Dataset(base_dir+'/CoarseTri/rundata/'+'GalvCoarse_0000.nc','r') except IOError: print 'No SUNTANS output available' mark=ncfile.variables['mark'][:] xe=ncfile.variables['xe'][:] ye=ncfile.variables['ye'][:] tide=[] #tide boundary mark river=[] #river boundary mark for ii in mark: if ii==3: tide.append(ii) if ii==2: river.append(ii) tide_index=[] for ind,mk in enumerate(mark): if mk==3: tide_index.append(ind) ###########Output the cooridinate of SUNTANS open boundary points######### open_boundary=[] for kk in tide_index: open_boundary.append([xe[kk],ye[kk]]) boundary=[] for i in range(len(open_boundary)): boundary.append(nctools.utmToLatLng(15,open_boundary[i][0],open_boundary[i][1])) ###########ROMS output############ roms_spill=spill_locations('GNOME_ROMS.nc') ################################## cbp=[] ###cbp is cross SUNTANS boundary point SUN13=[] for nn in range(len(roms_spill)): particle=roms_spill[nn] for i in range(len(particle)): find=False for j in range(len(boundary)): if abs(boundary[j][0]-particle[i][0])<0.0035 \ and abs(boundary[j][1]-particle[i][1])<0.0035: SUN13.append([boundary[j][0],boundary[j][1]]) find=True break if find==True: cbp.append(i) ###cbp is cross SUNTANS boundary point break if SUN13==[]: print '#########\n ROMS output particles will not cross SUNTANS boundary!! \n#########' print '#########\n check the Google map for details!! \n#########' raise RuntimeError('adjust initial locations and time period for GNOME run \ or you can change to mode 1 and rerun') else: print '#########\n %s particles generating at SUNTANS boundary!! \n#########'%str(len(SUN13)) timeformat='%Y-%m-%d' SUN_starttime=datetime.strptime(starttime,timeformat)+timedelta(math.floor(min(cbp)/(24*3600./dt))+1) SUN_starttime=SUN_starttime.strftime(timeformat) ##SUNTANS starttime before particle cross ROMS boundary diff=datetime.strptime(endtime,timeformat)-datetime.strptime(SUN_starttime,timeformat) period=diff.days*24 ####running SUNTANS from the SUN_starttime to endtime hydro_wrapper.runSUNTANS(SUN_starttime, endtime) ####generating input of GNOME from SUNTANS output infile=base_dir+'/CoarseTri/rundata/'+'GalvCoarse_0000.nc' outfile=base_dir+'/GNOME/'+'txsuntans.nc' Tx_SUNTANS(infile,outfile) coor=[] for i in range(len(SUN13)): coor.append(utm.from_latlon(SUN13[i][0],SUN13[i][1])[0:2]) yr=int(SUN_starttime[0:4]); #month=int(SUN_starttime[5:7].lstrip("0").replace("0", " ")) month=int(SUN_starttime[5:7].lstrip('0')) #day=int(SUN_starttime[8:].lstrip("0").replace("0", " ")) day=int(SUN_starttime[8:].lstrip('0')) row1='NetCDF Files' row2='[File] ./txsuntans.nc' f=open(os.getcwd()+'/GNOME/'+'current_SUNTANS.txt','w') f.write(row1+'\n') f.write(row2+'\n') f.close() work_dir=os.getcwd() os.chdir(work_dir+'/GNOME/') scripting.make_images_dir() pdb.set_trace() model = make_model(coor,yr,month,day,period,dt,images_dir=os.getcwd()+"/images") wdd=[0.01,0.04] model.full_run(wdd,logger=True) os.chdir(work_dir)