DataRepresentations_1.gif > DataRepresentations_2.gif

SIMULATIONTOOLS TUTORIAL DataRepresentations_3.gif

Data Representations

SimulationTools uses two different representations of numerical data.

The DataTable is designed for time-series data, and consists of a monotonically-increasing time coordinate and corresponding data values, which can be of any type.  The time coordinate does not have to be regularly spaced.  

The DataRegion represents an N-dimensional block of data on a uniform grid.  The data must consist of real or complex numbers, or the quantities None or Missing[].  The data is stored efficiently in memory. Each point has an associated set of coordinates, and these are specified by giving the origin and spacing of the DataRegion as {ox, oy, ... oz} and {dx, dy, ..., dz}.  

Collectively, DataTables and DataRegions are known in SimulationTools as Data Representations.  There are many functions for manipulating data representations.  Some only make sense for DataTables or DataRegions respectively, but many are defined to work on both types of object.

Many commonly-used Mathematica functions are defined on compatible DataTables and DataRegions (those with the same coordinates), for example Plus (+), Minus (-), Times (*), Divide (/), Sqrt, Power (d^a), Sin, Cos, Tan etc.

Reasons to use Data Representations instead of lists

Data Representations contain coordinate information as well as data; it is frequently desirable to keep the coordinates along with the data.

Mathematical operations defined on Data Representations operate only on the data, as opposed to the data and coordinates, which would be the case if you used a list containing data and coordinates.

Working with Data Representations

Both DataTables and DataRegions can be created from Mathematica lists.  They act as opaque objects and are printed in an abbreviated form to avoid cluttering up the notebook with all the numerical data.

Creating DataTables

Using ToDataTable[data], we can create a DataTable from a list of {t, f} pairs:

In[1]:=

DataRepresentations_4.gif

Out[1]=

DataRepresentations_5.gif

In[2]:=

DataRepresentations_6.gif

Out[2]=

DataRepresentations_7.gif

t is the independent variable and f is the dependent variable.

The independent variable t should be monotonically increasing, but the interval between points can vary.  The "range" of a DataTable is {t1, t2}, where t1 is the first and t2 is the last value of the independent variable.

Creating DataRegions

Using ToDataRegion[data, origin, spacing] we can create a DataRegion object from the (multidimensional) list data. This data is assumed to be in row-major order, eg. data[[ix,iy,iz]] for the case of 3D data. The DataRegion will have an origin and spacing given by the lists origin = {ox, oy, ...} and spacing = {dx, dy, ...}.  SimulationTools uses row-major order because that is the convention adopted by Mathematica.  Note that this corresponds to “C order”, not “Fortran order”.

In[3]:=

DataRepresentations_8.gif

Out[3]=

DataRepresentations_9.gif

In[4]:=

DataRepresentations_10.gif

Out[4]=

DataRepresentations_11.gif

Mathematical operations on Data Representations

You can use most numerical Mathematica functions which would work on lists of data also on Data Representations.  For example,

In[5]:=

DataRepresentations_12.gif

Out[5]=

DataRepresentations_13.gif

In[6]:=

DataRepresentations_14.gif

Out[6]=

DataRepresentations_15.gif

In[7]:=

DataRepresentations_16.gif

Out[7]=

DataRepresentations_17.gif

In[8]:=

DataRepresentations_18.gif

Out[8]=

DataRepresentations_19.gif

In[9]:=

DataRepresentations_20.gif

Out[9]=

DataRepresentations_21.gif

In[10]:=

DataRepresentations_22.gif

Out[10]=

DataRepresentations_23.gif

Here we have created a DataTable for a t coordinate, applied Sin and Cos to it, and formed the sum of their squares to obtain a DataTable which contains the value 1.  Note that the Sin and Cos functions operate only on the data part of the DataTable, and do not affect the coordinate part.  If you were to do the same with Mathematica lists, the coordinate part would also be operated upon.

(Technically, Data Representations can be used directly with all functions which have the attributes NumericFunction and Listable)

Multi-dimensional DataRegions support the same operations.

In[11]:=

DataRepresentations_24.gif

Out[11]=

DataRepresentations_25.gif

In[12]:=

DataRepresentations_26.gif

Out[12]=

DataRepresentations_27.gif

In[13]:=

DataRepresentations_28.gif

Out[13]=

DataRepresentations_29.gif

In[14]:=

DataRepresentations_30.gif

Out[14]=

DataRepresentations_31.gif

In[15]:=

DataRepresentations_32.gif

Out[15]=

DataRepresentations_33.gif

In[16]:=

DataRepresentations_34.gif

Out[16]=

DataRepresentations_35.gif

Converting between 1D DataRegions and DataTables

A 1D DataRegion can be converted to a DataTable object using ToDataTable[dr].

A DataTable can be converted to a 1D DataRegion using ToDataRegion[dt].  Note that the DataTable should have a uniform spacing.

Properties and data of Data Representations

ToListOfData returns the data in the Data Representation as a nested list.

In[17]:=

DataRepresentations_36.gif

Out[17]=

DataRepresentations_37.gif

ToListOfCoordinates returns the coordinates of all the points in the Data Representation

In[18]:=

DataRepresentations_38.gif

Out[18]=

DataRepresentations_39.gif

ToList returns a list containing all the data and all the coordinates from the Data Representation.

In[19]:=

DataRepresentations_40.gif

Out[19]=

DataRepresentations_41.gif

Dimensions returns a list {nx, ny, nz, ...} containing the number of points in each direction.

In[20]:=

DataRepresentations_42.gif

Out[20]=

DataRepresentations_43.gif

MinCoordinates returns the minimum coordinates of the Data Representation.

In[21]:=

DataRepresentations_44.gif

Out[21]=

DataRepresentations_45.gif

MaxCoordinates returns the maximum coordinates of the Data Representation

In[22]:=

DataRepresentations_46.gif

Out[22]=

DataRepresentations_47.gif

CoordinateRanges returns a list of the form {{xmin, xmax}, {ymin, ymax}, {zmin, zmax}, ...} describing the minimum and maximum coordinates of the DataRegion.

In[23]:=

DataRepresentations_48.gif

Out[23]=

DataRepresentations_49.gif

CoordinateSpacings returns the spacing between points in the Data Representation in each direction.

In[24]:=

DataRepresentations_50.gif

Out[24]=

DataRepresentations_51.gif

ArrayDepth returns an integer corresponding to the dimensionality of the data.

In[25]:=

DataRepresentations_52.gif

Out[25]=

DataRepresentations_53.gif

VariableName returns a string containing the name of the DataRegion (DataTables do not have an associated name).  This name can be set using the Variable option of ToDataRegion.

In[26]:=

DataRepresentations_54.gif

Interpolation

The Interpolation function has been overloaded to work on Data Representation objects. The resulting function will generically be a function of n variables, where n is the dimensionality of the data.

In[27]:=

DataRepresentations_55.gif

Out[27]=

DataRepresentations_56.gif

In[28]:=

DataRepresentations_57.gif

Out[28]=

DataRepresentations_58.gif

Perform a line integral using the interpolating function:

In[29]:=

DataRepresentations_59.gif

Out[29]=

DataRepresentations_60.gif

Extracting subsets of data

The Part function, i.e. d[[2]] etc, has been overloaded to work on Data Representation objects. You can extract a single value, for example d[[3,8,1]], or a lower-dimensional DataRegion, d[[All,All,12]].  You can also specify ranges of indices: d[[All,3;;8,12]].  Unless the result is a single point, the returned value is always a DataRegion.

The Slab function allows you to extract part of a DataRegion by coordinate rather than by index, as in Part above.  For example, if you have a 3D DataRegion and you want to obtain a slice in the xy plane at z = 3.5,  you can use d[[All,All,3.5]].  You can also specify coordinate ranges:  d[[-2.0;;+2.0, -2.0;;+2.0, 3.5]].

In[30]:=

DataRepresentations_61.gif

Out[30]=

DataRepresentations_62.gif

In[31]:=

DataRepresentations_63.gif

Out[31]=

DataRepresentations_64.gif

Merging DataRegions

Multiple DataRegions d1, d2, ... can be merged into a single enclosing one using

DataRepresentations_65.gif

This is not yet supported for DataTables.

Plotting

ListPlot ArrayPlot
ListLinePlot ListPlot3D
ListDensityPlot ListContourPlot

Plotting functions.

Several standard Mathematica plotting functions have been modified to work also with Data Representations.

ListPlot and ListLinePlot can be used with 1-dimensional DataRegions and DataTables.

In[32]:=

DataRepresentations_66.gif

Out[32]=

DataRepresentations_67.gif

ListDensityPlot, ArrayPlot, ListPlot3D and ListContourPlot can be used with 2-dimensional DataRegions.  The DataRange option is computed automatically from the coordinate information in the DataRegion.

In[33]:=

DataRepresentations_68.gif

Out[33]=

DataRepresentations_69.gif

In[34]:=

DataRepresentations_70.gif

Out[34]=

DataRepresentations_71.gif

In[35]:=

DataRepresentations_72.gif

Out[35]=

DataRepresentations_73.gif

Created with the Wolfram Language