Skip to content

Commit

Permalink
Test terrain calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-rohan-NOAA committed Mar 25, 2024
1 parent bd2f69f commit 45fed5f
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 2 deletions.
86 changes: 86 additions & 0 deletions derive_bathy_variables.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
library(akgfmaps)
library(MultiscaleDTM)

# 2023 Review: Queen case (3x3 neighborhood) for deriving seafloor terrain
neighbors <- 8
bpi_w = c(3, 64) # 2023 Review: AI and GOA Radius 3 x 65; EBS radius 3 x 64

x <- terra::rast(here::here("output", "efh_bathy", "efh_bathy_1km.tif"))

# SLOPE using terra ----
start1 <- Sys.time()
slope_t <- terra::terrain(x = x,
v = "slope",
unit = "degrees",
neighbors = neighbors)

# MultiscaleDTM: SLOPE (degrees), EASTNESS, AND NORTHNESS
# Queen case with window = 5
slope_aspect_dtm <- MultiscaleDTM::SlpAsp(r = x,
unit = "degrees", # Output units
w = c(5, 5),
method = "queen",
metrics = c("slope", "eastness", "northness"),
na.rm = TRUE)

# MultiscaleDTM: MEAN CURVATURE, PROFILE CURVATURE, SLOPE
# Derived from quadratic fit using OLS
curvature_slope_dtm <- MultiscaleDTM::Qfit(r = x,
unit = "degrees", # Output units
w = c(5, 5),
metrics = c("meanc", "profc", "qslope"),
na.rm = TRUE)

# MultiscaleDTM: BATHYMETRIC POSITION INDEX (BPI) ----
start1 <- Sys.time()
bpi_dtm <- MultiscaleDTM::BPI(r = x,
w = bpi_w,
unit = "cell", # Units for window
stand = "none",
na.rm = TRUE
)

end1 <- Sys.time()
difftime(end1, start1)


# Test 100-m resolution

x_100 <- terra::rast(here::here("output", "efh_bathy", "efh_bathy_100m.tif"))

# SLOPE using terra ----
start2 <- Sys.time()
slope_t <- terra::terrain(x = x_100,
v = "slope",
unit = "degrees",
neighbors = neighbors)

# MultiscaleDTM: SLOPE (degrees), EASTNESS, AND NORTHNESS
# Queen case with window = 5
slope_aspect_dtm <- MultiscaleDTM::SlpAsp(r = x_100,
unit = "degrees", # Output units
w = c(5, 5),
method = "queen",
metrics = c("slope", "eastness", "northness"),
na.rm = TRUE)

# MultiscaleDTM: MEAN CURVATURE, PROFILE CURVATURE, SLOPE
# Derived from quadratic fit using OLS
curvature_slope_dtm <- MultiscaleDTM::Qfit(r = x_100,
unit = "degrees", # Output units
w = c(5, 5),
metrics = c("meanc", "profc", "qslope"),
na.rm = TRUE)
diff(Sys.time(), start2)

# MultiscaleDTM: BATHYMETRIC POSITION INDEX (BPI) ----
start1 <- Sys.time()
bpi_dtm <- MultiscaleDTM::BPI(r = x_100,
w = bpi_w,
unit = "cell", # Units for window
stand = "none",
na.rm = TRUE
)

end2 <- Sys.time()
difftime(end2, start2)
10 changes: 8 additions & 2 deletions make_efh_bathymetry.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ library(akgfmaps)
library(reticulate)


dir.create(here::here("data", "efh_bathy"), recursive = TRUE)
dir.create(here::here("output", "efh_bathy"), recursive = TRUE)

# Transform GEBCO Z coordinates to match Alaska bathymetry (negative is up)
gebco <- terra::rast(here::here("data", "gebco_2023_n67.0_s54.0_w-175.0_e-154.0.tif"))
gebco <- gebco * -1
Expand All @@ -23,13 +26,16 @@ efh_bathy_trim <- terra::rast(here::here("data", "efh_bathy", "efh_bathy_100.tif

names(efh_bathy_trim) <- "depth"

terra::writeRaster(efh_bathy_trim, here::here("data", "efh_bathy", "efh_bathy_100m.tif"), overwrite = TRUE)
terra::writeRaster(efh_bathy_trim, here::here("output", "efh_bathy", "efh_bathy_100m.tif"), overwrite = TRUE)


# Resample the 100 m resolution grid to 1 km
efh_100m <- terra::rast(here::here("data", "efh_bathy", "efh_bathy_100m.tif"))

efh_1km <- terra::aggregate(efh_100m, fact = 10, fun = "mean")

terra::writeRaster(efh_1km, here::here("data", "efh_bathy", "efh_1km.tif"), overwrite = TRUE)
terra::writeRaster(efh_1km, here::here("output", "efh_bathy", "efh_bathy_1km.tif"), overwrite = TRUE)




File renamed without changes.

0 comments on commit 45fed5f

Please sign in to comment.