daqr provides functions to work with Data AcQuisition (DAQ) files
generated by minisim driving simulator. With daqr, you can convert a
daq file to hdf5 type, and get useful driving variables directly in
R. Behind the scenes, daqr uses
undaqTools python package by
Roger Lew.
You can install the development version of daqr from GitHub with:
# install.packages("devtools")
devtools::install_github("durraniu/daqr")You need to have python 2.7 and a few packages installed to use daqr.
You can get python and packages in one of the two ways discussed below.
If you already have python 2.7 installed, then make sure that you have the following packages or install them:
- scipy
- numpy
- matplotlib
- h5py
- nose
- sphinx
- numpydoc
- undaqTools
Then, in R, you can use reticulate to specify this installation of
python to start using daqr:
# install.packages("reticulate")
reticulate::use_python("path/to/python.exe")To start from scratch, use reticulate package in R to install python,
create a virtual environment, and install dependencies :
# install.packages("reticulate")
library(reticulate)
path_to_python <- install_python(version="2.7.18")
virtualenv_create("r-reticulate", python = path_to_python)
py_install(packages = c("scipy", "numpy", "matplotlib", "h5py",
"nose", "sphinx", "numpydoc", "undaqTools"),
python_version = "2.7.18",
envname = "r-reticulate")Now you are ready to use daqr.
The function read_daq_and_save_to_hdf5 will read the daq file and
save it to hdf5 format in the same location using the same file name.
library(daqr)
library(reticulate)
## Specify the environment to use
use_virtualenv("r-reticulate")
read_daq_and_save_to_hdf5("path/to/daq/file.daq")You can get several variables from driving data using the function
read_driver_data. It takes two arguments for file_name and metric.
The file_name parameter can be a daq file or a hdf5 file. The
units of variables in the resulting dataframe depends on metric. If
TRUE, then the units will be metric, if FALSE, the units will be
imperial.
library(daqr)
library(reticulate)
## Specify the environment to use
use_virtualenv("r-reticulate")
# Get driving data from daq file
read_driver_data("path/to/daq/file.daq")
# Get driving data from previously saved hdf5 file
read_driver_data("path/to/hdf5/file.hdf5")