;---------------------------------------------------------------------- ; vector_1.ncl ; ; Concepts illustrated: ; - Overlaying vectors and filled contours on a map ; - Manually attaching lat/lon coordinate arrays to a variable ; - Changing the length of the smallest vector as a fraction of the reference vector ; - Moving the vector reference annotation to the top right of the plot ; - Drawing curly vectors ; - Setting the color for vectors ; - Making the labelbar be vertical ; - Increasing the thickness of vectors ;---------------------------------------------------------------------- load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" ;************************************************ begin ;************************************************ ; open netCDF file ;************************************************ name_a=new(5,string) name_b=new(5,string) wks_name=new(6,string) name_a(0)="cpl_ocean.nc" name_a(1)="cpl_bl2_ocean.nc" name_a(2)="cpl_bl3_ocean.nc" name_a(3)="cpl_gfs_alpha_ocean.nc" name_a(4)="cpl_myj_ocean.nc" name_b(0)="cpl_ocean_u.nc" name_b(1)="cpl_bl2_ocean_u.nc" name_b(2)="cpl_bl3_ocean_u.nc" name_b(3)="cpl_gfs_alpha_ocean_u.nc" name_b(4)="cpl_myj_ocean_u.nc" wks = gsn_open_wks("ps","mld_t108") ; open a ps file gsn_define_colormap(wks,"BlAqGrYeOrRevi200") ; choose color map plot = new(5,graphic) plotstrV=new(5,graphic) plotV=new(5,graphic) do ifil = 0,4 print (ifil) a=addfile(name_b(ifil),"r") b=addfile(name_a(ifil),"r") ;************************************************ ; Read in Sea Surface Temperature Anomalies ; Read in U and V at 1000 mb [subscript 0] ; Determine the subscripts corresponding to Jan 88 ;************************************************ sst = a->layer_temperature(0,0,:,:) u = a->u_velocity(0,0,:,:) v = a->v_velocity(0,0,:,:) u_str = b->stress_u_velocity(0,:,:) v_str = b->stress_v_velocity(0,:,:) mld = b->mixed_layer_thickness(0,:,:) ; u_str@_FillValue=default_fillvalue("float") fill_uv= u_str@_FillValue u_str = where(abs(u_str).gt.100,fill_uv,u_str) ; v_str@_FillValue=default_fillvalue("float") v_str = where(abs(v_str).gt.100,fill_uv,v_str) ;print (u_str) lat_uv = a->Latitude(:) lon_uv = a->Longitude(:) ;************************************************ ; create plot ;************************************************ res = True ; plot mods desired res@cnFillOn = True ; turn on color for contours res@cnLinesOn = False ; turn off contour lines res@cnLineLabelsOn = False ; turn off contour line labels ; res@gsnScalarContour = True ; contours desired res@gsnSpreadColors = True ; use full color map res@gsnSpreadColorStart = 30 ;17 ; start at color 17 res@gsnSpreadColorEnd = 180 ; end at color 200 ; ; This is not necessary in V6.1.0 and later. Named colors can ; be used without having to first add them to the color map. ; i = NhlNewColor(wks,0.7,0.7,0.7) ; add gray to colormap res@mpLandFillColor = "gray" ; set land to be gray res@gsnAddCyclic = False ; res@mpMinLonF = -75 ;lon_uv(0) ;-98. ; select a subregion ; res@mpMaxLonF = -55 ;lon_uv(dimsizes(lon_uv)-1) ;-53. ; res@mpMinLatF = 30 ;lat_uv(0) ; 5.8 ; res@mpMaxLatF = 43 ;lat_uv(dimsizes(lat_uv)-1);32. res@mpMinLonF = -75 ;lon_uv(0) ;-98. ; select a subregion res@mpMaxLonF = -60 ;lon_uv(dimsizes(lon_uv)-1) ;-53. res@mpMinLatF = 30 ;lat_uv(0) ; 5.8 res@mpMaxLatF = 43 ;lat_uv(dimsizes(lat_uv)-1);32. res@lbOrientation = "Vertical" ; vertical label bar res@pmLabelBarOrthogonalPosF = -0.01 ; move label bar closer res@lbLabelStride = 4 ; note, when doing a subregion, NCL determines the range of the data from ; the full domain. If you wish to just consider the domain you are plotting, ; you must manually set those levels. res@cnLevelSelectionMode = "ManualLevels" ; set manual contour levels res@cnMinLevelValF = 10.0 ; set min contour level res@cnMaxLevelValF = 120.0 ; set max contour level res@cnLevelSpacingF = 10.0 ; set contour spacing res@gsnDraw = False ; turn off draw and frame res@gsnFrame = False ; b/c this is an overlay plot vres = True vres@vcRefMagnitudeF = 1.0 ; define vector ref mag vres@vcRefLengthF = 0.015 ; define length of vec ref vres@vcRefAnnoOrthogonalPosF = -1.0 ; move ref vector vres@vcRefAnnoArrowLineColor = "Black" ; change ref vector color vres@vcRefAnnoArrowUseVecColor = False ; don't use vec color for ref vres@vcMinDistanceF = 0.02 ; vres@vcGlyphStyle = "CurlyVector" ; turn on curley vectors ; vres@vcLineArrowColor = "deeppink1" ; change vector color vres@vcLineArrowColor = "white" ; change vector color vres@vcLineArrowThicknessF = 2.0 ; change vector thickness ; vres@vcVectorDrawOrder = "PostDraw" ; draw vectors last vres@gsnAddCyclic = False ; vres@mpMinLonF = -98. ; select a subregion ; vres@mpMaxLonF = -53. ; vres@mpMinLatF = 5.8 ; vres@mpMaxLatF = 32. vres@gsnDraw = False ; turn off draw and frame vres@gsnFrame = False ; b/c this is an overlay plot ; plotV(ifil) = gsn_csm_vector(wks,u,v,vres) strvres=vres strvres@vcLineArrowColor = "Black" ; change ref vector color ; plotstrV(ifil) = gsn_csm_vector(wks,u_str,v_str,strvres) ; plot=gsn_csm_vector_scalar_map_ce(wks,u(:,:),v(:,:),\ ; sst(:,:),res) plot(ifil) = gsn_csm_contour_map(wks,mld,res) ; overlay(plot(ifil),plotV(ifil)) ; overlay(plot(ifil),plotstrV(ifil)) end do gsn_panel(wks,plot,(/2,3/),False) ; draw(plot) ; frame(wks) end