Thanks Mary and Debasish very much:) Finally, I got my transect plot using
NCL. The only problem for now is the transect plot took the layer numbers as
the real altitudes although I defined "alt" using the real heights (see lines 17 to
20). Attached please find the code. Any mistake there?
--- Lin Su http://atoc.colorado.edu/~sul/ ---- Original message ---- >Date: Thu, 28 Aug 2008 20:42:26 -0600 >From: Mary Haley <haley_at_ucar.edu> >Subject: Re: Re: transect plot >To: Lin Su <Lin.Su_at_colorado.edu> >Cc: ncl-talk_at_ucar.edu > >Lin, > >You have the line: > > X&alt = alt > >The "X&alt" part is okay, because you've named one of your X >dimensions to be "alt". >The "alt" on the right side of the equation is not okay, though, >because you don't have >a local NCL variable with this name. > >You said that the real altitude values are stored in >Layer_Base_Altitude and >Layer_Top_Altitude, so you need to set X&alt equal to some >calculation based >on these two values. > >-Mary > >On Aug 28, 2008, at 12:18 PM, Lin Su wrote: > >> Thanks, Mary:) No more error at the dimensional issue on >> triple2grid right now. >> But the following error comes up: >> >> fatal:Variable (alt) is undefined >> fatal:Execute: Error occurred at or near line 36 in file tran.ncl >> >> The problem is I need to define the height for the transect plot >> although the >> second dimension in x (and the 1st dimension in X) is layer numbers >> (8 layers >> totally). The real altitudes' values are stored in >> Layer_Base_Altitude and >> Layer_Top_Altitude. >> >> Any ideas or suggestions to do this? >> >> Thanks for your great help as always! >> -Lin >> --- >> Lin Su >> http://atoc.colorado.edu/~sul/ >> >> >> >> >> 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 >> f = addfile("CAL_LID_L2_05kmALay-Prov- >> V2-01.2007-05-02T16-57-30ZN.hdf", "r") >> lat = f->Latitude ; (3001,3) >> lat_at_units = "degrees_north" >> lon = f->Longitude ; (3001,3) >> lon_at_units = "degrees_east" >> altBase = f->Layer_Base_Altitude ;(3001,8) >> altBase_at_long_name = altBase_at_hdf_name >> altBase@_FillValue = -9999. >> altTop = f->Layer_Top_Altitude ;(3001,8) >> altTop_at_units = "km" >> altTop_at_long_name = altTop_at_hdf_name >> altTop@_FillValue = -9999. >> numlayer = f->Number_Layers_Found ;(3001,1) >> numlayer_at_long_name = numlayer_at_hdf_name >> x = f->Feature_Optical_Depth_532 ; (3001,8) >> x_at_long_name = x_at_hdf_name >> x@_FillValue = -9999. >> ;printVarSummary(x) >> >> ;dimensional issues >> X = new((/8,3001/), float) >> X(0,:) = x(:,0) >> X(1,:) = x(:,1) >> X(2,:) = x(:,2) >> X(3,:) = x(:,3) >> X(4,:) = x(:,4) >> X(5,:) = x(:,5) >> X(6,:) = x(:,6) >> X(7,:) = x(:,7) >> X!0 = "alt" >> X&alt = alt >> LAT = lat(:,1 ) >> LON = lon(:,1 ) >> >> ;res = True >> ;res_at_sfXArray = LON >> ;res_at_sfYArray = LAT >> >> latS = 30. >> latN = 45. >> lonL = 130. >> lonR = 140. >> >> ;delete(res_at_sfXArray) >> ;delete(res_at_sfYArray) >> >> dlat = 0.25 ; create a grid >> dlon = 0.25 >> nlat = floattoint( (latN-latS)/dlat ) + 1 >> mlon = floattoint( (lonR-lonL)/dlon ) + 1 >> lonGrid = fspan(lonL, lonR, mlon) >> lonGrid!0 = "lon" >> lonGrid_at_units = "degrees_east" >> latGrid = fspan(latS, latN, nlat) >> latGrid!0 = "lat" >> latGrid_at_units = "degrees_north" >> >> TGRID = triple2grid(LON,LAT,X,lonGrid,latGrid, False) >> TGRID!0 = "alt" >> TGRID!1 = "lat" >> TGRID!2 = "lon" >> TGRID&alt = alt >> TGRID&lat = latGrid >> TGRID&lon = lonGrid >> >> printVarSummary(TGRID) >> printMinMax(TGRID, True) >> res_at_gsnCenterString = "Feature_Optical_Depth_532" >> >> ;transect plot >> ;calculate great circle along transect >> ;*************************** >> leftlat = 30 >> rightlat = 50 >> leftlon = 110 >> rightlon = 140 >> npts = 100 >> dist = gc_latlon(leftlat,leftlon,rightlat,rightlon,npts,2) >> points = ispan(0,npts-1,1)*1.0 >> ;************************** >> ;interpolate data to great circle >> ;*********************** >> trans = linint2_points(TGRID&lon,TGRID&lat,TGRID,True, >> dist_at_gclon,dist_at_gclat,2) >> copy_VarAtts(TGRID,trans) >> trans!0 = "alt" >> trans&alt = TGRID&alt >> ;plot >> wks = gsn_open_wks("x11","trans_os") >> gsn_define_colormap(wks,"BlAqGrYeOrReVi200") >> >> res1 = True >> res1_at_tmXBMode = "Explicit" >> res1_at_tmXBValue = (/points(0),points(npts-1)/) >> res1_at_tmXBLabels = (/leftlat +","+leftlon,rightlat+","+rightlon/) >> res1_at_cnFillOn = True >> res1_at_lbLabelAutoStride = True >> res1_at_gsnSpreadColors = True >> res1_at_cnLinesOn = False >> res1_at_lbOrientation = "vertical" >> res1_at_pmLabelBarOrthogonalPosF = -0.05 >> >> plot = gsn_csm_contour(wks,trans,res1) >> >> end >> _______________________________________________ >> ncl-talk mailing list >> ncl-talk_at_ucar.edu >> http://mailman.ucar.edu/mailman/listinfo/ncl-talk >
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
f = addfile("CAL_LID_L2_05kmALay-Prov-V2-01.2007-05-02T16-57-30ZN.hdf", "r")
lat = f->Latitude ; (3001,3)
lat_at_units = "degrees_north"
lon = f->Longitude ; (3001,3)
lon_at_units = "degrees_east"
altBase = f->Layer_Base_Altitude ;(3001,8)
altBase_at_long_name = altBase_at_hdf_name
altBase@_FillValue = -9999.
altTop = f->Layer_Top_Altitude ;(3001,8)
altTop_at_units = "km"
altTop_at_long_name = altTop_at_hdf_name
altTop@_FillValue = -9999.
alt = altTop(639,:) ;define alt
alt_at_units = "km"
alt_at_long_name = altTop_at_hdf_name
alt@_FillValue = -9999.
numlayer = f->Number_Layers_Found ;(3001,1)
numlayer_at_long_name = numlayer_at_hdf_name
x = f->Feature_Optical_Depth_532 ; (3001,8)
x_at_long_name = x_at_hdf_name
x@_FillValue = -9999.
;printVarSummary(x)
;dimensional issues
X = new((/8,3001/), float)
X(0,:) = x(:,0)
X(1,:) = x(:,1)
X(2,:) = x(:,2)
X(3,:) = x(:,3)
X(4,:) = x(:,4)
X(5,:) = x(:,5)
X(6,:) = x(:,6)
X(7,:) = x(:,7)
X!0 = "alt"
X&alt = alt
LAT = lat(:,1 )
LON = lon(:,1 )
res = True
res_at_sfXArray = LON
res_at_sfYArray = LAT
latS = 30.
latN = 40.
lonL = 134.
lonR = 137.
delete(res_at_sfXArray)
delete(res_at_sfYArray)
dlat = 0.25 ; create a grid
dlon = 0.25
nlat = floattoint( (latN-latS)/dlat ) + 1
mlon = floattoint( (lonR-lonL)/dlon ) + 1
lonGrid = fspan(lonL, lonR, mlon)
lonGrid!0 = "lon"
lonGrid_at_units = "degrees_east"
latGrid = fspan(latS, latN, nlat)
latGrid!0 = "lat"
latGrid_at_units = "degrees_north"
TGRID = triple2grid(LON,LAT,X,lonGrid,latGrid, False)
TGRID!0 = "alt"
TGRID!1 = "lat"
TGRID!2 = "lon"
TGRID&alt = alt
TGRID&lat = latGrid
TGRID&lon = lonGrid
printVarSummary(TGRID)
printMinMax(TGRID, True)
;res_at_gsnCenterString = "Feature_Optical_Depth_532"
;transect plot
;calculate great circle along transect
;***************************
leftlat = 30.
rightlat = 40.
leftlon = 134.
rightlon = 137.
npts = 100
dist = gc_latlon(leftlat,leftlon,rightlat,rightlon,npts,2)
points = ispan(0,npts-1,1)*1.0
;**************************
;interpolate data to great circle
;***********************
trans = linint2_points(TGRID&lon,TGRID&lat,TGRID,True, dist_at_gclon,dist_at_gclat,2)
; copy_VarAtts(TGRID,trans)
trans!0 = "alt"
;trans&alt = TGRID&alt ;coordinate variable for 0th dimension only
;plot
wks = gsn_open_wks("x11","trans_os")
;gsn_define_colormap(wks,"BlAqGrYeOrReVi200")
gsn_define_colormap(wks,"BlAqGrYeOrRe")
res1 = True
res1_at_tmXBMode = "Explicit" ; explicitly label x-axis
res1_at_tmXBValues = (/points(0),points(npts-1)/) ; points to label
; label values
res1_at_tmXBLabels = (/leftlat +", "+leftlon,rightlat+", "+rightlon/)
res1_at_cnFillOn = True ; turn on color
res1_at_lbLabelAutoStride = True ; nice label bar label stride
res1_at_gsnSpreadColors = True ; use full range of colormap
res1_at_gsnSpreadColorStart= 2;2
res1_at_gsnSpreadColorEnd = 101;173
res1_at_cnLinesOn = False ; turn off countour lines
res1_at_lbOrientation = "vertical" ; vertical label bar
res1_at_pmLabelBarOrthogonalPosF = -0.07 ;move label bar closer to plot (minus sign)
res1_at_tiMainString = "Transect" ; add title
res1_at_tiXAxisString = "lat/lon along transect"
; res1_at_trYReverse = True ; reverse y axis
; res1_at_trXReverse = True ; reverse x axis (neg longitudes)
res1_at_cnLevelSpacingF = 0.1 ; set contour spacing
plot = gsn_csm_contour(wks,trans,res1)
minlat = 0.
maxlat = 60.
minlon = 100.
maxlon = 180.
;********************************
; show transect on a map
;********************************
i = NhlNewColor(wks,0.8,0.8,0.8) ;add gray to continents
mres = True ; plot mods desired
mres_at_gsnFrame = False ; don't turn page yet
mres_at_gsnDraw = False ; don't draw yet
mres_at_tiMainString= "Transect Location" ; title
mres_at_mpMinLatF = minlat
mres_at_mpMaxLatF = maxlat
mres_at_mpMinLonF = minlon
mres_at_mpMaxLonF = maxlon
;mres_at_cnFillMode = True
;mres_at_cnFillDrawOrder = "PreDraw"
map = gsn_csm_map_ce(wks,mres) ; create map
draw(map)
; add polyline
pres = True ; polyline mods desired
pres_at_gsLineColor = "red" ; color of lines
pres_at_gsLineThicknessF = 2.0 ; line thickness
;pres_at_cnLineDrawOrder = "PostDraw"
gsn_polyline(wks,map,(/leftlon,rightlon/),(/leftlat,rightlat/),pres)
;draw(map)
frame(wks)
end
Received on Fri Aug 29 2008 - 11:23:35 MDT
This archive was generated by hypermail 2.2.0 : Mon Sep 08 2008 - 14:49:02 MDT