How to generate a 3D plot from CSV data?

   1958   1   0
User Avatar
Member
11 posts
Joined: Oct. 2016
Offline
Hi there,

First of all, forgive the rather lengthy explanation, but I want to make sure that the problem space is well defined, so please bear with me.

I need to build a 3D surface plot of some spectra data for a client. The spectra data will be supplied as float values in a CSV file and I will be (presumably) using the TableImport node to access this information.

The CSV file will be formatted as follows:
  • The first column of data will represent points along the X-axis (i.e. energy).
  • Many subsequent columns will each represent a set of Y-axis values (i.e. absorption) at a given temperature step. For example, there could be a 100 of these columns and I am assuming for the moment that the temperature steps will all be the same.

So, to summarise, the 3D plot will comprise energy along the X-axis, absorption up the Y-axis, and temperature along the Z-axis.

Using an example CSV data-set to experiment with, I have setup a TableImport node to read the X-axis values into one float attribute (energy), and the columns of Y-axis values into a single float attribute (absorption) which has an attribute length set equal to the number of temperature columns.

This data shows up nicely in the Geometry Spreadsheet and I can see the following columns listed and with the expected float values beneath:
“energy, absorption#0, absorption#1, absorption#2, absorption#3, absorption#4, …” where #-n represents the number in square brackets.

So far so good.

I then pipe the output of the TableImport node into a PointWrangle node with VEX code that should generate the 3D plot. For example, @P = set(@energy, @absorption, zoffset); .

However, when I try to treat the multiple @absorption values as an array of float values (e.g. using @absorption, where i = 0, 1, 2, …), the VEX compiler complains bitterly (e.g. “Ambiguous call to array index operator”). It seems that I can only access and plot the first column of absorption data against the energy (i.e. it will only recognise @absorption as a legitimate variable, and nothing else).

So there are two questions that I hope you might be able to answer for me:
  • How do you access values of an attribute that is in the form of a float array?
  • Is there a better method (Python?) that I could use to generate this 3D plot?

Once again, apologies for the lengthy explanation.

Thanks in advance,
Peter
Edited by peter_i - July 21, 2018 07:39:11
User Avatar
Member
11 posts
Joined: Feb. 2018
Offline
If I understand correctly, this should be pretty trivial, I think you can add an appropriate header to change a .csv into an .xyc or .pct or some other point cloud file. You can find what the header should say online somewhere and then change the extension. Sometimes I get files that don't come in xyz, but in your case that matters less. I would set attributes after, but it should be pretty easy to just set any attribute to p.


You could also write a loop that just gave xyz values based off of column values, pretty simple as well…I think that there is an Entgama tutorial on creating s starfield from array data with python that would work for your case.
  • Quick Links