I have some data that represents small-scale surface topography. The data is planar but not flat because it's impractical to level this microscope to a tolerance of microns. It looks like this:
I'd like to postprocess that slope out, such that the major axis is colinear with the long side of the blue rectangle and the vertical axis can then be rescaled to show meaningful topographic variation instead of the (really large) planar slope.
One approach here might be to do an orthogonal transformation via (basically) principal component analysis, eg. find the three eigenvalue/eigenvector pairs, and then treat the eigenvectors corresponding to the largest two eigenvalues as the new X and Y axes. I'd be very interested to see how this (or some better way) might be done efficiently in Mathematica (this data is generally in the millions of rows).
An example of my data is here.
and this is the code I've written so far (which depends on version 9+ for Downsample[]
):
pathToDatafile = "path\\to\\file\\6000s.xyz";
data = Import[pathToDatafile,"Table","HeaderLines"->15];
data = DeleteCases[data,{__,_String,_String}]; (*remove the "no data" lines that the instrument creates*)
data=Delete[data,-1]; (*throw away the instrument's pound sign at the end of the file*)
data = Downsample[data,{100,1}];(*downsample by a lot because we have way too many datapoints*)
ListPlot3D[data,
Mesh->None,
BoxRatios->Automatic,
PlotStyle->LightBlue,
Boxed->False,
Axes->{True,True,True},
AxesLabel->{"\[Mu]m","","\[Mu]m"},
PlotRange->{Automatic,Automatic,{0,250}},
ImageSize->Large
]
Answer
This solution is giving some artifacts, I believe, due to the downsampling, but the problem can be solved by using RotationTransform
similar to this
ListPlot3D[data]
ListPlot3D[RotationTransform[-2.2 Degree, {1, 0, 0}, data[[1]]]@data]
You can make an interactive leveler. This requires a severely downsampled dataset in order to work smoothly (at least on my computer)
subdata = Downsample[data, {100, 1}];
Manipulate[Module[{d},
d = RotationTransform[x Degree, {1, 0, 0}, subdata[[1]]]@subdata;
d = RotationTransform[y Degree, {0, 1, 0}, d[[1]]]@d;
ListPlot3D[d]
], {{x, 0}, -5, 5}, {{y, 0}, -5, 5}]
And then use those results on the full set of data
Module[{d},
d = RotationTransform[-2.16 Degree, {1, 0, 0}, data[[1]]]@data;
d = RotationTransform[0.12 Degree, {0, 1, 0}, d[[1]]]@d;
ListPlot3D[d]
]
Which gets you a slightly tweaked version of the image I have above, so I won't repost it.
Comments
Post a Comment