-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterpolate_flxObs-monthly.ncl
executable file
·74 lines (56 loc) · 2.61 KB
/
interpolate_flxObs-monthly.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
; Date: 9 Sep 2020
; Purpose: almost identical to previous script (interpolate_flxObs.ncl), but accounts for time component in monthly LH obs.
begin
; ----------------------------------
; Set file names of data to be read in and file to save things out as
fileName_ObsIn = "/Users/mdfowler/Documents/Analysis/CLUBB_initial/data/obs/sh_0.5x0.5.nc"
fileName_out = "/Users/mdfowler/Documents/Analysis/CLUBB_initial/data/processed_SHFLXmonthly_RegriddedObs.nc"
; Set file name with grid I actually want
fileName_GridIn = "/Users/mdfowler/Documents/Analysis/CLUBB_initial/data/f.e20.FHIST.f09_f09.cesm2_1.001.cam.h0.1951-59_PS.nc"
; Open file of observations and gridded data
fObs = addfile(fileName_ObsIn, "r")
fModel = addfile(fileName_GridIn, "r")
; -----------------------------------
; Read in target lat and lon
latModel = fModel->lat
lonModel = fModel->lon
; Read in obs data, lat, and lon
latObs = fObs->lat
lonObs = fObs->lon
timeObs = fObs->time
SHobs = fObs->sh
; Need to convert obs lon to be 0-360, not -180 to 180
SHobs = lonFlip(SHobs)
;lonObs = lonFlip(lonObs)
lonObs1 = fspan(0.25,359.75,720) ; Create evenly increasing lon array corresponding to re-ordered obs
; -------------------------------------
; Interpolate observations of flux to model grid using NCL
regridSH = linint2(lonObs1, latObs, SHobs, True, lonModel, latModel, 0)
; ------------------------------------
; Write out to netCDF file...
; Using code from: https://www.ncl.ucar.edu/Applications/method_1.shtml
system("/bin/rm -f " + fileName_out) ; remove any pre-existing file
ncdf = addfile(fileName_out,"c") ; open output netCDF file
;===================================================================
; create global attributes of the file (optional)
;===================================================================
fAtt = True ; assign file attributes
fAtt@title = "Using NCL Simple Approach to netCDF Creation for saving regridded data"
fAtt@source_file = "sh_0.5x0.5.nc"
fAtt@Conventions = "None"
fAtt@creation_date = systemfunc ("date")
fileattdef( ncdf, fAtt ) ; copy file attributes
;===================================================================
; output variables directly; NCL will call appropriate functions
; to write the meta data associated with each variable
;===================================================================
regridSH!0 = "time"
regridSH!1 = "lat"
regridSH!2 = "lon"
regridSH&time = timeObs
regridSH&lat = latModel
regridSH&lon = lonModel
regridSH@long_name = "SH from GBAF regridded to match model grid."
regridSH@units = "W/m2"
ncdf->SH_obs = regridSH
end