Skip to content

Commit

Permalink
Use da.load()
Browse files Browse the repository at this point in the history
  • Loading branch information
abarciauskas-bgse committed Nov 9, 2023
1 parent 607cae2 commit ed08474
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
16 changes: 13 additions & 3 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
DATA_DIR = "tests/fixtures"
test_zarr_store = os.path.join(DATA_DIR, "test_zarr_store.zarr")
test_reference_store = os.path.join(DATA_DIR, "reference.json")
test_netcdf_store = os.path.join(DATA_DIR, "3B42_Daily.19980101.7.nc4")
test_netcdf_store = os.path.join(DATA_DIR, "testfile.nc")
test_transposed_netcdf_store = os.path.join(DATA_DIR, "3B42_Daily.19980101.7.nc4")
test_remote_netcdf_store = "https://nex-gddp-cmip6.s3-us-west-2.amazonaws.com/NEX-GDDP-CMIP6/GISS-E2-1-G/historical/r1i1p1f2/pr/pr_day_GISS-E2-1-G_historical_r1i1p1f2_gn_1950.nc"
test_unconsolidated_store = os.path.join(DATA_DIR, "unconsolidated.zarr")
test_pyramid_store = os.path.join(DATA_DIR, "pyramid.zarr")
Expand All @@ -26,9 +27,15 @@
"variables": ["value"],
}
test_netcdf_store_params = {
"params": {"url": test_netcdf_store, "variable": "precipitation", "decode_times": False},
"params": {"url": test_netcdf_store, "variable": "data", "decode_times": False},
"variables": ["data"],
}

test_transposed_netcdf_store_params = {
"params": {"url": test_transposed_netcdf_store, "variable": "precipitation", "decode_times": False},
"variables": ["precipitation"],
}

test_remote_netcdf_store_params = {
"params": {
"url": test_remote_netcdf_store,
Expand Down Expand Up @@ -162,7 +169,7 @@ def test_get_tilejson_pyramid(app):

def get_tile_test(app, ds_params, zoom: int = 0):
response = app.get(
f"/tiles/1/0/0.png",
f"/tiles/0/0/0.png",
params=ds_params["params"],
)
assert response.status_code == 200
Expand All @@ -185,6 +192,9 @@ def test_get_tile_reference(app):
def test_get_tile_netcdf(app):
return get_tile_test(app, test_netcdf_store_params)

def test_get_tile_transposed_netcdf(app):
return get_tile_test(app, test_transposed_netcdf_store_params)


def test_get_tile_unconsolidated(app):
return get_tile_test(app, test_unconsolidated_store_params)
Expand Down
12 changes: 9 additions & 3 deletions titiler/xarray/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ def get_filesystem(
)
return http_filesystem.open(src_path)
else:
# TODO: In tests this is failing with IsADirectoryError: [Errno 21] Is a directory: 'fsspec_test_cache/2dd8b85c17ad82a17d403580bf19e9fb5cc9f05aaedcf8f3be8ef2431c00fbb2'
# local_filesystem = (
# fsspec.filesystem("filecache", **get_cache_args(protocol))
# if enable_fsspec_cache
# else fsspec.filesystem(protocol)
# )
# return local_filesystem.open(src_path)
return src_path


Expand Down Expand Up @@ -174,9 +181,8 @@ def arrange_coordinates(da: xarray.DataArray, xr_engine: str) -> xarray.DataArra
# if we're caching the data, we need to load the transposed data into memory rather than lazily loading it later.
# Trying to modify the data with rioxarray during the tile operation will result in an error:
# `cannot pickle io.BufferedReader`. This only happens when operating on a cached file, like NetCDF.
# if api_settings.enable_fsspec_cache and xr_engine == "h5netcdf":
# #da.load()
# pass
if api_settings.enable_fsspec_cache and xr_engine == "h5netcdf":
da.load()
return da


Expand Down

0 comments on commit ed08474

Please sign in to comment.