Skip to content

Instantly share code, notes, and snippets.

@coolbutuseless
Last active June 6, 2020 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coolbutuseless/2bdaa9a28c5da30ba86f09b701022899 to your computer and use it in GitHub Desktop.
Save coolbutuseless/2bdaa9a28c5da30ba86f09b701022899 to your computer and use it in GitHub Desktop.
ceramic test
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Define the extents of the image
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
roi <- raster::extent(110, 160, -45, -12)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Grab the satellite image and the elevation map
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
im <- ceramic::cc_location(roi)
el <- ceramic::cc_elevation(roi)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Extract the raw image data
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
imdata <- im@data@values
imdata <- array(as.vector(imdata), dim = c(im@ncols, im@nrows, 3))
imdata <- aperm(imdata, c(2, 1, 3))
imdata <- imdata/255
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Extract the raw elevation data into
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
el2 <- el
# el2 <- raster::resample(el2, im) # results in some NA values
# el2 <- raster::aggregate(el2, 2) # doesn't result in an exact size match with 'im'
# res(el2) <- res(im) # results in all NA values. Still not an exact size match
# dim(el2) <- dim(im)[1:2] # results in all NAs
eldata <- matrix(el2@data@values, nrow = el2@ncols, ncol = el2@nrows)
eldata <- t(eldata)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# These two data objects are different sizes!
# The elevation data, is almost but now quite 2x the
# resolution of the image data. What's the best way to align their dimensions?
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dim(imdata)
dim(eldata)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment