I have a netcdf
file that has the dimensions of lat
, lon
, time
and effect
. The file also have 3 different variables: rn
, prec
and tair
.
I want to read the file using terra
, but I get unexpected results when I do so:
# store the url where the netcdf data is hosted
url = "https://github.com/qquusshh/data_so/raw/main/data.nc"
# download the netcdf data in the current directory with the name "data.nc"
download.file(url, "data.nc")
# read the file
terra::rast("data.nc")
output:
class : SpatRaster
dimensions : 360, 3, 2160 (nrow, ncol, nlyr)
resolution : 1, 1 (x, y)
extent : -0.5, 2.5, -180, 180 (xmin, xmax, ymin, ymax)
coord. ref. :
sources : data.nc:rn (720 layers)
data.nc:prec (720 layers)
data.nc:tair (720 layers)
varnames : rn
prec
tair
names : rn_ef~9.5_1, rn_ef~8.5_1, rn_ef~7.5_1, rn_ef~6.5_1, rn_ef~5.5_1, rn_ef~4.5_1, ...
I would expect the nrow
to be lat
(180), ncol
to be lon
(360), nlyr
to be time
(3) and somehow another dimension containing the effect
.
When I use xarray
from python
, everything works perfectly:
# import the xarray library
import xarray as xr
# open the data
xr.open_dataset("data.nc")
output:
<xarray.Dataset>
Dimensions: (lat: 180, lon: 360, time: 3, effect: 4)
Coordinates:
* lat (lat) float32 89.5 88.5 87.5 86.5 85.5 ... -86.5 -87.5 -88.5 -89.5
* lon (lon) float64 -179.5 -178.5 -177.5 -176.5 ... 177.5 178.5 179.5
* time (time) datetime64[ns] 2019-12-29 2019-12-30 2019-12-31
* effect (effect) object 'inst' 'short' 'long' 'static'
Data variables:
rn (effect, lat, lon, time) float64 ...
prec (effect, lat, lon, time) float64 ...
tair (effect, lat, lon, time) float64 ...