I'm trying to read a .nc
raster file in R. The older function raster::raster()
reads the data perfectly fine. I'd like to reproduce the results using a newer function stars::read_stars()
, but somehow it does not work for me. The data CHAP_PM2.5_Y1K_2020_V4.nc
can be downloaded from here (~6.1 MB). Below is a minimal reproducible example:
library(stars)
library(raster)
pm_raster = raster::raster('CHAP_PM2.5_Y1K_2020_V4.nc')
pm_stars = stars::read_stars('CHAP_PM2.5_Y1K_2020_V4.nc')
# Warning messages:
# 1: In CPL_read_gdal(as.character(x), as.character(options), as.character(driver), :
# GDAL Message 1: The dataset has several variables that could be identified as vector fields,
# but not all share the same primary dimension. Consequently they will be ignored.
# 2: In CPL_read_gdal(as.character(x), as.character(options), as.character(driver), :
# GDAL Message 1: The dataset has several variables that could be identified as vector fields,
# but not all share the same primary dimension. Consequently they will be ignored.
The reading the files looks good, but the problem is when I plot them, the figure read by stars::read_stars
looks wrong:
plot(pm_raster, main = 'raster::raster')
plot(pm_stars, main = 'stars::read_stars')
It looks like the projection is wrong for stars::read_stars()
, but I have no clue on this. Any suggestion or comment would be appreciated.