;---------------------------------------------------------------------- ; minmax_4.ncl ; ; Concepts illustrated: ; - Using the WhiteBlue color map ; - Replacing colors in the existing color map with named colors ; - Changing the contour level spacing ; - Attaching polymarkers to a contour plot ; - Calculating the local minima/maxima of your data ; - Adding text strings at local minima/maxima locations ; - Drawing a custom legend outside of a map plot ;---------------------------------------------------------------------- ; ; These files are loaded by default in NCL V6.2.0 and newer ; load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" ; load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" begin ;---Open file and read in Sea Surface Temperature Anomalies a = addfile("/home/peni/skripsi/olr.day.kelvinmjoer.nc","r") k = a->kelvin t = a->time ;------custom time ymdStrt = 20160101 ; start yyyymmdd ymdLast = 20160201 ; last yrStrt = ymdStrt/10000 yrLast = ymdLast/10000 latS = -20 latN = 20 lonS = 60 lonN = 180 ;*********************************************************** ; Read user specified time and create required yyyyddd ;*********************************************************** time = a->time ; all times on file ymd = cd_calendar(time, -2) ; yyyymmdd iStrt = ind(ymd.eq.ymdStrt) ; index start iLast = ind(ymd.eq.ymdLast) ; index last delete(time) delete(ymd) print(iStrt+" ... "+iLast) ;*********************************************************** ; Read user specified time and create required yyyyddd ;*********************************************************** time = a->time(iStrt:iLast) ; time:units = "hours since" TIME = cd_calendar(time, 0) ; type float year = floattointeger( TIME(:,0) ) month = floattointeger( TIME(:,1) ) day = floattointeger( TIME(:,2) ) ddd = day_of_year(year, month, day) yyyyddd = year*1000 + ddd ; needed for input ;*********************************************************** wks = gsn_open_wks("png","minmax") ; send graphics to PNG file res = True res@gsnMaximize = True ; maximize plot in frame res@gsnDraw = False res@gsnFrame = False res@cnFillOn = True ; turn on contour fill res@cnFillPalette = "WhiteBlue" ; set color map res@cnLinesOn = True ; turn off contour lines res@cnLineLabelsOn = False ; turn off contour labels res@cnLevelSpacingF = 1.4 res@tiMainString = "Anomali OLR Reza" res@mpFillDrawOrder = "PostDraw" ; Draw map fill last res@mpMinLatF = latS ; zoom in on map res@mpMaxLatF = latN res@mpMinLonF = lonS ; zoom in on map res@mpMaxLonF = lonN ;---Create plot ;-----reza-------------- ntBegin = ind(yyyymmdd.eq.ymdStrt) ntEnd = ind(yyyymmdd.eq.ymdLast) ;----------------------- nt = ntBegin,ntEnd ;edit reza plot = gsn_csm_contour_map(wks,k(nt,:,:),res) ; ; Called local_min and local_max to get lat/lon locations of local ; minima and maxima. The lat/lon locations will be returned as ; index values in the X and Y dimensions, "xi" and "yi". ; iimin = local_min(k(nt,:,:),False,0.) iimax = local_max(k(nt,:,:),False,0.) mkres = True mkres@gsMarkerIndex = 16 ; filled dot mkres@gsMarkerSizeF = 8. ; make dot larger mkres@gsMarkerColor = "green" dumlow = gsn_add_polymarker(wks,plot,k&lon(iimin@xi),k&lat(iimin@yi),mkres) mkres@gsMarkerColor = "red" dumhgh = gsn_add_polymarker(wks,plot,k&lon(iimax@xi),k&lat(iimax@yi),mkres) draw(plot) ; Drawing the plot draws the attached markers too ;---Draw a legend at the bottom txres = True txres@txJust = "CenterLeft" txres@txFontHeightF = 0.02 mkres@gsMarkerSizeF = 10. ; make dot larger xpos = 0.15 ypos = 0.25 mkres@gsMarkerColor = "green" gsn_polymarker_ndc(wks,xpos,ypos,mkres) gsn_text_ndc(wks," Lokasi minimum lokal",xpos,ypos,txres) xpos = 0.55 ypos = 0.25 mkres@gsMarkerColor = "red" gsn_polymarker_ndc(wks,xpos,ypos,mkres) gsn_text_ndc(wks," Lokasi maksimum lokal",xpos,ypos,txres) frame(wks) end