trigrid + triangulate -> zero values -> ignore zeros on cgcontour [message #87290] |
Thu, 23 January 2014 03:56  |
jkobori19
Messages: 8 Registered: January 2014
|
Junior Member |
|
|
Dear All,
I'm having problem with a contour plot, which is actually not a problem, because the routine works fine,
I just want to make a little modification:
I have an M X N matrix, created with trigrid + triangulate. The input data (z component) has
a min value of 12, but the output matrix has a min value of 0, I guess this is normal.
What I would like to do is to ignore this zeros when creating the contour plot with cgcontour,
i.e. where the matrix has a value of 0, it will appear as a white area on the plot, and the rest fo them will appear normally as it should be.
Could You guys give some help?
Joe
|
|
|
|
Re: trigrid + triangulate -> zero values -> ignore zeros on cgcontour [message #87292 is a reply to message #87290] |
Thu, 23 January 2014 04:09   |
Yngvar Larsen
Messages: 134 Registered: January 2010
|
Senior Member |
|
|
What happens if you set the MISSING keyword of TRIGRID to !values.f_nan? The 0 value you observe is just the default value that TRIGRID uses if MISSING is not set.
I haven't checked whether CONTOUR handles NaNs well, but it should according to the documentation.
--
Yngvar
On Thursday, 23 January 2014 12:56:34 UTC+1, jkob...@gmail.com wrote:
> Dear All,
>
>
>
> I'm having problem with a contour plot, which is actually not a problem, because the routine works fine,
>
> I just want to make a little modification:
>
>
>
> I have an M X N matrix, created with trigrid + triangulate. The input data (z component) has
>
> a min value of 12, but the output matrix has a min value of 0, I guess this is normal.
>
> What I would like to do is to ignore this zeros when creating the contour plot with cgcontour,
>
> i.e. where the matrix has a value of 0, it will appear as a white area on the plot, and the rest fo them will appear normally as it should be.
>
>
>
> Could You guys give some help?
>
>
>
> Joe
|
|
|
|
|
|
Re: trigrid + triangulate -> zero values -> ignore zeros on cgcontour [message #87296 is a reply to message #87295] |
Thu, 23 January 2014 04:44   |
jkobori19
Messages: 8 Registered: January 2014
|
Junior Member |
|
|
On Thursday, January 23, 2014 1:36:39 PM UTC+1, David Fanning wrote:
> jkobori19@gmail.com writes:
>
>
>
>>
>
>> On Thursday, January 23, 2014 1:09:25 PM UTC+1, Matthew Argall wrote:
>
>>>> What I would like to do is to ignore this zeros when creating the contour plot with cgcontour,
>
>>>
>
>>>
>
>>>
>
>>> Have you tried the MISSINGVALUE keyword to cgContour?
>
>>
>
>> Hi,
>
>>
>
>> it gives an error: CONTOUR: Invalid value specified for keyword LEVELS: No finite elements.
>
>
>
> That seems odd. I presume you have downloaded and are using the latest
>
> version of the Coyote Library?
>
>
>
> http://www.idlcoyote.com/code_tips/fixcoyoteprogram.php
>
>
>
> Can I see the way you are calling the program?
>
>
>
> Cheers,
>
>
>
> David
>
>
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Hi David,
the code (without missingvalue):
TRIANGULATE, theta0i, thetaobsi, tr, b
mx=TRIGRID(theta0i, thetaobsi, ydi, tr, nx=res, ny=res, $
xgrid=xo, ygrid=yo, max_value=25)
levels=50
step = (Max(mx) - Min(mx)) / levels
userLevels = IndGen(levels) * step + Min(mx)
cgcontour, mx, xo, yo, /fill, xstyle=3, ystyle=3, $
levels=userLevels, xrange=[0.07,0.44], yrange=[0.04,0.45], $
xtitle="Jet half opening angle [rad]", $
ytitle="Observer half angle [rad]", $
Position=[0.1, 0.1, 0.83, 0.95], $
charthick=2, charsize=1.5, thick=3
cgColorbar, range=[12, 25], title="AB magnitude", $
/reverse, /vertical, /fit, $
divisions=7, charthick=2, charsize=1.5
|
|
|
Re: trigrid + triangulate -> zero values -> ignore zeros on cgcontour [message #87297 is a reply to message #87296] |
Thu, 23 January 2014 04:52   |
jkobori19
Messages: 8 Registered: January 2014
|
Junior Member |
|
|
On Thursday, January 23, 2014 1:44:00 PM UTC+1, jkob...@gmail.com wrote:
> On Thursday, January 23, 2014 1:36:39 PM UTC+1, David Fanning wrote:
>
>> jkobori19@gmail.com writes:
>
>>
>
>>
>
>>
>
>>>
>
>>
>
>>> On Thursday, January 23, 2014 1:09:25 PM UTC+1, Matthew Argall wrote:
>
>>
>
>>>> > What I would like to do is to ignore this zeros when creating the contour plot with cgcontour,
>
>>
>
>>>>
>
>>
>
>>>>
>
>>
>
>>>>
>
>>
>
>>>> Have you tried the MISSINGVALUE keyword to cgContour?
>
>>
>
>>>
>
>>
>
>>> Hi,
>
>>
>
>>>
>
>>
>
>>> it gives an error: CONTOUR: Invalid value specified for keyword LEVELS: No finite elements.
>
>>
>
>>
>
>>
>
>> That seems odd. I presume you have downloaded and are using the latest
>
>>
>
>> version of the Coyote Library?
>
>>
>
>>
>
>>
>
>> http://www.idlcoyote.com/code_tips/fixcoyoteprogram.php
>
>>
>
>>
>
>>
>
>> Can I see the way you are calling the program?
>
>>
>
>>
>
>>
>
>> Cheers,
>
>>
>
>>
>
>>
>
>> David
>
>>
>
>>
>
>>
>
>> --
>
>>
>
>> David Fanning, Ph.D.
>
>>
>
>> Fanning Software Consulting, Inc.
>
>>
>
>> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
>>
>
>> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
>
>
>
> Hi David,
>
>
>
>
>
> the code (without missingvalue):
>
>
>
> TRIANGULATE, theta0i, thetaobsi, tr, b
>
>
>
> mx=TRIGRID(theta0i, thetaobsi, ydi, tr, nx=res, ny=res, $
>
> xgrid=xo, ygrid=yo, max_value=25)
>
>
>
> levels=50
>
> step = (Max(mx) - Min(mx)) / levels
>
> userLevels = IndGen(levels) * step + Min(mx)
>
>
>
> cgcontour, mx, xo, yo, /fill, xstyle=3, ystyle=3, $
>
> levels=userLevels, xrange=[0.07,0.44], yrange=[0.04,0.45], $
>
> xtitle="Jet half opening angle [rad]", $
>
> ytitle="Observer half angle [rad]", $
>
> Position=[0.1, 0.1, 0.83, 0.95], $
>
> charthick=2, charsize=1.5, thick=3
>
>
>
> cgColorbar, range=[12, 25], title="AB magnitude", $
>
> /reverse, /vertical, /fit, $
>
> divisions=7, charthick=2, charsize=1.5
Sorry, I forgot that of course I'm using the latest Coyote Library.
|
|
|
|
Re: trigrid + triangulate -> zero values -> ignore zeros on cgcontour [message #87299 is a reply to message #87298] |
Thu, 23 January 2014 05:27   |
jkobori19
Messages: 8 Registered: January 2014
|
Junior Member |
|
|
On Thursday, January 23, 2014 2:12:16 PM UTC+1, David Fanning wrote:
> jkobori19@gmail.com writes:
>
>
>
>> the code (without missingvalue):
>
>
>
> Well, don't know. I can't reproduce the error with code that is similar
>
> to yours. Nor can I explain how such an error might occur from looking
>
> at the code. Sorry. :-(
>
>
>
> Cheers,
>
>
>
> David
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
It's OK, I'm trying to create the plot also in R, maybe I can do that there.
Thank You very much for the help anyway!
|
|
|
Re: trigrid + triangulate -> zero values -> ignore zeros on cgcontour [message #87300 is a reply to message #87293] |
Thu, 23 January 2014 06:31   |
Matthew Argall
Messages: 286 Registered: October 2011
|
Senior Member |
|
|
> it gives an error: CONTOUR: Invalid value specified for keyword LEVELS: No finite elements.
>> userLevels = IndGen(levels) * step + Min(mx)
Your "userLevels" do not have any finite elements. Check to see what they are. Perhaps set the /NAN keyword in the Min function.
IDL> data = dist(256)
IDL> userlevels = indgen(10)
IDL> userlevels = cgscalevector(userlevels, min(data), max(data))
IDL> print, userlevels
0.00000 20.1133 40.2265 60.3398 80.4530
100.566 120.680 140.793 160.906 181.019
IDL> cgcontour, data, /fill, LEVELS=userlevels
IDL> userlevels[3] = !values.f_nan
IDL> cgcontour, data, /fill, LEVELS=userlevels
IDL> userlevels += !values.f_nan
IDL> print, finite(userlevels)
0 0 0 0 0 0 0 0 0 0
IDL> cgcontour, data, /fill, LEVELS=userlevels
% CONTOUR: Invalid value specified for keyword LEVELS: No
finite elements.
% CONTOUR: Invalid value specified for keyword LEVELS: No
finite elements.
% CONTOUR: Invalid value specified for keyword LEVELS: No
finite elements.
|
|
|
Re: trigrid + triangulate -> zero values -> ignore zeros on cgcontour [message #87301 is a reply to message #87300] |
Thu, 23 January 2014 07:47   |
jkobori19
Messages: 8 Registered: January 2014
|
Junior Member |
|
|
On Thursday, January 23, 2014 3:31:24 PM UTC+1, Matthew Argall wrote:
>> it gives an error: CONTOUR: Invalid value specified for keyword LEVELS: No finite elements.
>
>
>
>>> userLevels = IndGen(levels) * step + Min(mx)
>
>
>
> Your "userLevels" do not have any finite elements. Check to see what they are. Perhaps set the /NAN keyword in the Min function.
>
>
>
> IDL> data = dist(256)
>
> IDL> userlevels = indgen(10)
>
> IDL> userlevels = cgscalevector(userlevels, min(data), max(data))
>
> IDL> print, userlevels
>
> 0.00000 20.1133 40.2265 60.3398 80.4530
>
> 100.566 120.680 140.793 160.906 181.019
>
> IDL> cgcontour, data, /fill, LEVELS=userlevels
>
>
>
> IDL> userlevels[3] = !values.f_nan
>
> IDL> cgcontour, data, /fill, LEVELS=userlevels
>
> IDL> userlevels += !values.f_nan
>
> IDL> print, finite(userlevels)
>
> 0 0 0 0 0 0 0 0 0 0
>
> IDL> cgcontour, data, /fill, LEVELS=userlevels
>
> % CONTOUR: Invalid value specified for keyword LEVELS: No
>
> finite elements.
>
> % CONTOUR: Invalid value specified for keyword LEVELS: No
>
> finite elements.
>
> % CONTOUR: Invalid value specified for keyword LEVELS: No
>
> finite elements.
Hi,
actually, for some reason now it doesn't give an error when using missingvalue... And it works fine! I don't know what did I do wrong so far,
but the plot seems to be OK now. I just change the elements of matrix to zero, where the particular value is greater then, let's say, 27,
then applying the missingvalue keyword, and everything looks good!
Thank You very much guys!
Actually, one more thing: when I ignore zeros, there will be less color levels on the plot, since the color corresponding to zero disappears. Is there a solution for this?
|
|
|
|
Re: trigrid + triangulate -> zero values -> ignore zeros on cgcontour [message #87379 is a reply to message #87303] |
Wed, 29 January 2014 06:19   |
jkobori19
Messages: 8 Registered: January 2014
|
Junior Member |
|
|
On Thursday, January 23, 2014 5:36:08 PM UTC+1, David Fanning wrote:
> jkobori19@gmail.com writes:
>
>
>
>> Actually, one more thing: when I ignore zeros, there will be less color levels on the plot, since the color corresponding to zero disappears. Is there a solution for this?
>
>
>
> Define more levels? Add a background color? Up to you, I guess. :-)
>
>
>
> Cheers,
>
>
>
> David
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Unfortunately, defining more levels doesn't solve my problem. I would like
to set the color levels so that they ignore the zeros and the starting level would correspond to the next value in the matrix. E.g.,
the elements start from a value of 13.83, the max value is 29.98.
The color table is 33 (cgloadct, 33), so the cgcolorbar shows colors from red to blue with continous transition, but the colors on the cgcontour are only from yellow to red.
I'm sorry if the solution is actually simple, I'm just a little bit confused with these color levels.
|
|
|
Re: trigrid + triangulate -> zero values -> ignore zeros on cgcontour [message #87380 is a reply to message #87379] |
Wed, 29 January 2014 08:17  |
Phillip Bitzer
Messages: 223 Registered: June 2006
|
Senior Member |
|
|
Well, there's always RTFM :-)
"Ignoring" values is simple. Simple start your levels at a value greater than the one you want to ignore. Case in point:
n=101 ;number of grid pts
;define the grid
x = findgen(n)/(n-1) & y = findgen(n)/(n-1)
xGrid = x # REPLICATE(1., n)
yGrid = REPLICATE(1., n) # y
z = SQRT(xGrid^2 + yGrid^2) ;make some data
levels = [0., 0.25, 0.5, 0.75, 1.]
;levels = [0.25, 0.5, 0.75, 1.] ;uncomment this out to "ignore" < 0.25
nLevels = N_ELEMENTS(levels)
cgLOADCT, 33, RGB_TABLE=rgb ;get a palette, but don't load the table
colorInd = cgSCALEVECTOR(LINDGEN(nLevels), 0, 255) ;select some colors from the paleete
rgbNew = rgb[colorInd, *] ;get *just* these colors
cgContour, z, x, y, LEVELS=levels, PALETTE=rgbNew, /CELL_FILL ;plot with only the colors you want
tNames = [STRCOMPRESS(levels, /REMOVE), ' '] ;get some ticknames
;plot the colorbar, with your palette
cgCOLORBAR, PALETTE=rgbNew, Divisions = nLevels, /FIT, TICKNAMES=tnames, /DISCRETE
Notice I don't actually load any color tables. There's no need.
Using the palette as I do above allows you to be a little more explicit with the colors you send to (cg)Contour and cgColorBar. I prefer to do these sort of plots in this manner. I also rarely need a continuous color bar - my work is usually much better suited for discrete cb's - so this allows me to ensure the colors match in the contour and cb.
|
|
|