Exemple #1
0
def load_model(location, images_dir):

    # import ipdb; ipdb.set_trace()

    (dir_name, filename) = os.path.split(location)

    scripting.make_images_dir(images_dir)
    imp_script = imp.load_source(filename.rstrip('.py'), location)
    model = imp_script.make_model(images_dir)
    return (model, imp_script)
Exemple #2
0
def load_model(location, images_dir):

    # import ipdb; ipdb.set_trace()

    filename = os.path.split(location)[1]

    scripting.make_images_dir(images_dir)
    imp_script = imp.load_source(filename.rstrip('.py'), location)
    model = imp_script.make_model(images_dir)
    return (model, imp_script)
def run_mul_GNOME(x,y,starttime,endtime,period,dt,opt='SUNTANS'):
    
    '''
    number--set up how many GNOME to run
    Run multiple GNOME;
    x,y--UTM coordinates for oil spill location;
    starttime='2014-08-21'
    endtime='2014-08-22'
    yr,month,day---oil spill start time;
    period---oil spill simulation duration;
    dt--oil spill time step in second
    opt--'SUNTANS' or 'ROMS' or 'both'
    '''
    yr=int(starttime[0:4]);
    #month=int(starttime[5:7].lstrip("0").replace("0", " "))
    month=int(starttime[5:7].lstrip('0'))
    #day=int(starttime[8:].lstrip("0").replace("0", " "))
    day=int(starttime[8:].lstrip('0'))
    timeformat='%Y-%m-%d'
    diff=datetime.strptime(endtime,timeformat)-datetime.strptime(starttime,timeformat)

    if diff.days*24 < period:
        raise IOError('Input period is longer than the data length')
            
    utm_x=x ; utm_y=y
    coor=[[utm_x,utm_y],[utm_x-10,utm_y],[utm_x-20,utm_y],[utm_x+10,utm_y],[utm_x+20,utm_y],[utm_x,utm_y-10],\
     [utm_x,utm_y-20],[utm_x,utm_y+10],[utm_x,utm_y+20],[utm_x-10,utm_y+10],[utm_x-10,utm_y-10],[utm_x+10,utm_y+10],[utm_x+10,utm_y-10]]
    
    work_dir=os.getcwd()
    
    os.chdir(work_dir+'/GNOME/')
            
    scripting.make_images_dir()
    model = make_model(coor,yr,month,day,period,dt,opt,images_dir=os.getcwd()+"/images")
    wdd=[0.01,0.04]
    model.full_run(wdd,logger=True)
    print 'end'
    os.chdir(work_dir) 
Exemple #4
0
    c_mover = CatsMover(curr_file)

    # this is the value in the file (default)
    # c_mover.scale_refpoint = (-66.082836, 18.469334)
    c_mover.scale_refpoint = (-66.084333333, 18.46966667)
    c_mover.scale = True
    c_mover.scale_value = 0.1

    model.movers += c_mover

    print 'adding a spill'

    end_time = start_time + timedelta(hours=12)
    spill = point_line_release_spill(num_elements=1000,
                                     release_time=start_time,
                                     start_position=(-66.16374,
                                                     18.468054, 0.0),
                                     # start_position=(-66.129099,
                                     #                 18.465332, 0.0),
                                     # end_release_time=end_time,
                                     )

    model.spills += spill

    return model

if __name__ == "__main__":
    scripting.make_images_dir()
    model = make_model()
    model.full_run()
Exemple #5
0
    print 'adding four spill'
    model.spills += point_line_release_spill(num_elements=NUM_ELEMENTS // 4,
                                             start_position=(145.25, 15.0,
                                                             0.0),
                                             release_time=start_time)
    model.spills += point_line_release_spill(num_elements=NUM_ELEMENTS // 4,
                                             start_position=(146.25, 15.0,
                                                             0.0),
                                             release_time=start_time)
    model.spills += point_line_release_spill(num_elements=NUM_ELEMENTS // 4,
                                             start_position=(145.75, 15.25,
                                                             0.0),
                                             release_time=start_time)
    model.spills += point_line_release_spill(num_elements=NUM_ELEMENTS // 4,
                                             start_position=(145.75, 14.75,
                                                             0.0),
                                             release_time=start_time)

    return model


if __name__ == '__main__':
    scripting.make_images_dir()
    model = make_model()

    for step in model:
        # print step
        print "step: %.4i -- memuse: %fMB" % (step['Renderer']['step_num'],
                                              utilities.get_mem_use())
Exemple #6
0
    comp_mover.pat1_speed = 19.44
    comp_mover.pat1_speed_units = 1
    comp_mover.pat1ScaleToValue = .138855
    comp_mover.pat2_angle = 225
    comp_mover.pat2_speed = 19.44
    comp_mover.pat2_speed_units = 1
    comp_mover.pat2ScaleToValue = .05121

    model.movers += comp_mover

    print 'adding a spill'

    end_time = gs.asdatetime(start_time) + gs.hours(12)
    spill = gs.point_line_release_spill(num_elements=100,
                                        start_position=(-70.911432, 42.369142,
                                                        0.0),
                                        release_time=start_time,
                                        end_release_time=end_time)

    model.spills += spill

    return model


if __name__ == "__main__":
    gs.make_images_dir()
    print "setting up the model"
    model = make_model()
    print "running the model"
    model.full_run()
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) 
Exemple #8
0
                                  default_num_method=method)
    i_w_mover = gs.PyWindMover(wind=ice_aware_wind,
                               default_num_method=method)

    # shifting to -360 to 0 longitude
    ice_aware_curr.grid.node_lon = ice_aware_curr.grid.node_lon[:] - 360
    model.movers += i_c_mover
    model.movers += i_w_mover

    print 'adding an Ice RandomMover:'
    model.movers += IceAwareRandomMover(ice_concentration=ice_aware_curr.ice_concentration,
                                        diffusion_coef=50000)


    # to visualize the grid and currents
#     renderer.add_grid(ice_aware_curr.grid)
#     renderer.add_vec_prop(ice_aware_curr)

    return model


if __name__ == "__main__":
    # gs.set_verbose()
    gs.make_images_dir()
    model = make_model()
    print "doing full run"
    startTime = gs.now()
    for step in model:
        print "step: %.4i" % (step['step_num'])
    print "it took %s to run" % (gs.now() - startTime)