【发布时间】:2018-04-26 09:50:31
【问题描述】:
我有一个以下格式的栅格堆栈,我 converted to NetCDF using this method。这可行,但纬度和经度变量以“米”为单位,这是光栅文件的范围,我需要它们以十进制度为单位。 R Grid文件为here,格式如下:
class : RasterBrick
dimensions : 205, 170, 34850, 12 (nrow, ncol, ncell, nlayers)
resolution : 1, 1 (x, y)
extent : 160.5, 330.5, 145.5, 350.5 (xmin, xmax, ymin, ymax)
coord. ref. : NA
data source : \TavgM_1981.grd
names : Jan.1981, Feb.1981, Mar.1981, Apr.1981, May.1981, Jun.1981, Jul.1981, Aug.1981, Sep.1981, Oct.1981, Nov.1981, Dec.1981
min values : 1.9912137, 0.8120775, 4.0446638, 4.4135274, 6.5349769, 8.6149150, 9.9991916, 11.8400562, 9.6407796, 3.5005649, 4.1205872, -0.6106244
max values : 9.850221, 9.121176, 10.238524, 9.858942, 11.669445, 14.260988, 15.722292, 17.235090, 15.708690, 11.598482, 11.552235, 8.981533
time : Jan 1981, Feb 1981, Mar 1981, Apr 1981, May 1981, Jun 1981, Jul 1981, Aug 1981, Sep 1981, Oct 1981, Nov 1981, Dec 1981
理想情况下,我想将其转换为具有以下格式的 NetCDF 文件以供模型读取:
Dimensions: (lat: 408, lon: 881, nb2: 2, time: 660)
Coordinates:
* lon (lon) float64 -44.81 -44.69 -44.56 -44.44 -44.31 -44.19 ...
* lat (lat) float64 21.81 21.94 22.06 22.19 22.31 22.44 22.56 22.69 ...
* time (time) datetime64[ns] 1951-01-16T12:00:00 1951-02-16T12:00:00 ...
Dimensions without coordinates: nb2
Data variables:
time_bnds (time, nb2) datetime64[ns] 1951-01-16T12:00:00 ...
tas (time, lat, lon) float64 nan nan nan nan nan nan nan nan nan ...
我尝试使用此方法将光栅砖范围转换为纬度/经度:
sputm <- SpatialPoints(test@extent@xmin, proj4string=CRS("+proj=utm +zone=29N +datum=WGS84"))
但这给出了这个错误:
Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘coordinates’ for signature ‘"numeric"’
编辑: 也试过了
crs(test) <- '+proj=merc +datum=WGS84'
x <- projectRaster(test, crs='+proj=longlat +datum=WGS84')
writeRaster(x, "rstack2.nc", overwrite=TRUE, format="CDF", varname="Temperature", varunit="degC",
longname="Temperature -- raster stack to netCDF", xname="Longitude", yname="Latitude", zname="Time (Month)")
但是当我在 panoply 中检查这个时,纬度和经度坐标都是 0.0。
我不知道从这里去哪里。
【问题讨论】:
-
原始 RasterBrick 的尺寸很奇怪。这真的是 1*1m 分辨率吗?在您的编辑中,您强制原始 CRS 为墨卡托。你怎么知道是这种情况?您没有原始文件的任何元数据来了解真正的 CRS 吗?我无法使用下载的文件,因为它缺少“.grd”文件。您也可以将其保存为“.tif”,以便我们进行测试。
-
顺便说一句,您的“编辑”就是这样做的方法。你只需要知道真正的原始CRS
-
谢谢 - 我已联系数据源以获取原始 CRS - 我拥有的文件中唯一的元数据是上面打印的内容(尺寸和范围) - 希望我能够获得更多.数据应该是一个 2.5 公里的水平网格。我已经添加了.grd file here - 但我认为不可能从中获得 CRS?也许是?
标签: r raster netcdf r-raster ncdf4