-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_files_volc_t_seasoncycl_rmved_ts_hist_rcp85.py
350 lines (309 loc) · 15.3 KB
/
create_files_volc_t_seasoncycl_rmved_ts_hist_rcp85.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
#################################################
###### INTRO ####################################
#################################################
#/usr/local/uvcdat/2012-08-24/bin/python
import os, string, gc, sys,getopt
sys.path.append('/export/bonfils2/PYFORT/bonfils/Functions/')
#sys.path.append('/home/bonfils2/PYFORT/bonfils/Functions/')
import vcs, cdutil, cdms2 as cdms, MV2 as MV, genutil, cdtime
from genutil import statistics
import Lynch1
import pyclimate.svdeofs
from Scientific.IO.NetCDF import *
from pyclimate.svdeofs import *
from pyclimate.ncstruct import *
sys.path.insert(0,"/export/bonfils2/NEWPYFORT/TRANSFO/build/lib.linux-i686-2.5")
#import Lynch
import numpy.oldnumeric as Numeric
import time
from Scientific.IO import FortranFormat
import numpy.oldnumeric.ma as MA
import sys,getopt # for external loop
dicmodels={'mpi_esm_lr': 'MPI-ESM-LR', 'cmcc_cesm': 'CMCC-CESM', 'cesm1_fastchem': 'CESM1-FASTCHEM', 'mri_cgcm3': 'MRI-CGCM3', 'ccsm4': 'CCSM4', 'cmcc_cms': 'CMCC-CMS', 'cesm1_waccm': 'CESM1-WACCM', 'cancm4': 'CanCM4', 'cesm1_cam5_1_fv2': 'CESM1-CAM5-1-FV2','cesm1_cam5': 'CESM1-CAM5', 'cnrm_cm5': 'CNRM-CM5', 'csiro_mk3_6_0': 'CSIRO-Mk3-6-0', 'ipsl_cm5a_lr': 'IPSL-CM5A-LR', 'giss_e2_h_cc': 'GISS-E2-H-CC', 'noresm1-me': 'NorESM1-ME','gfdl_esm2g': 'GFDL-ESM2G', 'cesm1_bgc': 'CESM1-BGC', 'mpi_esm_mr': 'MPI-ESM-MR', 'gfdl_cm3': 'GFDL-CM3', 'noresm1-m': 'NorESM1-M', 'cmcc_cm': 'CMCC-CM', 'hadcm3': 'HadCM3', 'ipsl_cm5b_lr': 'IPSL-CM5B-LR', 'gfdl_esm2m': 'GFDL-ESM2M', 'bcc_csm1_1_m': 'bcc-csm1-1-m', 'inmcm4': 'inmcm4', 'access1_3': 'ACCESS1-3', 'access1_0': 'ACCESS1-0', 'miroc5': 'MIROC5', 'giss_e2_r_cc': 'GISS-E2-R-CC', 'bcc_csm1_1': 'bcc-csm1-1', 'mpi_esm_p': 'MPI-ESM-P', 'hadgem2_cc': 'HadGEM2-CC', 'ipsl_cm5a_mr': 'IPSL-CM5A-MR', 'giss_e2_h': 'GISS-E2-H', 'miroc_esm': 'MIROC-ESM', 'miroc-esm-chem': 'MIROC-ESM-CHEM', 'miroc_esm_lr': 'MIROC-ESM-LR', 'miroc4h': 'MIROC4h', 'fio_esm': 'FIO-ESM', 'canesm2': 'CanESM2', 'giss_e2_r': 'GISS-E2-R', 'bnu_esm': 'BNU-ESM', 'hadgem2_ao': 'HadGEM2-AO', 'hadgem2_es': 'HadGEM2-ES', 'gfdl_cm2_p1': 'GFDL-CM2-P1', 'ec_earth': 'EC-EARTH', 'gfdl_cm2p1': 'GFDL-CM2P1', 'fgoals_s2': 'FGOALS-s2', 'fgoals_g2': 'FGOALS-g2'}
dicmodels2={'bcc_csm1_1':'bcc_r1i1p1',
'canesm2':'canesm2_r1i1p1',
'ccsm4':'ccsm4_r1i1p1',
'cnrm_cm5':'cnrm_r1i1p1',
'csiro_mk3_6_0':'csiro_r1i1p1',
'fgoals-g2_r1i1p1':'fgoals-g2_r1i1p1',
'gfdl_cm3':'gfdl_cm3_r1i1p1',
'gfdl_esm2m':'gfdl_esm2m_r1i1p1',
'giss_e2_h':'giss-e2-h_r1i1p1',
'giss_e2_r':'giss-e2-r_r1i1p1',
'giss_e2_r3':'giss-e2-r_r1i1p3',
'hadgem2_es':'hadgem2-es_r1i1p1',
'ipsl_cm5a_lr':'ipsl-cm5a-lr_r1i1p1',
'miroc-esm-chem':'miroc-esm-chem_r1i1p1',
'miroc_esm':'miroc-esm_r1i1p1',
'mri_cgcm3':'mri-cgcm3_r1i1p1',
'noresm1-m':'noresm1-m_r1i1p1'}
#var3='SPI_12'
var3='ts'
#var3='tas'
#var3='tls'
#var3='pr'
value=0
cdms.setNetcdfShuffleFlag(value) ## where value is either 0 or 1
cdms.setNetcdfDeflateFlag(value) ## where value is either 0 or 1
cdms.setNetcdfDeflateLevelFlag(value) ## where value is a integer between 0 and 9 included
###################################################
args=sys.argv[1:]
letters='e:i:f:r'
keywords=['exper=','ice=','filt=','rang=']
oexpt='default'
oice='default'
lowpass='default'
Pdateclimo='default'
opts,pargs=getopt.getopt(args,letters,keywords)
for o,p in opts:
if o in ['-e','--exper']:
oexpt=p
if o in ['-i','--ice']:
oice=p
if o in ['-f','--filt']:
lowpass=p
if o in ['-r','--rang']:
Pdateclimo=p
## ###################################
def timereg(s1):
y1time=str(cdtime.reltime(s1.getTime()[0], s1.getTime().units).tocomp(s1.getTime().getCalendar()))
y2time=str(cdtime.reltime(s1.getTime()[-1], s1.getTime().units).tocomp(s1.getTime().getCalendar()))
return y1time, y2time
x=vcs.init()
tpl1 = x.gettemplate( 'ASD1_of_4')
tpl2 = x.gettemplate( 'ASD2_of_4')
tpl3 = x.gettemplate( 'ASD3_of_4')
tpl4 = x.gettemplate( 'ASD4_of_4')
tpl1.mean.priority=0; tpl2.mean.priority=0; tpl3.mean.priority=0; tpl4.mean.priority=0
tpl1.max.priority=0; tpl2.max.priority=0; tpl3.max.priority=0; tpl4.max.priority=0
tpl1.min.priority=0; tpl2.min.priority=0; tpl3.min.priority=0; tpl4.min.priority=0
tpl1.comment1.x = 0.159090995789
tpl1.comment1.y = 0.979090995789
tpl1.comment2.x = 0.159090995789
tpl1.comment2.y = 0.949090995789
tpl2.comment1.x = 0.659090995789
tpl2.comment1.y = 0.979090995789
tpl2.comment2.x = 0.659090995789
tpl2.comment2.y = 0.949090995789
tpl3.comment1.x = 0.109090995789
tpl3.comment1.y = 0.209090995789
tpl4.comment1.x = 0.659090995789
tpl4.comment1.y = 0.209090995789
tpl1.line1.priority=1
tpl1.line1.x1=tpl1.box1.x1
tpl1.line1.x2=tpl1.box1.x2
tpl1.line1.y1=(tpl1.box1.y1+tpl1.box1.y2)/2.
tpl1.line1.y2=(tpl1.box1.y1+tpl1.box1.y2)/2.
tpl2.line1.priority=1
tpl2.line1.x1=tpl2.box1.x1
tpl2.line1.x2=tpl2.box1.x2
tpl2.line1.y1=(tpl2.box1.y1+tpl2.box1.y2)/2.
tpl2.line1.y2=(tpl2.box1.y1+tpl2.box1.y2)/2.
tpl3.line1.priority=1
tpl3.line1.x1=tpl3.box1.x1
tpl3.line1.x2=tpl3.box1.x2
tpl3.line1.y1=(tpl3.box1.y1+tpl3.box1.y2)/2.
tpl3.line1.y2=(tpl3.box1.y1+tpl3.box1.y2)/2.
tpl4.line1.priority=1
tpl4.line1.x1=tpl4.box1.x1
tpl4.line1.x2=tpl4.box1.x2
tpl4.line1.y1=(tpl4.box1.y1+tpl4.box1.y2)/2.
tpl4.line1.y2=(tpl4.box1.y1+tpl4.box1.y2)/2.
tpl2.source.priority = 0
tyw1=x.createyxvsx('new01agg')
tyw2=x.createyxvsx('new01aggg')
tyw3=x.createyxvsx('new01agggg')
tyw1.datawc_y1=-2.5 ; tyw1.datawc_y2=2.5
tyw2.datawc_y1=-2.5 ; tyw2.datawc_y2=2.5
tyw3.datawc_y1=-2.5 ; tyw3.datawc_y2=2.5
tyw1.linecolor=241 ; tyw1.line='solid' ; tyw1.linewidth=2 # black
tyw2.linecolor=242 ; tyw2.line='solid' ; tyw2.linewidth=2 # red
tyw3.linecolor=53 ; tyw3.line='solid' ; tyw3.linewidth=2 # red
#OBSPROJ='HADISST1'
#OBSPROJ='NOAA2'
#oice='_lrmIce'
#oice='_rmdIce'
#oice='_Ice'
#ONOAA3='NOAA3'
#OHADISST1='HADISST1'
ONOAA3='NOAA3b'
OHADISST1='HADISST1.1'
OBSPROJ3='ncdc'
if lowpass=='_lynch119': lowpass2='_lynch119'
if lowpass=='_nofiltr': lowpass2=''
#oregion1='PDO' #'PCR'
oregion2='IPO'
oregionBen='BEN'
oregion1='60S60N'
oregion3='12N60N'
OBSPROJ=oexpt
gg='pc1Arec'
ICEPROJ='Ice'
oice2='_lrmIce'
Palors='8models_weight'
if Pdateclimo=='19001993': peri=''
if Pdateclimo=='18571906': peri='_18571906'
if Pdateclimo=='19071956': peri='_19071956'
if Pdateclimo=='19572006': peri='_19572006'
oregion='825S825N'
if oregion=='825S825N': #-60., -20., 6., 18.
#regionBEN=cdutil.region.domain(latitude=(-82.5,82.5,'ccb')); endfi=''
regionBEN=cdutil.region.domain(latitude=(-20.,20.,'ccb')); endfi='20S20N'
#regionBEN=cdutil.region.domain(latitude=(30.,45.,'ccb'),longitude=(-122.,-90.,'ccb')); endfi='_NA'
#####################################################
#models=['GISS-E2-R','bcc-csm1-1','MPI-ESM-P','CCSM4','MIROC-ESM','FGOALS-gl','IPSL-CM5A-LR']
#models=['MPI-ESM-P','CCSM4','MIROC-ESM','FGOALS-gl','IPSL-CM5A-LR']
#models=['FGOALS-gl']
#models=['MPI-ESM-P']
#models=['GISS-E2-R','bcc-csm1-1']
models=os.listdir( '/big_disk_1/pcmdi/ipcc/data/hist_rcp85/atm/mo/ts')
rips=['r1i1p','r2i1p','r3i1p','r4i1p','r5i1p','r6i1p','r7i1p','r8i1p','r9i1p','r10i1p','r11i1p','r12i1p']
#rips=['r2i1p','r3i1p']
#rips=['r3i1p','r4i1p','r5i1p','r6i1p','r7i1p','r8i1p']
models.remove('PET0.ESMF_LogFile')
models.remove('ts_hist_rcp85_all_runs_rmclimo0009_removed_lrmIcepoub.nc')
#models=['giss_e2_r']
#oexpt='past1000' ### because!
#oexpt='hist_rcp85' ### because!
oexpt='historicalExt' ### because!
#oexpt='historicalNat' ### because!
#oexpt='historicalGHG' ### because!
#oexpt='historicalMisc' ### because!
if oexpt=='historicalMisc':
models = os.popen('ls /big_disk_1/pcmdi/ipcc/data/hist_rcp85/atm/mo/ts/*/historicalMisc/r*/ts*lrmIce.nc').readlines()
rips=['r1i1p']
mm=False
if oexpt=='historicalExt':
models = os.popen('ls /big_disk_1/pcmdi/ipcc/data/hist_rcp85/atm/mo/ts/*/historicalExt/r*/ts*lrmIce.nc').readlines()
rips=['r1i1p']
mm=False
if oexpt=='historicalGHG':
models = os.popen('ls /big_disk_1/pcmdi/ipcc/data/hist_rcp85/atm/mo/ts/*/historicalGHG/r*/ts*lrmIce.nc').readlines()
rips=['r1i1p']
mm=False
for m in models:
for rip in rips:
varss=[var3];
if not (oexpt=='historicalMisc' or oexpt=='historicalGHG' or oexpt=='historicalExt'): mm=dicmodels[m]; mmm=m; pp='1'
if oexpt=='hist_rcp85':
if rip=='r2i1p' and m=='giss_e2_h' and oexpt=='hist_rcp85': rip='r1i1p'; pp='2'
if rip=='r3i1p' and m=='giss_e2_h' and oexpt=='hist_rcp85': rip='r1i1p'; pp='3'
if rip=='r2i1p' and m=='giss_e2_r' and oexpt=='hist_rcp85': rip='r1i1p'; pp='2'
if rip=='r3i1p' and m=='giss_e2_r' and oexpt=='hist_rcp85': rip='r1i1p'; pp='3'
print m,mm
#if m=='FGOALS-gl': yr1='1000-1-1'
#if m!='FGOALS-gl': yr1='850-1-1'
#if m=='IPSL-CM5A-LR': yr2='1699-12-1'
#if m!='IPSL-CM5A-LR': yr2='1699-12-31'
#if m=='IPSL-CM5A-LR': yr2='1805-12-1'
#if m!='IPSL-CM5A-LR': yr2='1805-12-31'
for var in varss:
print m,var,mm, oexpt
if not (oexpt=='historicalMisc' or oexpt=='historicalGHG' or oexpt=='historicalExt') and var=='ts' or var=='pr' or var=='tas' or var=='tls':
try: f5 = cdms.open('/big_disk_1/pcmdi/ipcc/data/hist_rcp85/atm/mo/'+var+'/'+mmm+'/'+oexpt+'/'+rip+pp+'/'+var+'_'+mmm+'_'+oexpt+'.'+rip+pp+'_rmclimo0009_removed_lrmIce.nc' )
except: print 'Model missing:','/big_disk_1/pcmdi/ipcc/data/hist_rcp85/atm/mo/'+var+'/'+mmm+'/'+oexpt+'/'+rip+pp+'/'+var+'_'+mmm+'_'+oexpt+'.'+rip+pp+'_rmclimo0009_removed_lrmIce.nc', mmm,var; continue
f5 = cdms.open('/big_disk_1/pcmdi/ipcc/data/hist_rcp85/atm/mo/'+var+'/'+mmm+'/'+oexpt+'/'+rip+pp+'/'+var+'_'+mmm+'_'+oexpt+'.'+rip+pp+'_rmclimo0009_removed_lrmIce.nc' )
#try: f5 = cdms.open('/big_disk_1/pcmdi/ipcc/data/hist_rcp85/atm/mo/'+var+'/'+mmm+'/'+oexpt+'/'+var+'_'+mmm+'.'+oexpt+'.'+rip+pp+'.mo.nc' )
#except: print 'Model missing:',mmm,var, '/big_disk_1/pcmdi/ipcc/data/hist_rcp85/atm/mo/'+var+'/'+mmm+'/'+oexpt+'/'+var+'_'+mmm+'.'+oexpt+'.'+rip+pp+'.mo.nc' ; continue
#f5 = cdms.open('/big_disk_1/pcmdi/ipcc/data/hist_rcp85/atm/mo/'+var+'/'+mmm+'/'+oexpt+'/'+var+'_'+mmm+'.'+oexpt+'.'+rip+pp+'.mo.nc' )
if var=='ts' and oexpt=='historicalMisc' or oexpt=='historicalGHG' or oexpt=='historicalExt':
f5 = cdms.open(m[:-1])
if var=='SPI_12':
if oexpt=='historicalNat':
try: f5 = cdms.open('/bonfils2_storage_tmp/cmip5/'+oexpt+'/cmip5'+'.'+mm+'.'+oexpt+'.'+rip+pp+'.mo.atm.Amon.pr.ver-1.SPI_ALL_12.Base_same_1961-1990.nc' )
except: continue
if oexpt=='hist_rcp85':
try: f5 = cdms.open('/bonfils2_storage_tmp/cmip5/'+oexpt+'/pr'+'_'+mmm+'.'+oexpt+'.'+rip+pp+'.mo.SPI_ALL_12.Base_same_1961-1990.nc' )
except: continue
if oexpt=='historicalNat':f5 = cdms.open('/bonfils2_storage_tmp/cmip5/'+oexpt+'/cmip5'+'.'+mm+'.'+oexpt+'.'+rip+pp+'.mo.atm.Amon.pr.ver-1.SPI_ALL_12.Base_same_1961-1990.nc' )
if oexpt=='hist_rcp85':f5 = cdms.open('/bonfils2_storage_tmp/cmip5/'+oexpt+'/pr'+'_'+mmm+'.'+oexpt+'.'+rip+pp+'.mo.SPI_ALL_12.Base_same_1961-1990.nc' )
#t11=f5(var3,regionBEN,time=(yr1,yr2))
t11=f5(var3,regionBEN)
#t11=f5(var3) ; endfi='_global'
if string.split(timereg(t11)[0],'-')[1]!='1': raise
if string.split(timereg(t11)[1],'-')[1]!='12': raise
#if m=='FGOALS-gl':
# if string.split(timereg(t11)[0],'-')[0]!='1000':
# raise
#else:
# if string.split(timereg(t11)[0],'-')[0]!='850':
# raise
#if string.split(timereg(t11)[1],'-')[0]!='1699': raise
#if string.split(timereg(t11)[1],'-')[0]!='1805': raise
fm=cdms.open(str.split(f5.id,'ts_')[0]+'sftland_'+str.split(f5.id,'ts_')[1]) #[:-17]+'nc')
tm=fm('ts',regionBEN)
cdutil.times.setTimeBoundsMonthly(t11)
print t11.shape
t1=MV.zeros((t11.shape[0]),typecode=MV.float32)
t2=MV.zeros((t11.shape[0]),typecode=MV.float32)
#t1z=MV.zeros((t11.shape[0],t11.shape[1]),typecode=MV.float32)
#wgt = cdutil.area_weights(t11[0,:,:])
wgt2 = cdutil.area_weights(t11)*tm
#for i in range(t1.shape[0]):
# #print i
# t1[i] = cdutil.averager(t11[i,:,:],axis='xy',weight=wgt)
# #t1z[i] = cdutil.averager(t11[i,:,:],axis='x',weight=wgt)
t1=cdutil.averager(t11,axis='xy',weight=wgt2)
#raise
#t1.setAxis(0,t11.getAxis(0))
t2.setAxis(0,t11.getAxis(0))
#t1z.setAxis(0,t11.getAxis(0))
#t1z.setAxis(1,t11.getAxis(1))
##############
##############
##############
##############
# comment one or the other
##############
#MOY GLOBAL
##############
print timereg(t1)
acts=cdutil.ANNUALCYCLE.climatology(t1(time=('1960','2000','con')))
print timereg(t1(time=('1960','2000','con')))
print timereg(t1)
print acts.shape
#############acts=cdutil.ANNUALCYCLE.climatology(t1(time=(stclimo[0],enclimo[0]))) # does not work... maybe fixed by Charles
t2=cdutil.ANNUALCYCLE.departures(t1,ref=acts)# does not work... maybe fixed by Charles
#for i in range (int(t1.shape[0]/12)):
# t11[i*12:i*12+12]=cdutil.ANNUALCYCLE.departures(t1[i*12:i*12+12],ref=acts)
###x.plot(t1)
##x.plot(t11)
x.plot(t2)
#####
#fout=cdms.open('/bonfils2_storage_tmp/MSU/'+var3+'/'+mmm+'/'+rip+pp+'/'+var+'_'+oexpt+'_'+mmm+'_rmclimo10yr_removed_lrmIce2'+'.mon.rmSC_8501700.nc','w')
if var3=='SPI_12': fout=cdms.open('/bonfils2_storage_tmp/cmip5/'+oexpt+'/'+var+'_'+mmm+'_'+oexpt+'.'+rip+pp+'_rmclimo0009_removed_lrmIce'+'.mon.rmSC'+endfi+'22.nc','w')
else:
if not (oexpt=='historicalMisc' or oexpt=='historicalGHG' or oexpt=='historicalExt'):
fout=cdms.open('/big_disk_1/pcmdi/ipcc/data/hist_rcp85/atm/mo/'+var+'/'+mmm+'/'+oexpt+'/'+rip+pp+'/'+var+'_'+mmm+'_'+oexpt+'.'+rip+pp+'_rmclimo0009_removed_lrmIce'+'.mon.rmSC'+endfi+'.nc','w')
if oexpt=='historicalMisc' or oexpt=='historicalGHG' or oexpt=='historicalExt':
fout=cdms.open(m[:-4]+'.mon.rmSC'+endfi+'.nc','w')
print fout
fout.write(t2,id=var3,typecode='f')
fout.close()
## ##############
## #MOY ZONAL
## #############acts=cdutil.ANNUALCYCLE.climatology(t1(time=(stclimo[0],enclimo[0])))
## print timereg(t1z), 'timereg 1'
## actsz=cdutil.ANNUALCYCLE.climatology(t1z)
## print actsz.shape
## #
## #
## for i in range (int(t1z.shape[0]/12)):
## t1z[i*12:i*12+12]=cdutil.ANNUALCYCLE.departures(t1z[i*12:i*12+12],ref=actsz)
## #fout=cdms.open('/big_disk_1/pcmdi/ipcc/data/hist_rcp85/atm/mo/'+var+'/'+mm+'/'+oexpt+'/'+var+'_both___'+m+'.r2i1p1.'+oexpt+'.mon.rmSC_moyzonal.nc','w')
## fout=cdms.open('/bonfils2_storage_tmp/MSU/'+var+'_both___'+m+'.r2i1p1.'+oexpt+'.mon.rmSC_moyzonal_BEN.nc','w')
## fout.write(t1z,id='eqmsu_'+var,typecode='f')
## fout.close()
## print timereg(t1z), 'timereg 2'
## ##############
## ##############
## ##############
## ##############
## ##############
## # test to see if time step is unique or not
## tim=t1.getTime()[:]
## import numpy
## if len(tim)!=len(numpy.unique(tim)):
## raise
## ##############
#tlspi.setAxis(0,tmt[500:500+10200].getTime())