Importing AFM images in R and then displaying with Python in Quarto
Author
Thomas Gredig
Published
September 16, 2024
This document shows you how to use Python with Park AFM images. First step is to load the AFM image using the R package. It means that you have to install, the nanoAFMr package.
Please cite nanoAFMr 2.3.1 - see https://doi.org/10.5281/zenodo.7464877
Code
f =AFM.getSampleImages(type="tiff")[1]a =AFM.import(f)plot(a)
Graphing: Topography
The next step is to select the channel and convert the data into a matrix. The AFM.raster function returns a DataFrame with 3 components, x,y,z, which are in units of nanometers.
Code
d =AFM.raster(a, no=1)str(d)
'data.frame': 65536 obs. of 3 variables:
$ x: num 0 9.8 19.6 29.4 39.2 ...
$ y: num 0 0 0 0 0 0 0 0 0 0 ...
$ z: num 0.189 0.242 0.309 0.149 -0.179 ...
Now use the reticulate package in R, see R interface to Python, to be able to launch Python from within R.
Next use Python to graph the data with r.d which has the r. prefix. We can now look at the first few elements in z portion of the array:
@misc{gredig2024,
author = {Gredig, Thomas and Gredig, Thomas},
title = {AFM: {R} to {Python} {Converter}},
date = {2024-09-16},
url = {https://www.csulb.edu/~tgredig/posts/R-Python-Converter/nanoAFM_R_to_Python.html},
langid = {en}
}