[ncl-talk] Issue with ploting of irregular txt/nc file

Guido Cioni guidocioni at gmail.com
Tue Sep 6 05:43:14 MDT 2016


Dear Amit, 
You can plot a text file without converting it to a nc file, which could cause errors. Just use the function asciiread and then assign the values correctly before plotting. Below is an example (only relevant commands are reported):

; read the data (you have to specify number of rows and columns, here are assumed
; to be lon | lat | value (pv)

 File = asciiread ("data_pv.txt",(/245220,3/),"double")

 pv =File(:,2) ; last column
 lon=File(:,0) ; first column
 lat=File(:,1) ; second column

 Res=True
 Res at sfXArray = lon
 Res at sfYArray = lat

 Res at mpLimitMode  = "LatLon"
 Res at mpMaxLonF    = max(lon)                      
 Res at mpMinLonF    = min(lon)                                            
 Res at mpMinLatF    = min(lat)                    
 Res at mpMaxLatF    = max(lat)

 plot = gsn_csm_contour_map(wks,pv,Res)

Guido Cioni
http://guidocioni.altervista.org <http://guidocioni.altervista.org/> 

> On 06 Sep 2016, at 10:03, Amit Kumar <amitkumar.777 at hotmail.com> wrote:
> 
> Hi all,
> 
> I'm trying to plot a text file containing three columns lon , lat, value using ncl.
> 
> First I converted my text file to nc using CDO. The nc file is like:
> 
> ##################################################################################
> 
> Variable: f
> Type: file
> filename:    tir1
> path:    tir1.nc
>    file global attributes:
>       CDI : Climate Data Interface version ?? (http://mpimet.mpg.de/cdi <http://mpimet.mpg.de/cdi>)
>       Conventions : CF-1.4
>       history : Tue Sep 06 11:56:42 2016: cdo -f nc input,my_gridfile tir1.nc
>       CDO : Climate Data Operators version 1.7.0 (http://mpimet.mpg.de/cdo <http://mpimet.mpg.de/cdo>)
>    dimensions:
>       ncells = 53248
>       time = 1  // unlimited
>    variables:
>       double lon ( ncells )
>          standard_name :    longitude
>          units :    degrees_east
> 
>       double lat ( ncells )
>          standard_name :    latitude
>          units :    degrees_north
> 
>       double time ( time )
>          standard_name :    time
>          units :    hours since 0-0-0 00:00:00
>          calendar :    proleptic_gregorian
>          axis :    T
> 
>       float var1 ( time, ncells )
>          grid_type :    unstructured
>          coordinates :    lat lon
> ###################################################################################
> 
> but I'm getting following errors:
> 
> fatal:ScalarFieldInitialize: Insufficient number of elements in sfDataArray
> fatal:Unable to initialize layer-Can't Create
> fatal:Unable to access object with id:-4
> fatal:PID #-4 can't be found in NhlSetValues
> fatal:Unable to access object with id:-4
> warning:Unable to add DataItem "(null)" to DataList "cnScalarFieldData"
> fatal:CompileDataList:DataList has no valid members
> 
> 
> ######################################################################################
> 
> my script is :
> 
> load "/usr/share/ncarg/nclscripts/csm/gsn_code.ncl"
> load "/usr/share/ncarg/nclscripts/csm/gsn_csm.ncl"
> load "/usr/share/ncarg/nclscripts/csm/contributed.ncl"
> 
> 
> 
> begin
> ;---read in zonal winds
>   a                 = addfile("/home/amit/Desktop/tir1.nc","r")
> 
>   filename = "/media/amit/E/India_shapefile/State_bound(Satmet).shp"
> 
>   ;filename = "/media/amit/E/India_shapefile/Districtbound(Satmet).shp"
> 
> 
>   var                 = doubletofloat(a->var1)
>                       
> lat                 =  a->lat
> lon                 =  a->lon
> 
> 
>   wks = gsn_open_wks("png","TIR1")                ; send graphics to PNG file
> 
>   res                      = True                  ; plot mods desired
>   res at cnFillOn             = True                  ; turn on color fill
>   res at cnLinesOn            = False
>   res at gsnMaximize          = True     ; maximize plot in frame
>   res at gsnDraw              = False
>   res at gsnFrame             = False
> 
>   res at mpOutlineOn   = False   ; Use outlines from shapefile
>   res at mpFillOn      = False  
>   res at cnFillMode = "RasterFill"
>   res at trGridType = "TriangularMesh"
>   res at cnRasterSmoothingOn = False 
> 
> res at cnLevelSelectionMode = "ExplicitLevels"              
>   res at cnLevels             = (/190,220,240,250,260,265,270,275,280,285,290,300,320,360/) ;   ; 14 contour values
>   res at cnFillPalette        = (/"Grey","BlueViolet","Blue4","Blue2","Cornflowerblue","darkslategray1","Cyan"\
>                 ,"chartreuse","khaki1","Yellow"\                     ; 15 contour colors
>                               ,"Orange","darkorange4", "hotpink"    \
>                               ,"Red","Black" /)        
> 
> res at tiMainString      = "TIR1 Plot"
>   res at tiMainFontHeightF = 0.016 
>   res at gsnAddCyclic      = False
>   res at lbOrientation   = "Vertical"
> 
>   res at sfXArray             = lon
>   res at sfYArray        =  lat
> 
> 
> res at mpMinLonF             = 68.0
> res at mpMaxLonF             = 98.0
> res at mpMinLatF             = 0.0
> res at mpMaxLatF             = 38.0
> 
> res at pmTickMarkDisplayMode     = "Always"
> 
> res at tiXAxisString            = "Longitude"
> res at tiYAxisString            = "Lattitude"
> 
> res at tiXAxisFontHeightF         = 0.02
> res at tiYAxisFontHeightF         = 0.02 
> 
> res at gsnStringFontHeightF     = 0.005  
> 
>   plot = gsn_csm_contour_map(wks,var, res)        ; create plot
> 
> ;---Resource list for shapefile outlines
>  plres                     = True
>  plres at gsLineColor       = "black"
>  plres at gsLineThicknessF  = "1.5"
>  dumstr                = unique_string("poly")
>   
>  id = gsn_add_shapefile_polylines(wks,plot,filename,plres)
> 
>  draw(plot)
>   frame(wks)
> 
> end
> ####################################################################################################################
> 
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu <mailto:ncl-talk at ucar.edu>
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk <http://mailman.ucar.edu/mailman/listinfo/ncl-talk>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160906/600e2372/attachment.html 


More information about the ncl-talk mailing list