-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREGRID_SEVIRI.ncl
executable file
·200 lines (167 loc) · 6.83 KB
/
REGRID_SEVIRI.ncl
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
; $ID: REGRID_SEVIRI.ncl V01 01/12/2014 22:30 BRUCE EXP$
;
;******************************************************************************
; PROGRAM REGRID_SEVIRI.ncl READS 3-HOURLY EMISSION DATA CALCULATED FROM
; GFED_PREPROCESS SUBROUTINE (0.5*0.5), AND REGRID IT INTO WRFCHEM GRID BOX.
;
; VARIABLES:
; ============================================================================
; (1 )
;
; NOTES:
; ============================================================================
; (1 ) ORIGINALLY WRITTEN BY BRUCE. (01/12/2014)
; (2 ) VARIABLES (iy, im, id) ARE INPUTTED FROM SPECIFICATION OF NCL OPTIONS,
; WHICH ARE AS FOLLOWING:
; ncl iy=2010 im=2 id=1 REGRID_SEVIRI.ncl. (01/13/2014)
;******************************************************************************
; LOAD FUNCTIONS AND PROCEDURES
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl"
begin
; reading the input data (lat-lon grid: SEVIRI=1.0x1.0)
; NOTE: this part can be modified according to different cases
datir = "/Volumes/TOSHIBA_3A/idata/emission/smoke/FEER-SEVIRI/HOURLY_GRID/"
datir_out = "/Volumes/TOSHIBA_3A/idata/emission/smoke/FEER-SEVIRI/HOURLY_WRF/test/"
datir_grid= "../results/grids/"
datir_out = "../results/regrid/SEVIRI/"
idom = "d01" ;"d02" ; d01 ; domain index
nx = 129 ;297 ; 129
ny = 84 ;120 ; 84
mt = 24
dlon = 1.0
dlat = 1.0
mx = 112
my = 82
; end modification region
; read in the wrf lat and lon info
rlat = asciiread(datir_grid + "lat_"+idom+".txt", (/ny,nx/), "float")
rlon = asciiread(datir_grid + "lon_"+idom+".txt", (/ny,nx/), "float")
; note: corner_rlat and corner_rlon only for "conserve" interpolation method
corner_rlat = asciiread(datir_grid + "corner_lat_"+idom+".txt", (/ny,nx,4/), "float")
corner_rlon = asciiread(datir_grid + "corner_lon_"+idom+".txt", (/ny,nx,4/), "float")
; below to begin the regridding from lat-lon to lambert projection
srcGridName = "src_SCRIP.nc"
dstGridName = "dst_SCRIP.nc"
wgtFileName = "LL_2_CWRF.nc"
ndays = (/31,28,31,30,31,30,31,31,30,31,30,31/)
temp_regrid = new((/mt,ny,nx/), "float")
temp = new((/my,mx/), "float")
temp@missingValue = -9999.
temp@_FillValue = -9999.
Opt = True
dimNames = (/"time", "lat", "lon" /)
dimSizes = (/ -1, ny, nx /)
dimUnlim = (/True, False, False /)
;do iy = 2010,2010 ;2003,2011
cyear = iy
; do im = 1,1 ;1,12
if (im .ge. 10) then
cmonth = im
else
cmonth = "0" + im
end if
if (iy .eq. 2004 .or. iy .eq. 2008 .or. iy .eq. 2012) then
ndays(1) = 29
else
ndays(1) = 28
end if
; do id = 1,1;ndays(im-1)
if (id .ge. 10) then
cday = id
else
cday = "0" + id
end if
flnm_out = datir_out + cyear + "/SEVIRI_Emissions_NSSA_" + cyear + cmonth + cday + "_" + idom + ".nc"
do ihr = 0,mt-1
if (ihr .ge. 10) then
chr = ihr
else
chr = "0"+ihr
end if
cdate = cday + chr
f_log = True
if (f_log) then
flnm = datir+cyear+"_data_only/SEVIRI_Emissions_NSSA_"+cyear+cmonth+cdate+"00.dat"
;read in the source data (this data from north to south)
temp = asciiread(flnm, (/my,mx/), "float")
if (all(ismissing(temp))) then
temp = 0.0
end if
delete(Opt)
; for source grids
Opt = True
Opt@LLCorner = (/ -30.5, -40.5/)
Opt@URCorner = (/ 50.5, 70.5/)
Opt@Mask2D = where(.not.ismissing(temp),1,0)
Opt@ForceOverwrite = True
Opt@PrintTimings = True
latlon_to_SCRIP(srcGridName,"1deg",Opt)
delete(Opt)
; for destination grids
Opt = True
Opt@ForceOverwrite = True
Opt@PrintTimings = True
Opt@Title = "WRF Grid"
Opt@GridCornerLat = corner_rlat
Opt@GridCornerLon = corner_rlon
curvilinear_to_SCRIP(dstGridName, rlat, rlon, Opt)
delete(Opt)
; for weight
Opt = True
Opt@InterpMethod = "conserve" ; "bilinear","patch","conserve"
Opt@ForceOverwrite = True
Opt@PrintTimings = True
Opt@Debug = True
ESMF_regrid_gen_weights(srcGridName, dstGridName, wgtFileName, Opt)
delete(Opt)
; for final data
Opt = True
Opt@PrintTimings = True
Opt@ForceOverwrite = True
Opt@Debug = True
temp_regrid(ihr,:,:) = ESMF_regrid_with_weights(temp,wgtFileName, Opt)
else
temp_regrid(ihr,:,:) = -9999.
end if
end do
lat2d = temp_regrid@lat2d
lon2d = temp_regrid@lon2d
dim = dimsizes(lat2d)
nlat = dim(0)
nlon = dim(1)
system("rm -f "+flnm_out)
n = addfile(flnm_out, "c")
fAtt = True ; assign file attributes
fAtt@CREATION_DATE = systemfunc ("date")
fAtt@DECODE_BY = "ESMF_regridding.ncl was used. ALL were made by Dr. Feng Zhang, UNL. [email protected]"
fileattdef( n, fAtt ) ; copy file attributes
delete(dimNames)
delete(dimSizes)
delete(dimUnlim)
; define dimension
dimNames = (/"time", "lat", "lon" /)
dimSizes = (/ -1, ny, nx /)
dimUnlim = (/True, False, False /)
filedimdef(n,dimNames,dimSizes,dimUnlim)
; output variables
filevardef(n, "smoke_emission", "float", (/ "time", "lat", "lon" /) )
temp_regrid@long_name = "SEVIRI Sahel smoke PM2.5 emission"
temp_regrid@units = "kg/km2/hr"
temp_regrid@missingValue = -9999.
temp_regrid@_FillValue = -9999.
n->smoke_emission = temp_regrid
filevardef(n, "lat", "float", (/ "lat", "lon" /) )
rlat@long_name = "latitude"
rlat@units = "degree"
n->lat = rlat
filevardef(n, "lon", "float", (/ "lat", "lon" /) )
rlon@long_name = "longitude"
rlon@units = "degree"
n->lon = rlon
; end do
; end do
;end do
end