Re: Setup lat2d / lon2d from NDFD data

From: Adam Phillips <asphilli_at_nyahnyahspammersnyahnyah>
Date: Mon Jul 26 2010 - 15:19:36 MDT

Hi Mark,
Arrays attached as attributes to another array can only be 1
dimensional. Thus, when you did this:
lon2d = wspd_file->longitude
lat2d = wspd_file->latitude
(snip)
U@lat2d = lat2d
U@lon2d = lon2d

The 2D latitudes and longitudes get attached as 1D arrays to U as
attributes. (The conversion from 2D->1D is done behind the scenes.) This
is all correct. When you go to plot the U array, NCL automatically
checks for the attributes lat2d and lon2d. If it finds them, it converts
them to 2D arrays and properly applies them as coordinate variables to
the array to be plotted.

When you referred to the attributes as 2D arrays, NCL returned an error
message. You should refer to the lat2d and lon2d arrays themselves. Try
changing this:
res@mpLeftCornerLatF = U@lat2d(0,0)
res@mpLeftCornerLonF = U@lon2d(0,0)
res@mpRightCornerLatF = U@lat2d(nlat-1,nlon-1)
res@mpRightCornerLonF = U@lon2d(nlat-1,nlon-1)

to this:

res@mpLeftCornerLatF = lat2d(0,0)
res@mpLeftCornerLonF = lon2d(0,0)
res@mpRightCornerLatF = lat2d(nlat-1,nlon-1)
res@mpRightCornerLonF = lon2d(nlat-1,nlon-1)

Let the group know if this doesn't fix your issue...
Adam

On 07/26/2010 02:02 PM, Mark wrote:
> Hi All,
>
> I'm trying to plot some NDFD grib2 wind data and I am have difficulty
> properly setting up the resulting NCL based lat2d / lon2d variables. It
> seems like the resulting lat2d / lon2d variables are somehow one
> dimensional whereas they should be two dimensional.
>
> Here is the script:
> ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>
>
> begin
>
> wdir_file =
> addfile("/home/mark/Degrib/degrib/bin/WindDir_07231800.nc","r") ;
> Created from degrib.
> wspd_file =
> addfile("/home/mark/Degrib/degrib/bin/WindSpd_07231800.nc","r") ; A
> printVarSummary has some info on this below.
> printVarSummary(wspd_file)
>
> lon2d = wspd_file->longitude
> lat2d = wspd_file->latitude
> printVarSummary(lat2d)
> printVarSummary(lon2d)
>
> nlat = dimsizes(lat2d(:,0))
> nlon = dimsizes(lon2d(0,:))
> rad = 4.0*atan(1.0)/180.
>
> U = -wspd_file->WindSpd_SFC(0,:,:)*sin(rad*wdir_file->WindDir_SFC(0,:,:))
> ;U!0 = "lat2d"
> ;U!1 = "lon2d"
> U@_FillValue = 9999
> U@MapProjection = wspd_file->MapProjection
> U@YCells = wspd_file->YCells
> U@XCells = wspd_file->XCells
> U@lat2d = lat2d
> U@lon2d = lon2d
> U@ProjectionHr = wspd_file->ProjectionHr
> printVarSummary(U)
>
> V = -wspd_file->WindSpd_SFC(0,:,:)*cos(rad*wdir_file->WindDir_SFC(0,:,:))
> ;U!0 = "lat2d"
> ;U!1 = "lon2d"
> V@_FillValue = 9999
> V@MapProjection = wspd_file->MapProjection
> V@YCells = wspd_file->YCells
> V@XCells = wspd_file->XCells
> V@lat2d = lat2d
> V@lon2d = lon2d
> V@ProjectionHr = wspd_file->ProjectionHr
>
> ;****************************************************************************
> ; PREPARE PLOT
> ;****************************************************************************
>
> wks = gsn_open_wks("X11","vector") ; open an X11 window
>
> res = True
> res@gsnLeftString = "Wind"
> res@tfDoNDCOverlay = True
> res@gsnAddCyclic = False ; regional data
> res@gsnMaximize = True ; Use full area
> res@vcRefMagnitudeF = 10.0 ; define vector ref mag
> res@vcRefLengthF = 0.045 ; define length of vec ref
> res@vcGlyphStyle = "CurlyVector" ; turn on curly vectors
> res@vcMinDistanceF = 0.017
> res@pmTickMarkDisplayMode = "Always"
> res@mpFillOn = False ; turn off map fill
> res@mpOutlineDrawOrder = "PostDraw" ; draw continental outline last
> res@mpOutlineBoundarySets = "GeophysicalAndUSStates" ; state boundaries
>
> ;****************************************************************************
> ; usually, when data is placed onto a map, it is TRANSFORMED to the
> specified
> ; projection. Since this model is already on a native lambert conformal
> grid,
> ; we want to turn OFF the tranformation.
> ;****************************************************************************
> res@tfDoNDCOverlay = True
>
>
> ;****************************************************************************
> ; The following 4 pieces of information are REQUIRED to properly display
> ; data on a native lambert conformal grid. This data should be specified
> ; somewhere in the model itself.
> ;****************************************************************************
> res@mpProjection = "LambertConformal"
> res@mpLambertParallel1F = 25.
> res@mpLambertParallel2F = 25.
> res@mpLambertMeridianF = -95.
>
>
> res@mpLimitMode = "Corners" ; choose range of map
> res@mpLeftCornerLatF = U@lat2d(0,0) ; ERROR HERE [fatal:Attributes only
> have one dimension, 2 subscripts used]
> res@mpLeftCornerLonF = U@lon2d(0,0)
> res@mpRightCornerLatF = U@lat2d(nlat-1,nlon-1)
> res@mpRightCornerLonF = U@lon2d(nlat-1,nlon-1)
>
> vector = gsn_csm_vector_map_ce(wks,U(:,:),V(:,:),res)
>
> end
> ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Here is some of the relevant output:
>
> FROM printVarSummary(wspd_file):
>
> Variable: wspd_file
> (0)
> filename: WindSpd_07231800
> path: /home/mark/Degrib/degrib/bin/WindSpd_07231800.nc
> file global attributes:
> title : GRIB Data translated to NetCDF
> Conventions : CF-1.0
> CreatedBy : degrib
> comment : Used degrib with: -NetCDF 3
> references : http://www.nws.noaa.gov/mdl/NDFD_GRIB2Decoder/
> dimensions:
> ncl_scalar = 1
> ProjectionHr = 1 // unlimited
> YCells = 689
> XCells = 1073
> variables:
> character MapProjection ( ncl_scalar )
> long_name : MapProjection
> grid_mapping_name : lambert_conformal_conic
> EarthShape : sphere
> EarthRadius_KM : 6371.2
> EarthRadius : 6371.200000 km
> standard_parallel : 25
> longitude_of_central_meridian : -95
> latitude_of_projection_origin : 25
> LowerLeftLatitude : 20.191999
> LowerLeftLongitude : -121.554001
>
> double YCells ( YCells )
> units : m
> long_name : y coordinate of projection
> standard_name : projection_y_coordinate
> grid_spacing : 5079.406000 m
> TrueGridLength_Latitude : 25
> _CoordinateAxisType : GeoY
>
> double XCells ( XCells )
> units : m
> long_name : x coordinate of projection
> standard_name : projection_x_coordinate
> grid_spacing : 5079.406000 m
> TrueGridLength_Latitude : 25
> _CoordinateAxisType : GeoX
>
> float longitude ( YCells, XCells )
> long_name : longitude coordinate
> units : degrees_east
> precision : 6
> grid_mapping : MapProjection
> standard_name : longitude
> _CoordinateAxisType : Lon
>
> float latitude ( YCells, XCells )
> long_name : latitude coordinate
> units : degrees_north
> precision : 6
> grid_mapping : MapProjection
> standard_name : latitude
> _CoordinateAxisType : Lat
>
> float WindSpd_SFC ( ProjectionHr, YCells, XCells )
> long_name : Wind speed
> units : knots
> coordinates : longitude latitude
> ReferenceTime : 1279897200
> ReferenceTimeString : 2010-07-23 15:00:00 00:00
> gridType : SCALAR
> level : SFC
> DescriptiveLevel : 0[-] SFC="Ground or water surface"
> OriginatingCenter : ( 8, 65535 )
> precision : 3
> valid_min : 0
> valid_max : 40.043
> NumMissing : 371047
> _FillValue : 9999
> missing_value : 9999
> grid_mapping : MapProjection
> GRIBMessageVersion : 2
> GRIBMessageUnits : m/s
> GRIB2_Discipline : 0
> GRIB2_Sect4TemplateNumber : 0
> GRIB2_Sect4ParameterCategory : 2
> GRIB2_Sect4ParameterNumber : 1
> GRIB2_GenerationProcess : 2
> GRIB2_FstFixedSurfaceType : 1
> GRIB2_FstFixedSurfaceValue : 0
> GRIB2_SndFixedSurfaceType : 255
> GRIB2_SndFixedSurfaceValue : 0
>
> short ProjectionHr ( ProjectionHr )
> long_name : Projection Hour After ReferenceTime
> units : hours since 2010-07-23 15:00:00 00:00
> _CoordinateAxisType : Time
> FirstValidTime : 1279908000
> FirstValidTimeString : 2010-07-23 18:00:00 00:00
> FirstProjectionHR : 3
>
>
> FROM printVarSummary(lat2d):
>
> Variable: lat2d
> Type: float
> Total Size: 2957188 bytes
> 739297 values
> Number of Dimensions: 2
> Dimensions and sizes: [YCells | 689] x [XCells | 1073]
> Coordinates:
> YCells: [-263789.4687076081..3230841.859292392]
> XCells: [-2763204.499231992..2681918.732768008]
> Number Of Attributes: 6
> long_name : latitude coordinate
> units : degrees_north
> precision : 6
> grid_mapping : MapProjection
> standard_name : latitude
> _CoordinateAxisType : Lat
>
> FROM printVarSummary(U):
>
> Variable: U
> Type: float
> Total Size: 2957188 bytes
> 739297 values
> Number of Dimensions: 2
> Dimensions and sizes: [689] x [1073]
> Coordinates:
> Number Of Attributes: 7
> ProjectionHr : 3
> lon2d : <ARRAY of 739297 elements>
> lat2d : <ARRAY of 739297 elements>
> XCells : <ARRAY of 1073 elements>
> YCells : <ARRAY of 689 elements>
> MapProjection : 0x00
> _FillValue : 9999
>
> FINALLY, here is the error, which occurs at the line
> "res@mpLeftCornerLatF = U@lat2d(0,0)"
>
> fatal:Attributes only have one dimension, 2 subscripts used
> fatal:Execute: Error occurred at or near line 86 in file
> Plot_NDFD_Wind_Vectors.ncl
>
> In looking at the various printVarSummaries, it appears:
> 1) The original latitude and longitude start out as 2D.
> 2) The intermediate variables lat2d and lon2d are 2D
> 3) The final variables U@lat2d, U@lon2d (and V@lat2d, V@lon2d i assume)
> appear to be 1d arrays.
>
> Any ideas as to what I'm doing wrong? All help is greatly welcomed.
>
> Thanks!
>
> Mark
>
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

-- 
__________________________________________________
Adam Phillips 
asphilli@ucar.edu
National Center for Atmospheric Research   tel: (303) 497-1726
Climate and Global Dynamics Division         fax: (303) 497-1333
P.O. Box 3000				
Boulder, CO 80307-3000    http://www.cgd.ucar.edu/cas/asphilli
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Jul 26 15:19:45 2010

This archive was generated by hypermail 2.1.8 : Wed Jul 28 2010 - 10:42:06 MDT