Description Usage Arguments Value Author(s) Examples
View source: R/interpolatePoints.R
Use multivariate matching to interpolate simulation output results to high resolution maps
1 2 3 4 5 6 7 8 9 10 11 12 13 |
matches |
data frame. Output from |
output_results |
data frame. Simulation output results for all simulated sites (Subset cells). The first column and the rownames should correspond to the unique identifiers for the Subsetcells. Importantly, these identifiers need to match the identifiers in the 'subset_cell' column of the 'matches' data frame. |
exclude_poor_matches |
boolean. Indicates whether poor matches (defined as Target cells that are more than the designated 'matching_distance' from their matched Subset cell) should be excluded from matching. Defaults to TRUE. |
subset_cell_names |
character. This is the name of the column in the
'matches' data frame that provides the unique identity of the Subset cells
matched to each Target cell. Defaults to "subset_cell". When 'matches' is the
output from |
quality_name |
character. This is the name of the column in the
'matches' data frame that provides the matching quality between the Subset cells
and Target cells. Defaults to ""matching_quality"". When 'matches' is the
output from |
matching_distance |
numeric. Gives the maximum allowable matching quality value (weighted Euclidean distance) between Target and Subset cells. Default value is 1.5. |
raster_template |
one of the raster layers used for input data. |
plotraster |
boolean. Indicates if raster should be plotted to a map. Defaults to TRUE. |
saveraster |
boolean. Indicates if a raster should be saved to file. Defaults to TRUE. |
filepath |
provides path for location where raster will be saved. Defaults to working directory. |
overwrite |
boolean. Indicates whether saving the rasters will be allowed to overwrite existing files with the same name. Defaults to FALSE. |
Raster files of interpolated output variables.
Rachel R. Renne
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | # Load targetcells data for Target Cells
data(targetcells)
# Create data frame of potential matching variables for Target Cells
allvars <- makeInputdata(targetcells)
# Subset to include only matching variables
matchingvars <- allvars[,c("cellnumbers","x","y","bioclim_01","bioclim_04",
"bioclim_09","bioclim_12","bioclim_15","bioclim_18")]
# Create raster_template
raster_template <- targetcells[[1]]
# Create vector of matching criteria
criteria <- c(0.7,42,3.3,66,5.4,18.4)
# For an example where subset cells were generated from kpoints function
# Find solution for k = 200
results1 <- kpoints(matchingvars,criteria = criteria,klist = 200,n_starts = 1,
min_area = 50,iter = 50,raster_template = raster_template)
# Get points from solution to kpoints algorithm
subsetcells <- results1$solutions[[1]]
# Find matches and calculate matching quality
quals <- multivarmatch(matchingvars, subsetcells, criteria = criteria,
matchingvars_id = "cellnumbers",
raster_template = raster_template,
subset_in_target = TRUE)
# Create toy data set of "output variables"
# There are really just climate variables from the 'targetcells' rasters,
# but we will treat them as output variables to illustrate the method
output_results <- allvars[rownames(subsetcells),
c("cellnumbers","bioclim_02","bioclim_03",
"bioclim_16","bioclim_17")]
# Interpolate simulation output to rasters
interpolatePoints(matches = quals, output_results = output_results,
exclude_poor_matches = TRUE,
subset_cell_names = "subset_cell",
quality_name = "matching_quality",
matching_distance = 1.5,
raster_template = raster_template,
plotraster = TRUE,
saveraster = FALSE,
overwrite = FALSE)
###################################
# For example where subset cells were not generated from kpoints function
# Remove previous subsetcells
rm(subsetcells)
# Get points from solution to kpoints algorithm
data(subsetcells)
# Pull results from subsetcells
output_results <- subsetcells[,c("site_ids","Dryprop","CwetWinter","CdrySummer",
"Cwet8","Dryall","Dryany")]
rownames(output_results) <- output_results$site_ids
# Remove duplicates (representing cells with same climate but different soils--
# we want to match on climate only)
subsetcells <- subsetcells[!duplicated(subsetcells$site_id),]
# Pull out matching variables only, with site_id that identifies unique climate
subsetcells1 <- subsetcells[,c("site_id","X_WGS84","Y_WGS84","bioclim_01",
"bioclim_04","bioclim_09","bioclim_12",
"bioclim_15","bioclim_18")]
# Ensure that site_id will be values unique to subsetcells
subsetcells1$site_id <- paste0("00",subsetcells$site_id)
# Find matches and calculate matching quality
quals <- multivarmatch(matchingvars, subsetcells=subsetcells1,
criteria = criteria,
matchingvars_id = "cellnumbers",
subsetcells_id = "site_id",
raster_templat = targetcells[[1]],
subset_in_target = FALSE)
# Bring in matching variables for secondary matching
# Subset to include only secondaryvars
secondaryvars <- allvars[,c("cellnumbers","x","y","sand","clay")]
# Remove previous subsetcells
rm(subsetcells)
# Bring in secondary id variable from subsetcells
data(subsetcells)
# Remove duplicates (keeping only site-specific soils with site_ids ending
# in ".1").
subsetcells <- subsetcells[!duplicated(subsetcells$site_id),]
# Pull out matching variables only, with site_id that identifies unique climate
subsetcells <- subsetcells[,c("site_id","X_WGS84","Y_WGS84",
"sand","clay"),]
# Convert sand and clay to percentage from fraction
subsetcells$sand <- subsetcells$sand*100
subsetcells$clay <- subsetcells$clay*100
# Make sure subsetcell ids are unique
subsetcells$site_id <- paste0("00",subsetcells$site_id)
# Bring in "other" treatments
data(setsoiltypes)
other_treatments = setsoiltypes
# Calculate criteria
criteria = c((max(secondaryvars$sand,na.rm = TRUE)-
min(secondaryvars$sand,na.rm = TRUE))/10,
(max(secondaryvars$clay,na.rm = TRUE)-
min(secondaryvars$clay,na.rm = TRUE))/10)
# Run secondary matching on soils data
quals2 <- secondaryMatching(secondaryvars = secondaryvars, matches = quals,
subsetcells=subsetcells,subsetcells_id = "site_id",
subset_in_target = FALSE, criteria = criteria,
raster_template = raster_template,
reference_treatment = "1",
other_treatments = other_treatments)
# Interpolate simulation output to rasters
interpolatePoints(matches = quals2, output_results = output_results,
exclude_poor_matches = TRUE,
subset_cell_names = "subset_cell_secondary",
quality_name = "matching_quality",
matching_distance = 1.5,
raster_template = raster_template,
plotraster = TRUE,
saveraster = FALSE,
overwrite = FALSE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.