Introduction to the sarp.snowprofile package

Functions to import/export various formats of snow profiles, with basic formatting and visualization functions.

library(sarp.snowprofile)

1. Snowprofile objects

The package uses S3 classes for individual snow profiles (class snowprofile) or lists of multiple snow profiles (class snowprofileSet). Objects with these classes can be created, manipulated, and visualized.

A snowprofile object contains data about a snow stratigraphy profile. It is structured as a list with metadata (e.g. profile name and location) and a data.frame containing layer properties. Mandatory parts of a snowprofile object include:

A snowprofileSet object is simply a list of multiple snowprofile objects.

The package includes sample data packaged into three snowprofileSet objects:

## Print the structure of a single `snowprofile` object
Profile <- SPpairs$C_day1
str(Profile)

Check out an empty snowprofile object to understand which information can potentially go where:

snowprofile(dropNAs = FALSE)

2. Profile creation

The package includes functions to create a snowprofile object by importing common file formats as well as provides constructor functions to manually create a snowprofile.

2.1 Import profiles from file

Import functions for generic snow profiles include::

and import functions for simulated profiles produced with the snow cover model SNOWPACK include:

Note that prf and pro files contain multiple profiles and thus the import functions return a snowprofileSet, while CAAML, csv, and sno files return a single snowprofile.

## Import a CAAML file
# Filename <- "path/to/file.caaml"
# Profile <- snowprofileCaaml(Filename)

# ## Import all profiles from a directory of CAAML files and create a `snowprofileSet`
# CaamlFiles <- list.files('path/to/caamlprofiles', full.names = T)
# Profiles <- lapply(CaamlFiles, snowprofileCaaml)
# Profiles <- snowprofileSet(Profiles)

An additional parser readSmet is also provided to read other input and output files from SNOWPACK.

2.2 Manually construct profiles

To manually create a snowprofile object see the help pages for the constructor functions snowprofile() and snowprofileLayers() where metadata and layer properties are provided as function arguments.

2.3 Formatting profiles

Import and constructor functions perform several validation checks for consistent structure (e.g. variable names, consistent layer thickness/depth/height). Sometimes profiles may be malformatted (e.g. files have different formatting than the functions in this package, future changes to this R package), so this package provides functions for checking profiles for formatting discrepancies and reformatting them if necessary. validate_snowprofile raises errors (or silently print error messages) in case of formatting discrepancies and reformat_snowprofile can conveniently correct data types or rename metadata / layer properties. See examples in the help files for these functions for examples of how it identify and correct errors in malformatted profiles

3. Profile manipulation

print, summary, and rbind methods exist to summarize and extract contents from snowprofile and snowprofileSet objects.

3.1 Print

Print contents of a snowprofile to the console.

Profile <- SPpairs$A_manual
print(Profile)

3.2 Summary

Extract metadata from a single profile or set of profiles into a data.frame.

summary(Profile)
summary(SPgroup)

Summary methods are useful to extract subsets of a snowprofileSet based on some attribute (e.g. location, time).

## Subset all profiles from SPgroup with elevation > 2000 m
Metadata <- summary(SPgroup)
Alpine <- SPgroup[Metadata$elev > 2000]
print(paste(length(Alpine), 'of', length(SPgroup), 'profiles in SPgroup are above 2000 m'))

3.3 Rbind

rbind methods merge metadata and layer properties from one or many profiles into a large data.frame that is convenient for analysis tasks.

## Rbind SPgroup 
TabularProfile <- rbind(SPgroup)
names(TabularProfile)

## Tabulate all grain types
table(TabularProfile$gtype)

## Get elevations of profiles with SH layers > 5 mm
SH_layers <- subset(TabularProfile, gtype == 'SH' & gsize > 5)
sort(SH_layers$elev)

4. Profile visualization

Plot methods exist for individual profiles and sets of profiles:

## Plot a single hardness profile
plot(Profile)
## Plot a timeline
plot(SPtimeline)
## Plot all profiles in the group and sort by height
plot(SPgroup, SortMethod = 'hs')

The package also includes several getColour... and setColour... functions to define colour palettes for various profile properties.



Try the sarp.snowprofile package in your browser

Any scripts or data that you put into this service are public.

sarp.snowprofile documentation built on Feb. 10, 2022, 1:06 a.m.