def __init__(self):
        file2read = netcdf.NetCDFFile("/scratch/general/am8e13/results36km/grid.nc",'r')
        bathy = file2read.variables['HFacC']
        self.bathy = bathy[:]*1
        Z = file2read.variables['Z']
        Z = Z[:]*1
        self.Z = Z
        lat = file2read.variables['XC']
        self.lat = lat[:]*1
        lon = file2read.variables['YC']
        self.lon = lon[:]*1
        file1 = '/hpcdata/scratch/am8e13/cs_36km_tutorial/run_input/theta.phc_210_192_50_12'
        self.T = komod.mitbin(file1,xdim=192,ydim=210,zdim=50,datatype='float32')
        self.T = np.squeeze(self.T,axis=0)
        self.T[self.bathy == 0] = np.nan
        file1 = '/hpcdata/scratch/am8e13/cs_36km_tutorial/run_input/salt.phc_210_192_50_12'
        self.S = komod.mitbin(file1,xdim=192,ydim=210,zdim=50,datatype='float32')
        self.S = np.squeeze(self.S,axis=0)
        self.S[self.bathy == 0] = np.nan
        self.rho = rho(self.S,self.T)
        self.rhop = rhop(self.S,self.T)
        self.depth = Z
        # calculate jmd 95 density                                                                                                                                       
        self.rho_jmd = np.zeros_like(self.rho)
        for z in range(len(self.Z)):
            self.rho_jmd[z,:,:] = densjmd95(self.S[z,:,:],self.T[z,:,:],-9.81*self.Z[z]*1025)

        self.title = 'PHC'
        self.dataDyn = {}
        temp_lv = np.nanmean(np.nanmean(self.T,axis=1),axis=1)
        self.dataDyn['theta_lv_mean'] = (np.ones((400,1))*temp_lv)
        temp_lv = np.nanmean(np.nanmean(self.S,axis=1),axis=1)
        self.dataDyn['salt_lv_mean'] = (np.ones((400,1))*temp_lv)
        self.dataDyn['rho_lv_mean'] = rhop(self.dataDyn['salt_lv_mean'],self.dataDyn['theta_lv_mean'])
def read_core(path):
    # This function is meant to read and store the forcing fields
    # Load adata files
    xdim = 320
    ydim = 160
    
    data_ave = {'v10m': np.zeros(366*4) , 'u10m' : np.zeros(366*4), 'rain': np.zeros(366), \
                'dlw' : np.zeros(366) , 'dsw' : np.zeros(366) , 'tmp2m_degC' : np.zeros(366*4) , \
                'spfh2m' : np.zeros(366*4), 'rain': np.zeros(12),}
    tdim_v = {'v10m': 366*4 , 'u10m' : 366*4, 'rain': 366, 'dlw' : 366 , 'dsw' : 366 , 'tmp2m_degC' : 366*4 , \
                'spfh2m' : 366*4, 'rain': 12,}
    
    time_core = {'v10m': 366*4 , 'u10m' : 366*4, 'rain': 366, 'dlw' : 366 , 'dsw' : 366 , 'tmp2m_degC' : 366*4 , \
                'spfh2m' : 366*4, 'rain': 12,}
    for var in data_ave: 
        name = path+'CORE2_'+str(var)
        data_read = komod.mitbin(name,xdim=192,ydim=94,tdim=tdim_v[var],datatype='float32')
        data_av = np.mean(np.mean(data_read,axis = 3),axis = 2).squeeze(axis = 1)
        
        if var == 'dlw' or var == 'dsw':
            data_ave[var] = -data_av
        else: 
            data_ave[var] = data_av
        
        time_core[var] = np.array(range(len(data_av)))/float(tdim_v[var])

    clim = {'data_ave' : data_ave}  
    print 'read CORE2'
    return clim,time_core
Exemplo n.º 3
0
    def read_nemo(self,res):
        if res == '83':
            xdim = 3059
            ydim = 4322
            zdim = 75
            ycut = 2000
            self.title = 'Nemo 1/12'
        elif res == '25':
            xdim = 1021
            ydim = 1442
            zdim = 64
            ycut = 700
            self.title = 'Nemo 1/4'

        path = '/scratch/general/am8e13/NEMO_data/'
        mask_nemo = komod.mitbin(path+'NEMO'+res+'_mask',xdim=xdim,ydim=ydim,zdim=zdim,datatype='float32')
        lat_nemo = komod.mitbin(path+'NEMO'+res+'_lat',xdim=xdim,ydim=ydim,datatype='float32')
        lon_nemo = komod.mitbin(path+'NEMO'+res+'_lon',xdim=xdim,ydim=ydim,datatype='float32')
        depth_nemo = komod.mitbin(path+'NEMO'+res+'_depth',xdim=1,ydim=1,zdim=zdim,datatype='float32')
        T_nemo = komod.mitbin(path+'NEMO'+res+'_temp',xdim=xdim,ydim=ydim,zdim=zdim,datatype='float32')
        S_nemo = komod.mitbin(path+'NEMO'+res+'_salt',xdim=xdim,ydim=ydim,zdim=zdim,datatype='float32')
        ice_nemo = komod.mitbin(path+'NEMO'+res+'_ice',xdim=xdim,ydim=ydim,datatype='float32')

        T_nemo[mask_nemo == 0] = np.nan
        T_nemo = T_nemo.squeeze(axis=0)
        T_nemo = T_nemo[:,ycut:,:]

        S_nemo[mask_nemo == 0] = np.nan
        S_nemo = S_nemo.squeeze(axis=0)
        S_nemo = S_nemo[:,ycut:,:]

        ice_nemo[0,0,mask_nemo[0,0,:,:]==0] = np.nan
        ice_nemo = ice_nemo.squeeze(axis=0)
        ice_nemo = ice_nemo.squeeze(axis=0)
        ice_nemo = ice_nemo[ycut:,:]

        lat_nemo = lat_nemo.squeeze(axis=0)
        lat_nemo = lat_nemo.squeeze(axis=0)
        lat_nemo = np.array(lat_nemo[ycut:,:])
        lon_nemo = lon_nemo.squeeze(axis=0)
        lon_nemo = lon_nemo.squeeze(axis=0)
        lon_nemo = np.array(lon_nemo[ycut:,:])

        self.lat = lat_nemo
        self.lon = lon_nemo
        self.T = T_nemo
        self.S = S_nemo
        self.mask = mask_nemo
        self.ice = ice_nemo

        self.depth = np.zeros(zdim)
        for j in range(zdim):
            self.depth[j] = -depth_nemo[0,j,0,0]
    def __init__(self):
        file2read = netcdf.NetCDFFile("/scratch/general/am8e13/results36km/grid.nc",'r')
        bathy = file2read.variables['HFacC']
        self.bathy = bathy[:]*1
        self.res = 36
        Z = file2read.variables['Z']
        Z = Z[:]*1
        self.Z = Z
        lat = file2read.variables['YC']
        self.lat = lat[:]*1
        lon = file2read.variables['XC']
        self.lon = lon[:]*1
        file1 = '/scratch/general/am8e13/WOA/WOA05_THETA_210x192x50_arctic'
        self.T = komod.mitbin(file1,xdim=192,ydim=210,zdim=50,datatype='float32')
        self.T = np.squeeze(self.T,axis=0)
        self.T[self.bathy == 0] = np.nan
        file1 = '/scratch/general/am8e13/WOA/WOA05_SALT_210x192x50_arctic'
        self.S = komod.mitbin(file1,xdim=192,ydim=210,zdim=50,datatype='float32')
        self.S = np.squeeze(self.S,axis=0)
        self.S[self.bathy == 0] = np.nan
        self.rho = rho(self.S,self.T)
        self.rhop = rhop(self.S,self.T)
        self.depth = Z
        # calculate jmd 95 density                                                                                                                
        
        # 18 km files                                                                                                                             
        file1 = '/scratch/general/am8e13/WOA/WOA05_THETA_420x384x50_arctic'
        self.T18 = komod.mitbin(file1,xdim=384,ydim=420,zdim=50,datatype='float32')
        self.T18 = np.squeeze(self.T18,axis=0)
        file1 = '/scratch/general/am8e13/WOA/WOA05_SALT_420x384x50_arctic'
        self.S18 = komod.mitbin(file1,xdim=384,ydim=420,zdim=50,datatype='float32')
        self.S18 = np.squeeze(self.S18,axis=0)

        file2read = netcdf.NetCDFFile("/scratch/general/am8e13/results18km/grid.nc",'r')
        bathy = file2read.variables['HFacC']
        self.bathy = bathy[:]*1
        self.T18[self.bathy == 0] = np.nan
        self.S18[self.bathy == 0] = np.nan

        self.rho18 = rho(self.S18,self.T18)
        self.rhop18 = rhop(self.S18,self.T18)

        # 9 km files                                                                                                                              
        file1 = '/scratch/general/am8e13/WOA/WOA05_THETA_840x768x50_arctic'
        self.T9 = komod.mitbin(file1,xdim=768,ydim=840,zdim=50,datatype='float32')
        self.T9 = np.squeeze(self.T9,axis=0)
        file1 = '/scratch/general/am8e13/WOA/WOA05_SALT_840x768x50_arctic'
        self.S9 = komod.mitbin(file1,xdim=768,ydim=840,zdim=50,datatype='float32')
        self.S9 = np.squeeze(self.S9,axis=0)

        file2read = netcdf.NetCDFFile("/scratch/general/am8e13/results9km/grid.nc",'r')
        bathy = file2read.variables['HFacC']
        self.bathy = bathy[:]*1
        self.T9[self.bathy == 0] = np.nan
        self.S9[self.bathy == 0] = np.nan

        self.rho9 = rho(self.S9,self.T9)
        self.rhop9 = rhop(self.S9,self.T9)


        self.rho_jmd = np.zeros_like(self.rho)
        for z in range(len(self.Z)):
            self.rho_jmd[z,:,:] = densjmd95(self.S[z,:,:],self.T[z,:,:],-9.81*self.Z[z]*1025)

        self.title = 'Woa'
        self.dataDyn = {}
        temp_lv = np.nanmean(np.nanmean(self.T,axis=1),axis=1)
        self.dataDyn['theta_lv_mean'] = (np.ones((400,1))*temp_lv)
        temp_lv = np.nanmean(np.nanmean(self.S,axis=1),axis=1)
        self.dataDyn['salt_lv_mean'] = (np.ones((400,1))*temp_lv)
        self.dataDyn['rho_lv_mean'] = rhop(self.dataDyn['salt_lv_mean'],self.dataDyn['theta_lv_mean'])
def read_forcing(path,dataset,init_year,tot_years):
    # This function is meant to read and store the forcing fields
    # Load adata files
    xdim = 320
    ydim = 160
    tdim = [365*4,366*4]

    data = {'v10m': np.zeros(360*tot_years) , 'u10m' : np.zeros(360*tot_years), \
            'rain': np.zeros(360*tot_years) , 'dlw' : np.zeros(360*tot_years) , \
            'dsw' : np.zeros(360*tot_years) , 'tmp2m_degC' : np.zeros(360*tot_years) , \
            'spfh2m' : np.zeros(360*tot_years), 'rain': np.zeros(360*tot_years)}

    data_all = {'v10m': np.zeros(360*tot_years*4) , 'u10m' : np.zeros(360*tot_years*4), \
                'rain': np.zeros(360*tot_years*4) , 'dlw' : np.zeros(360*tot_years*4) , \
                'dsw' : np.zeros(360*tot_years*4) , 'tmp2m_degC' : np.zeros(360*tot_years*4) , \
                'spfh2m' : np.zeros(360*tot_years*4), 'rain': np.zeros(360*tot_years*4)}


    data_ave = {'v10m': np.zeros(360) , 'u10m' : np.zeros(360), 'rain': np.zeros(360), \
                'dlw' : np.zeros(360) , 'dsw' : np.zeros(360) , 'tmp2m_degC' : np.zeros(360) , \
                'spfh2m' : np.zeros(360), 'rain': np.zeros(360*33),}

    data_ave_all = {'v10m': np.zeros(360*4) , 'u10m' : np.zeros(360*4), 'rain': np.zeros(360*4), \
                'dlw' : np.zeros(360*4) , 'dsw' : np.zeros(360*4) , 'tmp2m_degC' : np.zeros(360*4) , \
                'spfh2m' : np.zeros(360*4), 'rain': np.zeros(360*4),}

    for var in data:
        data_av = []
        #print "Now reading:"+str(var)
        for year in range(tot_years):
            if calendar.isleap(init_year+year):
                tdim_ly = 1
                n_pop = 6
            else:
                tdim_ly = 0
                n_pop = 5

            name = path+dataset+str(var)+'_'+str(init_year+year)
            data_read = komod.mitbin(name,xdim=xdim,ydim=ydim,zdim=1,tdim=tdim[tdim_ly],datatype='float32')
            data_av_temp = np.mean(np.mean(data_read,axis = 3),axis = 2).squeeze(axis = 1)        
            to_pop = random.sample(range(len(data_av_temp)), 4*n_pop)
            data_av_temp = np.delete(data_av_temp,to_pop,0) 
            data_all[var]=data_av_temp
            # Daily average for plotting purpose
            data_av_temp_daily = np.zeros(360)
            for day in range(360):
                data_av_temp_daily[day] = np.mean(data_av_temp[day*4 : day*4 +4])
                
            data_av = np.concatenate([data_av,data_av_temp_daily])
            data[var] = data_av

        name = path+dataset+str(var)+'_average'
        data_read = komod.mitbin(name,xdim=xdim,ydim=ydim,zdim=1,tdim=360*4,datatype='float32')
        data_climy_av = np.mean(np.mean(data_read,axis = 3),axis = 2).squeeze(axis = 1)
        data_ave_all[var]=data_climy_av  
        data_climy_av_daily = np.zeros(360)
        for day in range(360):
            data_climy_av_daily[day] = np.mean(data_climy_av[day*4 : day*4 +4])

        data_climy_33_years = []
        for year in range(tot_years):
            data_climy_33_years = np.concatenate([data_climy_33_years, data_climy_av_daily])

        data_ave[var] = data_climy_33_years
        
    clim = {'data' : data , 'data_all' : data_all , 'data_ave' : data_ave , 'data_ave_all' : data_ave_all}
    
    print 'read '+dataset
        
    return clim