Functions to import/export various formats of snow profiles, with basic formatting and visualization functions.
library(sarp.snowprofile)
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:
station and station_id provide a profile namedatetime timestamplatlon, elev, angle, aspect location informationhs total snow heightlayers a data.frame of class snowprofileLayers that contains layer properties (each row is a layer and each column is a property such as depth or grain size). A snowprofileSet object is simply a list of multiple snowprofile objects.
The package includes sample data packaged into three snowprofileSet objects:
SPgroup contains 12 profiles from different locations with the same timestampSPtimeline contains 11 profiles from the same location with different timestampsSPpairs contains various other snow profiles## 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)
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.
Import functions for generic snow profiles include::
snowprofileCaaml)snowprofileCsv)and import functions for simulated profiles produced with the snow cover model SNOWPACK include:
snowprofilePrf)snowprofilePro)snowprofileSno)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.
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.
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
print, summary, and rbind methods exist to summarize and extract contents from snowprofile and snowprofileSet objects.
Print contents of a snowprofile to the console.
Profile <- SPpairs$A_manual print(Profile)
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'))
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)
Plot methods exist for individual profiles and sets of profiles:
plot.snowprofile produces a hardness profile for a single snowprofile objectplot.snowprofileSet produces several types of plots for a snowprofileSet including timelines and side-by-side stratigraphies## 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.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.