Question about the VTK XML StructuredGrid data file format - vtk

I am trying to output my numerical simulation data in vtk format.
My grid is structured and I need to use the VTK's XML format.
My greatest confusion is about the WholeExtent and the Piece Extent attributes.
E.g., the VTK pdf manual says
StructuredGrid WholeExtent = "x1 x2 y1 y2 z1 z2".
What exactly are these x1, x2's, etc? A similar question is about the x1, x2's in the Piece Extent attribute.
Thank you!

I got the answer on the VTK forum, courtesy of Dan Lipsa.
It is easier to explain it using a minimum working example.
Suppose we have a 10x6x1 (2D) grid, 2 CPUs in the x-direction, 1 CPU in the remaining directions. That is, Proc 1 has 6x6x1 and Proc 2 has 5x6x1 grid points, respectively. Then I've these lines of code in my vts files:
Processor 1:
StructuredGrid WholeExtent=" 1 6 1 6 1 1 "
Piece Extent=" 1 6 1 6 1 1 "
Processor 2:
StructuredGrid WholeExtent=" 6 10 1 6 1 1 "
Piece Extent=" 6 10 1 6 1 1 "
A sample data file can be found at the following link:
VTK forum

Related

Histogram with ggplot2 requires a continuous x variable

I have a dataset in a table format that looks like this:
test frequency
1 test40 3
2 test33 5
3 test19 2
4 test4521 1
5 test34 1
6 test27 3
7 test42 3
8 test35 1
....
If I use this command:
library(ggplot2)
ggplot(t, aes("frequency")) +
geom_histogram()
("t" is the name of my table)
Then RStudio says: "StatBin requires a continuous x variable: the x variable is discrete. Perhaps you want stat="count"?"
I just want to see how many times a 3 or a 5 etc. occurs.
Thanks for your help.
It looks like your data is already aggregated? Maybe the ggplot2::geom_histogram() function might not appropriate for you to use? Have you tried the geom_col() function? This simply takes the numbers declared in the input data frame, and displays a column plot with that data.
Using the below code
# Declare data frame
t <- data.frame(test = c("test40", "test33", "test19", "test4521",
"test34", "test27", "test42", "test35"),
frequency = c(3, 5, 2, 1,
1, 3, 3, 1))
returns the data frame like this
# View data
print(t)
test frequency
1 test40 3
2 test33 5
3 test19 2
4 test4521 1
5 test34 1
6 test27 3
7 test42 3
8 test35 1
and therefore you can plot it like this
# Load package
library(ggplot2)
# Generate column plot
ggplot(t, aes(test, frequency)) +
geom_col()
If you simply wanted a count of the times that the number 2 or the number 3 occurred in your data frame, then yes the geom_histogram() is the correct function to use. See, the geom_histogram() function counts the frequency that a term occurs in the data frame, then returns the result. It has an internal validation that looks at the type of data that you are trying to plot across the x-axis, and notices that if it is discrete, then you need to parse the parameter stat="count" in the function. If you don't include this parameter, then ggplot will try to bin your data to create the histogram, which is illogical because all you want is a count.
Check out this link for a description of the difference between continuous and discrete data: What is the difference between discrete data and continuous data?
With this in mind, you can plot the histogram like this
# Generate histogram plot
ggplot(t, aes(frequency)) +
geom_histogram(stat="count")
I hope that helps mate.

Excel rotate radar chart

I have been trying to create a windrose that displays the occurence of multiple wind speeds and their respective wind direction. Using other very helpful posts on here I've gotten pretty close to what I want. There is just one thing I can't seem to fix.
As you can see in the figure below the graph starts at 0 degrees while I want the "North" wind direction to start at -11,25 (or +348,75) degrees.
Currently the radial axis labels are added using a pie chart while the rest of the data is plotted in a filled radar chart. It is easy to rotate the pie chart but I can't seem to find a similar function for rotating the radar chart. Any help would be much appreciated. The excel file is attached beneath the figure.
EDIT: Locked excel file against editing
Excel file
I haven't fully digested the netiquette of this website and not sure if it is a good idea to try giving you an answer 6+ months after you posted. Also hope that by this time you found an answer.
If not, this link should be of help:
https://superuser.com/questions/687036/how-to-make-a-pie-radar-chart
In the example the creator made one field for each degree and started the first series, which would be equivalent to your north at 0°. However nothing prevents you from starting at 348.
I have not tested but I also think that nothing prevents you from adding even more "resolution", e.g. half-degree steps.. or even more to your discretion.
EDIT: following L.Guthardt's feedback.
In order to provide you an answer I opted to simplify your table and chart. Mostly for convenience, but also because I struggle to get a full understanding of the original "architecture". Still, the solution should work at any level and is based on two key elements:
first you will have to double the number of rows from 16 to 32 (thus each quadrant being repeated two times, e.g. ... nne - nne - ne - ne...)
second, you have to start and finish with N as showcased here
Direction Cat6
N 6
NNE 4 4
NNE 6
NE 4 4
NE 6
ENE 4 4
ENE 6
E 4 4
E 6
ESE 4 4
ESE 6
SE 4 4
SE 6
SSE 4 4
SSE 6
S 4 4
S 6
SSW 4 4
SSW 6
SW 4 4
SW 6
WSW 4 4
WSW 6
W 4 4
W 6
WNW 4 4
WNW 6
NW 4 4
NW 6
NNW 4 4
NNW 6
N 4 4
which will generate
for the pie chart I used a separate range with alternate gaps in the labels
Direction Dummy
N 1
1
NNE 1
1
NE 1
1
ENE 1
1
E 1
1
ESE 1
1
SE 1
1
SSE 1
1
S 1
1
SSW 1
1
SW 1
1
WSW 1
1
W 1
1
WNW 1
1
NW 1
1
NNW 1
1
Rotating radar charts in Excel can be achieved by building a separate table for plotting the chart. It would have three columns:
Column A: New categories
Column B: Original categories (calculated from A)
Column C: Original data using VLOOKUP() on B
The chart will be plotted using columns B and C. Column B category numbers are offset by the desired number of categories.
If the chart needs to be rotated by other than multiples of a category degree (e.g., 30 degrees for 12 categories), you would need to add rows in between (corresponding to the amount of rotation in relation to the category degree). For example, to rotate a 12-category radar chart by multiples of 15 degrees, one extra row is needed in-between each original category row (to create 24 new categories). In this case, you would need to calculate the intermediate values by linearly interpolating between actual data points.
The trick is that blank category values are not displayed on the chart and the values for these categories blend in smoothly with the real data (because they are interpolated).
I will post an example if the above is not clear enough.
P.S. I cannot look at your new Excel file (in Answers) because it exceeds 5 MB (see screenshot 1).
So I did keep working on this problem and the best solution I've come up with (while using Microsoft Excel) looks as follows:
Currently, the number of sectors in the plot is fixed at 16. If I want to make this number variable, the table required for the plot data requires a very large amount of lookup functions which make the spreadsheet too slow to work with.
I've uploaded the new Excel file here to take a look at:
Excel file

Weighted Trendline in Excel

This is an extension to the question asked in the forums a few years ago:
Excel produces scatter diagrams for sets of pair values. It also gives the option of producing a best fit trendline and formula for the trendline. It also produces bubble diagrams which take into consideration a weight provided with each value. However, the weight has no influence on the trendline or formula. Here is an example set of values, with their mappings and weights.
Value Map Weight
0 1 10
1 2 10
2 5 10
3 5 20
4 6 20
5 1 1
I have used the formula that brettDJ offered:
=INDEX(LINEST(B2:B7*C2:C7^0.5,IF({1,0},1,A2:A7)*C2:C7^0.5,TRUE,TRUE),3,1)
However, I could not understand why we used the ^0.5 here to sqrt the weights.
The original question is here

Plotting columns by calling their header with GnuPlot

I have file of this format:
x y1 y2 y3 ei1 ei2 ei3 es1 es2 es3
1 4 5 4 7 7 2 4 7 7
2 7 3 3 3 8 3 3 3 8
3 2 1 4 4 9 6 4 4 9
I want to produce plots similar to what the following command would
give
plot "filename" using 1:2:5:8 with yerrorbars
but using the columns headers(x, y1, ei1 and es1) to call them.
How can this be done?
Page 84 of the gnuplot manual (documenting the using command) reads:
Height Weight Age
val1 val1 val1
... ... ...
then the following plot commands are all equivalent
plot ’datafile’ using 3:1, ’’ using 3:2
plot ’datafile’ using (column("Age")):(column(1)), \
’’ using (column("Age")):(column(2))
plot ’datafile’ using "Age":"Height", ’’ using "Age":"Weight"
However when I tried them I only got the row indices versus themselves.
Taking a quick look at the documentation for gnuplot 4.4 vs gnuplot 4.6 (current stable release), it appears that the feature you are trying to use was probably introduced in gnuplot 4.5 (Odd numbers are the development branches -- when they are deemed stable, they get incremented to an even number). The only way that can think of to accomplish this is to write a simple script in some other language which returns the column number (to stdout). Here's a simple example using python although I'm positive that you could do this in awk if you wanted to remain in an all-POSIX environment:
#python indexing is 0 based, gnuplot datafile indexing 1 based
COL_AGE=`python -c 'print(open("datafile").readline().split().index("AGE")+1)'`
COL_HEIGHT=`python -c 'print(open("datafile").readline().split().index("HEIGHT")+1)'`
plot "datafile" u COL_AGE:COL_HEIGHT
This little script doesn't do anything fancy (It assumes the column headers are on the first line for example), but using the power of python, it would be pretty easy to extend the script further:
#!/usr/bin/env python
import sys
with open(sys.argv[1]) as f
for line in f:
if (line.strip()):
print (line.split().index(sys.argv[2])+1)
sys.exit(0)
Now you can call this script as: python script.py datafile AGE to find out which column "AGE" is in. It is an error if "AGE" isn't in any column.

sqrt not returning correct values in C++

I have been working on this homework problem for about 6 hours.
We are given a volume in gallons, and have to find the radius and diameter of a cylinder (the pond). I can't figure out what I'm doing wrong. cmath is included in my program. Here is the code:
1 //dblPondRadius = sqrt((dblPondVolumeCube)/M_PI*11));
2
3 dblPondVolumeCube = static_cast<double(intPondVolume)*.13368;
4
5 dblPondRadius = dblPondVolumeCube/(M_PI*11);
6
7 dblPondRadius = sqrt (dblPondVolumeCube);
8
9 dblPondDiameter = dblPondRadius*2;
Line 3 converts the gallons into cubic feet
Line 5 is step 1 of the pond radius formula that was given to us (see formula in the comment at top of code)
Line 7 is step 2 of the formula
Line 9 computes the diameter
The whole rest of the program is dependent on calculations from the diameter. It's due in 1.5 hours please help!!!
Line 5 sets dblPondRadius, then line 7 sets it again, without reference to the previous value, so line 5's work is thrown away.

Resources