Exemple #1
0
        files = []
        for fi in range(nfile):
            filename = filedir+diag+'.'+yrstr[fi]+'ann.nc'
            files.append(filename)
        ts = pp.ts_multi_files(files,var[vi],0)
        if zm:
            ts = np.nanmean(ts,-1)
        #%%
        if init and vi==0:
            outfile = outdir+'dim.'+simo[i]+'.npz'
            fio.save(outfile,lat=lat,lon=lon,phalf=phalf,land_mask=land_mask,year=yr)
        if init3d:
            tmp = nc.netcdf_file(files[-1],'r',mmap=True)
            pfull = tmp.variables['pfull'][:].astype(np.float64)
            outfile = outdir+'dim.'+simo[i]+'.npz'
            fio.save(outfile,pfull=pfull)
        if init3dp:
            tmp = nc.netcdf_file(files[-1],'r',mmap=True)
            level = tmp.variables['level'][:].astype(np.float64)
            outfile = outdir+'dim.'+simo[i]+'.npz'
            fio.save(outfile,level=level)
        for flagi in range(nflag):
            ts_flag = ts
            outdir_sub='ts/'+sub_dict[flag[flagi]]+'/'
            if (flag[flagi] != ''):
                ts_flag = pp.month_to_year(ts,flag[flagi])
            outfile = outdir+outdir_sub+diago+'.'+timeo+'.'+simo[i]+'.npz'
            fio.save(outfile,**{varo[vi]:ts_flag})
    print var[vi]
    
Exemple #2
0
        lon = fs[-1].variables['lon'][:].astype(np.float64)
        nlat = np.size(lat)
        nlon = np.size(lon)
    #phalf = fs[-1].variables['phalf'][:].astype(np.float64)
    #zsurf = fs[-1].variables['zsurf'][:].astype(np.float64)
    if ('land_mask' in fs[-1].variables):
        land_mask = fs[-1].variables['land_mask'][:].astype(np.float64)
    fs[-1].close()
    #%%
    filedir = atmdir+indir_sub
    files = []
    for fi in range(nfile):
        filename = filedir+diag+'.'+yrstr[fi]+'.nc'
        files.append(filename)
    ts = pp.ts_multi_files(files,var,0)
    ts = np.array(ts)
    #%%
    if (flag != ''):
        ts = pp.month_to_year(ts,yr_ts,flag)
    if zm:
        ts_zon = np.mean(ts,-1)
    if gm:
        area = grid.calcGridArea(lat,lon)
        area.shape = [1,nlat,nlon]
        ts_glb = np.sum(ts*area,-1)
        ts_glb = np.sum(ts_glb,-1)
        ts_glb = ts_glb/np.sum(area)
        print ts_glb
    plt.plot(ts_zon[0,:]-ts_zon[0,0])
plt.legend(pert,fontsize=10)
Exemple #3
0
         uMSE = np.sum(MSEMon * uMon * dpMon, 0) / GRAV
         uMSEMC[yri * 12 + moni, :, :] = uMSE
         wMC[yri * 12 + moni, :, :, :] = np.mean(omega, 0)
         wMSEbot[yri * 12 +
                 moni, :, :] = (np.mean(omega * MSE, 0)[-1, ...]) / GRAV
         wMSEtop[yri * 12 +
                 moni, :, :] = (np.mean(omega * MSE, 0)[0, ...]) / GRAV
 #%%
 #mind = [6,7,8]
 """
 if init:
     outfile = outdir+'dim.'+pert_dict[pert[i]]+'.npz'
     fio.save(outfile,lat=lat,lon=lon,phalf=phalf,land_mask=land_mask,year=yr)
 """
 for flagi in range(nflag):
     vhTot = pp.month_to_year(vMSETot, yr_ts, flag[flagi])  #*20650/1e19
     vhMC = pp.month_to_year(vMSEMC, yr_ts, flag[flagi])
     vhTr = pp.month_to_year(vMSETr, yr_ts, flag[flagi])
     uhTot = pp.month_to_year(uMSETot, yr_ts, flag[flagi])
     uhMC = pp.month_to_year(uMSEMC, yr_ts, flag[flagi])
     uhTr = pp.month_to_year(uMSETr, yr_ts, flag[flagi])
     whbot = pp.month_to_year(wMSEbot, yr_ts, flag[flagi])
     whtop = pp.month_to_year(wMSEtop, yr_ts, flag[flagi])
     net = pp.month_to_year(net_atm, yr_ts, flag[flagi])
     de = pp.month_to_year(dene, yr_ts, flag[flagi])
     """
     outdir_sub='ts/'+sub_dict[flag[flagi]]+'/'
     outfile = outdir+outdir_sub+diago+'.'+timeo+'.'+pert_dict[pert[i]]+'.npz'
     fio.save(outfile,vMSETot_col=vhTot,vMSEMC_col=vhMC,vMSETr_col=vhTr,\
              uMSETot_col=uhTot,uMSEMC_col=uhMC,uMSETr_col=uhTr,\
              wMSEbot=whbot,wMSEtop=whtop,net_atm=net,dene_col=de)
Exemple #4
0
         uMSE = np.sum(uTr*MSETr*dpMon,1)/GRAV
         uMSETr[yri*12+moni,:,:] = np.mean(uMSE,0)
         uMSE = np.sum(MSEMon*uMon*dpMon,0)/GRAV
         uMSEMC[yri*12+moni,:,:] = uMSE
         wMC[yri*12+moni,:,:,:] = np.mean(omega,0)
         wMSEbot[yri*12+moni,:,:] = (np.mean(omega*MSE,0)[-1,...])/GRAV
         wMSEtop[yri*12+moni,:,:] = (np.mean(omega*MSE,0)[0,...])/GRAV
 #%%
 #mind = [6,7,8]
 """
 if init:
     outfile = outdir+'dim.'+pert_dict[pert[i]]+'.npz'
     fio.save(outfile,lat=lat,lon=lon,phalf=phalf,land_mask=land_mask,year=yr)
 """
 for flagi in range(nflag):
     vhTot = pp.month_to_year(vMSETot,yr_ts,flag[flagi])#*20650/1e19
     vhMC = pp.month_to_year(vMSEMC,yr_ts,flag[flagi])
     vhTr = pp.month_to_year(vMSETr,yr_ts,flag[flagi])
     uhTot = pp.month_to_year(uMSETot,yr_ts,flag[flagi])
     uhMC = pp.month_to_year(uMSEMC,yr_ts,flag[flagi])
     uhTr = pp.month_to_year(uMSETr,yr_ts,flag[flagi])
     whbot = pp.month_to_year(wMSEbot,yr_ts,flag[flagi])
     whtop = pp.month_to_year(wMSEtop,yr_ts,flag[flagi])
     net = pp.month_to_year(net_atm,yr_ts,flag[flagi])
     de = pp.month_to_year(dene,yr_ts,flag[flagi])
     """
     outdir_sub='ts/'+sub_dict[flag[flagi]]+'/'
     outfile = outdir+outdir_sub+diago+'.'+timeo+'.'+pert_dict[pert[i]]+'.npz'
     fio.save(outfile,vMSETot_col=vhTot,vMSEMC_col=vhMC,vMSETr_col=vhTr,\
              uMSETot_col=uhTot,uMSEMC_col=uhMC,uMSETr_col=uhTr,\
              wMSEbot=whbot,wMSEtop=whtop,net_atm=net,dene_col=de)
Exemple #5
0
for i in range(ts_ann.shape[0]):
    nan_ind = np.where(np.isnan(ts_ann[i,:,:]))
    land_mask[0,nan_ind[0],nan_ind[1]] = 0
ts_ann[np.where(np.isnan(ts_ann))]=0

ts_gm = np.sum(np.nansum(ts_ann*area*land_mask,-1),-1)/np.nansum(area*land_mask)
land_mask.shape = (nlat,nlon)
area.shape = (nlat,nlon)
weight = area/np.sum(area)
"""
if zm:
    ts = np.mean(ts,-1)
#%%
if init:
    outfile = outdir+'dim.'+obs+'.npz'
    fio.save(outfile,lat=lat,lon=lon,land_mask=land_mask)
if init3d:
    tmp = nc.netcdf_file(files[-1],'r',mmap=True)
    pfull = tmp.variables['pfull'][:].astype(np.float64)
    outfile = outdir+'dim.'+obs+'.npz'
    fio.save(outfile,pfull=pfull)
ts_flag = ts.copy()
for flagi in range(nflag):
    if (flag[flagi] != ''):
        ts_flag = pp.month_to_year(ts,yr_ts,flag[flagi])
    outdir_sub='ts/'+sub_dict[flag[flagi]]+'/'
    outfile = outdir+outdir_sub+diago+'.'+timeo+'.'+obs+'.npz'
    fio.save(outfile,**{varo:ts_flag})

Exemple #6
0
Fichier : test.py Projet : szy21/py
# -*- coding: utf-8 -*-
"""
Created on Mon Apr 25 09:49:37 2016

@author: Zhaoyi.Shen
"""

import matplotlib.pyplot as plt
import numpy as np
import sys
sys.path.append('/home/z1s/PythonScripts')
import postprocess as pp

fdir = '/archive/Zhaoyi.Shen/fms/ulm/AM2/AM2_control_1990/gfdl.ncrc3-default-prod-openmp/pp/atmos_level/'
f = fdir+'ts/annual/16yr/atmos_level.1983-1998.netrad_toa.nc'
ncf = nc.netcdf_file(f,'r',mmap=True)
ann = ncf.variables['netrad_toa'][0,0,0].astype(np.float64)
f = fdir+'ts/monthly/16yr/atmos_level.198301-199812.netrad_toa.nc'
ncf = nc.netcdf_file(f,'r',mmap=True)
tmp = ncf.variables['netrad_toa'][:12,0,0].astype(np.float64)
mon = pp.month_to_year(tmp,np.ones(1),'annual')
Exemple #7
0
sys.path.append('/home/z1s/py/lib')
import binfile_io as fio
import postprocess as pp
import numpy as np
from scipy.io import netcdf as nc
import calendar

arr1 = np.arange(1,25,1)
yr = np.array((1999,2000))
ans_key = {'annual':np.array((2382/365.,6776/366.)),\
    'MAM':np.array((368/92.,1472/92.)),\
    'JJA':np.array((645/92.,1749/92.)),\
    'SON':np.array((910/91.,2002/91.)),\
    'DJF':np.array((87/59.,1181/91.))}
for flag in ['MAM','JJA','SON','DJF']:
    arr2 = pp.month_to_year(arr1,yr,flag)
    ans = ans_key[flag]
    if np.max(np.abs(arr2-ans)) < 1e-8:
        print flag+':Correct!'
    else:
        print flag+':',arr2,ans

fdir = '/archive/Zhaoyi.Shen/fms/ulm/AM2/AM2_control_1990/gfdl.ncrc3-default-prod-openmp/pp/atmos_level/'
fname = fdir+'ts/annual/16yr/atmos_level.1983-1998.netrad_toa.nc'
f = nc.netcdf_file(fname,'r')
ann = f.variables['netrad_toa'][:]
fname = fdir+'ts/monthly/16yr/atmos_level.198301-199812.netrad_toa.nc'
f = nc.netcdf_file(fname,'r')
tmp = f.variables['netrad_toa'][:]
mon = pp.month_to_year(tmp,np.ones(16),'annual')
diff = np.abs(mon-ann)
Exemple #8
0
import numpy as np
from scipy.io import netcdf as nc
import calendar

arr1 = np.arange(1,25,1)
yr = np.array((1999,2000))
ans_key = {'annual':np.array((2382/365.,6776/366.)),\
    'MAM':np.array((368/92.,1472/92.)),\
    'JJA':np.array((645/92.,1749/92.)),\
    'SON':np.array((910/91.,2002/91.)),\
    'DJF':np.array((87/59.,1181/91.)),\
    'JAS':np.array((735/92.,1839/92.)),\
    'MJJASO':np.array((1380/184.,3588/184.)),\
    'JJASON':np.array((1555/183.,3751/183.))}
for flag in ans_key:
    arr2 = pp.month_to_year(arr1,yr,flag)
    ans = ans_key[flag]
    if np.max(np.abs(arr2-ans)) < 1e-8:
        print flag+':Correct!'
    else:
        print flag+':',arr2,ans
#%%
fdir = '/archive/Zhaoyi.Shen/fms/ulm/AM2/AM2_control_1990/gfdl.ncrc3-default-prod-openmp/pp/atmos_level/'
fname = fdir+'ts/annual/16yr/atmos_level.1983-1998.netrad_toa.nc'
f = nc.netcdf_file(fname,'r')
ann = f.variables['netrad_toa'][:]
f.close()
fname = fdir+'ts/monthly/16yr/atmos_level.198301-199812.netrad_toa.nc'
f = nc.netcdf_file(fname,'r')
tmp = f.variables['netrad_toa'][:]
f.close()