|
Contour Chart error ? |
Posted by Maxx on May-11-2012 22:33 |
|
Hi Peter,
I have something strange happening with my contour plots when they are interpolating at
zero.
If you have a look at the plot attached then the entire plot area should be white when all
the data is zero (0). But what is happening is that the area is gray, which I presume is the
colour of the boundary line.
If I set the data to 0.1 or -0.1 then the plot display OK (as in all white). Also if I set the
data to 1 (another boundary cutoff) then the plot will display OK as well (as in all light
blue).
I presume this has something to do with interpolating with zeros.. (?)
|
Re: Contour Chart error ? |
Posted by Peter Kwan on May-12-2012 00:57 |
|
Hi Maxx,
In ChartDirector Ver 5.0.x, the contour line at z = 0 refers to the positions at z = 0. If the entire surface is at z = 0, then the entire surface will be colored using the contour color. The default contour color is semi-transparent black, so it becomes grey when painted over the background (which is white at z = 0).
In ChartDirector Ver 5.1, the contour at z = 0 is now defined as a transition from z != 0 to z = 0. So the z = 0 contour is drawn only if the neighbouring region is not z = 0. If you are using ChartDirector for .NET or JSP/Java, the ChartDirector Ver 5.1 is already in our download page. If you are using other editions of ChartDirector, you may have to wait until next week or the week after next. (We usually update our download page only on Sundays when the traffic is low.)
I am not sure why in your case, the issue does now occur at z = 1. I suspect it is due to rounding issue. May be the contour level is not exactly at z = 1, but at z = 1.00000000000001. (When you define the contour levels, you may be asking ChatDirector to use a step of 0.5 unit or ChartDirector may automatically determine the step. During the computation, there may be rounding errors.) These rounding errors do not usually affect the graph, as it is too small to be visible. For example, if the z level of two adjacent pixels goes from z = 1 to z = 2, ChartDirector will determine that it must have gone through the level z = 1.00000000000001, So it will plot the contour, and it will determine that the contour is extremely close to z = 1. So essentially, what is visible is the same as if the contour is at z = 1.
In any case, the ChartDirector Ver 5.1 should address this issue.
If you do not want to use ChartDirector Ver 5.1 yet, we usually suggest people to add or subtract a small "irregular" number to the z value. For example, you may add:
z[i] += (z[i] < 0) ? 0.0000000198793281 : -0.0000000198793281;
As the number is so small, it should not affect the chart. It is hoped that the irregular number will avoid a large region of z values to be at an exact contour level.
Hope this can help.
Regards
Peter Kwan |
Re: Contour Chart error ? |
Posted by Maxx on May-12-2012 08:05 |
|
Thanks Peter for your detailed reply.
I have attached another plot to give you a better idea of the problem I am having.
The first 6 degrees (4 rows) of this plot are all zero's, yet they show up as a lot of 'wavy
lines' (red and blue).
I am not really sure as to what I 'should' expect as I guess it should theoretically be neither
red nor blue, but the way it keeps changing seems odd.
I am currently using PHP so I might have to wait til the PHP version is released.
Much appreciated...
|
Re: Contour Chart error ? |
Posted by Peter Kwan on May-15-2012 00:00 |
|
Hi Maxx,
The reason that the first 6 degrees are red/blue is because they are non-zero, and fluctuates between positive and negative values.
Your data only mean a some points in the first 6 degrees are zero. This does not automatically mean the entire surface is zero. If you use spline surface interpolation (that is, using a smooth surface, which is the default), ChartDirector will try to determine the values of the surface by using your data points.
I have attached an image to illustrate what is spline interpolation in 1D. Note that in spline interpolation, the curve can and usually will exceed or fall below the data values of the points. Imagine the top two points in the spline interpolation are at zero. You can see that the spline curve can rise above zero. This is a natural and normal way to fit a curve on a set of data points. (In contrast, in linear interpolation, the line can never exceed the data points.) If you imagine in the illustrator, there are additional zero points between the two top points, it is normal that the curve will fluctuate up and down. The fluctuation will be less and less (approach zero) as there are more and more zero points.
For your case, even if the fluctuation is infinitesimal, it will still cause a change in color, as the fluctuation is around an exact contuor level.
As this effect is normal and natural, even if you swtich to another version of ChartDirector, it should look similar.
If you want the zero surface to be exactly zero at one color, it means the entire surface is not smooth. (There must be a "kink" to abruptly switch the slope of your surface to exactly horizontal z = 0.)
For your case, the followings are some suggestions:
(a) Are the zero values at the first 6 degrees are just artificial values and are not real data? If this is the case, you may consider to use other artificial values such as 0.05. This can help avoid the z = 0 contour and also make the color well-defined. (As you have already noticied, the color at z = 0 can be red or blue.)
(b) If the intention of have zero values at the first 6 degrees is to ask ChartDirector to draw something (instead of leaving them empty), you may consider not to put any data points at all except at the border (if you must have some data values before they are gridded data, use NoValue for the zero point at the first 6 degrees that are not at the border). The region will still fluctuates between red and blue, but it may look more natural. (The unnatural red/blue coloring is because the data points themselves are not natural. If those points are removed, the region may look more natural.) There are also other methods to introduce "artificial data". Instead of using all zeros, you can use z = 0.05, or simply copy the same data from the nearest valid row.
(c) I notice the land in your chart is black. I assume it is a foreground image. You can consider to modify your foreground image to cover the first 6 degrees as well with a color of your choice.
(d) Instead of using smooth interpolation, you may use linear interpolation. See ContourLayer.setSmoothInterpolation.
Hope this can help.
Regards
Peter Kwan
|
Re: Contour Chart error ? |
Posted by Maxx on May-15-2012 09:39 |
|
Ah, forgot about the Smoothing. That makes sense..
I have turned of smoothing and I am back to what I had in the first question.
I guess I was thinking that if the four corners of my grid point was zero then any
interpolation (using linear/nearest neighbor) would also be zero.
I could just blank out the top 6 degrees but that wouldn't solve the issue if there were
areas of zero elsewhere in the data (unlikely, but possible).
BTW, I am using Shapefiles to draw directly onto the drawArea.
Here is what I have without smoothing:
|
Re: Contour Chart error ? |
Posted by Peter Kwan on May-16-2012 03:26 |
|
Hi Maxx,
If there some zero points in your real data, and ChartDirector does not draw the surface as zero (due to smooth interpolation), it may be doing the correct thing and it may better match the reality (that the surface is not entirely zero). If you look at the spline line example in my last message, the spline line may be the more correct line, in which a normal person may have expect that the "peak" of the line would exceed the neighbouring points for that type of data. It all depends on the nature of your data.
For the entirely grey region at the top 6 degrees, it is the contour color at z = 0. In ChartDirector Ver 5.1, inside of considering the z = 0 positions to be the contour at z = 0, ChartDirector using the border between z = 0 and z != 0 as the contour. So the solid grey region will not appear in Ver 5.1.
Hope this can help.
Regards
Peter Kwan |
Re: Contour Chart error ? |
Posted by Maxx on May-25-2012 08:50 |
|
Hey Peter,
Just a followup to say everything works perfectly in 5.1.
Thanks mate.... |
|