library(terra)
library(tidyverse)
####Matlab数据在R语言中进行翻转####
####标准的翻转过程#####
pre <- rast("E:/future_climate/青藏高原中心/126/CanESM5_126_pr.nc")
#提取其中一年
prey <- app(terra::subset(pre, 1827:2192), fun = sum, na.rm = TRUE,cores=12)
plot(prey)
#set CRS
crs(prey) <- "EPSG:4326"
# #> prey
# class : SpatRaster
# dimensions : 296, 141, 1 (nrow, ncol, nlyr)
# resolution : -0.1089057, 0.1089057 (x, y)
# extent : 40.8365, 25.4808, 73.40403, 105.6401 (xmin, xmax, ymin, ymax)
# coord. ref. : lon/lat WGS 84 (EPSG:4326)
# source(s) : memory
# name : sum
# min value : 45.9
# max value : 5249.3
###从图形上看,值的横纵坐标要进行互相。
prey2 <- t(flip(prey, direction='v'))
plot(prey2)
# #prey2
# > prey2
# class : SpatRaster
# dimensions : 141, 296,