[ncl-talk] CSV file plotting issue.
Ajay Bankar
ajaybankar123 at gmail.com
Tue Jan 7 06:51:06 MST 2020
I tried experimenting with frame() but nothing worked. It's still
interpolating data outside shapefile.
On Sat, Dec 7, 2019 at 9:01 PM Rick Brownrigg <brownrig at ucar.edu> wrote:
> Hi,
>
> Regarding the second issue, the bad-float values, this little scriplet:
>
> infile = "sample.csv"
> lines = asciiread(infile, -1, "string")
>
> numLines = dimsizes(lines)
> do i=1,numLines-1
> rain = tofloat(str_get_field(lines(i), 7, ","))
> print(i + ": " + rain)
> end do
>
> reveals that in some cases, there is a value of "NA" for rain. For
> example, see lines 672, 1320, 1610 -- there are probably several dozen
> instances. I'm not sure there's much harm in allowing those cases to be
> treated as missing values; they'll be ignored in the contouring.
>
> I don't really know about the shapefile issue. You have:
>
> plot = gsn_csm_contour_map(wks,rain,res)
> var_mask = shapefile_mask_data(rain,shp_filename,True)
> plot_mask = gsn_csm_contour_map(wks,var_mask,res)
> ...
> draw(plot_mask)
> frame(wks)
>
> Even though you explicitly "draw" plot_mask, the fact that "plot" was
> generated against the workstation "wks", I'm wondering if its getting drawn
> when the call to frame() is made (I don't know for certain how that works
> under the hood). Perhaps experiment with that. If that does not resolve the
> issue, please repost to the group.
>
> Rick
>
>
> On Sat, Dec 7, 2019 at 2:26 AM Ajay Bankar via ncl-talk <ncl-talk at ucar.edu>
> wrote:
>
>> Dear NCL Users,
>> I'm trying to make spatial plot of rainfall from
>> station data available in csv file. I wrote the following script but data
>> is not masking with shapefile. Also I'm getting the warning as:
>> *warning:tofloat: A bad value was passed to (string) tofloat, input
>> strings must contain numeric digits, replacing with missing value.*
>> I have attached plot and sample data file for reference.
>>
>> Thanks for any help!
>>
>> load "$NCARG_ROOT/lib/ncarg/nclex/gsun/gsn_code.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>> load "/scratch/rakesh/WRF-AJAY/WRFV3/RUN_14AUG/NCL_PROGRAM/shp.ncl"
>>
>> begin
>> ;-- shapefile name
>> shp_filename =
>> "/scratch/Administrative_Boundary_Headquarters/District_Boundary.shp"
>> infile =
>> "/scratch/rakesh/WRF-AJAY/DATASETS/STATION/station_data_final.csv"
>> lines = asciiread(infile, -1, "string")
>> ;print(lines)
>> ;delim = ","
>>
>> rain = tofloat( str_get_field(lines(1:), 7, ","))
>> rain at lat1d = tofloat( str_get_field(lines(1:), 5, ","))
>> rain at lon1d = tofloat( str_get_field(lines(1:), 6, ","))
>> ;print(rain)
>>
>> ;-- define sub-region, here for Karnataka
>> minlat = 11
>> maxlat = 19
>> minlon = 73.5
>> maxlon = 79.1
>>
>> ;-- open workstation
>> wks_type = "pdf"
>> wks = gsn_open_wks(wks_type,"1_station_plot")
>> ;-- resource settings
>> res = True
>> res at gsnDraw = False ;-- don't
>> draw plot yet
>> res at gsnFrame = False ;-- don't
>> advance frame yet
>> res at gsnMaximize = True ;--
>> maximize plot in frame
>>
>> ; res at tfDoNDCOverlay = True
>>
>> cmap := read_colormap_file("BlAqGrYeOrReVi200")
>> cmap(0,:) = (/0,0,0,0/) ; make first color fully transparent
>> res at cnFillOn = True
>> res at cnLinesOn = False
>> res at cnLineLabelsOn = False
>> res at cnFillPalette = cmap
>> ;"BlueYellowRed"
>> res at cnLevelSelectionMode = "ManualLevels" ;--
>> manually set contour levels
>> res at cnMinLevelValF = 5 ; 260.0
>> ;-- contour min lev
>> res at cnMaxLevelValF = 95 ; 280.0
>> ;-- contour max lev
>> res at cnLevelSpacingF = 10 ; 0.5
>> ;-- contour spacing
>> res at gsnAddCyclic = False
>>
>> res at mpGridLineColor = 0 ;"grey40"
>> res at mpFillOn = False
>> res at mpOutlineOn = False
>> res at mpGeophysicalLineColor = "black"
>> res at mpLimitMode = "LatLon"
>> res at mpMinLatF = minlat
>> res at mpMaxLatF = maxlat
>> res at mpMinLonF = minlon
>> res at mpMaxLonF = maxlon
>> ;res at mpAreaMaskingOn = True
>>
>> res at lbBoxMinorExtentF = 0.1 ;--
>> decrease height of labelbar boxes
>> res at pmLabelBarOrthogonalPosF = 0.08 ;-- move
>> labelbar to the left side of plot
>> res at lbBoxMinorExtentF = 0.2 ;--
>> decrease height of labelbar boxes
>>
>> res at pmTickMarkDisplayMode = "Always"
>> res at tmXTOn = False
>> res at tiMainString = "STATION DATA PLOT"
>>
>> ;-- create plot
>> plot = gsn_csm_contour_map(wks,rain,res)
>> var_mask = shapefile_mask_data(rain,shp_filename,True)
>>
>> ;-- create contours of masked data
>> plot_mask = gsn_csm_contour_map(wks,var_mask,res)
>>
>> ;-- add plot_mask to plot
>> lnres = True
>> lnres at gsLineColor = "black"
>> lnres at gsLineThicknessF = 1.0
>>
>> plot at lines = gsn_add_shapefile_polylines(wks, plot_mask,
>> shp_filename, lnres)
>>
>> ;-- draw the plot and advance the frame
>> draw(plot_mask)
>> frame(wks)
>> end
>> --
>>
>> *Thanks & Regards,*
>>
>> *Ajay Bankar.*
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
--
*Thanks & Regards,*
*Ajay Bankar.*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20200107/55977c71/attachment.html>
More information about the ncl-talk
mailing list