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

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

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:

  1. class : SpatRaster
  2. dimensions : 185, 97, 1 (nrow, ncol, nlyr)
  3. resolution : 0.09999998, 0.1000001 (x, y)
  4. extent : 34.2, 43.9, 62.3, 80.80002 (xmin, xmax, ymin, ymax)
  5. coord. ref. : lon/lat WGS 84
  6. source : _(1).nc:precipitationCal
  7. varname : precipitationCal (Daily accumulated precipitation (combined microwave-IR) estimate)
  8. name : precipitationCal
  9. unit : mm
  10. 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:

  1. class : SpatRaster
  2. dimensions : 185, 97, 1 (nrow, ncol, nlyr)
  3. resolution : 0.09999998, 0.1000001 (x, y)
  4. extent : 34.2, 43.9, 62.3, 80.80002 (xmin, xmax, ymin, ymax)
  5. coord. ref. : lon/lat WGS 84
  6. source : _(1).nc:precipitationCal
  7. varname : precipitationCal (Daily accumulated precipitation (combined microwave-IR) estimate)
  8. name : precipitationCal
  9. unit : mm
  10. 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

以下是您提供的翻译:

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

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

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

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

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


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

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

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

  1. 62.3500022888184 62.4500083923340 62.5499992370605 ...
  2. 80.5500030517578 80.6500091552734 80.7500152587891

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

  1. ext(r) <- round(ext(r), 4)
  2. r
  3. #class : SpatRaster
  4. #dimensions : 185, 97, 1 (nrow, ncol, nlyr)
  5. #resolution : 0.1, 0.1 (x, y)
  6. #extent : 34.2, 43.9, 62.3, 80.8 (xmin, xmax, ymin, ymax)
  7. #coord. ref. : lon/lat WGS 84
  8. #source : __1_.nc:precipitationCal
  9. #varname : precipitationCal (Daily accumulated precipitation #(combined microwave-IR) estimate)
  10. #name : precipitationCal
  11. #unit : mm
  12. #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:

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

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

  1. print((43.95 - 34.15) / 97, digits=10)
  2. #[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

  1. f <- "__1_.nc"
  2. r <- rast(f)
  3. res(r)
  4. #[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:

  1. 62.3500022888184 62.4500083923340 62.5499992370605 ...
  2. 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:

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

答案2

得分: 0

以下是翻译好的部分:

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

  1. r<-rast("file")
  2. ext(r)
  3. SpatExtent : 34.2000038226446, 43.9000022808711, 62.3000022535739, 80.8000152940335 (xmin, xmax, ymin, ymax)

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

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

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

  1. r&lt;-rast(&quot;file&quot;)
  2. ext(r)
  3. 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:

  1. ext(r)&lt;-c(34.2, 43.9, 62.3, 80.8)
  2. r
  3. class : SpatRaster
  4. dimensions : 185, 97, 1 (nrow, ncol, nlyr)
  5. resolution : 0.1, 0.1 (x, y)
  6. extent : 34.2, 43.9, 62.3, 80.8 (xmin, xmax, ymin, ymax)
  7. coord. ref. : lon/lat WGS 84
  8. source : _(1).nc:precipitationCal
  9. varname : precipitationCal (Daily accumulated precipitation (combined microwave-IR) estimate)
  10. name : precipitationCal
  11. unit : mm
  12. 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:

确定