-
Notifications
You must be signed in to change notification settings - Fork 214
/
test_io.py
34 lines (30 loc) · 1.03 KB
/
test_io.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""
Test input/output (I/O) utilities.
"""
import numpy as np
import pytest
import xarray as xr
from pygmt.helpers import GMTTempFile
from pygmt.io import load_dataarray
def test_io_load_dataarray():
"""
Check that load_dataarray works to read a NetCDF grid with
GMTDataArrayAccessor information loaded.
"""
with GMTTempFile(suffix=".nc") as tmpfile:
grid = xr.DataArray(
data=np.random.rand(2, 2), coords=[[0.1, 0.2], [0.3, 0.4]], dims=("x", "y")
)
grid.to_netcdf(tmpfile.name)
dataarray = load_dataarray(tmpfile.name)
assert dataarray.gmt.gtype == 0 # Cartesian grid
assert dataarray.gmt.registration == 1 # Pixel registration
# this would fail if we used xr.open_dataarray instead of
# load_dataarray
dataarray.to_netcdf(tmpfile.name)
def test_io_load_dataarray_cache():
"""
Check that load_dataarray fails when the cache argument is used.
"""
with pytest.raises(TypeError):
_ = load_dataarray("somefile.nc", cache=True)