R terra/raster: 上传 netcdf 文件会改变分辨率

huangapple go评论76阅读模式
英文:

R terra/raster: uploading a netcdf file alters resolution

问题

I have netcdf files (GPM IMERG precipitation) which are supposed to be at 0.1x0.1 resolution like in the red box at the bottom here:

Well the pixel size is not exactly 0.1 on the image, but at least its height and width are the same.

However when uploading the netcdf via terra:: or raster:: the resolution slightly changes:

class       : SpatRaster 
dimensions  : 185, 97, 1  (nrow, ncol, nlyr)
resolution  : 0.09999998, 0.1000001  (x, y)
extent      : 34.2, 43.9, 62.3, 80.80002  (xmin, xmax, ymin, ymax)
coord. ref. : lon/lat WGS 84 
source      : _(1).nc:precipitationCal 
varname     : precipitationCal (Daily accumulated precipitation (combined microwave-IR) estimate) 
name        : precipitationCal 
unit        :               mm 
time (days) : 2000-06-04 

Any solution on how to transform the rasters in R back to their original resolution would be welcomed. Btw, does this has to do with rounding coordinates of the extent in R packages?

英文:

I have netcdf files (GPM IMERG precipitation) which are supposed to be at0.1x0.1 resolution like in the red box at the bottom here:

R terra/raster: 上传 netcdf 文件会改变分辨率

Well the pixel size is not exactly 0.1 on the image, but at least its height and width are the same.

However when uploading the netcdf via terra:: or raster:: the resolution slightly changes:

class       : SpatRaster 
dimensions  : 185, 97, 1  (nrow, ncol, nlyr)
resolution  : 0.09999998, 0.1000001  (x, y)
extent      : 34.2, 43.9, 62.3, 80.80002  (xmin, xmax, ymin, ymax)
coord. ref. : lon/lat WGS 84 
source      : _(1).nc:precipitationCal 
varname     : precipitationCal (Daily accumulated precipitation (combined microwave-IR) estimate) 
name        : precipitationCal 
unit        :               mm 
time (days) : 2000-06-04 

Any solution on how to transform the rasters in R back to their original resolution would be welcomed. Btw, does this has to do with rounding coordinates of the extent in R packages?

答案1

得分: 1

以下是您提供的翻译:

你能指向那个文件吗?据我所见,网站上显示的范围或分辨率要么是错误的。根据这些数字,应该是:

print((43.9000038 - 34.20000855) / 97, digits=10)
#[1] 0.09999995103

也许网站上的分辨率是使用单元格的中心计算的,所以你会得到

print((43.95 - 34.15) / 97, digits=10)
#[1] 0.1010309582

没有文件很难确定。但我会把赌注押在网站上是错的。


通过您的文件,我还看到了这个

f <- "__1_.nc"
r <- rast(f)
res(r)
#[1] 0.09999998 0.10000007

但从写入文件的角度来看,这是正确的。提供的单元格的x和y坐标并不严格规则(但几乎如此)。例如,这是前三个和后三个y坐标:

62.3500022888184 62.4500083923340 62.5499992370605 ...  
80.5500030517578 80.6500091552734 80.7500152587891

光从文件本身来看,我无法确定这些小数是否是有意的还是粗心造成的,我认为是后者,在这种情况下,四舍五入范围似乎是合理的:

ext(r) <- round(ext(r), 4)
r
#class       : SpatRaster 
#dimensions  : 185, 97, 1  (nrow, ncol, nlyr)
#resolution  : 0.1, 0.1  (x, y)
#extent      : 34.2, 43.9, 62.3, 80.8  (xmin, xmax, ymin, ymax)
#coord. ref. : lon/lat WGS 84 
#source      : __1_.nc:precipitationCal 
#varname     : precipitationCal (Daily accumulated precipitation #(combined microwave-IR) estimate) 
#name        : precipitationCal 
#unit        :               mm 
#time (days) : 2000-06-04 
英文:

Can you point to that file? From what I can see, either the extent or the resolution shown on the website is wrong. Based on these numbers, it should be:

print((43.9000038 - 34.20000855) / 97, digits=10)
#[1] 0.09999995103

Perhaps for the website the resolution was computed using the center of the cells, so that you get

print((43.95 - 34.15) / 97, digits=10)
#[1] 0.1010309582

It is hard to be sure without the file. But I would put my money on the website being wrong.


With your file I also see this

f <- "__1_.nc"
r <- rast(f)
res(r)
#[1] 0.09999998 0.10000007

But that is correct in the sense that that does reflect the x and y coordinates written to the file. The x and y coordinates for the cells that are provided are not strictly regular (but nearly so). For example, here are the first and last three y coordinates:

62.3500022888184 62.4500083923340 62.5499992370605 ...  
80.5500030517578 80.6500091552734 80.7500152587891

From the file alone I cannot say whether these small decimals are intentional or stem from sloppiness, I assume the latter and in that case it indeed seems reasonable to round the extent:

ext(r) <- round(ext(r), 4)
r
#class       : SpatRaster 
#dimensions  : 185, 97, 1  (nrow, ncol, nlyr)
#resolution  : 0.1, 0.1  (x, y)
#extent      : 34.2, 43.9, 62.3, 80.8  (xmin, xmax, ymin, ymax)
#coord. ref. : lon/lat WGS 84 
#source      : __1_.nc:precipitationCal 
#varname     : precipitationCal (Daily accumulated precipitation #(combined microwave-IR) estimate) 
#name        : precipitationCal 
#unit        :               mm 
#time (days) : 2000-06-04 

答案2

得分: 0

以下是翻译好的部分:

似乎修正了范围边界后,分辨率得到了纠正。以下是上传文件后的文件范围:

r<-rast("file")
ext(r)

SpatExtent : 34.2000038226446, 43.9000022808711, 62.3000022535739, 80.8000152940335 (xmin, xmax, ymin, ymax)

我已经将范围坐标的小数部分四舍五入,分辨率得到了纠正:

ext(r)<-c(34.2, 43.9, 62.3, 80.8)

r

class       : SpatRaster 
dimensions  : 185, 97, 1  (nrow, ncol, nlyr)
resolution  : 0.1, 0.1  (x, y)
extent      : 34.2, 43.9, 62.3, 80.8  (xmin, xmax, ymin, ymax)
coord. ref. : lon/lat WGS 84 
source      : _(1).nc:precipitationCal 
varname     : precipitationCal (Daily accumulated precipitation (combined microwave-IR) estimate) 
name        : precipitationCal 
unit        :               mm 
time (days) : 2000-06-04 
英文:

It seems that amending the extent boundaries corrects the resolution. Here is an extent of the file after uploading:

r&lt;-rast(&quot;file&quot;)
ext(r)

SpatExtent : 34.2000038226446, 43.9000022808711, 62.3000022535739, 80.8000152940335 (xmin, xmax, ymin, ymax)

Ive rounded the decimals of the extent coordinates and the resolution was coreccted:

ext(r)&lt;-c(34.2, 43.9, 62.3, 80.8)

r

class       : SpatRaster 
dimensions  : 185, 97, 1  (nrow, ncol, nlyr)
resolution  : 0.1, 0.1  (x, y)
extent      : 34.2, 43.9, 62.3, 80.8  (xmin, xmax, ymin, ymax)
coord. ref. : lon/lat WGS 84 
source      : _(1).nc:precipitationCal 
varname     : precipitationCal (Daily accumulated precipitation (combined microwave-IR) estimate) 
name        : precipitationCal 
unit        :               mm 
time (days) : 2000-06-04 

huangapple
  • 本文由 发表于 2023年5月18日 00:24:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76274246.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定