[ncl-talk] Dimension (nlon) of (var0) does not have an associated coordinate variable

Guido Cioni guidocioni at gmail.com
Thu Feb 2 10:17:02 MST 2017


I'm pretty sure NCL is referring to ll_ind, which is 2-Dimensional :)  (see https://www.ncl.ucar.edu/Document/Functions/Contributed/getind_latlon2d.shtml <https://www.ncl.ucar.edu/Document/Functions/Contributed/getind_latlon2d.shtml>).

Guido Cioni
http://guidocioni.altervista <http://guidocioni.altervista/>.org

> On 02 Feb 2017, at 18:14, Hughlett, Taylor M <taylor.hughlett at uta.edu> wrote:
> 
> Good afternoon,
> 
> Thank you very much for the suggestion! I have used the function that you recommended, but now I am receiving the following error:
> 
> Number of subscripts do not match number of dimensions of variable,(1) Subscripts used, (2) Subscripts expected
> 
> It occurs at the line where I actually create the plot:
> 
> plot(0)   = gsn_csm_xy (wks,years,var0(:,ll_ind(0),ll_ind(1)),res)
> 
> I have checked that var0 is three dimensional, and I have specified three subscripts required…
> 
> Have I missed something?
> 
> Taylor M Hughlett, Ph.D.
> UTA Earth and Environmental Sciences
> 500 Yates St.
> Geoscience Bldg Rm 117
> Arlington, TX 76013-0049
> 
> The Full Code:
> 
> 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"
> 
> begin
> 
> ;**************************************************
> ; Set file paths and plot specifics
> ;**************************************************
> 
> print("Setting File Paths")
> 
> ;***** File Paths and Names *****
> 
> case       = "b.e12.B1850C5CN.f09_g16.YD13ka.003"
> filen      = "b.e12.B1850C5CN.f09_g16.YD13ka.003.pop.SFWF.1_cat_840.nc"
> file_loc   = "/glade/scratch/hughlett/csm/b.e12.B1850C5CN.f09_g16.YD13ka.003/ocn/tseries/cat/"
> grid       = "b.e12.B1850C5CN.f09_g16.YD13ka.003.pop.h.0810.nc"
> grid_loc   = "/glade/scratch/hughlett/csm/b.e12.B1850C5CN.f09_g16.YD13ka.003/ocn/hist/"
> plot_loc   = "/glade/scratch/hughlett/plots/b.e12.B1850C5CN.f09_g16.YD13ka.003/timeseries"
> 
> ;***** Variable to Plot *****
> 
> var        = "SFWF"
> 
> ;***** Text for Plot *****
> 
> CenterString = "Surface Freshwater Flux"
> YAxisString  = "SFWF (Sverdrups)"
> XAxisString  = "Years"
> 
> ;***** Start and End Time for Plot *****
> 
> plot_begin = 0001
> plot_end   = 840
> 
> ;***** Data Options (0 = no, 1 = yes) *****
> 
> smooth  = 0
> dtrd    = 0
> ncwrite = 0
> 
> ;**************************************************
> ; Read In and Process Data
> ;**************************************************
> 
> print("Reading in and processing data")
> ;***** Read in All Variables *****
> 
> fvar  = addfile(file_loc+filen,"r")
> fgrid = addfile(grid_loc+grid,"r")
> 
> var0  = fvar->SFWF(:,:,:)
> lat2d = fgrid->TLAT
> lon2d = fgrid->TLONG
> 
> lat = 50
> lon = 28
> 
> ;***** Create a More Plottable Timeline *****
> 
> years = ispan(plot_begin,plot_end,1)
> nyrs = dimsizes(years)
> 
> ;***** Get indicies of the point to plot *****
> 
> ll_ind = getind_latlon2d( lat2d, lon2d, lat, lon)
> 
> ;**************************************************
> ; Open workstation, set plot resources, and plot
> ;**************************************************
> 
> print("Creating Plot")
> 
> ;***** Create Plot Name *****
> 
> pname = var + "." + case + "_" + "timeseries_0m" + plot_begin + "-" + plot_end
> 
> ;***** Open workstation *****
> 
> wks = gsn_open_wks("ps",plot_loc+pname)
> 
> ;***** Set Resources *****
> 
> res                      = True
> res at gsnMaximize          = True
> res at gsnFrame             = False
> res at gsnDraw              = False
> res at vpHeightF            = .23
> res at vpWidthF             = .783
> res at tiXAxisFontHeightF   = .015
> res at tiYAxisFontHeightF   = .015
> res at tmYLLabelFontHeightF = .015
> res at tmXBLabelFontHeightF = .015
> res at gsnLeftString        = " "
> res at gsnRightString       = " "
> res at xyLineColor          = (/"black"/)
> res at gsnCenterString      = CenterString
> res at tiYAxisString        = YAxisString
> res at tiXAxisString        = XAxisString
> res at trYMinF              = 15
> res at trYMaxF              = 19
> 
> ;***** Create New Plot *****
> 
> plot      = new(1,graphic)
> plot(0)   = gsn_csm_xy (wks,years,var0(:,ll_ind(0),ll_ind(1)),res)
> 
> print("Plot Created")
> 
> end
> 
> 
> 
> From: Alan Brammer <abrammer at albany.edu <mailto:abrammer at albany.edu>>
> Date: Wednesday, February 1, 2017 at 2:15 PM
> To: "Hughlett, Taylor M" <taylor.hughlett at uta.edu <mailto:taylor.hughlett at uta.edu>>
> Cc: "ncl-talk at ucar.edu <mailto:ncl-talk at ucar.edu>" <ncl-talk at ucar.edu <mailto:ncl-talk at ucar.edu>>
> Subject: Re: [ncl-talk] Dimension (nlon) of (var0) does not have an associated coordinate variable
> 
>  If you were plotting a map, like Barry Lynn's similar question today also on ncl-talk, you would want to do:
> 
> var0 at lon2d = lon2d
> var0 at lat2d = lat2d
> 
> The below lines are not needed. 
>     ; LON2D  = lon2d(::1,::1)        ;; I don’t think (::1,::1) does anything,  it will take all values with an increment of 1, i.e. the whole array. 
>     ; LAT2D  = lat2d(::1,::1)   ;   so this is just redundant characters which aren’t needed. 
> You don’t need to replicate a variable that already exists. 
> 
> To set coordinate variables named nlon and nlat, you want to use the & syntax not the @ syntax, but coordinate subscripting won’t work with 2d coordinates anyway. 
> 
> So instead get the index of the point you want using:
> https://www.ncl.ucar.edu/Document/Functions/Contributed/getind_latlon2d.shtml <https://www.ncl.ucar.edu/Document/Functions/Contributed/getind_latlon2d.shtml>
> e.g.
> 
> ll_ind = getind_latlon2d( lat2d, lon2d, 28,50)
>>> plot(0)   = gsn_csm_xy (wks, years, var0(:, ll_ind(0), ll_ind(1) ), res)
> 
> 
> 
> Good luck, 
> 
> Alan
> 
> 
> ##############################
> Alan Brammer,
> Post-Doc Researcher
> 
> Department of Atmospheric and Environmental Sciences,
> University at Albany, State University of New York, Albany, NY, 12222
> abrammer at albany.edu <mailto:abrammer at albany.edu>
> ##############################
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170202/a2e52702/attachment.html 


More information about the ncl-talk mailing list