source: TOOLS/CMIP6_FORCING/CO2_EMISSIONS/regrid.pro @ 5920

Last change on this file since 5920 was 4045, checked in by oboucher, 6 years ago

Scripts to prepare CO2 emissions for IPSL-CM6 ESM

File size: 6.0 KB
Line 
1pro regrid
2filename='/data/obolmd/CMIP6/CO2_EMISSIONS_48x36/flux_2D_CO2_1867.nc'
3print, filename
4NETCDFREAD,filename,'flux',flux,dimflux
5NETCDFREAD,filename,'lat',lat,dimlat0
6NETCDFREAD,filename,'lon',lon,dimlon0
7NETCDFREAD,filename,'TIME',time,dimtime0
8dimlat=dimlat0(0)
9dimlon=dimlon0(0)
10dimtime=dimtime0(0)
11print, 'dim flux=', dimflux
12A = float([     [3./4., 1./8., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1./8.],$
13                [1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0., 0., 0., 0.],$
14                [0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0., 0., 0.],$
15                [0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0., 0.],$
16                [0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0.],$
17                [0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0.],$
18                [0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0.],$
19                [0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0.],$
20                [0., 0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0.],$
21                [0., 0., 0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0.],$
22                [0., 0., 0., 0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8.],$
23                [1./8., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1./8., 3./4.]   ])
24A = float([     [1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],$
25                [0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],$
26                [0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0.],$
27                [0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0.],$
28                [0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0.],$
29                [0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0.],$
30                [0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.],$
31                [0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0.],$
32                [0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0.],$
33                [0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0.],$
34                [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0.],$
35                [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.]   ])
36fluxinit=flux
37fluxinit=flux
38flux_check=flux
39for lo=0,dimlon-1 do begin
40for la=0,dimlat-1 do begin
41flux_check(lo,la,*) = invert(A) ## transpose(fluxinit(lo,la,*))
42endfor
43endfor                 
44m_bloq = make_array(dimlon,dimlat,12,value=0)           ; Matrice booléenne "mois à bloquer ou non"
45if total(where(flux_check lt 0)) ne -1 then m_bloq(where(flux_check lt 0)) = 1
46; Correction/adaptation de la matrice S&Z en fonction du masque booléen m_bloq
47for lo=0,dimlon-1 do begin
48for la=0,dimlat-1 do begin
49whereneg = where(flux_check(lo,la,*) lt 0)              ; (12 pts max) Identification de potentiels points à problÚmes, corrigés négativement
50nbannul=n_elements(whereneg)*(total(whereneg) ne -1)
51flux_corr=flux_check(lo,la,*)                           ; Création d'un vecteur pour recevoir les valeurs corrigées, initialisé à flux_check au cas où on n'ait rien à faire d'autre qu'une seule itération
52A2 = A                                                  ; Je repars de la matrice A initiale, ce pour chaque point de grille
53;                                                       ; Potentiellement plusieurs passages pour éliminer toutes les valeurs négatives
54while nbannul ne 0 do begin                             ; Si l'on a effectivement des émissions corrigées négativement...
55m_bloq(lo,la,whereneg) = 1                              ; Update de la matrice m_bloq
56for m=0,11 do begin
57if m eq 11 then begin                                   ; Pour plus de facilité, mois précédents et suivants codés ici
58p=10
59s=0
60endif else if m eq 0 then begin
61p=11
62s=1
63endif else begin
64p = m-1
65s = m+1
66endelse
67if m_bloq(lo,la,m) then begin                           ; Je traite les mois bloqués en eux-mêmes
68A2(p,m) = 0.
69A2(m,m) = 1.
70A2(s,m) = 0.
71endif                                                   ; Fin du cas si l'on est sur un mois bloqué
72if ~m_bloq(lo,la,m) then begin                          ; Je traite les mois non bloqués, pour ceux adjacents à un mois bloqué
73if m_bloq(lo,la,p) and m_bloq(lo,la,s) then begin               ; Mois encadré de deux mois bloqués
74A2(p,m) = 1./4.
75A2(m,m) = 1./2.
76A2(s,m) = 1./4.
77endif else if m_bloq(lo,la,p) and ~m_bloq(lo,la,s) then begin   ; Mois précédent bloqué (uniquement)
78A2(p,m) = 2./8.
79A2(m,m) = 5./8.
80A2(s,m) = 1./8.
81endif else if ~m_bloq(lo,la,p) and m_bloq(lo,la,s) then begin   ; Mois suivant bloqué (uniquement)
82A2(p,m) = 1./8.
83A2(m,m) = 5./8.
84A2(s,m) = 2./8.
85endif
86endif                                                           ; Fin du cas mois non bloqué
87endfor                                                          ; Fin de la boucle sur les mois, balayage de la matrice
88flux_corr = invert(A2) ## transpose(fluxinit(lo,la,*))          ; Ré-itération de la multiplication matricielle avec la matrice A modifiée (A2)
89whereneg = where(flux_corr lt 0)                                ; (12 pts max) Ré-identification de potentiels nouveaux points à problÚmes, corrigés négativement
90nbannul=n_elements(whereneg)*(total(whereneg) ne -1)
91endwhile                                                        ; Fin du cas où l'on avait des problÚmes d'émissions corrigées négativement
92; *** IMPORTANT ! *** Pour signaler les mois bloqués, on prend la convention suivante :
93;       valeur négative ou nulle <=> mois bloqué
94;       valeur positive <=> mois à interpolation classique
95flux(lo,la,*) = flux_corr                                       ; En sortie de la boucle while, normalement flux_corr est complÚtement positif
96endfor                                                          ; Fin boucle lat
97endfor                                                          ; Fin boucle lon
98nbnegtotal = n_elements(where(m_bloq eq 1)) * (total(where(m_bloq eq 1)) ne -1)
99if nbnegtotal ne 0 then flux(where(m_bloq eq 1)) = -flux(where(m_bloq eq 1))            ; Je force à des valeurs négatives
100;
101month_in_year=12
102nbpoint=1682
103flux2=fltarr(nbpoint,month_in_year)
104flux2(*,*)=0.0
105;
106for l=0,month_in_year-1 do begin
107flux2(0,l)=TOTAL(flux(*,0,l))/float(dimlon)
108flux2(nbpoint-1,l)=TOTAL(flux(*,dimlat-1,l))/float(dimlon)
109endfor
110;
111pt=1
112for j=1,dimlat-2  do begin
113for i=0,dimlon-1  do begin
114for l=0,month_in_year-1 do begin
115  flux2(pt,l)=flux(i,j,l)
116endfor
117pt=pt+1
118endfor
119endfor
120;
121;saving netcdf file
122;
123fluxstruct={vector:fltarr(nbpoint),time:fltarr(month_in_year), $
124            flx_CO2:fltarr(nbpoint,month_in_year) }
125;
126fluxstruct.vector=float(indgen(nbpoint)+1)
127;;fluxstruct.time=float(indgen(month_in_year)+1)
128fluxstruct.time=[15, 45, 75, 105, 135, 165, 195, 225, 255, 285, 315, 345]
129fluxstruct.flx_CO2=flux2
130;
131attributes = {units:strarr(3),long_name:strarr(3)}
132attributes.units = ['vector','days since 1960-01-01','flux']
133attributes.long_name = ['vector', 'time', 'flux']
134;
135dimensions = {isdim:intarr(3), links:intarr(2,3)}
136       dimensions.isdim =  [1,1,0]  ; (1=dimension, 0=variable)
137       dimensions.links = [ [-1,-1],[-1,-1],[0,1]    ]
138;
139netcdfwrite,'/data/obolmd/CMIP6/CO2_EMISSIONS_48x36/flux_1D_CO2_1867.nc',fluxstruct,clobber=1, attributes=attributes, dimensions=dimensions
140;
141end
Note: See TracBrowser for help on using the repository browser.