[ncl-talk] plotting station rainfall
Karin Meier-Fleischer
meier-fleischer at dkrz.de
Sun Sep 20 05:09:12 MDT 2015
Hi Geeta,
the markers were not plotted because the plot will be created before the polymarker were drawn.
You have to set the resource res at gsnFrame = False.
I’ve written a short script just to show you how to handle ASCII data and how to draw the
polymarker onto of the map.
;*********** Load Libraries ************************************
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
;***************************************************************
; User Input
;***************************************************************
diri = "./" ; input directory
fili = "input_new.txt" ; input file
;***************************************************************
; Read ASCII data
;***************************************************************
tStr = asciiread(diri+fili, -1,"string")
delim = " "
lat = tofloat(str_get_field(tStr,1,delim))
lon = tofloat(str_get_field(tStr,2,delim))
hgt = tofloat(str_get_field(tStr,3,delim))
rf = tofloat(str_get_field(tStr,4,delim))
wks=gsn_open_wks("ps","stn-v2")
res = True
res at gsnDraw = False
res at gsnFrame = False
res at mpMinLatF = 0.0
res at mpMaxLatF = 20.0
res at mpMinLonF = 60.0
res at mpMaxLonF = 80.0
plot = gsn_csm_map(wks,res)
res_mark = True
res_mark at gsMarkerIndex = 2
res_mark at gsMarkerSizeF = 0.01
res_mark at gsMarkerColor = "red"
dum =gsn_add_polymarker(wks,plot,lon,lat,res_mark)
draw(plot)
frame(wks)
end
Bye,
Karin
> Am 20.09.2015 um 11:58 schrieb Geeta Geeta <geetag54 at yahoo.com>:
>
> thanks karin.
> I tried a few things ;
> 1. changed the string variables to float. But The markers were not plotted.
> Got the following warning message.
>
> Copyright (C) 1995-2014 - All Rights Reserved
> University Corporation for Atmospheric Research
> NCAR Command Language Version 6.2.1
> The use of this software is governed by a License Agreement.
> See http://www.ncl.ucar.edu/ for more details.
>
> Variable: tStr
> Type: string
> Total Size: 20 bytes
> 5 values
> Number of Dimensions: 1
> Dimensions and sizes: [5]
> Coordinates:
> Number Of Attributes: 1
> _FillValue : missing
>
>
> Variable: temptStr
> Type: string
> Total Size: 20 bytes
> 5 values
> Number of Dimensions: 1
> Dimensions and sizes: [5]
> Coordinates:
> Number Of Attributes: 1
> _FillValue : missing
> (0) missing
> (1) missing
> (2) missing
> (3) missing
> (4) missing
> warning:stringtofloat: a bad value was passed; input strings must contain numeric digits, replacing with missing value
> warning:stringtofloat: a bad value was passed; input strings must contain numeric digits, replacing with missing value
> warning:stringtofloat: a bad value was passed; input strings must contain numeric digits, replacing with missing value
> warning:stringtofloat: a bad value was passed; input strings must contain numeric digits, replacing with missing value
>
>
> Variable: lat
> Type: string
> Total Size: 20 bytes
> 5 values
> Number of Dimensions: 1
> Dimensions and sizes: [5]
> Coordinates:
> Number Of Attributes: 1
> _FillValue :
> (0) lat
> (1) 12.57
> (2) 12.3
> (3) 13.06
> (4) 13.06
>
>
> Variable: lon
> Type: string
> Total Size: 20 bytes
> 5 values
> Number of Dimensions: 1
> Dimensions and sizes: [5]
> Coordinates:
> Number Of Attributes: 1
> _FillValue :
> (0) lon
> (1) 77.38
> (2) 78.18
> (3) 77.24
> (4) 77.24
>
>
> Variable: hgt
> Type: string
> Total Size: 20 bytes
> 5 values
> Number of Dimensions: 1
> Dimensions and sizes: [5]
> Coordinates:
> Number Of Attributes: 1
> _FillValue :
> (0) hgt
> (1) 919.6
> (2) 882.2
> (3) 900
> (4) 900
>
>
> Variable: rf
> Type: string
> Total Size: 20 bytes
> 5 values
> Number of Dimensions: 1
> Dimensions and sizes: [5]
> Coordinates:
> Number Of Attributes: 1
> _FillValue :
> (0) rf
> (1) 5.6
> (2) 67.
> (3) 0.1
> (4) 0.1
>
>
> Variable: lat_fl
> Type: float
> Total Size: 20 bytes
> http://www.ncl.ucar.edu/ <http://www.ncl.ucar.edu/>
>
> 2. Seeing this error, I changed my data file (input_new.txt) attached in which I removed the top string
>
> but still the the dots/markers are not plotted.
>
> 3. Sending the script and the input files.
>
> pls suggest.
> thanks
>
> Geeta.
>
>
>
> On Sunday, 20 September 2015 1:35 AM, Karin Meier-Fleischer <meier-fleischer at dkrz.de> wrote:
>
>
> Hi Geeta,
>
> the error message is telling you what is wrong - type mismatch in gsn_add_polymarker.
>
> Take a look at the gsn_add_polymarker function page:
> http://www.ncl.ucar.edu/Document/Graphics/Interfaces/gsn_add_polymarker.shtml <http://www.ncl.ucar.edu/Document/Graphics/Interfaces/gsn_add_polymarker.shtml>
>
> gsn_add_polymarker wants to have a numeric type for x and y (in your case lon and lat).
>
> function gsn_add_polymarker (
> wks [1] : graphic,
> plot [1] : graphic,
> x [*] : numeric,
> y [*] : numeric,
> res [1] : logical
> )
>
> return_val <http://www.ncl.ucar.edu/Document/Functions/return_val.shtml> [1] : graphic
> In your script the lat and lon arrays are defined as strings but gsn_add_polymarker
> expects a numeric type. Use tofloat() function for lat and lon conversion.
>
> Bye,
> Karin
>
>> Am 19.09.2015 um 21:02 schrieb Geeta Geeta <geetag54 at yahoo.com <mailto:geetag54 at yahoo.com>>:
>>
>> dear users.
>> I am trying to plot station data and taking help of the some available scripts. (station_4.ncl)
>>
>> I am getting this error
>> fatal:Argument type mismatch on argument (2) of (gsn_add_polymarker) can not coerce
>> fatal:["Execute.c":8578]:Execute: Error occurred at or near line 62 in file stn-v2.ncl
>>
>> I am attaching my script.
>> Kindly suggest what s the problem.
>>
>> when I execute this I get following......
>> (4) 77.24
>>
>>
>> Variable: hgt
>> Type: string
>> Total Size: 20 bytes
>> 5 values
>> Number of Dimensions: 1
>> Dimensions and sizes: [5]
>> Coordinates:
>> Number Of Attributes: 1
>> _FillValue :
>> (0) hgt
>> (1) 919.6
>> (2) 882.2
>> (3) 900
>> (4) 900
>>
>>
>> Variable: rf
>> Type: string
>> Total Size: 20 bytes
>> 5 values
>> Number of Dimensions: 1
>> Dimensions and sizes: [5]
>> Coordinates:
>> Number Of Attributes: 1
>> _FillValue :
>> (0) rf
>> (1) 5.6
>> (2) 67.
>> (3) 0.1
>> (4) 0.1
>> fatal:Argument type mismatch on argument (2) of (gsn_add_polymarker) can not coerce
>> fatal:["Execute.c":8578]:Execute: Error occurred at or near line 62 in file stn-v2.ncl
>>
>>
>> I am attaching my input file and the script.
>>
>> Geeta.
>> <stn-v2.ncl><input1.txt>_______________________________________________
>> 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
>
>
>
>
>
> <stn-v2.ncl><input1.txt><input_new.txt>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150920/3dfbfddc/attachment.html
More information about the ncl-talk
mailing list