1- import dask .array
21import pystac_client
32import pytest
4- import xarray as xr
53
64from tests .utils import STAC_URLS , requires_icechunk , requires_planetary_computer
75from xpystac .core import to_xarray
@@ -12,30 +10,6 @@ def test_to_xarray_with_cog_asset(simple_cog):
1210 assert ds
1311
1412
15- def test_to_xarray_with_pystac_client_search (simple_search ):
16- ds = to_xarray (simple_search )
17- assert ds
18-
19-
20- def test_to_xarray_returns_dask_backed_object (simple_search ):
21- ds = to_xarray (simple_search )
22- assert isinstance (ds .blue .data , dask .array .Array )
23- assert ds .blue .data .npartitions > 1
24-
25-
26- def test_to_xarray_with_pystac_client_search_passes_kwargs_through (simple_search ):
27- ds = to_xarray (simple_search , bands = ["red" , "green" , "blue" ], chunks = {})
28- assert list (ds .data_vars ) == ["red" , "green" , "blue" ]
29- assert ds .blue .data .npartitions == 1
30-
31-
32- @pytest .mark .parametrize ("stacking_library" , ["odc.stac" , "stackstac" ])
33- def test_to_xarray_with_different_stacking_library (simple_search , stacking_library ):
34- ds = to_xarray (simple_search , stacking_library = stacking_library )
35- assert isinstance (ds , xr .Dataset )
36- assert "band" not in ds .dims
37-
38-
3913@requires_planetary_computer
4014def test_to_xarray_with_pystac_client_search_with_patch_url ():
4115 import planetary_computer as pc
@@ -47,24 +21,13 @@ def test_to_xarray_with_pystac_client_search_with_patch_url():
4721 collections = ["sentinel-2-l2a" ],
4822 datetime = "2020-05-01" ,
4923 )
50-
51- ds = to_xarray ( search , assets = [ "B4" , "B3" , "B2" ], stacking_library = "odc.stac" )
24+ item = next ( search . items ())
25+ asset = item . assets [ "B04" ]
5226
5327 with pytest .raises (RasterioIOError , match = "HTTP response code: 409" ):
54- ds . B01 . max (). compute ( )
28+ to_xarray ( asset )
5529
56- ds = to_xarray (
57- search ,
58- assets = ["B4" , "B3" , "B2" ],
59- stacking_library = "odc.stac" ,
60- patch_url = pc .sign ,
61- )
62- assert ds .B01 .max ().compute () == 11080
63-
64-
65- def test_to_xarray_with_drop_variables_raises (simple_search ):
66- with pytest .raises (KeyError , match = "not implemented for pystac items" ):
67- to_xarray (simple_search , drop_variables = ["blue" ])
30+ to_xarray (asset , patch_url = pc .sign )
6831
6932
7033def test_to_xarray_with_bad_type ():
@@ -145,20 +108,6 @@ def test_to_xarray_zarr_with_zarr_extension():
145108 to_xarray (zarr_asset )
146109
147110
148- @pytest .mark .skip (reason = "not yet supported with kerchunk >=0.2.8" )
149- def test_to_xarray_with_item_collection_with_kerchunk_attrs_in_data_cube (
150- data_cube_kerchunk ,
151- ):
152- ds = to_xarray (data_cube_kerchunk )
153- assert ds
154-
155-
156- @pytest .mark .skip (reason = "not yet supported with kerchunk >=0.2.8" )
157- def test_to_xarray_with_list_with_kerchunk_attrs_in_data_cube (data_cube_kerchunk ):
158- ds = to_xarray ([i for i in data_cube_kerchunk ])
159- assert ds
160-
161-
162111@pytest .mark .skip (reason = "not yet supported with kerchunk >=0.2.8" )
163112def test_to_xarray_with_item_with_kerchunk_attrs_in_data_cube (data_cube_kerchunk ):
164113 ds = to_xarray ([i for i in data_cube_kerchunk ][- 1 ])
0 commit comments