[ncl-talk] convert png to nc file after plot command
zoe jacobs
zoejacobs1990 at gmail.com
Wed Jul 29 00:58:26 MDT 2020
Dear all NCL users,
I have a script (attached) which gives me monthly averages of
precipitation and plots the result as png files. I wonder if there is any
command in NCL which could convert the png file to nc file after plot
command?
Please kindly advise me in this regard,
Many thanks in advance,
Best wishes,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20200729/7e1190ea/attachment.html>
-------------- next part --------------
fils = systemfunc ("ls precip.*.nc") ; file paths
a = addfiles (fils, "r")
printVarSummary (a)
ListSetType (a, "cat") ; concatenate (=default)
;************************************************
; Read the file
;************************************************
ymdStrt = 19790101 ; climatology start year/month
ymdLast = 19801231 ; " last year/month a time = f->time
time = a[:]->time
yyyymmdd= cd_calendar(time, -2)
print(yyyymmdd)
ntStrt = ind(yyyymmdd.eq.ymdStrt) ; start time index
ntLast = ind(yyyymmdd.eq.ymdLast) ; last time index
print("ntStrt="+ntStrt+" ntLast="+ntLast)
prc = a[:]->precip(ntStrt:ntLast,:,:) ; read T from all files
printVarSummary (prc)
printMinMax (prc,0)
;************************************************
; Compute Year-month means or totals
;************************************************
;;prcMonth = calculate_monthly_values(prc, "avg", 0, False) ; mm/day
;;prcMonth at units = "mm/day"
prcMonth = calculate_monthly_values(prc, "sum", 0, False) ; mm/month
prcMonth at units = "mm/month" ; monthly total
printVarSummary (prcMonth)
printMinMax (prcMonth,0)
;************************************************
; Compute monthly climatology from all year-month means
;************************************************
prcClm = clmMonTLL(prcMonth)
printVarSummary (prcClm) ; (12,lat,lon)
printMinMax (prcClm,0)
;************************************************
; Explore [statistical dispersion] the monthly climatology
;************************************************
opt_sd = True
opt_sd at PrintStat = True
stat_prc = stat_dispersion(prcClm, opt_sd )
;************************************************
; Plot
;*************************************************
months = (/"January", "February", "March", "April" \
,"May", "June", "July", "August" \
,"September", "October", "November" \
,"December" /)
nmos = dimsizes(months)
wks = gsn_open_wks("png","climo_prc_ghcn") ; send graphics to PNG file
plot = new (nmos, graphic) ; create graphical array
res = True ; plot options desired
res at gsnDraw = False
res at gsnFrame = False
res at cnFillOn = True ; turn on color fill
res at cnInfoLabelOn = False ; turn off contour info label
res at cnLinesOn = False ; turn off contour lines
res at cnLineLabelsOn = False ; turn off line labels
res at cnFillMode = "RasterFill" ; Raster Mode
;;res at cnFillPalette = "????" ; set color map
;;res at cnLevelSelectionMode = "ManualLevels" ; set manual contour levels
;;res at cnMinLevelValF = 0 ; set min contour level
;;res at cnMaxLevelValF = 300 ; set max contour level
;;res at cnLevelSpacingF = 20.0 ; set contour spacing
res at cnLevelSelectionMode = "ExplicitLevels"
;;res at cnLevels = (/ 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300/) ; 12 contour values
;;res at cnLevels = (/ 10, 20, 30, 40, 50, 75,100,125,150, 200, 300, 400/) ; 12 contour values
res at cnLevels = (/ 10, 20, 30, 40, 50, 75,100,150,200, 300, 400, 500/) ; 12 contour values
res at cnFillPalette = (/"WhiteSmoke" \ ; 13 colors
,"PaleTurquoise","PaleGreen","SeaGreen3" ,"Yellow" \
,"Orange","HotPink","Red","Violet", "Purple" \
,"burlywood3", "Brown", "Black"/)
res at mpFillOn = False ; turn off gray continents
res at mpCenterLonF = 0 ; Centers the plot at 0
res at lbLabelBarOn = False ; No single label bar
do nmo=0,nmos-1 ; loop over the months
res at gsnLeftString = months(nmo)
plot(nmo) = gsn_csm_contour_map(wks,prcClm(nmo,:,:), res) ; create plot
end do
;************************************************
; create panel plots
;*************************************************
resP = True ; panel options
resP at gsnPanelMainString = "GHCN: Precipitation: "+(ymdStrt/10000)+"-"+(ymdLast/10000)
resP at gsnMaximize = True ; maximize image
resP at gsnPanelLabelBar = True ; Add common label bar
gsn_panel(wks,plot,(/4,3/),resP)
More information about the ncl-talk
mailing list