Re: overlaying gradient contours

From: Chris Fletcher <chris.fletcher_at_nyahnyahspammersnyahnyah>
Date: Fri, 14 Aug 2009 12:24:42 -0400

Yes, that's fixed it. Thanks very much.

Also, to get sensible results I had to flip the latitude order with
   u = u(::-1,:)
because the reanalysis data were oriented north-south.

Chris

On Fri, 2009-08-14 at 10:19 -0600, Dennis Shea wrote:
> I see the issue
>
> plot=gsn_csm_contour_map_overlay(wks,u,vdiv*1e5,res1,res2)
>
> The "vdiv*1e5" creates a temporary variable that contains
> no meta data.
>
> replace the above with the following
>
> vdiv = vdiv*1e5
>
> plot=gsn_csm_contour_map_overlay(wks,u,vdiv,res1,res2)
>
>
>
> Adam Phillips wrote:
> > Hi Chris,
> > From what you sent in the original email:
> >
> > >>> Variable: u
> > >>> Type: float
> > >>> Total Size: 42048 bytes
> > >>> 10512 values
> > >>> Number of Dimensions: 2
> > >>> Dimensions and sizes: [lat | 73] x [lon | 144]
> > >>> Coordinates:
> > >>> lat: [90..-90] <================= latitude coordinate
> > variable
> > >>> lon: [ 0..357.5] <=============== longitude coordinate
> > variable
> > >>> Number Of Attributes: 15
> >
> > The latitude and longitude coordinate information is attached to the u /
> > v arrays. So you should be good to go there. However, NCL also needs the
> > units attribute of the latitude/longitude coordinate variables to be set
> > as well. The units attribute is usually set in the netCDF file, but not
> > always. The "Data either does not contain a valid latitude coordinate
> > array or doesn't contain one at all." error message is an indication
> > that this might be the problem.
> >
> > Try this:
> >
> > dir = "/home/cgf/projects/"
> > f = addfile (dir+"uwnd200.nc", "r")
> > u = f->uwnd ; (lat,lon)
> > f2 = addfile (dir+"vwnd200.nc", "r")
> > v = f2->vwnd
> >
> > u&lat_at_units = "degrees_north"
> > u&lon_at_units = "degrees_east"
> > v&lat_at_units = "degrees_north"
> > v&lon_at_units = "degrees_east"
> > udiv=u
> > vdiv=v
> > gradsf(u,udiv,vdiv)
> >
> > ; plot as normal
> >
> > There is a FAQ written for that specific error message, if you'd like to
> > learn more:
> > http://www.ncl.ucar.edu/FAQ/#err_msgs_012
> >
> > Let us know if that doesn't fix your issue.
> > Best regards,
> > Adam
> >
> > Chris Fletcher wrote:
> >> Thanks for your reply. I removed the lines as suggested but I still get
> >> the same problem, and warning about "Data either does not contain a
> >> valid latitude coordinate array or doesn't contain one at all."
> >>
> >> I'm still unclear about the lat/lon2d arrays for this grid. Are they
> >> required? If so, should I create them on the fly (I don't think they
> >> are available to be read from the data file), then assign them using
> >> u_at_lon2d and u_at_lat2d?
> >>
> >> On Fri, 2009-08-14 at 08:07 -0600, Dennis Shea wrote:
> >>> [1]
> >>> These are *not* two-dimensional latitude or longitude arrays.
> >>> The variables u and vdiv are two-dimensiona BUT the
> >>> coordinate variables are classic netCDF one dimensional
> >>> coordinates.
> >>>
> >>> By Unidata/netCDF definition a "coordinate variable"
> >>> is a one-dimensional array of monotonically {in/de}creasing
> >>> values"
> >>>
> >>> Variable: u
> >>> Type: float
> >>> Total Size: 42048 bytes
> >>> 10512 values
> >>> Number of Dimensions: 2
> >>> Dimensions and sizes: [lat | 73] x [lon | 144]
> >>> Coordinates:
> >>> lat: [90..-90] <=== coord variable
> >>> lon: [ 0..357.5] <=== coord variable
> >>>
> >>>
> >>> Remove:
> >>> lat2d = f->lat
> >>> lon2d = f->lon
> >>> printVarSummary(lat2d)
> >>> printVarSummary(lon2d)
> >>>
> >>> u_at_lon2d=lon2d
> >>> u_at_lat2d=lat2d
> >>> v_at_lon2d=lon2d
> >>> v_at_lat2d=lat2d
> >>>
> >>> [2] Delete or comment the following
> >>>
> >>> res1_at_mpMinLonF = 0. ; select a subregion
> >>> res1_at_mpMaxLonF = 360.
> >>> res1_at_mpMinLatF = -90.
> >>> res1_at_mpMaxLatF = 90.
> >>>
> >>> The default is a global grid.
> >>>
> >>> ======================================
> >>> Good luck
> >>>
> >>>
> >>> Chris Fletcher wrote:
> >>>> Hi, question from a new user:
> >>>>
> >>>> I am trying to use gsn_csm_contour_map_overlay to display an NCEP/NCAR
> >>>> reanalysis wind field (shaded) and its meridional gradient (contour).
> >>>>
> >>>> However, the contour data won't plot correctly (it appears compressed
> >>>> into a smaller region in the top-right -- see attached). I believe the
> >>>> lon/lat2d variables and their "units" attribute are defined correctly
> >>>> (although the warnings suggest otherwise). The problem appears to be
> >>>> that the gradsf procedure modifies the coordinates somehow, because I
> >>>> can contour overlay the wind field with itself without a problem.
> >>>>
> >>>> Thanks in advance, all the output follows.
> >>>> Chris
> >>>>
> >>>>
> >>>>
> >>>> I see the following warnings from my script:
> >>>> (0) is_valid_latlon2d_attr: Warning: The 'lat2d' attribute must
> >>>> either be the same dimension sizes as the data, or one element larger in
> >>>> both directions. Your data will most likely not be overlaid on the map
> >>>> correctly.
> >>>> (0) is_valid_latlon2d_attr: Warning: The 'lon2d' attribute must
> >>>> either be the same dimension sizes as the data, or one element larger in
> >>>> both directions. Your data will most likely not be overlaid on the map
> >>>> correctly.
> >>>> (0) check_for_y_lat_coord: Warning: Data either does not contain a
> >>>> valid latitude coordinate array or doesn't contain one at all.
> >>>> (0) A valid latitude coordinate array should have a 'units' attribute
> >>>> equal to one of the following values:
> >>>> (0) 'degrees_north' 'degrees-north' 'degree_north' 'degrees
> >>>> north' 'degrees_N' 'Degrees_north' 'degree_N' 'degreeN' 'degreesN' 'deg
> >>>> north'
> >>>> (0) check_for_lon_coord: Warning: Data either does not contain a
> >>>> valid longitude coordinate array or doesn't contain one at all.
> >>>> (0) A valid longitude coordinate array should have a 'units'
> >>>> attribute equal to one of the following values:
> >>>> (0) 'degrees_east' 'degrees-east' 'degree_east' 'degrees east'
> >>>> 'degrees_E' 'Degrees_east' 'degree_E' 'degreeE' 'degreesE' 'deg east'
> >>>>
> >>>>
> >>>>
> >>>> ;Here are the details from printVarSummary
> >>>> ;***********************************************
> >>>> Variable: lat2d
> >>>> Type: float
> >>>> Total Size: 292 bytes
> >>>> 73 values
> >>>> Number of Dimensions: 1
> >>>> Dimensions and sizes: [lat | 73]
> >>>> Coordinates:
> >>>> lat: [90..-90]
> >>>> Number Of Attributes: 3
> >>>> units : degrees_north
> >>>> actual_range : ( 90, -90 )
> >>>> long_name : Latitude
> >>>>
> >>>>
> >>>> Variable: lon2d
> >>>> Type: float
> >>>> Total Size: 576 bytes
> >>>> 144 values
> >>>> Number of Dimensions: 1
> >>>> Dimensions and sizes: [lon | 144]
> >>>> Coordinates:
> >>>> lon: [ 0..357.5]
> >>>> Number Of Attributes: 3
> >>>> units : degrees_east
> >>>> long_name : Longitude
> >>>> actual_range : ( 0, 357.5 )
> >>>>
> >>>>
> >>>> Variable: u
> >>>> Type: float
> >>>> Total Size: 42048 bytes
> >>>> 10512 values
> >>>> Number of Dimensions: 2
> >>>> Dimensions and sizes: [lat | 73] x [lon | 144]
> >>>> Coordinates:
> >>>> lat: [90..-90]
> >>>> lon: [ 0..357.5]
> >>>> Number Of Attributes: 15
> >>>> lat2d : <ARRAY of 73 elements>
> >>>> lon2d : <ARRAY of 144 elements>
> >>>> long_name : Monthly mean u wind
> >>>> actual_range : ( -66.37, 124.4 )
> >>>> valid_range : ( -125, 160 )
> >>>> units : m/s
> >>>> missing_value : 32766
> >>>> precision : 2
> >>>> least_significant_digit : 1
> >>>> var_desc : u-wind
> >>>> U
> >>>> dataset : CDC Derived NCEP Reanalysis Products
> >>>> AC
> >>>> level_desc : Multiple levels
> >>>> F
> >>>> statistic : Mean
> >>>> M
> >>>> parent_stat : Other
> >>>> -
> >>>> _FillValue : 32766
> >>>>
> >>>>
> >>>> Variable: vdiv
> >>>> Type: float
> >>>> Total Size: 42048 bytes
> >>>> 10512 values
> >>>> Number of Dimensions: 2
> >>>> Dimensions and sizes: [lat | 73] x [lon | 144]
> >>>> Coordinates:
> >>>> lat: [90..-90]
> >>>> lon: [ 0..357.5]
> >>>> Number Of Attributes: 15
> >>>> _FillValue : 32766
> >>>> parent_stat : Other
> >>>> -
> >>>> statistic : Mean
> >>>> M
> >>>> level_desc : Multiple levels
> >>>> F
> >>>> dataset : CDC Derived NCEP Reanalysis Products
> >>>> AC
> >>>> var_desc : v-wind
> >>>> V
> >>>> least_significant_digit : 1
> >>>> precision : 2
> >>>> missing_value : 32766
> >>>> units : m/s
> >>>> valid_range : ( -125, 160 )
> >>>> actual_range : ( -66.65, 66.39 )
> >>>> long_name : Monthly mean v wind
> >>>> lon2d : <ARRAY of 144 elements>
> >>>> lat2d : <ARRAY of 73 elements>
> >>>>
> >>>>
> >>>>
> >>>> Here is my script:
> >>>> ;***********************************************
> >>>> 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
> >>>> ;*************************************************
> >>>> dir = "/home/cgf/projects/"
> >>>> f = addfile (dir+"uwnd200.nc", "r")
> >>>> u = f->uwnd ; (lat,lon)
> >>>> lat2d = f->lat
> >>>> lon2d = f->lon
> >>>> f2 = addfile (dir+"vwnd200.nc", "r")
> >>>> v = f2->vwnd
> >>>> printVarSummary(lat2d)
> >>>> printVarSummary(lon2d)
> >>>>
> >>>> u_at_lon2d=lon2d
> >>>> u_at_lat2d=lat2d
> >>>> v_at_lon2d=lon2d
> >>>> v_at_lat2d=lat2d
> >>>> udiv=u
> >>>> vdiv=v
> >>>> gradsf(u,udiv,vdiv)
> >>>> ;
> >>>> ; ************
> >>>> ; plotting
> >>>> ;
> >>>> ;
> >>>> wks = gsn_open_wks("ps","wind") ; open a workstation
> >>>> gsn_define_colormap(wks,"BlWhRe")
> >>>> ;************************************************
> >>>> ; resource list for first data array
> >>>> ;************************************************
> >>>> res1 = True
> >>>> res1_at_gsnDraw = False ; don"t draw
> >>>> res1_at_gsnFrame = False ; don"t advance frame
> >>>>
> >>>> res1_at_cnLevelSelectionMode = "ManualLevels" ; set manual contour levels
> >>>> res1_at_cnMinLevelValF = -5. ; set min contour level
> >>>> res1_at_cnMaxLevelValF = 45. ; set max contour level
> >>>> res1_at_cnLevelSpacingF = 2 ; set contour spacing
> >>>>
> >>>> res1_at_lbOrientation = "Vertical" ; vertical label bar
> >>>> res1_at_lbLabelAutoStride = True ; optimal label stride
> >>>> res1_at_gsnSpreadColors = True ; use full range of colors
> >>>> res1_at_gsnSpreadColorEnd = -3 ; don"t use added gray
> >>>>
> >>>> ; res1_at_mpCenterLonF = 180. ; center plot at 180
> >>>>
> >>>> res1_at_mpMinLonF = 0. ; select a subregion
> >>>> res1_at_mpMaxLonF = 360.
> >>>> res1_at_mpMinLatF = -90.
> >>>> res1_at_mpMaxLatF = 90.
> >>>>
> >>>> ;************************************************
> >>>> ; resource list for second data array
> >>>> ;************************************************
> >>>> res2 = True
> >>>> res2_at_cnLevelSelectionMode = "ManualLevels" ; set manual contour levels
> >>>> res2_at_cnMinLevelValF = -10. ; set min contour level
> >>>> res2_at_cnMaxLevelValF = 10. ; set max contour level
> >>>> res2_at_cnLevelSpacingF = 0.5 ; set contour spacing
> >>>> res2_at_cnLineLabelsOn = True
> >>>> res2_at_gsnContourZeroLineThicknessF = 2. ; doubles thickness of
> >>>> zero contour
> >>>> res2_at_gsnContourNegLineDashPattern = 1 ; sets negative contours
> >>>> to dash pattern 1
> >>>>
> >>>> printVarSummary(u)
> >>>> printVarSummary(vdiv)
> >>>>
> >>>> plot=gsn_csm_contour_map_overlay(wks,u,vdiv*1e5,res1,res2)
> >>>> draw(plot)
> >>>> frame(wks)
> >>>> end
> >>>>
> >>>>
> >>>>
> >>
> >> _______________________________________________
> >> ncl-talk mailing list
> >> List instructions, subscriber options, unsubscribe:
> >> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
> >

-- 
-----------------------------------------------
Chris Fletcher, Research Associate
+ Dept. of Physics, U. of Toronto, 60 St. George St.,Toronto, ON, M5S  
1A7, Canada.
+ Tel: +1-416-946-0344
+ Home page: http://www.atmosp.physics.utoronto.ca/people/cgf/
-----------------------------------------------
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Aug 14 2009 - 10:24:42 MDT

This archive was generated by hypermail 2.2.0 : Fri Aug 14 2009 - 13:47:46 MDT