Functions to import/export various formats of snow profiles, with basic formatting and visualization functions.
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.
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_idprovide a profile name
hstotal snow height
snowprofileLayersthat contains layer properties (each row is a layer and each column is a property such as depth or grain size).
snowprofileSet object is simply a
list of multiple
The package includes sample data packaged into three
SPgroupcontains 12 profiles from different locations with the same timestamp
SPtimelinecontains 11 profiles from the same location with different timestamps
SPpairscontains 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
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
## 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
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
rbind methods exist to summarize and extract contents from
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
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.snowprofileproduces a hardness profile for a single
plot.snowprofileSetproduces several types of plots for a
snowprofileSetincluding 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
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.