如何使用R中的“ggOceanMaps”包来修复浅海地形分辨率较差?

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

How to fix poor bathymetry resolution using "ggOceanMaps" package in R?

问题

我正在使用R中的ggOceanMaps,并尝试创建一个显示南加利福尼亚的海底地形数据的地图。然而,海底地形数据显示模糊,这让我认为这个包可能没有足够好的海底地形数据来制作一个特定区域的放大地图。有没有人知道这个问题是否可以解决,或者我应该使用另一个包?

这是我使用的代码:

dt <- data.frame(lon = c(-125, -125, -111, -111), lat = c(28, 37, 37, 28))

basemap(data = dt, bathymetry = TRUE) 

我得到了一个漂亮的地图,但海底地形分辨率不好。

英文:

I am using ggOceanMaps in R and I tried to create a map of Southern California with bathymetry data. However, the bathymetry is blurred out, which makes me think the package does not have good bathymetry data to make a close-up map of a given area. Does anyone know if the problem can be fixed or if I should use another package?

This is the code I used:

dt <- data.frame(lon = c(-125, -125, -111, -111), lat = c(28, 37, 37, 28))

basemap(data = dt, bathymetry = TRUE)

I got a nice map but with bad bathymetric resolution.

答案1

得分: 1

使用 ggOceanMaps 的新版本(2.0;希望很快可以在CRAN上找到),您可以绘制高达15秒弧分辨率的栅格海底地形:

library(ggOceanMaps)
#&gt; Loading required package: ggplot2
#&gt; ggOceanMaps: Setting data download folder to a temporary folder
#&gt; /var/folders/9v/b70pd53x04d3jjmlrbcgp4_w0000gv/T//RtmpjBq0J0. This
#&gt; means that any downloaded map data need to be downloaded again when you
#&gt; restart R. To avoid this problem, change the default path to a
#&gt; permanent folder on your computer. Add following lines to your
#&gt; .Rprofile file: {.ggOceanMapsenv &lt;- new.env(); .ggOceanMapsenv$datapath
#&gt; &lt;- &#39;YourCustomPath&#39;}. You can use usethis::edit_r_profile() to edit the
#&gt; file.&#39;~/Documents/ggOceanMapsLargeData&#39;would make it in a writable
#&gt; folder on most operating systems.
options(ggOceanMaps.datapath = &quot;~/Documents/ggOceanMapsLargeData&quot;)

packageVersion(&quot;ggOceanMaps&quot;)
#&gt; [1] &#39;2.0.0&#39;

dt &lt;- data.frame(lon = c(-125, -125, -111, -111), lat = c(28, 37, 37, 28))
basemap(data = dt, bathymetry = TRUE, bathy.style = &quot;rcb&quot;)

如何使用R中的“ggOceanMaps”包来修复浅海地形分辨率较差?<!-- -->

您可以使用任何栅格数据,例如marmap来下载ETOPO栅格数据,分辨率高达15秒弧分辨率(查看marmap::getNOAA.bathy()中的resolution参数):

library(marmap); library(stars); library(sf)
#&gt; Registered S3 methods overwritten by &#39;adehabitatMA&#39;:
#&gt;   method                       from
#&gt;   print.SpatialPixelsDataFrame sp  
#&gt;   print.SpatialPixels          sp
#&gt; 
#&gt; Attaching package: &#39;marmap&#39;
#&gt; The following object is masked from &#39;package:grDevices&#39;:
#&gt; 
#&gt;     as.raster
#&gt; Loading required package: abind
#&gt; Loading required package: sf
#&gt; Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE

limits &lt;- auto_limits(dt, expand.factor = 1.1)$projLimits
bm &lt;- basemap(data = dt)

mar_bathy &lt;- marmap::getNOAA.bathy(lon1 = limits[&quot;xmin&quot;], lon2 = limits[&quot;xmax&quot;], lat1 = limits[&quot;ymin&quot;], lat2 = limits[&quot;ymax&quot;])
#&gt; Querying NOAA database ...
#&gt; This may take seconds to minutes, depending on grid size
#&gt; Building bathy matrix ...
bathy &lt;- raster_bathymetry(stars::st_as_stars(marmap::as.raster(mar_bathy)), depths = NULL)
#&gt;   |                                                                              |                                                                      |   0%  |                                                                              |=========                                                             |  12%  |                                                                              |==================                                                    |  25%  |                                                                              |==========================                                            |  38%  |                                                                              |===================================                                   |  50%  |                                                                              |============================================                          |  62%  |                                                                              |====================================================                  |  75%  |                                                                              |=============================================================         |  88%  |                                                                              |======================================================================| 100%

p &lt;- bm + 
  stars::geom_stars(data = bathy$raster) +
  ggplot2::scale_fill_gradientn(
    name = &quot;Depth (m)&quot;, breaks = seq(0,5e3,1e3), limits = c(0,NA), 
    colors = colorRampPalette(c(&quot;#F7FBFF&quot;, &quot;#DEEBF7&quot;, &quot;#9ECAE1&quot;, &quot;#4292C6&quot;, &quot;#08306B&quot;))(8)
  )

reorder_layers(p)

如何使用R中的“ggOceanMaps”包来修复浅海地形分辨率较差?<!-- -->

至于其他选择,您还可以使用marmap包绘制海底地形图:

marmap::autoplot.bathy(mar_bathy, geom=c(&quot;r&quot;, &quot;c&quot;), colour=&quot;white&quot;, size=0.1) + marmap::scale_fill_etopo()
#&gt; Warning in ggplot2::geom_raster(ggplot2::aes_string(fill = &quot;z&quot;), ...): Ignoring
#&gt; unknown parameters: `colour` and `size`

如何使用R中的“ggOceanMaps”包来修复浅海地形分辨率较差?<!-- -->

<sup>创建于2023年6月30日,使用reprex v2.0.2</sup>

英文:

With the new version of ggOceanMaps (2.0; hopefully soon on CRAN), you can plot raster bathymetries up to 15 arc-second resolution:

library(ggOceanMaps)
#&gt; Loading required package: ggplot2
#&gt; ggOceanMaps: Setting data download folder to a temporary folder
#&gt; /var/folders/9v/b70pd53x04d3jjmlrbcgp4_w0000gv/T//RtmpjBq0J0. This
#&gt; means that any downloaded map data need to be downloaded again when you
#&gt; restart R. To avoid this problem, change the default path to a
#&gt; permanent folder on your computer. Add following lines to your
#&gt; .Rprofile file: {.ggOceanMapsenv &lt;- new.env(); .ggOceanMapsenv$datapath
#&gt; &lt;- &#39;YourCustomPath&#39;}. You can use usethis::edit_r_profile() to edit the
#&gt; file.&#39;~/Documents/ggOceanMapsLargeData&#39;would make it in a writable
#&gt; folder on most operating systems.
options(ggOceanMaps.datapath = &quot;~/Documents/ggOceanMapsLargeData&quot;)

packageVersion(&quot;ggOceanMaps&quot;)
#&gt; [1] &#39;2.0.0&#39;

dt &lt;- data.frame(lon = c(-125, -125, -111, -111), lat = c(28, 37, 37, 28))
basemap(data = dt, bathymetry = TRUE, bathy.style = &quot;rcb&quot;)

如何使用R中的“ggOceanMaps”包来修复浅海地形分辨率较差?<!-- -->

You can use any raster data, for example, marmap to download ETOPO raster data up to 15 arc-second resolution (see the resolution argument in marmap::getNOAA.bathy())

library(marmap); library(stars); library(sf)
#&gt; Registered S3 methods overwritten by &#39;adehabitatMA&#39;:
#&gt;   method                       from
#&gt;   print.SpatialPixelsDataFrame sp  
#&gt;   print.SpatialPixels          sp
#&gt; 
#&gt; Attaching package: &#39;marmap&#39;
#&gt; The following object is masked from &#39;package:grDevices&#39;:
#&gt; 
#&gt;     as.raster
#&gt; Loading required package: abind
#&gt; Loading required package: sf
#&gt; Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE

limits &lt;- auto_limits(dt, expand.factor = 1.1)$projLimits
bm &lt;- basemap(data = dt)

mar_bathy &lt;- marmap::getNOAA.bathy(lon1 = limits[&quot;xmin&quot;], lon2 = limits[&quot;xmax&quot;], lat1 = limits[&quot;ymin&quot;], lat2 = limits[&quot;ymax&quot;])
#&gt; Querying NOAA database ...
#&gt; This may take seconds to minutes, depending on grid size
#&gt; Building bathy matrix ...
bathy &lt;- raster_bathymetry(stars::st_as_stars(marmap::as.raster(mar_bathy)), depths = NULL)
#&gt;   |                                                                              |                                                                      |   0%  |                                                                              |=========                                                             |  12%  |                                                                              |==================                                                    |  25%  |                                                                              |==========================                                            |  38%  |                                                                              |===================================                                   |  50%  |                                                                              |============================================                          |  62%  |                                                                              |====================================================                  |  75%  |                                                                              |=============================================================         |  88%  |                                                                              |======================================================================| 100%

p &lt;- bm + 
  stars::geom_stars(data = bathy$raster) +
  ggplot2::scale_fill_gradientn(
    name = &quot;Depth (m)&quot;, breaks = seq(0,5e3,1e3), limits = c(0,NA), 
    colors = colorRampPalette(c(&quot;#F7FBFF&quot;, &quot;#DEEBF7&quot;, &quot;#9ECAE1&quot;, &quot;#4292C6&quot;, &quot;#08306B&quot;))(8)
  )

reorder_layers(p)

如何使用R中的“ggOceanMaps”包来修复浅海地形分辨率较差?<!-- -->

As for alternatives, you can also use the marmap package to plot bathymetric maps:

marmap::autoplot.bathy(mar_bathy, geom=c(&quot;r&quot;, &quot;c&quot;), colour=&quot;white&quot;, size=0.1) + marmap::scale_fill_etopo()
#&gt; Warning in ggplot2::geom_raster(ggplot2::aes_string(fill = &quot;z&quot;), ...): Ignoring
#&gt; unknown parameters: `colour` and `size`

如何使用R中的“ggOceanMaps”包来修复浅海地形分辨率较差?<!-- -->

<sup>Created on 2023-06-30 with reprex v2.0.2</sup>

huangapple
  • 本文由 发表于 2023年6月22日 06:39:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76527578.html
匿名

发表评论

匿名网友

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

确定