Skip to content

Commit 76ef8f2

Browse files
authored
Merge pull request #288 from jiajic/patch_raster_loading
fix: terra rast() noflip
2 parents 1111b02 + 1388325 commit 76ef8f2

9 files changed

+40
-48
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Imports:
4141
methods,
4242
reticulate (>= 1.25),
4343
stats,
44-
terra (>= 1.7-41)
44+
terra (>= 1.8-21)
4545
Suggests:
4646
Biobase,
4747
chihaya,

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
- replace internal usage of deprecated create_spat_net_obj -> createSpatNetObj and set_spatialNetwork -> setSpatialNetwork when calculating spatial networks.
1515
- fix `createGiottoPolygon()` not preserving attributes from `data.table` inputs
1616
- fix `loadGiotto()` error when a non-expected reticulate environment is already activated in the session
17+
- fix `createGiottoLargeImage()` and `createGiottoPolygonsFromMask()` to align with {terra} `v1.8-21` `rast(noflip = TRUE)` [#1102](https://github.com/drieslab/Giotto/issues/1102) by StevenWijnen and rbutleriii
1718

1819
## changes
1920
- move {magick} from imports to suggests
21+
- {terra} `>=v1.8-21`
2022

2123
## enhancements
2224
- `[[` can now be used to select channels in `giottoLargeImage`-inheriting objects

R/create.R

+19-15
Original file line numberDiff line numberDiff line change
@@ -2363,7 +2363,7 @@ setMethod(
23632363
# try failure means it should be vector file
23642364
try_rast <- tryCatch(
23652365
{
2366-
terra::rast(x)
2366+
.create_terra_spatraster(x)
23672367
},
23682368
error = function(e) {
23692369
return(invisible(NULL))
@@ -2426,10 +2426,10 @@ setMethod(
24262426
fill_holes = TRUE,
24272427
poly_IDs = NULL,
24282428
ID_fmt = "cell_",
2429-
flip_vertical = TRUE,
2430-
shift_vertical_step = TRUE,
2431-
flip_horizontal = TRUE,
2432-
shift_horizontal_step = TRUE,
2429+
flip_vertical = FALSE,
2430+
shift_vertical_step = FALSE,
2431+
flip_horizontal = FALSE,
2432+
shift_horizontal_step = FALSE,
24332433
remove_unvalid_polygons = TRUE,
24342434
calc_centroids = FALSE,
24352435
verbose = TRUE) {
@@ -2493,10 +2493,12 @@ setMethod(
24932493
#' each polygon in the mask file.
24942494
#' @param ID_fmt character. Only applied if `poly_IDs = NULL`. Naming scheme for
24952495
#' poly_IDs. Default = "cell_". See *ID_fmt* section.
2496-
#' @param flip_vertical flip mask figure in a vertical manner
2497-
#' @param shift_vertical_step shift vertical (boolean or numerical)
2498-
#' @param flip_horizontal flip mask figure in a horizontal manner
2499-
#' @param shift_horizontal_step shift horizontal (boolean or numerical)
2496+
#' @param flip_vertical,flip_horizontal logical. Flip output polygons across y
2497+
#' (vertical) or x (horizontal) axis.
2498+
#' @param shift_vertical_step,shift_horizontal_step logical or numeric. When
2499+
#' `FALSE`, no shift is performed. When numeric, a shift of
2500+
#' \eqn{image height \times step} (vertical) or \eqn{image width \times step}
2501+
#' (horizontal) is performed.
25002502
#' @param remove_unvalid_polygons remove unvalid polygons (default: TRUE)
25012503
#' @concept mask polygon
25022504
#' @section mask_method:
@@ -2532,10 +2534,10 @@ createGiottoPolygonsFromMask <- function(
25322534
fill_holes = TRUE,
25332535
poly_IDs = NULL,
25342536
ID_fmt = "cell_",
2535-
flip_vertical = TRUE,
2536-
shift_vertical_step = TRUE,
2537-
flip_horizontal = TRUE,
2538-
shift_horizontal_step = TRUE,
2537+
flip_vertical = FALSE,
2538+
shift_vertical_step = FALSE,
2539+
flip_horizontal = FALSE,
2540+
shift_horizontal_step = FALSE,
25392541
calc_centroids = FALSE,
25402542
remove_unvalid_polygons = TRUE,
25412543
verbose = FALSE) {
@@ -2593,10 +2595,12 @@ createGiottoPolygonsFromMask <- function(
25932595

25942596
## flip across axes ##
25952597
if (isTRUE(flip_vertical)) {
2596-
terra_polygon <- .flip_spatvect(terra_polygon)
2598+
terra_polygon <- .flip_spatvect(terra_polygon,
2599+
direction = "vertical")
25972600
}
25982601
if (isTRUE(flip_horizontal)) {
2599-
terra_polygon <- .flip_spatvect(terra_polygon)
2602+
terra_polygon <- .flip_spatvect(terra_polygon,
2603+
direction = "horizontal")
26002604
}
26012605

26022606
# convert to DT format since we want to be able to compare number of geoms

R/images.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ reconnect_giottoImage_MG <- function(
682682
#' @keywords internal
683683
#' @returns spatRaster object
684684
.create_terra_spatraster <- function(image_path) {
685-
raster_object <- try(handle_warnings(terra::rast(x = image_path))$result)
685+
raster_object <- try(terra::rast(x = image_path, noflip = TRUE))
686686
if (inherits(raster_object, "try-error")) {
687687
stop(raster_object, " can not be read by terra::rast() \n")
688688
}

R/interoperability.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -2509,7 +2509,7 @@ seuratToGiottoV5 <- function(sobject,
25092509

25102510

25112511

2512-
# Find SueratImages, extract them, and pass to create image
2512+
# Find SeuratImages, extract them, and pass to create image
25132513
image_list <- list()
25142514
for (i in names(sobject@images)) {
25152515
simg <- sobject[[i]]

R/methods-flip.R

-12
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,6 @@ setMethod(
163163
}
164164
)
165165

166-
#' @rdname flip
167-
#' @export
168-
setMethod("flip", signature("giottoLargeImage"), function(x, direction = "vertical", x0 = 0, y0 = 0) {
169-
a <- get_args_list()
170-
a$x <- as(x, "giottoAffineImage") # convert to giottoAffineImage
171-
res <- do.call(flip, args = a)
172-
return(res)
173-
})
174-
175166
#' @rdname flip
176167
#' @export
177168
setMethod("flip", signature("giottoAffineImage"), function(x, direction = "vertical", x0 = 0, y0 = 0) {
@@ -367,9 +358,6 @@ setMethod("flip", signature("affine2d"), function(x, direction = "vertical", x0
367358

368359
#' @name .flip_large_image
369360
#' @title Flip a giottoLargeImage object
370-
#' @description Flip a giottoPoints over a designated x or y value depending on
371-
#' direction param input. Note that this behavior is different from terra's
372-
#' implementation of flip for SpatVectors where flips happen over the extent
373361
#' @param image giottoLargeImage
374362
#' @param direction character. Direction to flip. Should be either partial
375363
#' match to 'vertical' or 'horizontal'

man/createGiottoPolygon.Rd

+14-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/flip.Rd

+1-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/relate.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)