【问题标题】:Raster plot of Netcdf climate data is rotated in RNetcdf 气候数据的栅格图在 R 中旋转
【发布时间】:2017-04-20 11:09:57
【问题描述】:

我是使用 NetCDF 文件的新手,我无法在其他地方找到我的问题的答案。

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

我的问题:地图在 x 轴上显示 lat,在 y 轴上显示 long。如何翻转这些轴?此外,似乎纬度的值也是倒置的。 (见下面的链接地图)

    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

【问题讨论】:

    标签: r maps raster netcdf


    【解决方案1】:

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

    s <- stack("pr_2015.nc", varname="precipitation_amount")
    
    s2 <- t(flip(s, direction='y' ))
    

    【讨论】:

    • 感谢您的回答。我尝试了 s2,但我的计算机上的过程很慢,所以我退出了它。相反,这个替代版本成功了:flip(t(s),direction='x')
    【解决方案2】:

    您可以使用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)
    

    【讨论】:

      猜你喜欢
      • 2013-12-29
      • 2019-07-16
      • 1970-01-01
      • 2020-08-16
      • 1970-01-01
      • 2018-10-06
      • 1970-01-01
      • 2015-09-03
      • 2021-01-03
      相关资源
      最近更新 更多