A package for reading, mapping, and analyzing Cavity Ring Down Spectroscopy (CRDS) raw data generated by Picarro instruments.
This package includes functions for reading, mapping metadata, plotting, and analyzing these datasets.
Install the package with
# install.packages("devtools")
devtools::install_github("https://github.com/KopfLab/isoCRDS/")
This is a copy of the example file that can be found as Example.html
and Example.qmd
. I highly recommend opening the .html
file, which shows function output.
This workflow assumes you have run your samples on the Picarro CRDS and collected a day's worth of .dat
files in a single directory.
Move your .dat
files into your working directory. Each batch of files that correspond to a continuous stretch of time should share a directory. If you have multiple continuous stretches of data, use different folders for them and process them separately. (This will make the plotting and mapping much more straightforward.)
The .dat
file is unwieldy, but at its core it is a delimited table data structure. This package has two functions for reading .dat
files: iso_read_crds()
and iso_read_many_crds()
. The first function is for reading a single .dat
file.
iso_read_many_crds()
takes a directory as an argument and reads all the .dat
files in it. It combines them all into a single dataframe.
# reading many files into a single dataframe
full_crds_data <- iso_read_many_crds("data/2023-08-04_Memory_Test/")
glimpse(full_crds_data)
# how many rows?
count(full_crds_data)
iso_read_crds()
takes in a single .dat
file and returns a single dataframe. This function is useful if you only have a short interval of data.
# Reading a single file
single_crds_data <- iso_read_crds("data/2023-08-04_Memory_Test/CFIDS2308-20230804-001241Z-DataLog_User.dat")
# how many rows?
count(single_crds_data)
Once you have read in your data, you can inspect its quality using iso_plot_crds()
which displays commonly measured parameters.
iso_plot_crds(full_crds_data)
If you are happy with the quality of your data, save the dataframe as a .RDS
file. This is useful both as a cache (so you don't need to do the time-consuming step of iso_read_many_crds()
again.)
#| eval: false
saveRDS("cache/my_crds_data.RDS")
"Map my data?" Yes! You likely have discrete samples represented in your CRDS data, and you probably want to delimit what data corresponds to what sample. There are two ways to do this:
We include a function iso_map_crds()
which takes two arguments:
-
crds_data
: a CRDS tibble, like the one we generated withiso_read_many_crds()
. -
sample_map
: a tibble with three columns:sample_id
,datetime_start
, anddatetime_end
. You can create this sample map in excel or in R while you collect your data on Picarro.For example: you inject a sample onto the Picarro. Note the time at which it begins to show up and stabilize in the cavity. Note the time at which you want to stop measuring it. Notate these in datetime format:
yyy-mm-dd hh:mm:ss
.
Once you have imported your CRDS data and your sample map into your R session, you can map your samples to specific datetime intervals.
#| eval: false
# import our manually-notated sample map
inj_map <- readxl::read_excel("data/sample_map/sample_map.xlsx")
# map the data!
injection_mapped <- iso_map_crds(
crds_data = crds_injection,
sample_map = inj_map
)
You may opt to use our interactive Shiny app for sample mapping. This shiny app can be launched with:
#| eval: false
# launch the interactive CRDS data mapping tool:
iso_crds_app()
You will be prompted to upload the .RDS
file that you generated in step 2. Once you've uploaded the file, you can create an interactive plot.
- Select appropriate plot axes.
- Use the rectangular select tool to select your sample data.
- Press the Add Sample_ID button. This marks the data you selected as belonging to your sample.
For example, selecting the plateau a region of heightened$CO_2$ or$CH_4$ . - Input the sample name in the Enter Sample Name box.
- When you are done selecting data and inputting sample names, use the Save Mapped Data button to save an updated
.RDS
file that is mapped.
You can re-import this dataset back into your R session and pass it downstream to any analyses you like.
#| eval: false
mapped_data <- readRDS("mapped_data.rds")
crds_summarized <- mapped_data |>
group_by(sample_id) |>
summarize(
mean_d13CH4 = mean(Delta_iCH4_Raw),
mean_d13CO2 = mean(Delta_Raw_iCO2)
)
crds_summarized
crds_summarized |>
pivot_longer(c(mean_d13CH4, mean_d13CO2),
names_to = "measurement",
values_to = "d13C_VPDB") |>
ggplot(
aes(
x = sample_id,
y = d13C_VPDB,
color = measurement,
fill = measurement
)
) +
geom_point(size = 3, alpha = 0.5) +
theme_bw()