Revision d0cf2921
Added by Jim Regetz over 12 years ago
- ID d0cf29217aa1d92b84e32735fa07d4bde1072089
terrain/research/oregon/arcgis/v2/multiscalesmooth9a_clean.R | ||
---|---|---|
82 | 82 |
} else { |
83 | 83 |
0 |
84 | 84 |
} |
85 |
z <- list(expand(ingrid, extent(
|
|
85 |
full.extent <- extent(
|
|
86 | 86 |
xmin(ingrid)-floor(addx)*xres(ingrid), |
87 | 87 |
xmax(ingrid)+ceiling(addx)*xres(ingrid), |
88 | 88 |
ymin(ingrid)-floor(addy)*yres(ingrid), |
89 | 89 |
ymax(ingrid)+ceiling(addy)*yres(ingrid) |
90 |
))) |
|
91 |
v <- list(calc(z[[1]], function(x) ifelse(!is.na(x), sd^2, NA))) |
|
90 |
) |
|
92 | 91 |
|
93 | 92 |
# create grids |
94 | 93 |
|
... | ... | |
96 | 95 |
# Also note that v0_bg is an uncertainty, not a sample variance |
97 | 96 |
# and v1_bg is total variances, but both are labelled as "between-group" to simplify the smoothing |
98 | 97 |
|
98 |
# create lists to hold the series of successively coarsened grids of |
|
99 |
# values and variances, respectively; the first element of each is |
|
100 |
# the grid at the original input resolution |
|
101 |
# ...insert initial grid of values, but expanded to full extent |
|
102 |
z <- list(expand(ingrid, full.extent)) |
|
103 |
# ...insert initial grid of variances |
|
104 |
if (is.numeric(sd) && length(sd)==1) { |
|
105 |
v <- list(calc(z[[1]], function(x) ifelse(!is.na(x), sd^2, NA))) |
|
106 |
} else if (class(sd)=="RasterLayer") { |
|
107 |
if (identical(extent(sd), extent(ingrid))) { |
|
108 |
v <- list(overlay(z[[1]], sd, fun=function(z, sd) |
|
109 |
ifelse(!is.na(z), sd^2, NA))) |
|
110 |
} else { |
|
111 |
stop("sd raster extent differs from ingrid extent") |
|
112 |
} |
|
113 |
} else { |
|
114 |
stop("sd must be a single number or a RasterLayer") |
|
115 |
} |
|
116 |
|
|
99 | 117 |
# set initial "group variance" to individual msmt variance (noise) |
100 | 118 |
v.g = v[[1]] |
101 | 119 |
# weighting for aggregation, based on total variance |
Also available in: Unified diff
enhanced smoother to accept sd as a raster, not just a constant