obc_dict = dict(south=1, east=1, north=1, west=1)

    elif 'grd_nwmed5km.nc' in roms_grd:
        sigma_params = dict(theta_s=6.5, theta_b=0, hc=110, N=36)
        obc_dict = dict(south=0, east=1, north=1, west=1)

    elif 'grd_nwmed5km_NARROW_STRAIT.nc' in roms_grd:
        sigma_params = dict(theta_s=6.5, theta_b=0, hc=110, N=36)
        obc_dict = dict(south=0, east=1, north=1, west=1)

    else:
        print 'No sigma parameters defined for grid: %s' % roms_grd
        raise Exception

    # Set up a RomsGrid object
    romsgrd = RomsGrid(''.join((roms_dir, roms_grd)), sigma_params, 'ROMS')
    romsgrd.set_bry_dx()
    romsgrd.set_bry_maskr()
    romsgrd.set_bry_areas()

    if variable_correction:

        if 'west' in open_boundary:
            bry_surface_area = romsgrd.area_west * romsgrd.maskr_west
        elif 'east' in open_boundary:
            bry_surface_area = romsgrd.area_east * romsgrd.maskr_east
        elif 'south' in open_boundary:
            bry_surface_area = romsgrd.area_south * romsgrd.maskr_south
        elif 'north' in open_boundary:
            bry_surface_area = romsgrd.area_north * romsgrd.maskr_north
Esempio n. 2
0
    #ini_filename = 'ini_nwmed5km_ecco2_199201.nc'
    #ini_filename = 'ini_nwmed5km_ecco2_TEST_CONSTANT.nc'
    #ini_filename = 'ini_na6km_198501_Akima.nc'
    #ini_filename = 'ini_na5_198501_BILINEAR.nc'

    #balldist = 250000. # distance (m) for kde_ball (should be 2dx at least?)

    #_END USER DEFINED VARIABLES_______________________________________

    plt.close('all')

    fillval = 9999

    # Initialise RomsGrid object for child grid
    romsgrd = RomsGrid(''.join((roms_dir, roms_grd)),
                       sigma_params,
                       model_type='ROMS')
    romsgrd = prepare_romsgrd(romsgrd)

    # Set up a RomsData object for the initial file
    romsini = RomsData(roms_dir + ini_filename, model_type='ROMS')

    # Create an initial file
    romsini.create_ini_nc(romsgrd, fillval, created_by='py_ecco2ini.py')

    ini_date_num = datetime(int(ini_date[:4]), int(ini_date[4:6]),
                            int(ini_date[6:]))
    ini_date_num = plt.date2num(ini_date_num) + 0.5

    day_zero_num = datetime(int(day_zero[:4]), int(day_zero[4:6]),
                            int(day_zero[6:]))
Esempio n. 3
0
    
    plt.close('all')
    
    #--Begin user defined options-----------------------------------
    

    sigma_params = dict(theta_s=None, theta_b=None, hc=None, N=None)

    
    #directory = '/marula/emason/runs2014/NA75_IA/'
    #frc_file = directory + 'blk_NA2009_2008-2010_6hr.nc'
    #grd = RomsGrid(directory + 'roms_grd_NA2009_7pt5km.nc', sigma_params, 'ROMS')
    
    directory = '/marula/emason/runs2014/NWMED2_unstable/'
    frc_file = directory + 'blk_nwmed_2km_2006-2006_6hr.nc'
    grd = RomsGrid(directory + 'grd_nwmed_2km.nc', sigma_params, 'ROMS')
    
    year_str = 2006
    year_end = 2006
    
    if 'blk' in frc_file:
        savefile = directory + 'cfsr_blk_monthly_%s-%s.nc' %(str(year_str), str(year_end))
    else:
        savefile = directory + 'cfsr_frc_monthly_%s-%s.nc' %(str(year_str), str(year_end))
    
    


    #--End user defined options-----------------------------------

    Mp, Np = grd.maskr().shape
Esempio n. 4
0
    end_date += '12'

    dtstrdt = plt.datetime.datetime(np.int(start_date[:4]),
                                    np.int(start_date[4:6]),
                                    np.int(start_date[6:8]),
                                    np.int(start_date[8:]))

    dtenddt = plt.datetime.datetime(np.int(end_date[:4]),
                                    np.int(end_date[4:6]),
                                    np.int(end_date[6:8]),
                                    np.int(end_date[8:]))

    dtstr, dtend = plt.date2num(dtstrdt), plt.date2num(dtenddt)

    # Set up a RomsGrid object
    romsgrd = RomsGrid(''.join((roms_dir, roms_grd)), sigma_params, 'ROMS')
    romsgrd.set_bry_dx()
    romsgrd.set_bry_maskr()
    romsgrd.set_bry_areas()

    # Get surface areas of open boundaries
    chd_bry_surface_areas = []
    for boundary, is_open in zip(obc_dict.keys(), obc_dict.values()):

        if 'west' in boundary and is_open:
            chd_bry_surface_areas.append(
                romsgrd.area_west.sum(axis=0) * romsgrd.maskr_west)

        elif 'east' in boundary and is_open:
            chd_bry_surface_areas.append(
                romsgrd.area_east.sum(axis=0) * romsgrd.maskr_east)
Esempio n. 5
0
    
    dtenddt = plt.datetime.datetime(np.int(end_date[:4]),
                                    np.int(end_date[4:6]),
                                    np.int(end_date[6:8]),
                                    np.int(end_date[8:]))
    
    # Number of records at daily frequency
    #delta = plt.datetime.timedelta(days=1)
    #numrec = plt.drange(dtstrdt, dtenddt, delta).size + 1

    dtstr, dtend = plt.date2num(dtstrdt), plt.date2num(dtenddt)
    #time_array = np.arange(plt.date2num(dtstrdt),
                           #plt.date2num(dtenddt) + 1, 1)

    # Set up a RomsGrid object
    romsgrd = RomsGrid(''.join((roms_dir, roms_grd)), sigma_params, 'ROMS')
    romsgrd.set_bry_dx()
    romsgrd.set_bry_maskr()
    romsgrd.set_bry_areas()
    
    # Set flag for zero longitude crossing
    romsgrd.check_zero_crossing()
    
    # Get surface areas of open boundaries
    chd_bry_surface_areas = []
    for open_boundary, flag in zip(obc_dict.keys(), obc_dict.values()):
        if 'west' in open_boundary and flag:
            chd_bry_surface_areas.append(romsgrd.area_west.sum(axis=0) *
                                         romsgrd.maskr_west)
        elif 'east' in open_boundary and flag:
            chd_bry_surface_areas.append(romsgrd.area_east.sum(axis=0) *
Esempio n. 6
0
def Process_Mercator(mercator_file,roms_grd,bry_file,overlap,overlap_file,params):

    print('\n\nProcessing Mercator Lateral Boundaries')
    print('----------------------------------------')
    print(mercator_file)
    
    sigma_params = dict(theta_s=params[0], theta_b=params[1], hc=params[2], N=params[3])
    obc_dict = dict(south=params[4], east=params[5], north=params[6], west=params[7]) # 1=open, 0=closed
    day_zero = params[8] # offset in days since 2000
    bry_cycle = params[9]  # days, 0 means no cycle
    balldist = params[10] # meters
    
    mercator_ssh_file = \
    mercator_temp_file = \
    mercator_salt_file = \
    mercator_u_file = \
    mercator_v_file = mercator_file
    
    plt.close('all')
    fillval = 9999.  
    
    overlap_offset = 0

    if 'IBI_daily' in mercator_file or 'ibi' in mercator_file:
        k2c = -273.15
    
    # Set up a RomsGrid object
    romsgrd = RomsGrid(roms_grd, sigma_params, 'ROMS')
    romsgrd.set_bry_dx()
    romsgrd.set_bry_maskr()
    romsgrd.set_bry_areas()
    
    # Get surface areas of open boundaries
    chd_bry_surface_areas = []
    for boundary, is_open in zip(obc_dict.keys(), obc_dict.values()):
        
        if 'west' in boundary and is_open:
            chd_bry_surface_areas.append(romsgrd.area_west.sum(axis=0) * romsgrd.maskr_west)
        
        elif 'east' in boundary and is_open:
            chd_bry_surface_areas.append(romsgrd.area_east.sum(axis=0) * romsgrd.maskr_east)
        
        elif 'south' in boundary and is_open:
            chd_bry_surface_areas.append(romsgrd.area_south.sum(axis=0) * romsgrd.maskr_south)
        
        elif 'north' in boundary and is_open:
            chd_bry_surface_areas.append(romsgrd.area_north.sum(axis=0) * romsgrd.maskr_north)
    
    # Get total surface of open boundaries
    chd_bry_total_surface_area = np.array([area.sum() for area in chd_bry_surface_areas]).sum()
    
    # Set up a RomsData object for creation of the boundary file
    romsbry = RomsData(bry_file, 'ROMS')
    romsbry.create_bry_nc(romsgrd, obc_dict, bry_cycle, fillval, 'py_mercator2roms')
    
    
    mercator_vars = dict(SSH = mercator_ssh_file,
                         TEMP = mercator_temp_file,
                         SALT = mercator_salt_file,
                         U = mercator_u_file)
    
    for mercator_var, mercator_file in zip(mercator_vars.keys(), mercator_vars.values()):
        
        print('\n\nProcessing variable *%s*' % mercator_var)
        proceed = False
        
        with netcdf.Dataset(mercator_file) as nc:
            try:
                mercator_date_start = nc.variables['time_counter'][0]
                mercator_date_end = nc.variables['time_counter'][-1]
                mercator_time_units = nc.variables['time_counter'].units
                mercator_time_origin = nc.variables['time_counter'].time_origin
                mercator_time_origin = plt.date2num(plt.datetime.datetime.strptime(
                                            mercator_time_origin, '%Y-%b-%d %H:%M:%S'))
            except Exception:
                mercator_date_start = nc.variables['time'][0]
                mercator_date_end = nc.variables['time'][-1]
                mercator_time_units = nc.variables['time'].units
                mercator_time_origin = mercator_time_units.partition(' ')[-1].partition(' ')[-1]
                mercator_time_origin = plt.date2num(plt.datetime.datetime.strptime(
                                            mercator_time_origin, '%Y-%m-%d %H:%M:%S'))
                
        if 'seconds' in mercator_time_units:
            mercator_dates = np.arange(mercator_date_start, mercator_date_end + 86400, 86400)
            mercator_dates /= 86400.
        elif 'hours' in mercator_time_units:
            mercator_dates = np.arange(mercator_date_start, mercator_date_end + 24, 24)
            mercator_dates /= 24.
        else:
            raise Exception('deal_with_when_a_problem')
        
        mercator_dates += mercator_time_origin
        #mercator_dates = mercator_dates[np.logical_and(mercator_dates >= dtstr,
        #                                               mercator_dates <= dtend)]
        #print(mercator_dates)
        #exit()
        
        for boundary, is_open in zip(obc_dict.keys(), obc_dict.values()):
            
            print('\n--- processing %sern boundary' % boundary)
            
            if 'west' in boundary and is_open:
                romsgrd_at_bry = WestGrid(roms_grd, sigma_params, 'ROMS')
                proceed = True
            
            elif 'north' in boundary and is_open:
                romsgrd_at_bry = NorthGrid(roms_grd, sigma_params, 'ROMS')
                proceed = True
            
            elif 'east' in boundary and is_open:
                romsgrd_at_bry = EastGrid(roms_grd, sigma_params, 'ROMS')
                proceed = True
            
            elif 'south' in boundary and is_open:
                romsgrd_at_bry = SouthGrid(roms_grd, sigma_params, 'ROMS')
                proceed = True
            
            else:
                proceed = False #raise Exception
            
            if proceed:
                
                romsgrd_at_bry = prepare_romsgrd(romsgrd_at_bry)
                mercator = MercatorData(mercator_file, 'Mercator', mercator_var, romsgrd_at_bry)
                mercator, proceed = prepare_mercator(mercator, balldist)
                
                if 'U' in mercator_var:
                    mercator_v = MercatorData(mercator_v_file, 'Mercator', 'V', romsgrd_at_bry,
                                         i0=mercator.i0, i1=mercator.i1, j0=mercator.j0, j1=mercator.j1)
                    mercator_v, junk = prepare_mercator(mercator_v, balldist)
                
                tind = 0     # index for writing records to bry file
                ttotal = np.shape(mercator_dates)
                
                for dt in mercator_dates:
                            
                    printProgressBar (tind, ttotal[0]-1)
                    
                    dtnum = math.floor(dt - day_zero)
                               
                    # Read in variables
                    mercator.get_variable(dt).fillmask()
                        
                    # Calculate barotropic velocities
                    if mercator.vartype in 'U':
                            
                        mercator_v.get_variable(dt).fillmask()
                        
                        # Rotate to zero angle
                        for k in np.arange(mercator.depths().size):
                            u, v = mercator.datain[k], mercator_v.datain[k]
                            mercator.datain[k], mercator_v.datain[k] = mercator.rotate(u, v, sign=-1)
                        
                        mercator.interp2romsgrd()
                        mercator_v.interp2romsgrd()
                        
                        # Rotate u, v to child angle
                        for k in np.arange(romsgrd.N).astype(np.int):
                            u, v = mercator.dataout[k], mercator_v.dataout[k]
                            mercator.dataout[k], mercator_v.dataout[k] = romsgrd.rotate(u, v, sign=1,
                                                                     ob=boundary)
                        
                        mercator.set_barotropic()
                        mercator_v.set_barotropic()
                        
                    else:
                        
                        mercator.interp2romsgrd()
                        
                        
                    # Write to boundary file
                    with netcdf.Dataset(romsbry.romsfile, 'a') as nc:
                            
                        if mercator.vartype in 'U':
                            
                            if boundary in ('north', 'south'):
                                u = romsgrd.half_interp(mercator.dataout[:,:-1],
                                                        mercator.dataout[:,1:])
                                ubar = romsgrd.half_interp(mercator.barotropic[:-1],
                                                           mercator.barotropic[1:])
                                u *= romsgrd_at_bry.umask()
                                ubar *= romsgrd_at_bry.umask()
                                v = mercator_v.dataout
                                vbar = mercator_v.barotropic
                                v *= romsgrd_at_bry.vmask()
                                vbar *= romsgrd_at_bry.vmask()
                                nc.variables['u_%s' % boundary][tind] = u
                                nc.variables['ubar_%s' % boundary][tind] = ubar
                                nc.variables['v_%s' % boundary][tind] = v
                                nc.variables['vbar_%s' % boundary][tind] = vbar
                            
                            elif boundary in ('east', 'west'):
                                u = mercator.dataout
                                ubar = mercator.barotropic
                                u *= romsgrd_at_bry.umask()
                                ubar *= romsgrd_at_bry.umask()
                                v = romsgrd.half_interp(mercator_v.dataout[:,:-1],
                                                        mercator_v.dataout[:,1:])
                                vbar = romsgrd.half_interp(mercator_v.barotropic[:-1],
                                                           mercator_v.barotropic[1:])
                                v *= romsgrd_at_bry.vmask()
                                vbar *= romsgrd_at_bry.vmask()
                                nc.variables['v_%s' % boundary][tind] = v
                                nc.variables['vbar_%s' % boundary][tind] = vbar
                                nc.variables['u_%s' % boundary][tind] = u
                                nc.variables['ubar_%s' % boundary][tind] = ubar
                            
                            else:
                                raise Exception('Unknown boundary: %s' % boundary)
                        
                        elif mercator.vartype in 'SSH':
                            
                            nc.variables['zeta_%s' % boundary][tind] = mercator.dataout
                            nc.variables['bry_time'][tind] = np.float(dtnum)
            
                        elif mercator.vartype in 'TEMP':
                            
                            if (mercator.dataout > 100.).any():
                                mercator.dataout += k2c # Kelvin to Celcius
                            nc.variables['temp_%s' % boundary][tind] = mercator.dataout
                        
                        else:
                            
                            varname = mercator.vartype.lower() + '_%s' % boundary
                            nc.variables[varname][tind] = mercator.dataout
                    
                    if (tind < overlap):
                        # Write overlap to previous boundary file
                        
                        with netcdf.Dataset(overlap_file, 'a') as nc:
                        
                            if (overlap_offset == 0):
                                overlap_offset = nc.dimensions['bry_time'].size
                                
                            t_overlap = tind + overlap_offset
                            
                            if mercator.vartype in 'U':
                                
                                if boundary in ('north', 'south'):
                                    u = romsgrd.half_interp(mercator.dataout[:,:-1],
                                                            mercator.dataout[:,1:])
                                    ubar = romsgrd.half_interp(mercator.barotropic[:-1],
                                                               mercator.barotropic[1:])
                                    u *= romsgrd_at_bry.umask()
                                    ubar *= romsgrd_at_bry.umask()
                                    v = mercator_v.dataout
                                    vbar = mercator_v.barotropic
                                    v *= romsgrd_at_bry.vmask()
                                    vbar *= romsgrd_at_bry.vmask()
                                    nc.variables['u_%s' % boundary][t_overlap] = u
                                    nc.variables['ubar_%s' % boundary][t_overlap] = ubar
                                    nc.variables['v_%s' % boundary][t_overlap] = v
                                    nc.variables['vbar_%s' % boundary][t_overlap] = vbar
                                
                                elif boundary in ('east', 'west'):
                                    u = mercator.dataout
                                    ubar = mercator.barotropic
                                    u *= romsgrd_at_bry.umask()
                                    ubar *= romsgrd_at_bry.umask()
                                    v = romsgrd.half_interp(mercator_v.dataout[:,:-1],
                                                            mercator_v.dataout[:,1:])
                                    vbar = romsgrd.half_interp(mercator_v.barotropic[:-1],
                                                               mercator_v.barotropic[1:])
                                    v *= romsgrd_at_bry.vmask()
                                    vbar *= romsgrd_at_bry.vmask()
                                    nc.variables['v_%s' % boundary][t_overlap] = v
                                    nc.variables['vbar_%s' % boundary][t_overlap] = vbar
                                    nc.variables['u_%s' % boundary][t_overlap] = u
                                    nc.variables['ubar_%s' % boundary][t_overlap] = ubar
                                
                                else:
                                    raise Exception('Unknown boundary: %s' % boundary)
                            
                            elif mercator.vartype in 'SSH':
                                
                                nc.variables['zeta_%s' % boundary][t_overlap] = mercator.dataout
                                nc.variables['bry_time'][t_overlap] = np.float(dtnum)
                
                            elif mercator.vartype in 'TEMP':
                                
                                if (mercator.dataout > 100.).any():
                                    mercator.dataout += k2c # Kelvin to Celcius
                                nc.variables['temp_%s' % boundary][t_overlap] = mercator.dataout
                            
                            else:
                                
                                varname = mercator.vartype.lower() + '_%s' % boundary
                                nc.variables[varname][t_overlap] = mercator.dataout
                    
                    
                        
                    tind += 1

    
    
    # Correct volume fluxes and write to boundary file
    print('\nProcessing volume flux correction')
    #with netcdf.Dataset(romsbry.romsfile, 'a') as nc:
    with netcdf.Dataset(bry_file, 'a') as nc:                
        bry_times = nc.variables['bry_time'][:]
        boundarylist = []
        for bry_ind in range(bry_times.size):
            uvbarlist = []
            for boundary, is_open in zip(obc_dict.keys(), obc_dict.values()):
                if 'west' in boundary and is_open:
                    uvbarlist.append(nc.variables['ubar_west'][bry_ind])
                elif 'east' in boundary and is_open:
                    uvbarlist.append(nc.variables['ubar_east'][bry_ind])
                elif 'north' in boundary and is_open:
                    uvbarlist.append(nc.variables['vbar_north'][bry_ind])
                elif 'south' in boundary and is_open:
                    uvbarlist.append(nc.variables['vbar_south'][bry_ind])
                if bry_ind == 0 and is_open:
                    boundarylist.append(boundary)
            fc = bry_flux_corr(boundarylist,
                               chd_bry_surface_areas,
                               chd_bry_total_surface_area,
                               uvbarlist)
            print('------ barotropic velocity correction:', fc, 'm/s')
            for boundary, is_open in zip(obc_dict.keys(), obc_dict.values()):
                if 'west' in boundary and is_open:
                    nc.variables['u_west'][bry_ind] -= fc
                    nc.variables['ubar_west'][bry_ind] -= fc
                elif 'east' in boundary and is_open:
                    nc.variables['u_east'][bry_ind] += fc
                    nc.variables['ubar_east'][bry_ind] += fc
                elif 'north' in boundary and is_open:
                    nc.variables['v_north'][bry_ind] += fc
                    nc.variables['vbar_north'][bry_ind] += fc
                elif 'south' in boundary and is_open:
                    nc.variables['v_south'][bry_ind] -= fc
                    nc.variables['vbar_south'][bry_ind] -= fc
                    
    if (overlap>0):
        print('\nProcessing volume flux correction for overlap')
        with netcdf.Dataset(overlap_file, 'a') as nc:                
            bry_times = nc.variables['bry_time'][:]
            boundarylist = []
            for bry_ind in range(bry_times.size-overlap,bry_times.size):
                uvbarlist = []
                for boundary, is_open in zip(obc_dict.keys(), obc_dict.values()):
                    if 'west' in boundary and is_open:
                        uvbarlist.append(nc.variables['ubar_west'][bry_ind])
                    elif 'east' in boundary and is_open:
                        uvbarlist.append(nc.variables['ubar_east'][bry_ind])
                    elif 'north' in boundary and is_open:
                        uvbarlist.append(nc.variables['vbar_north'][bry_ind])
                    elif 'south' in boundary and is_open:
                        uvbarlist.append(nc.variables['vbar_south'][bry_ind])
                    if bry_ind == (bry_times.size-overlap) and is_open:
                        boundarylist.append(boundary)
                fc = bry_flux_corr(boundarylist,
                                   chd_bry_surface_areas,
                                   chd_bry_total_surface_area,
                                   uvbarlist)
                print('------ barotropic velocity correction:', fc, 'm/s')
                for boundary, is_open in zip(obc_dict.keys(), obc_dict.values()):
                    if 'west' in boundary and is_open:
                        nc.variables['u_west'][bry_ind] -= fc
                        nc.variables['ubar_west'][bry_ind] -= fc
                    elif 'east' in boundary and is_open:
                        nc.variables['u_east'][bry_ind] += fc
                        nc.variables['ubar_east'][bry_ind] += fc
                    elif 'north' in boundary and is_open:
                        nc.variables['v_north'][bry_ind] += fc
                        nc.variables['vbar_north'][bry_ind] += fc
                    elif 'south' in boundary and is_open:
                        nc.variables['v_south'][bry_ind] -= fc
                        nc.variables['vbar_south'][bry_ind] -= fc
    
    
    print('all done')
Esempio n. 7
0
if __name__ == '__main__':

    plt.close('all')

    #--Begin user defined options-----------------------------------

    sigma_params = dict(theta_s=None, theta_b=None, hc=None, N=None)

    #directory = '/marula/emason/runs2014/NA75_IA/'
    #frc_file = directory + 'blk_NA2009_2008-2010_6hr.nc'
    #grd = RomsGrid(directory + 'roms_grd_NA2009_7pt5km.nc', sigma_params, 'ROMS')

    directory = '/marula/emason/runs2014/NWMED2_unstable/'
    frc_file = directory + 'blk_nwmed_2km_2006-2006_6hr.nc'
    grd = RomsGrid(directory + 'grd_nwmed_2km.nc', sigma_params, 'ROMS')

    year_str = 2006
    year_end = 2006

    if 'blk' in frc_file:
        savefile = directory + 'cfsr_blk_monthly_%s-%s.nc' % (str(year_str),
                                                              str(year_end))
    else:
        savefile = directory + 'cfsr_frc_monthly_%s-%s.nc' % (str(year_str),
                                                              str(year_end))

    #--End user defined options-----------------------------------

    Mp, Np = grd.maskr().shape
     sigma_params = dict(theta_s=6.5, theta_b=0, hc=110, N=36)
     obc_dict = dict(south=0, east=1, north=1, west=1)
 
 elif 'grd_nwmed5km_NARROW_STRAIT.nc' in roms_grd:
     sigma_params = dict(theta_s=6.5, theta_b=0, hc=110, N=36)
     obc_dict = dict(south=0, east=1, north=1, west=1)
 
 else:
     print 'No sigma parameters defined for grid: %s' %roms_grd
     raise Exception
 
 
 
 
 # Set up a RomsGrid object
 romsgrd = RomsGrid(''.join((roms_dir, roms_grd)), sigma_params, 'ROMS')
 romsgrd.set_bry_dx()
 romsgrd.set_bry_maskr()
 romsgrd.set_bry_areas()
 
 if variable_correction:
     
     if 'west' in open_boundary:
         bry_surface_area  = romsgrd.area_west * romsgrd.maskr_west
     elif 'east' in open_boundary:
         bry_surface_area  = romsgrd.area_east * romsgrd.maskr_east
     elif 'south' in open_boundary:
         bry_surface_area  = romsgrd.area_south * romsgrd.maskr_south
     elif 'north' in open_boundary:
         bry_surface_area  = romsgrd.area_north * romsgrd.maskr_north
     
Esempio n. 9
0
    #ini_filename = 'ini_na5_198501_BILINEAR.nc'
    
    
    #balldist = 250000. # distance (m) for kde_ball (should be 2dx at least?)



    #_END USER DEFINED VARIABLES_______________________________________
    
    plt.close('all')
    
    fillval = 9999
    
    
    # Initialise RomsGrid object for child grid
    romsgrd = RomsGrid(''.join((roms_dir, roms_grd)), sigma_params, model_type='ROMS')
    romsgrd = prepare_romsgrd(romsgrd)

    # Set up a RomsData object for the initial file
    romsini = RomsData(roms_dir + ini_filename, model_type='ROMS')

    # Create an initial file
    romsini.create_ini_nc(romsgrd, fillval, created_by='py_ecco2ini.py')
    
    ini_date_num = datetime(int(ini_date[:4]), int(ini_date[4:6]), int(ini_date[6:]))
    ini_date_num = plt.date2num(ini_date_num) + 0.5
    
    day_zero_num = datetime(int(day_zero[:4]), int(day_zero[4:6]), int(day_zero[6:]))
    day_zero_num = plt.date2num(day_zero_num)
    
    if ini_date_num != day_zero_num:
Esempio n. 10
0
    end_date += '12'
    
    dtstrdt = plt.datetime.datetime(np.int(start_date[:4]),
                                    np.int(start_date[4:6]),
                                    np.int(start_date[6:8]),
                                    np.int(start_date[8:]))
    
    dtenddt = plt.datetime.datetime(np.int(end_date[:4]),
                                    np.int(end_date[4:6]),
                                    np.int(end_date[6:8]),
                                    np.int(end_date[8:]))
    
    dtstr, dtend = plt.date2num(dtstrdt), plt.date2num(dtenddt)

    # Set up a RomsGrid object
    romsgrd = RomsGrid(''.join((roms_dir, roms_grd)), sigma_params, 'ROMS')
    romsgrd.set_bry_dx()
    romsgrd.set_bry_maskr()
    romsgrd.set_bry_areas()
    
    
    # Get surface areas of open boundaries
    chd_bry_surface_areas = []
    for boundary, is_open in zip(obc_dict.keys(), obc_dict.values()):
        
        if 'west' in boundary and is_open:
            chd_bry_surface_areas.append(romsgrd.area_west.sum(axis=0) * romsgrd.maskr_west)
        
        elif 'east' in boundary and is_open:
            chd_bry_surface_areas.append(romsgrd.area_east.sum(axis=0) * romsgrd.maskr_east)
        
Esempio n. 11
0
        u_str = 'U'
        v_str = 'V'
    else:
        ssh_str = 'ssh'
        temp_str = 'temp'
        salt_str = 'salt'
        u_str = 'u'
        v_str = 'v'

    day_zero = datetime(int(day_zero[:4]), int(day_zero[4:6]), int(day_zero[6:]))
    day_zero = plt.date2num(day_zero)

    

    # Initialise SodaGrid and RomsGrid objects for both parent and child grids
    romsgrd = RomsGrid(''.join((roms_dir, roms_grd)), sigma_params, 'ROMS')
    
    romsgrd = prepare_romsgrd(romsgrd)
    
    romsgrd.set_bry_dx()
    romsgrd.set_bry_maskr()
    romsgrd.set_bry_areas()
    
    # Get surface areas of open boundaries and prepare boundary grids
    chd_bry_surface_areas = []
    boundary_grids = []
    for open_boundary, flag in zip(obc_dict.keys(), obc_dict.values()):
        if 'west' in open_boundary and flag:
            chd_bry_surface_areas.append(romsgrd.area_west.sum(axis=0) * romsgrd.maskr_west)
            boundary_grids.append(WestGrid(roms_dir + roms_grd, sigma_params, 'ROMS'))
        elif 'east' in open_boundary and flag: