[ncl-talk] Help With My GFS NCl Script

Dave Allured - NOAA Affiliate dave.allured at noaa.gov
Tue Aug 30 20:23:59 MDT 2016


Kerwyn,

(1)  In NCL, metadata is lost when using normal math operators.  You are
creating the variables spd and temp1 without metadata.

There is an easy method to preserve metadata when doing math operations on
arrays.  Simply assign one of the input arrays first, and then the metadata
will be preserved "on the left hand side" when you use a math expression.
For example:

    spd = u_wund
    spd = (u_wind*u_wind + v_wind*v_wind)^(0.5) ; m/s

    temp1 = temp
    temp1 = temp - 273

You will now see that these new variables have proper coordinates and
metadata, when you do printVarSummary AFTER these lines of code.

(2)  I think you added the following lines in an attempt to add the missing
metadata.  In the case of  GFS Grib files, all of the necessary metadata
should already be attached to the input variables.  Therefore you do not
need to do any of the following, and they are possibly creating more
problems.  I recommend removing all of these lines unless you have a good
reason to keep some of them.

Do not worry about coordinate names such as lat_3 and lon_3.  That is
normal with Grib files, and NCL should handle this just fine:

temp1!0="lat"
temp1!1="lon"

;temp1 at lat1d = lat1d
;temp1 at lon1d = lon1d

;temp1&lat at units="degrees_north"
;temp1&lon at units="degrees_east"

hgt!0="lat"
hgt!1="lon"
hgt&lat at units="degrees_north"
hgt&lon at units="degrees_east"

u_wind!0="lat"
u_wind!1="lon"
u_wind&lat at units="degrees_north"
u_wind&lon at units="degrees_east"

v_wind!0="lat"
v_wind!1="lon"
v_wind&lat at units="degrees_north"
v_wind&lon at units="degrees_east"

Also remove:

;spd!0="lat"
;spd!1="lon"
;spd&lat at units="degrees_north"
;spd&lon at units="degrees_east"

(3)  Here is a debugging tip.  Overlay plots are harder to debug because
there is a lot going on at the same time.  Temporarily set these resources
to True until you get individual plots working properly.  Then set them
back to false to get only the final overlay plot:

    res at gsnDraw
    res at gsnFrame

--Dave


On Tue, Aug 30, 2016 at 7:50 PM, Kerwyn Texeira <ktish86 at gmail.com> wrote:

> Hi ncl-talk,
>
> I getting some errors while plotting GFS analysis data.  I  believe that
> there is some confusion with the lat, lon and rest of the data.  The lat
> and lon have a 1-dimensional array while the other set of data has a
> 2-dimensional array.  However, I am getting a plot though but I would like
> to know how to correct the errors below:  I'll appreciate whatever help
> that I can get.
>
> Thanks in advance!
>
> Error message:
>
> (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'
>
> Variable outputs:
> Variable: u_wind
> Type: float
> Total Size: 260640 bytes
>             65160 values
> Number of Dimensions: 2
> Dimensions and sizes:   [lat_3 | 181] x [lon_3 | 360]
> Coordinates:
>             lat_3: [90..-90]
>             lon_3: [ 0..359]
> Number Of Attributes: 13
>   lv_ISBL3 :    200
>   center :      US National Weather Service - NCEP (WMC)
>   long_name :   u-component of wind
>   units :       m/s
>   _FillValue :  1e+20
>   level_indicator :     100
>   grid_number : 3
>   parameter_table_version :     2
>   parameter_number :    33
>   model :       Analysis from GFS (Global Forecast System)
>   forecast_time :       0
>   forecast_time_units : hours
>   initial_time :        01/10/2014 (18:00)
>
> Variable: v_wind
> Type: float
> Total Size: 260640 bytes
>             65160 values
> Number of Dimensions: 2
> Dimensions and sizes:   [lat_3 | 181] x [lon_3 | 360]
> Coordinates:
>             lat_3: [90..-90]
>             lon_3: [ 0..359]
> Number Of Attributes: 13
>   lv_ISBL3 :    200
>   center :      US National Weather Service - NCEP (WMC)
>   long_name :   v-component of wind
>   units :       m/s
>   _FillValue :  1e+20
>   level_indicator :     100
>   grid_number : 3
>   parameter_table_version :     2
>   parameter_number :    34
>   model :       Analysis from GFS (Global Forecast System)
>   forecast_time :       0
>   forecast_time_units : hours
>   initial_time :        01/10/2014 (18:00)
>
> Variable: hgt
> Type: float
> Total Size: 260640 bytes
>             65160 values
> Number of Dimensions: 2
> Dimensions and sizes:   [lat_3 | 181] x [lon_3 | 360]
> Coordinates:
>             lat_3: [90..-90]
>             lon_3: [ 0..359]
> Number Of Attributes: 13
>   lv_ISBL3 :    200
>   center :      US National Weather Service - NCEP (WMC)
>   long_name :   Geopotential height
>   units :       gpm
>   _FillValue :  1e+20
>   level_indicator :     100
>   grid_number : 3
>   parameter_table_version :     2
>   parameter_number :    7
>   model :       Analysis from GFS (Global Forecast System)
>   forecast_time :       0
>   forecast_time_units : hours
>   initial_time :        01/10/2014 (18:00)
>
> Variable: lat1d
> Type: float
> Total Size: 724 bytes
>             181 values
> Number of Dimensions: 1
> Dimensions and sizes:   [lat_3 | 181]
> Coordinates:
>             lat_3: [90..-90]
> Number Of Attributes: 3
>   long_name :   latitude
>   grid_description :    65160-point (181x360) global longitude-latitude
> grid.  (0,0) at 0E, 90N, matrix layout.  N.B.: prime meridian not
> duplicated.
>   units :       degrees_north
>
> Variable: lon1d
> Type: float
> Total Size: 1440 bytes
>             360 values
> Number of Dimensions: 1
> Dimensions and sizes:   [lon_3 | 360]
> Coordinates:
>             lon_3: [ 0..359]
> Number Of Attributes: 3
>   long_name :   longitude
>   grid_description :    65160-point (181x360) global longitude-latitude
> grid.  (0,0) at 0E, 90N, matrix layout.  N.B.: prime meridian not
> duplicated.
>   units :       degrees_east
>
> Variable: temp1
> Type: float
> Total Size: 260640 bytes
>             65160 values
> Number of Dimensions: 2
> Dimensions and sizes:   [181] x [360]
> Coordinates:
> Number Of Attributes: 1
>   _FillValue :  1e+20
>
> Variable: spd
> Type: float
> Total Size: 260640 bytes
>             65160 values
> Number of Dimensions: 2
> Dimensions and sizes:   [181] x [360]
> Coordinates:
> Number Of Attributes: 1
>   _FillValue :  1e+20
>
> 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
>
> a = addfile("./gfsanl_3_20140110_1800_000.grb", "r")
>
> wks_type = "png"
> wks_type at wkWidth = 2500
> wks_type at wkHeight = 2500
>
> wks= gsn_open_wks(wks_type, "speed_narr")
> gsn_define_colormap(wks,"matlab_jet")
>
> lat1d = a->lat_3
> lon1d = a->lon_3
> hgt = a->HGT_3_ISBL({200},:,:)
> temp = a->TMP_3_ISBL({200},:,:)
> u_wind = a->U_GRD_3_ISBL({200},:,:)
> v_wind = a->V_GRD_3_ISBL({200},:,:)
>
> ;printVarSummary(temp)
> printVarSummary(u_wind)
> printVarSummary(v_wind)
> printVarSummary(hgt)
> printVarSummary(lat1d)
> printVarSummary(lon1d)
>
>
> spd = (u_wind*u_wind + v_wind*v_wind)^(0.5) ; m/s
>
>
> u_wind = u_wind*1.94384449
> v_wind = v_wind*1.94384449
>
> temp1 = temp - 273
> printVarSummary(temp1)
> temp1!0="lat"
> temp1!1="lon"
>
> ;temp1 at lat1d = lat1d
> ;temp1 at lon1d = lon1d
>
> ;temp1&lat at units="degrees_north"
> ;temp1&lon at units="degrees_east"
>
> hgt!0="lat"
> hgt!1="lon"
> hgt&lat at units="degrees_north"
> hgt&lon at units="degrees_east"
>
> u_wind!0="lat"
> u_wind!1="lon"
> u_wind&lat at units="degrees_north"
> u_wind&lon at units="degrees_east"
>
> v_wind!0="lat"
> v_wind!1="lon"
> v_wind&lat at units="degrees_north"
> v_wind&lon at units="degrees_east"
>
> spd = spd*1.94384449
> printVarSummary(spd)
>
> ;spd!0="lat"
> ;spd!1="lon"
> ;spd&lat at units="degrees_north"
> ;spd&lon at units="degrees_east"
>
>
> res = True
> res at gsnDraw = False
> res at gsnFrame = False
> res at cnLineLabelsOn =False
> res at cnFillOn = True
> res at mpOutlineBoundarySets = "geophysicalandusstates"
> res at mpGeophysicalLineThicknessF =5.0
> res at mpUSStateLineThicknessF = 5.0
> res at mpNationalLineThicknessF = 5.0
> res at tiMainString = "Winds (kts) at 200hpa on Jan 11 at 12:00UTC"
> res at tiMainFont = "helvetica"
> res at tiMainFontHeightF = 0.022
> res at pmTickMarkDisplayMode = "Always"
> res at mpProjection = "CylindricalEquidistant"
> res at mpDataBaseVersion = "MediumRes"
> res at mpOutlineOn = False
> res at lbOrientation = "Vertical"
> ;res at tiMainOffsetYF = -0.03
> res at mpFillOn  = False
> res at mpOutlineOn = True
> ;res at tfDoNDCOverlay = True
> res at mpMinLatF = 18.0
> res at mpMaxLatF = 48.0
> res at mpMinLonF = -160.0
> res at mpMaxLonF = -114.5
> res at gsnLeftString = "Geopotential Height (gpm) and Winds (kts)"
> res at gsnStringFontHeightF = 0.020
> res at gsnRightString = ""
> res at gsnMaximize = True
> res at mpShapeMode = "FreeAspect"
> res at lbTitleString = "Winds (kts)"
> res at lbTitleDirection = "Across"
> res at lbTitleAngleF = 90
> res at lbTitlePosition = "Right"
> res at lbTitleFontHeightF = 0.020
> res at gsnAddCyclic = False
> ;res at cnLevelSelectionMode = "ManualLevels"
> ;res at cnMinLevelValF = 10
> ;res at cnMaxLevelValF =130
> ;res at cnLevelSpacingF =10.0
>
> res1 = True
> res1 at gsnDraw = False
> res1 at gsnFrame = False
> res1 at cnLineColor = "Black"
> res1 at gsnContourLineThicknessesScale = 7.5
> res1 at gsnAddCyclic = False
> ;res1 at tfDoNDCOverlay = True
> res1 at gsnLeftString = ""
> res1 at gsnRightString = ""
> res1 at cnInfoLabelOn = False
> res1 at cnLineLabelBackgroundColor = "white"
> res1 at cnLineLabelInterval = 1.0
> res1 at cnLevelSelectionMode = "EqualSpacedLevels"
>
>
> res2 = True
> res2 at gsnDraw = False
> res2 at gsnFrame = False
> res2 at vcWindBarbLineThicknessF = 3.0
> res2 at vcRefLengthF =0.018
> res2 at vcRefMagnitudeF = 10
> ;res2 at tfDoNDCOverlay = True
> res2 at vcMinDistanceF = 0.025
> res2 at vcGlyphStyle = "WindBarb"
> res2 at gsnRightString =""
> res2 at gsnLeftString = ""
> res2 at vcRefAnnoOn = False
> res2 at gsnAddCyclic = False
>
>
> geo = gsn_csm_contour(wks, hgt, res1)
>
> speed = gsn_csm_contour_map(wks, spd, res)
>
> vector = gsn_csm_vector(wks, u_wind, v_wind, res2)
>
> overlay(speed, geo)
> overlay(speed, vector)
>
> draw(speed)
> frame(wks)
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
> end
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160830/5d156598/attachment.html 


More information about the ncl-talk mailing list