Skip to main content

import - How to read CDF (Common Data Format) file?


I don't understand, what Import does with CDF.


If I enter



In[17]:= data = Import[ExampleFile]
Out[17]= {"Pose"}

what I can do with returned object? How can I return Pose entry only?


If I try to specify this as element name as string, I am failing:


In[18]:= data = Import[ExampleFile, "Pose"]

During evaluation of In[18]:= Import::noelem: The Import element "Pose" is not present when importing as NASACDF.

Out[18]= $Failed


UPDATE


I noticed, that it showed entity name in quotes. In notebook it looks different:


enter image description here


i.e. w/o quotes.


UDPATE 2


Shared example: https://drive.google.com/open?id=0By8pZ9a2478YOGlhZUlRU3VNb28


UPDATE 3


Apparently Mathematica has a bug here, because the data returned is reshaped incorrectly.


Here is Matlab transcript, reading the same file:



>> data = cdfread(ExampleFile,'Variable', {'Pose'});
>> data = data{1};
>> size(data)

ans =

992 96

>> data(1,1:5)


ans =

1×5 single row vector

-287.2470 64.5002 933.7140 -417.2063 37.0789

>> data(1:5,1)

ans =


5×1 single column vector

-287.2470
-287.6960
-288.1260
-288.5740
-288.9960

An here is Mathematicas:


In[47]:= data = Import[ExampleFile, "Elements"]

data = Import[ExampleFile, "Data"];
Dimensions[data]
data[[1, 1, 1, 1]]

Out[47]= {"Annotations", "Data", "DataEncoding", "DataFormat", \
"Datasets", "Metadata"}

Out[49]= {1, 1, 992, 96}

Out[50]= -287.247


data[[1, 1, 1, Range[5]]]

Out[54]= {-287.247, -287.696, -288.126, -288.574, -288.996}

In[55]:= data[[1, 1, Range[5], 1]]

Out[55]= {-287.247, -497.341, -378.209, -376.513, -370.388}

I.e. although Mathematica indicates the similar shape of data, i.t. fills that shape in different way.



I.e. what Matlab cosiders as row, Mathematica considers as column, and what Mathematica considers as column, is unknown.


So, I still need instructions if I am incorrectly operating with Mathematica's ND arrays, or, if it is Mathematica bug, I need to know, how to recover from it.


UPDATE 4


For now I see the following way to recover original data from corrupted one:


dims = Dimensions[data]
data = ArrayReshape[
data, {dims[[1]], dims[[2]], dims[[4]], dims[[3]]}];
data = Transpose[data, {1, 2, 4, 3}];

Answer



In WL this format is known as NASACDF



In doubt you can always import "Elements" and try each one:


Import["Posing.cdf", "Elements"]


{"Annotations", "Data", "DataEncoding", "DataFormat", "Datasets", "Metadata"}

Import["Posing.cdf", "Data"]

enter image description here


Initially returned {"Pose"} was a list of datasets stored in a file. You can extract specific dataset via:



 Import["Posing.cdf", {"Datasets", "Pose"}]

All that and more can of course be learned from linked documentation page.


Comments

Popular posts from this blog

plotting - Filling between two spheres in SphericalPlot3D

Manipulate[ SphericalPlot3D[{1, 2 - n}, {θ, 0, Pi}, {ϕ, 0, 1.5 Pi}, Mesh -> None, PlotPoints -> 15, PlotRange -> {-2.2, 2.2}], {n, 0, 1}] I cant' seem to be able to make a filling between two spheres. I've already tried the obvious Filling -> {1 -> {2}} but Mathematica doesn't seem to like that option. Is there any easy way around this or ... Answer There is no built-in filling in SphericalPlot3D . One option is to use ParametricPlot3D to draw the surfaces between the two shells: Manipulate[ Show[SphericalPlot3D[{1, 2 - n}, {θ, 0, Pi}, {ϕ, 0, 1.5 Pi}, PlotPoints -> 15, PlotRange -> {-2.2, 2.2}], ParametricPlot3D[{ r {Sin[t] Cos[1.5 Pi], Sin[t] Sin[1.5 Pi], Cos[t]}, r {Sin[t] Cos[0 Pi], Sin[t] Sin[0 Pi], Cos[t]}}, {r, 1, 2 - n}, {t, 0, Pi}, PlotStyle -> Yellow, Mesh -> {2, 15}]], {n, 0, 1}]

plotting - Plot 4D data with color as 4th dimension

I have a list of 4D data (x position, y position, amplitude, wavelength). I want to plot x, y, and amplitude on a 3D plot and have the color of the points correspond to the wavelength. I have seen many examples using functions to define color but my wavelength cannot be expressed by an analytic function. Is there a simple way to do this? Answer Here a another possible way to visualize 4D data: data = Flatten[Table[{x, y, x^2 + y^2, Sin[x - y]}, {x, -Pi, Pi,Pi/10}, {y,-Pi,Pi, Pi/10}], 1]; You can use the function Point along with VertexColors . Now the points are places using the first three elements and the color is determined by the fourth. In this case I used Hue, but you can use whatever you prefer. Graphics3D[ Point[data[[All, 1 ;; 3]], VertexColors -> Hue /@ data[[All, 4]]], Axes -> True, BoxRatios -> {1, 1, 1/GoldenRatio}]

plotting - Mathematica: 3D plot based on combined 2D graphs

I have several sigmoidal fits to 3 different datasets, with mean fit predictions plus the 95% confidence limits (not symmetrical around the mean) and the actual data. I would now like to show these different 2D plots projected in 3D as in but then using proper perspective. In the link here they give some solutions to combine the plots using isometric perspective, but I would like to use proper 3 point perspective. Any thoughts? Also any way to show the mean points per time point for each series plus or minus the standard error on the mean would be cool too, either using points+vertical bars, or using spheres plus tubes. Below are some test data and the fit function I am using. Note that I am working on a logit(proportion) scale and that the final vertical scale is Log10(percentage). (* some test data *) data = Table[Null, {i, 4}]; data[[1]] = {{1, -5.8}, {2, -5.4}, {3, -0.8}, {4, -0.2}, {5, 4.6}, {1, -6.4}, {2, -5.6}, {3, -0.7}, {4, 0.04}, {5, 1.0}, {1, -6.8}, {2, -4.7}, {3, -1.