Netcdf 气候数据的栅格图在 R 中旋转

Raster plot of Netcdf climate data is rotated in R

我刚开始使用 NetCDF 文件,我无法在其他地方找到问题的答案。

2015 年每日降水数据(来自 Gridmet):https://www.northwestknowledge.net/metdata/data/pr_2015.nc

我的问题:地图显示的 x 轴为纬度,y 轴为经度。如何翻转这些轴?此外,纬度值似乎也颠倒了。 (见下面的链接地图)

    library(raster)
    library(ncdf4)
    nc15 <- nc_open("C:\Users\vsteen\Desktop\BorealToad\Climate\pr_2015.nc")        
    b <- brick("C:\Users\vsteen\Desktop\BorealToad\Climate\pr_2015.nc",varname="precipitation_amount")
    plot(b[[3]])



    print(nc15)
 1 variables (excluding dimension variables):
    float precipitation_amount[lat,lon,day]   
        units: mm
        description: Daily Accumulated Precipitation
        _FillValue: -32767
        esri_pe_string: GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]]
        coordinates: lon lat
        cell_methods: time: sum(interval: 24 hours)
        missing_value: -32767

 3 dimensions:
    lon  Size:1386
        units: degrees_east
        description: longitude
    lat  Size:585
        units: degrees_north
        description: latitude
    day  Size:365
        units: days since 1900-01-01 00:00:00
        calendar: gregorian
        description: days since 1900-01-01

9 global attributes:
    author: John Abatzoglou - University of Idaho, jabatzoglou@uidaho.edu
    date: 20 September 2016
    note1: The projection information for this file is: GCS WGS 1984.
    note2: Citation: Abatzoglou, J.T., 2013, Development of gridded surface meteorological data for ecological applications and modeling, International Journal of Climatology, DOI: 10.1002/joc.3413
    last_permanent_slice: 365
    last_early_slice: 365
    note3: Data in slices after last_permanent_slice (1-based) are considered provisional and subject to change with subsequent updates
    note4: Data in slices after last_early_slice (1-based) are considered early and subject to change with subsequent updates
    note5: Days correspond approximately to calendar days ending at midnight, Mountain Standard Time (7 UTC the next calendar day)

    str(nc15$dim)

    List of 3
    $ lon:List of 10
    ..$ name         : chr "lon"
    ..$ len          : int 1386
    ..$ unlim        : logi FALSE
    ..$ group_index  : int 1
    ..$ group_id     : int 65536
    ..$ id           : int 0
    ..$ dimvarid     :List of 5
    .. ..$ id         : int 0
    .. ..$ group_index: int 1
    .. ..$ group_id   : int 65536
    .. ..$ list_index : num -1
    .. ..$ isdimvar   : logi TRUE
    .. ..- attr(*, "class")= chr "ncid4"
    ..$ units        : chr "degrees_east"
    ..$ vals         : num [1:1386(1d)] -125 -125 -125 -125 -125 ...
    ..$ create_dimvar: logi TRUE
    ..- attr(*, "class")= chr "ncdim4"
   $ lat:List of 10
    ..$ name         : chr "lat"
    ..$ len          : int 585
    ..$ unlim        : logi FALSE
    ..$ group_index  : int 1
    ..$ group_id     : int 65536
    ..$ id           : int 1
    ..$ dimvarid     :List of 5
    .. ..$ id         : int 1
    .. ..$ group_index: int 1
    .. ..$ group_id   : int 65536
    .. ..$ list_index : num -1
    .. ..$ isdimvar   : logi TRUE
    .. ..- attr(*, "class")= chr "ncid4"
    ..$ units        : chr "degrees_north"
    ..$ vals         : num [1:585(1d)] 49.4 49.4 49.3 49.3 49.2 ...
    ..$ create_dimvar: logi TRUE
    ..- attr(*, "class")= chr "ncdim4"
   $ day:List of 11
    ..$ name         : chr "day"
    ..$ len          : int 365
    ..$ unlim        : logi FALSE
    ..$ group_index  : int 1
    ..$ group_id     : int 65536
    ..$ id           : int 2
    ..$ dimvarid     :List of 5
    .. ..$ id         : int 2
    .. ..$ group_index: int 1
    .. ..$ group_id   : int 65536
    .. ..$ list_index : num -1
    .. ..$ isdimvar   : logi TRUE
    .. ..- attr(*, "class")= chr "ncid4"
    ..$ units        : chr "days since 1900-01-01 00:00:00"
    ..$ calendar     : chr "gregorian"
    ..$ vals         : num [1:365(1d)] 42003 42004 42005 42006 42007 ...
    ..$ create_dimvar: logi TRUE
    ..- attr(*, "class")= chr "ncdim4"
  >

在此先感谢您的帮助。将不胜感激!

Rotated U.S. precipitation map

您可以使用光栅包中的 transposeflip 的组合:

s <- stack("pr_2015.nc", varname="precipitation_amount")

s2 <- t(flip(s, direction='y' ))

您可以使用stars包直接从netcdf文件中读取数据,没有“旋转”问题。

library(stars)

s2 <- read_ncdf("pr_2015.nc", var = "precipitation_amount")

这是时间序列中第一张图片的绘图,只是为了展示如何使用 read_ncdf(没有旋转)读取图片。

# Chose the first image from the time series
s2<- s2[,,,1]
# Plot to see it
plot(s2)