[ncl-talk] ncl-talk Digest, Vol 161, Issue 23
Dawit Abebe
dawit.kan at gmail.com
Tue Apr 18 08:50:01 MDT 2017
Dear All,
I was trying to plot a spatial map of SPI but having a challenge indexing coordinates. I pasted my script as well as the point a stuck (red text) from NCL output below.
Thank you so much for your support as usual.
Dawit
1. My script
;=========================================================================================
;spi spatial map plot
;=========================================================================================
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
diri = "./"
fili = "pre_cru_1901_2014.nc"
f = addfile(diri+fili, "r")
prc = f->pre
prc at _FillValue = -999.0
pmsg = prc at _FillValue
printVarSummary(prc)
dimp = dimsizes(prc)
ntim = dimp(0)
nlat = dimp(1)
mlon = dimp(2)
run = (/12/)
nrun = dimsizes(run)
spi = new((/nrun,ntim,nlat,mlon/), typeof(prc), pmsg)
opt = True
do nr=0,nrun-1
spi(nr,:,:,:)= dim_spi_n(prc, run(nr), True, 0)
end do
copy_VarCoords(prc,spi(0,:,:,:))
spi at long_name = "SPI"
spi!0 = "run"
spi&run = run
printVarSummary(spi)
;========================================================================================
; Plot parameter
;========================================================================================
dimp = dimsizes(prc)
ntim = dimp(0)
nlat = dimp(1)
mlon = dimp(2)
yyyymm = f->time
yyyymm = yyyymm/100
year = yyyymm/100
yrStrt = 1901
yrLast = 2014
nyear = yrLast-yrStrt+1
yyyymm = yyyymm_time(yrStrt, yrLast, "integer")
yrfrac = (/ yyyymm_to_yyyyfrac(yyyymm, 0.0) /)
prc&time = (/ yyyymm /)
;========================================================================================
wks = gsn_open_wks ("ps","spi")
gsn_define_colormap(wks,"BlueWhiteOrangeRed")
gsn_reverse_colormap(wks) ; Reverse the color map.
res = True
res at gsnDraw = False ; don't draw
res at gsnFrame = False ; don't advance frame
res at gsnSpreadColors = True
res at cnFillOn = True ; color Fill
res at cnFillMode = "RasterFill" ; Raster Mode
res at cnLinesOn = False ; Turn off contour lines
res at cnLevelSelectionMode = "ManualLevels" ; set manual contour levels
res at cnMinLevelValF = -3.0 ; set min contour level
res at cnMaxLevelValF = 3.0 ; set max contour level
res at cnLevelSpacingF = 0.5 ; set contour spacing
res at lbLabelBarOn = False ; turn off individual cb's
resP = True ; panel resources
resP at txString = False
resP at gsnPanelLabelBar= True ; add common colorbar
plot = new ( 5, "graphic")
do nl=0,nlat-1
do ml=0,mlon-1
do nr=0,nrun-1
spi(nr,:,:,:)= dim_spi_n(prc, run(nr), True, 0)
spi at long_name = "SPI"
spi at units = "nrun="+run(nr)
copy_VarCoords(prc,spi(0,:,:,:))
spi!0 = "run"
spi&run = run
printVarSummary(spi)
res at gsnCenterString = yyyymm({192112})
plot(0) = gsn_csm_contour_map_ce(wks,spi({192112},:,:,:), res)
res at gsnCenterString = yyyymm({192212})
plot(1) = gsn_csm_contour_map_ce(wks,spi({192212},:,:,:), res)
res at gsnCenterString = yyyymm({192712})
plot(2) = gsn_csm_contour_map_ce(wks,spi({192712},:,:,:), res)
res at gsnCenterString = yyyymm({197312})
plot(3) = gsn_csm_contour_map_ce(wks,spi({197312},:,:,:), res)
res at gsnCenterString = yyyymm({198412})
plot(4) = gsn_csm_contour_map_ce(wks,spi({198412},:,:,:), res)
end do
end do
end do
gsn_panel(wks,plot,(/5,1/),resP) ; now draw as one plot
end
2. NCL output from exciting the script above
(my_ncl) Dagemawes-MacBook-Pro:~ dawitabebe$ ncl -Q spi12_plotmap_script.ncl
Variable: prc
Type: double
Total Size: 393984 bytes
49248 values
Number of Dimensions: 3
Dimensions and sizes: [time | 1368] x [lat | 4] x [lon | 9]
Coordinates:
time: [ 380..41987]
lat: [3.75..5.25]
lon: [36.75..40.75]
Number Of Attributes: 5
correlation_decay_distance : 450
long_name : precipitation
units : mm/month
missing_value : 9.96920996839e+36
_FillValue : -999
Variable: spi
Type: double
Total Size: 393984 bytes
49248 values
Number of Dimensions: 4
Dimensions and sizes: [run | 1] x [time | 1368] x [lat | 4] x [lon | 9]
Coordinates:
run: [12..12]
time: [ 380..41987]
lat: [3.75..5.25]
lon: [36.75..40.75]
Number Of Attributes: 2
long_name : SPI
_FillValue : -999
Variable: spi
Type: double
Total Size: 393984 bytes
49248 values
Number of Dimensions: 4
Dimensions and sizes: [run | 1] x [time | 1368] x [lat | 4] x [lon | 9]
Coordinates:
run: [12..12]
time: [190101..201412]
lat: [3.75..5.25]
lon: [36.75..40.75]
Number Of Attributes: 4
units : nrun=12
long_name : SPI
run : 12
_FillValue : -999
fatal:NclOneDValGetClosestIndex: finish coordinate index out of range, can't continue
fatal:Could not obtain coordinate indexes, unable to perform subscript
fatal:["Execute.c":8640]:Execute: Error occurred at or near line 98 in file spi12_plotmap_script.ncl
(my_ncl) Dagemawes-MacBook-Pro:~ dawitabebe$
……………………………………...
> On Apr 18, 2017, at 10:29 AM, ncl-talk-request at ucar.edu wrote:
>
> Send ncl-talk mailing list submissions to
> ncl-talk at ucar.edu
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
> or, via email, send a message with subject or body 'help' to
> ncl-talk-request at ucar.edu
>
> You can reach the person managing the list at
> ncl-talk-owner at ucar.edu
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of ncl-talk digest..."
>
>
> Today's Topics:
>
> 1. Re: Problem with gsn_add_text (Stavros Dafis)
> 2. Problem with contour plot (Guilherme Martins)
> 3. Re: Problem with gsn_add_text (Rick Brownrigg)
> 4. Re: Problem with contour plot (Mary Haley)
> 5. how to draw this kind of plot (wen)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Mon, 17 Apr 2017 21:48:31 +0300
> From: Stavros Dafis <sdafis at cc.uoi.gr>
> Subject: Re: [ncl-talk] Problem with gsn_add_text
> To: Rick Brownrigg <brownrig at ucar.edu>
> Cc: "ncl-talk at ucar.edu" <ncl-talk at ucar.edu>
> Message-ID: <1492454911.58f50dffc9203 at webmail.uoi.gr>
> Content-Type: text/plain; charset=ISO-8859-7
>
> Dear Rick, thank you for your suggestion, I have tried to assign both the
> FillValue and the missing value (@missing_value) but nothing seems to work.
>
> I forgot to mention that I am using NCL 6.2.0, 6.3.0 and 6.4.0, on different
> machines.
>
>
> --
> Stavros NTAFIS (DAFIS)
> -----------------------------------------------
> Physicist - Meteorologist, M.Sc.
> Research Associate, National Observatory of Athens
> (+33)9 81 94 22 12, Mobile: +30 697 04 20 242
> ---------------
> Weather charts:
> http://www.meteo.gr
> http://www.meteo.gr/meteomaps/
>
>
> Quoting Rick Brownrigg <brownrig at ucar.edu>:
>
>> Hi Stavros,
>>
>> I don't know for certain, but I suspect you need to assign the _FillValue
>> to the string array "points" that you constructed from "t2" (I don't see
>> how the attributes from t2 would carry to points via the sprintf() ).
>>
>> Hope that helps...
>> Rick
>>
>> On Sun, Apr 16, 2017 at 12:56 PM, Stavros Dafis <sdafis at cc.uoi.gr> wrote:
>>
>>> Hello everyone, I am facing a problem with the function gsn_add_text. In
>>> the
>>> description of the function, it is mentioned that no missing values will be
>>> plotted:
>>>
>>> “This function attaches a list of text strings to the given plot.
>>> The text
>>> strings will be drawn only when the plot is drawn. If a missing value is
>>> encountered in the text strings or x/y values, then no text string will be
>>> drawn at this pair.”
>>>
>>> My script reads a netCDF file with 3 variables t2(lat,lon), lat(lat),
>>> lon(lon),
>>> so in order to attach values on the plot using this function, I have to
>>> make
>>> new 2-D variables for lat/lon and define the string to be plotted on the
>>> map.
>>> Values are assigned just fine on the plot, over the land, but missing
>>> values
>>> are also printed over the sea. I tried to use landsea masking but my data
>>> have
>>> high horizontal resolution (5km). Any suggestions?
>>>
>>> I have the same problem with WRF data, with already 2-D lat/lon arrays.
>>>
>>> This is the part of the code which prints the values:
>>> .
>>> .
>>> .
>>> contour = gsn_csm_contour_map(wks,t2,res)
>>>
>>> t2 at missing_value = -1
>>> t2 at _FillValue = -1
>>> (default missing values = -999)
>>>
>>> lat2 = new(dimsizes(t2),typeof(lat),-1)
>>> lon2 = new(dimsizes(t2),typeof(lon),-1)
>>>
>>> nb = dimsizes(t2)
>>>
>>> do nl=0,nb(0)-1,1
>>> do ml=0,nb(1)-1,1
>>>
>>> lat2(nl,ml) = lat(nl)
>>> lon2(nl,ml) = lon(ml)
>>>
>>> end do
>>> end do
>>>
>>> points = sprintf("%3.0f", t2)
>>> ;points = ""+t2(:,:)+""
>>>
>>> values = gsn_add_text(wks,contour,points,lon2(:,:),lat2(:,:),True)
>>>
>>>
>>>
>>> --
>>> Stavros NTAFIS (DAFIS)
>>> -----------------------------------------------
>>> Physicist - Meteorologist, M.Sc.
>>> Research Associate, National Observatory of Athens
>>> (+33)9 81 94 22 12, Mobile: +30 697 04 20 242
>>> ---------------
>>> Weather charts:
>>> http://www.meteo.gr
>>> http://www.meteo.gr/meteomaps/
>>>
>>>
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> ncl-talk at ucar.edu
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>
>
>
> ------------------------------
>
> Message: 2
> Date: Mon, 17 Apr 2017 19:00:02 +0000
> From: Guilherme Martins <jgmsantos at gmail.com>
> Subject: [ncl-talk] Problem with contour plot
> To: NCL <ncl-talk at ucar.edu>
> Message-ID:
> <CAH+t_hMaRUDHM0wMkLC9cz2pFmMYGXgGC+X+bcxDLo=+8fgWQg at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Dear users,
>
> After searching extensively on the NCL website I was not able to find a
> solution to my problem. I only want values within the contour of the
> continent, but some edges appear in the figure that are stemming from the
> mask that I applied and I do not know how to remove this. The figure is
> attached for a better view of my problem.
>
> Best regards,
>
> Guilherme.
> --
> ------------------------------------------------------------------------------------------------
> Instituto Nacional de Pesquisas Espaciais (INPE)
> Centro de Previs?o de Tempo e Estudos Clim?ticos (CPTEC)
> Divis?o de Sat?lites e Sistemas Ambientais (DSA)
> Programa de Monitoramento de Queimadas
> Telefone (INPE/CP): +55 12 3186-9205 || Celular (TIM): +55 12 98111-4292
> E-mail: guilherme.martins at inpe.br || jgmsantos at gmail.com
> Skype: guilherme.martins.
> Homepage: https://sites.google.com/site/jgmsantos
> Curr?culo Lattes: http://lattes.cnpq.br/5997657584785803
> ------------------------------------------------------------------------------------------------
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170417/c3215b0e/attachment-0001.html
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: figure.png
> Type: image/png
> Size: 58495 bytes
> Desc: not available
> Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170417/c3215b0e/attachment-0001.png
>
> ------------------------------
>
> Message: 3
> Date: Mon, 17 Apr 2017 14:32:43 -0600
> From: Rick Brownrigg <brownrig at ucar.edu>
> Subject: Re: [ncl-talk] Problem with gsn_add_text
> To: Stavros Dafis <sdafis at cc.uoi.gr>
> Cc: "ncl-talk at ucar.edu" <ncl-talk at ucar.edu>
> Message-ID:
> <CAGKRhbHX1v-1sJ3G=QrXGA+0wSJ2KKsBB_7GqbCnp9krh9fkkQ at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Hi,
>
> You used -1 as _FillValue for variable "t2". Note it is an integer value --
> what type is the array t2 -- float or int? In any case, you created the
> formatted string array "points" from t2 as "%3.0f", so that any data values
> in t2 that were -1 are now " -1", and thus it seems your _FillValue should
> be " -1". Did you do this, and do the types between data and _FillValue
> agree everywhere?
>
> If that's not the issue, I think we may need to see script and dataset to
> figure out what the issue is.
>
> HTH...
> Rick
>
> On Mon, Apr 17, 2017 at 12:48 PM, Stavros Dafis <sdafis at cc.uoi.gr> wrote:
>
>> Dear Rick, thank you for your suggestion, I have tried to assign both the
>> FillValue and the missing value (@missing_value) but nothing seems to work.
>>
>> I forgot to mention that I am using NCL 6.2.0, 6.3.0 and 6.4.0, on
>> different
>> machines.
>>
>>
>> --
>> Stavros NTAFIS (DAFIS)
>> -----------------------------------------------
>> Physicist - Meteorologist, M.Sc.
>> Research Associate, National Observatory of Athens
>> (+33)9 81 94 22 12, Mobile: +30 697 04 20 242
>> ---------------
>> Weather charts:
>> http://www.meteo.gr
>> http://www.meteo.gr/meteomaps/
>>
>>
>> Quoting Rick Brownrigg <brownrig at ucar.edu>:
>>
>>> Hi Stavros,
>>>
>>> I don't know for certain, but I suspect you need to assign the _FillValue
>>> to the string array "points" that you constructed from "t2" (I don't see
>>> how the attributes from t2 would carry to points via the sprintf() ).
>>>
>>> Hope that helps...
>>> Rick
>>>
>>> On Sun, Apr 16, 2017 at 12:56 PM, Stavros Dafis <sdafis at cc.uoi.gr>
>> wrote:
>>>
>>>> Hello everyone, I am facing a problem with the function gsn_add_text.
>> In
>>>> the
>>>> description of the function, it is mentioned that no missing values
>> will be
>>>> plotted:
>>>>
>>>> “This function attaches a list of text strings to the given plot.
>>>> The text
>>>> strings will be drawn only when the plot is drawn. If a missing value
>> is
>>>> encountered in the text strings or x/y values, then no text string
>> will be
>>>> drawn at this pair.”
>>>>
>>>> My script reads a netCDF file with 3 variables t2(lat,lon), lat(lat),
>>>> lon(lon),
>>>> so in order to attach values on the plot using this function, I have to
>>>> make
>>>> new 2-D variables for lat/lon and define the string to be plotted on
>> the
>>>> map.
>>>> Values are assigned just fine on the plot, over the land, but missing
>>>> values
>>>> are also printed over the sea. I tried to use landsea masking but my
>> data
>>>> have
>>>> high horizontal resolution (5km). Any suggestions?
>>>>
>>>> I have the same problem with WRF data, with already 2-D lat/lon arrays.
>>>>
>>>> This is the part of the code which prints the values:
>>>> .
>>>> .
>>>> .
>>>> contour = gsn_csm_contour_map(wks,t2,res)
>>>>
>>>> t2 at missing_value = -1
>>>> t2 at _FillValue = -1
>>>> (default missing values = -999)
>>>>
>>>> lat2 = new(dimsizes(t2),typeof(lat),-1)
>>>> lon2 = new(dimsizes(t2),typeof(lon),-1)
>>>>
>>>> nb = dimsizes(t2)
>>>>
>>>> do nl=0,nb(0)-1,1
>>>> do ml=0,nb(1)-1,1
>>>>
>>>> lat2(nl,ml) = lat(nl)
>>>> lon2(nl,ml) = lon(ml)
>>>>
>>>> end do
>>>> end do
>>>>
>>>> points = sprintf("%3.0f", t2)
>>>> ;points = ""+t2(:,:)+""
>>>>
>>>> values = gsn_add_text(wks,contour,points,lon2(:,:),lat2(:,:),True)
>>>>
>>>>
>>>>
>>>> --
>>>> Stavros NTAFIS (DAFIS)
>>>> -----------------------------------------------
>>>> Physicist - Meteorologist, M.Sc.
>>>> Research Associate, National Observatory of Athens
>>>> (+33)9 81 94 22 12, Mobile: +30 697 04 20 242
>>>> ---------------
>>>> Weather charts:
>>>> http://www.meteo.gr
>>>> http://www.meteo.gr/meteomaps/
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> ncl-talk mailing list
>>>> ncl-talk at ucar.edu
>>>> List instructions, subscriber options, unsubscribe:
>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>
>>>
>>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170417/01bd2242/attachment-0001.html
>
> ------------------------------
>
> Message: 4
> Date: Mon, 17 Apr 2017 15:02:08 -0600
> From: Mary Haley <haley at ucar.edu>
> Subject: Re: [ncl-talk] Problem with contour plot
> To: Guilherme Martins <jgmsantos at gmail.com>
> Cc: NCL <ncl-talk at ucar.edu>
> Message-ID:
> <CACNN_CJz1yvpMXMABZ8FhSEov1T0qN63rzsNBBVXBhLos3UKjg at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Guilherme,
>
> Please see examples shapefiles_21.ncl at:
>
> http://www.ncl.ucar.edu/Applications/shapefiles.shtml#ex21
>
> It explains why you see these "blocky" contours in NCL.
>
> Simply put, if you have four points that represent a box at the edge of a
> domain, and three of them have data one them and one is missing, then NCL
> will only draw contours in half of the box, because it won't extrapolate to
> that missing point.
>
> The real question is: do you simply want the graphics not to have gaps, or
> do you actually want there to be data in locations that fall just outside
> the geographical boundary? You can do things to force values just outside
> the geographical boundary, but this depends on how you are masking in the
> first place.
>
> If you are masking based on a shapefile, then see example shapefiles_18.ncl
> on the same page:
>
> http://www.ncl.ucar.edu/Applications/shapefiles.shtml#ex18
>
> Note, however, that this mask is now returning values outside the range of
> interest.
>
> If you are simply trying to mask your data *graphically* by some
> geographical area, then instead of trying to use a mask function, you can
> draw the full data, and then draw polygons filled in with white in the
> areas you don't want to see graphically. That's what example 21 is showing.
>
> --Mary
>
>
> On Mon, Apr 17, 2017 at 1:00 PM, Guilherme Martins <jgmsantos at gmail.com>
> wrote:
>
>> Dear users,
>>
>> After searching extensively on the NCL website I was not able to find a
>> solution to my problem. I only want values within the contour of the
>> continent, but some edges appear in the figure that are stemming from the
>> mask that I applied and I do not know how to remove this. The figure is
>> attached for a better view of my problem.
>>
>> Best regards,
>>
>> Guilherme.
>> --
>> ------------------------------------------------------------
>> ------------------------------------
>> Instituto Nacional de Pesquisas Espaciais (INPE)
>> Centro de Previs?o de Tempo e Estudos Clim?ticos (CPTEC)
>> Divis?o de Sat?lites e Sistemas Ambientais (DSA)
>> Programa de Monitoramento de Queimadas
>> Telefone (INPE/CP): +55 12 3186-9205 <+55%2012%203186-9205> || Celular
>> (TIM): +55 12 98111-4292 <+55%2012%2098111-4292>
>> E-mail: guilherme.martins at inpe.br || jgmsantos at gmail.com
>> Skype: guilherme.martins.
>> Homepage: https://sites.google.com/site/jgmsantos
>> Curr?culo Lattes: http://lattes.cnpq.br/5997657584785803
>> ------------------------------------------------------------
>> ------------------------------------
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170417/96b2b947/attachment-0001.html
>
> ------------------------------
>
> Message: 5
> Date: Tue, 18 Apr 2017 15:29:04 +0800 (CST)
> From: wen <wenguanhuan at 163.com>
> Subject: [ncl-talk] how to draw this kind of plot
> To: ncl-list <ncl-talk at ucar.edu>
> Message-ID: <5de3ed86.9f7f.15b7ff6fb6f.Coremail.wenguanhuan at 163.com>
> Content-Type: text/plain; charset="gbk"
>
> Hi all,
> I am trying to use TRMM 3B42 data to draw this kind of plot. I haven't found a example on the website to draw it. Do anyone know how to make it. Which function should I
> use. Thank you!
>
>
>
>
>
>
>
>
> --
>
> ??
> ???
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170418/b09be439/attachment.html
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: ??1.png
> Type: image/png
> Size: 249741 bytes
> Desc: not available
> Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170418/b09be439/attachment.png
>
> ------------------------------
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
> End of ncl-talk Digest, Vol 161, Issue 23
> *****************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170418/3ab27fbd/attachment.html
More information about the ncl-talk
mailing list