|
|
|
|
|
|
|
|
|
|
| require(raster)
|
| require(sf)
|
| require(data.table)
|
|
|
| gridsize = 0.25
|
|
|
|
|
|
|
| wind_west <- raster('../NatCap_temp/westcoastwind/output/npv_US_millions.tif')
|
|
|
| wind_east <- raster('../NatCap_temp/eastcoastwind/output/npv_US_millions.tif')
|
|
|
|
|
| grid <- readRDS('temp/SPsf2.rds')
|
|
|
|
|
| wind_east.t <- projectRaster(wind_east, crs=crs(grid))
|
| wind_west.t <- projectRaster(wind_west, crs=crs(grid))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| wind_east_dt <- data.table(cbind(coordinates(wind_east.t), npv=extract(x=wind_east.t, y=extent(wind_east.t))))
|
| wind_west_dt <- data.table(cbind(coordinates(wind_west.t), npv=extract(x=wind_west.t, y=extent(wind_west.t))))
|
| wind_dt <- rbind(wind_east_dt, wind_west_dt)
|
|
|
| wind_dt[, latgrid := floor(y/gridsize)*gridsize + gridsize/2]
|
| wind_dt[, longrid := floor(x/gridsize)*gridsize + gridsize/2]
|
|
|
| wind_sum <- wind_dt[, .(npv = mean(npv, na.rm = TRUE)), by = c('latgrid', 'longrid')]
|
|
|
|
|
| wind_sum[, plot(longrid, latgrid, col=c('red', 'blue')[1+(npv > 0)], pch=16, cex=0.05)]
|
| wind_sum[, plot(longrid, latgrid, col=c('red', 'blue')[1+(npv > 0)], pch=16, cex=0.5, xlim=c(-80, -60), ylim=c(40, 45))]
|
|
|
|
|
|
|
| grid$latgrid <- floor(grid$lat/gridsize)*gridsize + gridsize/2
|
| grid$longrid <- floor(grid$lon/gridsize)*gridsize + gridsize/2
|
| plot(grid$longrid, grid$latgrid, pch=16, cex=0.05)
|
|
|
| wind_sum[, keep := FALSE]
|
| wind_sum[paste(latgrid, longrid) %in% paste(grid$latgrid, grid$longrid), keep := TRUE]
|
| wind_sum[, sum(keep)]
|
| wind_sum[, sum(!keep)]
|
|
|
| wind_sum[keep == TRUE, plot(longrid, latgrid, col=c('red', 'blue')[1+(npv > 0)], pch=16, cex=0.25)]
|
| wind_sum[, plot(longrid, latgrid, col=c('red', 'blue')[keep+1], pch=16, cex=0.25)]
|
|
|
|
|
| wind.out <- wind_sum[keep == TRUE, .(lat = latgrid, lon = longrid, npv = npv)]
|
|
|
|
|
| minnpv <- wind.out[!is.na(npv), min(npv)]
|
| wind.out[is.na(npv), npv := minnpv]
|
|
|
| wind.out[, plot(lon, lat, col=c('red', 'blue')[1+(npv > 0)], pch=16, cex=0.25)]
|
|
|
|
|
| missing <- !(paste(grid$latgrid, grid$longrid) %in% wind.out[, paste(lat, lon)])
|
| sum(missing)
|
|
|
|
|
| write.csv(wind.out, gzfile('output/wind_npv.csv.gz'))
|
|
|
|
|
|
|
|
|
|
|
| require(raster)
|
| require(sf)
|
| require(data.table)
|
|
|
| gridsize = 0.25
|
|
|
|
|
| wave_west <- raster('../NatCap_temp/westcoastwave/output/npv_usd.tif')
|
|
|
| wave_east <- raster('../NatCap_temp/eastcoastwave/output/npv_usd.tif')
|
|
|
|
|
| grid <- readRDS('temp/SPsf2.rds')
|
|
|
|
|
| wave_east.t <- projectRaster(wave_east, crs=crs(grid))
|
| wave_west.t <- projectRaster(wave_west, crs=crs(grid))
|
|
|
|
|
|
|
| wave_west.t1 <- crop(wave_west.t, extent(165, 180, 40, 65))
|
| wave_west.t2 <- crop(wave_west.t, extent(-180, -100, 0, 90))
|
|
|
|
|
| wave_east_dt <- data.table(cbind(coordinates(wave_east.t), npv=extract(x=wave_east.t, y=extent(wave_east.t))))
|
| wave_west_dt1 <- data.table(cbind(coordinates(wave_west.t1), npv=extract(x=wave_west.t1, y=extent(wave_west.t1))))
|
| wave_west_dt2 <- data.table(cbind(coordinates(wave_west.t2), npv=extract(x=wave_west.t2, y=extent(wave_west.t2))))
|
| wave_dt <- rbind(wave_east_dt, wave_west_dt1, wave_west_dt2)
|
| nrow(wave_east_dt)
|
| nrow(wave_west_dt1)
|
| nrow(wave_west_dt2)
|
| nrow(wave_dt)
|
|
|
| wave_dt[, latgrid := floor(y/gridsize)*gridsize + gridsize/2]
|
| wave_dt[, longrid := floor(x/gridsize)*gridsize + gridsize/2]
|
|
|
| wave_sum <- wave_dt[, .(npv = mean(npv, na.rm = TRUE)), by = c('latgrid', 'longrid')]
|
| nrow(wave_sum)
|
|
|
|
|
| wave_sum[, plot(longrid, latgrid, col=c('red', 'blue')[1+(npv > 0)], pch=16, cex=0.05)]
|
|
|
|
|
|
|
| grid$latgrid <- floor(grid$lat/gridsize)*gridsize + gridsize/2
|
| grid$longrid <- floor(grid$lon/gridsize)*gridsize + gridsize/2
|
|
|
| wave_sum[, keep := FALSE]
|
| wave_sum[paste(latgrid, longrid) %in% paste(grid$latgrid, grid$longrid), keep := TRUE]
|
| wave_sum[, sum(keep)]
|
| wave_sum[, sum(!keep)]
|
|
|
| wave_sum[keep == TRUE, plot(longrid, latgrid, col=c('red', 'blue')[1+(npv > 0)], pch=16, cex=0.05)]
|
| wave_sum[, plot(longrid, latgrid, col=c('red', 'blue')[1+keep], pch=16, cex=0.05)]
|
|
|
|
|
| wave.out <- wave_sum[keep == TRUE, .(lat = latgrid, lon = longrid, npv = npv)]
|
|
|
|
|
| minnpv <- wave.out[!is.na(npv), min(npv)]
|
| wave.out[is.na(npv), npv := minnpv]
|
|
|
| wave.out[, plot(lon, lat, col=c('red', 'blue')[1+(npv > 0)], pch=16, cex=0.05)]
|
|
|
|
|
| missing <- !(paste(grid$latgrid, grid$longrid) %in% wave.out[, paste(lat, lon)])
|
| sum(missing)
|
|
|
|
|
| write.csv(wave.out, gzfile('output/wave_npv.csv.gz'))
|
|
|
|
|