Re: VisAD Newbie : Help with doing simple 3D plot

Hi Ethan,

> I've been playing around with VisAD a bit, but I seriously think that I'm
> not getting anywhere by myself. I really need help. So if any of these sound
> too easy for you, please be patient. Thanks.
> 
> I'm basically just trying to do a 3D plot, but don't really understand how
> VisAD works, particularly the data model. I've read the VisAD guide, but to
> no avail. Too much information which I don't understand, probably. I've also
> gone through some of the progams in the examples directory, but i can't find
> any documentation describing what each test program is trying to do, so not
> too much help there either.

Sorry for your problems.  The root of the problem is that I
am better at writing software than at writing documentation
(although the length of the Guide proves that I try).

> >From what I know, there are basically 3 steps to creating a plot.
> 1) creating the data model
> 2) creating the mappings with ScalarMap()
> 3) creating the display itself

Correct.

> I'm really stuck at the data model part. So I hope to solve just the data
> model in this mail. Hopefully I'll have less problems...
> 
> Basically I'm just displaying a 3D plot, and my data is a time series of
> various financial instruments. Below is some description of my data model.
>   - I believe it would be (RealType.Time -> (value1, value2,value3))
>   - valueX has no units.
>   - valueX are all float/double values
>   - valueX are sampled at equal time intervals
> 
> I believe this is about as simple a model as it can get, but alas, how do I
> do it???
> 
> >From the little understanding I have, I think creating the model should
> be...
> 
>     RealType time = {RealType.Time};
> 
>     RealType value1 = new RealType("value1", Null, Null);
>     RealType value2 = new RealType("value2", Null, Null);
>     RealType value3 = new RealType("value3", Null, Null);
>     RealType[] values = {value1, value2, value3};
> 
>     RealTupleType time_type = new RealTupleType(time);
>     RealTupleType valuestuple = new RealTupleType(values);
> 
>     FunctionType time_values = new FunctionType(time_type, valuestuple);

Good up to here.

>     FlatField data = FlatField.makeField(time_values);  // is this right ???

FlatField.makeField is only intended as a helper for our
examples/TestNN.java programs.  Please don't use it.  You'll
need to construct a FlatField explicitly, first constructing
a Set of time samples:

>     Linear1DSet ???  // how & where do I create the Linear1DSet?

This will be a set of times.  This is where you use DateTime.
For example, in examples/Test03.java we use:

  // different time resolution test
  // 2 May 99, 15:51:00
  double start = new DateTime(1999, 122, 57060).getValue();
  Set time_set
    new Linear1DSet(time_type, start, start + 3000.0, ntimes);

You'd do something like this, where ntimes is the number of
time samples in your data.  If your times are not evenly spaced,
then use a Gridded1DSet, also as in examples/Test03.java.

Once you have a Set, then construct your FlatField by:

  FlatField data = new FlatField(time_values, time_set);

Then you will need to fill in the values for value1,
value2 and value3, as follows:

> And populating the model with data should be...
> 
>     double val1 = ...
>     double val2 = ...
>     double val3 = ...
>     double[] valss = {val1, val2, val3};
> 
>     // add record to new_data
>     RealTuple record = new RealTuple(valuestuple, values);
> 
>     index = ???  // can i use the DateTime class to convert a string of time
> to some index?
>     new_data.setSample(index, record);

Instead, do this:

  double[][] values = new double[3][ntimes];
  for (int i=0; i<ntimes; i++) {
    values[0][i] = value1 at time step i
    values[0][i] = value2 at time step i
    values[0][i] = value3 at time step i
  }
  data.setSamples(values);

> I'm sure there's something wrong somewhere, or things that I may have
> overlooked. Would really appreciate if anyone can help me out here. Thanks a
> million in advance.

Good luck, and please let the list know if you have further
problems (I am leaving for 3 weeks travel this Friday, so
hopefully others on the list can help while I am away).

> Also, below are some of the other things which I want to be able to do.
> Would these affect the data model in any way?
>   - the FlatField will be written out to a .nc file at later time

The visad.data.netcdf.Plain.save() method should create a
netCDF file from your FlatField with no problems.

>   - for scalar mappings, all the 4 variables can be assigned to any display
> types
>     e.g. animation of v1 vs v2 vs v3, or time vs v2 vs v3 with v1 varying
> RGB

This should be no problem.  You'll use statement like:

  DisplayImplJ3D display = new DisplayImplJ3D("finance");
  display.addMap(new ScalarMap(value1, Display.XAxis));
  . . .

And don't forget to create a JFrame and add() display.getComponent()
to the JFrame or a sub-JPanel.

>   - remote visualization of the data from another machine.

This isn't too difficult.  See Test14.java and Test15.java
in visad/examples.  You construct a DataReferenceImpl to your
data, and a RemoteDataReference from that, then link it to a
URL using a RemoteServerImpl.  On the remote machine you
construct a DisplayImplJ3D, then a RemoteDisplayImpl from that,
retrieve the RemoteDataReference from the URL via the
RemoteServer, and link them using:

   RemoteDisplayImpl.addReference(RemoteDataReference);

Cheers,
Bill
----------------------------------------------------------
Bill Hibbard, SSEC, 1225 W. Dayton St., Madison, WI  53706
hibbard@xxxxxxxxxxxxxxxxx  608-263-4427  fax: 608-263-6738
http://www.ssec.wisc.edu/~billh/vis.html