Re: Lat lon coordinate variable dims

From: Katrina Bennett <kebennett_at_nyahnyahspammersnyahnyah>
Date: Wed Apr 02 2014 - 12:10:03 MDT

Hello,

Sorry to delay my response to ncl-talk!

Dennis's code worked perfectly for me. I see how this needs to be done
now.. Thank you very much for your help and assistance!

Katrina

~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Katrina E. Bennett
PhD Candidate
University of Alaska Fairbanks
International Arctic Research Center
907-474-1939 kebennett@alaska.edu

On Mon, Mar 24, 2014 at 11:06 AM, Dennis Shea <shea@ucar.edu> wrote:

> Based on your data snippet, a guess is that the grid is rectilinear.
> This means the grid can be completely described
> by one dimensional lat and lon arrays. In netCDF-speak,
> these are called by a special name ... 'coordinate variables'
> NCL graphics codes are 'netCDF aware' and will use these
> for graphic rendering.
> ---
> See "Coordinate Systems" at
> https://www.unidata.ucar.edu/software/netcdf/docs/
> BestPractices.html#Coordinate%20Systems
> ---
> See attached ... untested
>
> Please use printVarSummary(...) and print(..)
> to see the results of various steps.
>
> Also, like R (your tool) it is often best to encapsulate
> repeated tasks within a function to simplify
> and clarify code.
>
> D
>
>
>
>
> On 3/24/14, 12:36 PM, Brammer, Alan P wrote:
>
>> precDJF2D = onedtond(prec_DJF1D,(/npts,ncol/)) ; convert 1D array to a
>> 2D array
>> precMAM2D = onedtond(prec_MAM1D,(/npts,ncol/)) ; convert 1D array to a
>> 2D array
>> precJJA2D = onedtond(prec_JJA1D,(/npts,ncol/)) ; convert 1D array to a
>> 2D array
>> precSON2D = onedtond(prec_SON1D,(/npts,ncol/)) ; convert 1D array to a
>> 2D array
>>
>> are these lines correct ? It seems you should be making a 2d array that
>> is nlat x nlon (or nlon x nlat; to match up with your dimension names
>> below) instead. I would presume that there is also this error or similar
>> being printed out "warning:onedtond : output dimension sizes have fewer
>> elements than input, some data not copied"
>>
>> insert a printVarSummary(precDJF2D) between line 46 & 57 and see if the
>> array size looks right.
>>
>>
>>
>> Alan.
>>
>>
>>
>> ##############################
>> Alan Brammer,
>> PhD Student,
>>
>> Department of Atmospheric and Environmental Sciences,
>> University at Albany, State University of New York, Albany, NY, 12222
>> abrammer@albany.edu<mailto:abrammer@albany.edu>
>> ##############################
>>
>>
>> On Mar 24, 2014, at 12:04 AM, Katrina Bennett <kebennett@alaska.edu
>> <mailto:kebennett@alaska.edu>> wrote:
>>
>> I am trying to bring in a csv file with coordinates in lat/lon and then
>> create 2d variables and then map these variables using the panel_6.ncl
>> template.
>>
>> My confusion is around assigning the lat/lon variables. I have only used
>> ncl once before this so I am still learning. I looked at many different
>> examples of csv import and assign lat/lon but I am still getting the
>> following errors:
>>
>>
>> fatal:Coordinate variables must be the same dimension as their dimension
>> fatal:No coordinate variable exists for dimension (lat) in variable
>> (precDJF2D)
>> fatal:["Execute.c":8128]:Execute: Error occurred at or near line 57 in
>> file 4polar_maps.ncl
>>
>>
>>
>> Here is my code:
>> ;************************************
>> ; panel_6.ncl
>> ;
>> ; Concepts illustrated:
>> ; - Paneling four plots on a page
>> ; - Adding white space around paneled plots
>> ;
>> ;************************************
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>> ;************************************
>> begin
>> nlat = 13
>> nlon = 96
>>
>> asciif = asciiread("/import/c/w/kbennett/WAGNER/orig/all_precfn2.csv",
>> -1, "float")
>> ncol = 6 ; # of columns
>> npts = dimsizes(asciif)/ncol ; # of points
>>
>> print ("Number of npts " + npts)
>>
>> data = onedtond(asciif,(/npts,ncol/)) ; npts x ncol
>> ;print (data(:,0))
>> ;lon,lat,DJFmmka,DJFsig,MAMmmka,MAMsig,JJAmmka,JJAsig,SONmmka,SONsig
>> lat1d = data(:,1)
>> lon1d = data(:,0)
>>
>> lon1d@units = "degrees_east"
>> lon1d@long_name = "lon"
>> lat1d@units = "degrees_north"
>> lat1d@long_name = "lat"
>>
>> prec_DJF1D = data(:,2) ; 1st create a 1d array
>> ;prec_DJFsig = data(:,3) ; 1st create a 1d array
>> prec_MAM1D = data(:,3) ; 1st create a 1d array
>> ;prec_MAMsig = data(:,5) ; 1st create a 1d array
>> prec_JJA1D = data(:,4) ; 1st create a 1d array
>> ;prec_JJAsig = data(:,7) ; 1st create a 1d array
>> prec_SON1D = data(:,5) ; 1st create a 1d array
>> ;prec_SONsig = data(:,9) ; 1st create a 1d array
>> precDJF2D = onedtond(prec_DJF1D,(/npts,ncol/)) ; convert 1D array to a
>> 2D array
>> precMAM2D = onedtond(prec_MAM1D,(/npts,ncol/)) ; convert 1D array to a
>> 2D array
>> precJJA2D = onedtond(prec_JJA1D,(/npts,ncol/)) ; convert 1D array to a
>> 2D array
>> precSON2D = onedtond(prec_SON1D,(/npts,ncol/)) ; convert 1D array to a
>> 2D array
>>
>> ; Assign named dimensions
>> precDJF2D!0 = "lon"
>> precDJF2D!1 = "lat"
>> precMAM2D!0 = "lon"
>> precMAM2D!1 = "lat"
>> precJJA2D!0 = "lon"
>> precJJA2D!1 = "lat"
>> precSON2D!0 = "lon"
>> precSON2D!1 = "lat"
>>
>> ; Assign coordinate variables
>> precDJF2D&lat = lat1d
>> precDJF2D&lon = lon1d
>> precMAM2D&lat = lat1d
>> precMAM2D&lon = lon1d
>> precJJA2D&lat = lat1d
>> precJJA2D&lon = lon1d
>> precSON2D&lat = lat1d
>> precSON2D&lon = lon1d
>>
>> ;************************************
>> ;create plot
>> ;************************************
>> wks = gsn_open_wks("png","panel") ; open a png file
>> gsn_define_colormap(wks,"gui_default") ; choose colormap
>> plot = new(4,graphic) ; create graphic array
>>
>> res = True
>> res@cnFillOn = True ; turn on color fill
>> res@gsnDraw = False ; do not draw picture
>> res@gsnFrame = False ; do not advance frame
>> res@gsnPolar = "NH" ; select northern hemisphere
>> res@lbOrientation = "Vertical" ; vertical label bar
>> ; res@gsnAddCyclic = False
>> res@trXMinF = min(lat1d)
>> res@trXMaxF = max(lat1d)
>> res@trYMinF = min(lon1d)
>> res@trYMaxF = min(lon1d)
>>
>> plot(0)=gsn_csm_contour_map_polar(wks,precDJF2D,res)
>> plot(1)=gsn_csm_contour_map_polar(wks,precMAM2D,res)
>> plot(2)=gsn_csm_contour_map_polar(wks,precSON2D,res)
>> plot(3)=gsn_csm_contour_map_polar(wks,precJJA2D,res)
>>
>> ; draw panel without white space
>> gsn_panel(wks,plot,(/2,2/),False)
>>
>> ; draw panel with white space added
>> resP = True
>> resP@gsnPanelYWhiteSpacePercent = 5
>> resP@gsnPanelXWhiteSpacePercent = 5
>> gsn_panel(wks,plot,(/2,2/),resP)
>>
>> end
>>
>> ;************************************
>>
>>
>>
>>
>> This is what the first 10 lines of my data looks like:
>>
>> "lon","lat","DJF","MAM","JJA","SON"
>> 0,87.1590945558629,1.38447505131676,3.9054964926648,-3.
>> 9386162686046,1.05695082807242
>> 3.75,87.1590945558629,1.36185868022609,3.89670093682657,-4.
>> 34662668586562,0.908322062034282
>> 7.5,87.1590945558629,1.37052975794326,3.82423903911227,-4.
>> 64227628445981,0.83524295936969
>> 11.25,87.1590945558629,1.30806855744817,3.76288928938478,-4.
>> 90907575351071,0.730026786178644
>> 15,87.1590945558629,1.17795321601124,3.64811392237327,-5.
>> 22059802771348,0.599228710484037
>> 18.75,87.1590945558629,0.956059206087634,3.5322960292734,-5.
>> 41920570457574,0.489581327294277
>> 22.5,87.1590945558629,0.783329287589404,3.36918405542919,-5.
>> 58526455756134,0.320871568192774
>> 26.25,87.1590945558629,0.677955497475461,3.25939083195208,-5.
>> 73636498302219,0.210919362690496
>> 30,87.1590945558629,0.551645815273951,3.11092339482815,-5.
>> 93283519009343,0.0722272558700274
>> 33.75,87.1590945558629,0.436237774019278,3.04292256564622,-6.
>> 1559265596307,-0.109367042951931
>>
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> Katrina E. Bennett
>> PhD Candidate
>> University of Alaska Fairbanks
>> International Arctic Research Center
>> 907-474-1939 kebennett@alaska.edu<mailto:kebennett@alaska.edu>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Apr 2 12:10:13 2014

This archive was generated by hypermail 2.1.8 : Thu Apr 03 2014 - 13:36:27 MDT