Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ debug = [
server = [
"uvicorn"
]
gcs = [
"gcsfs"
]

[project.urls]
Homepage = "https://github.com/developmentseed/titiler-xarray"
Expand Down
15 changes: 14 additions & 1 deletion titiler/xarray/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
from titiler.xarray.redis_pool import get_redis
from titiler.xarray.settings import ApiSettings

try:
import gcsfs
except ImportError: # pragma: nocover
gcsfs = None # type: ignore

api_settings = ApiSettings()
cache_client = get_redis()

Expand All @@ -27,7 +32,7 @@ def parse_protocol(src_path: str, reference: Optional[bool] = False):
"""
Parse protocol from path.
"""
match = re.match(r"^(s3|https|http)", src_path)
match = re.match(r"^(s3|gs|https|http)", src_path)
protocol = "file"
if match:
protocol = match.group(0)
Expand Down Expand Up @@ -66,6 +71,14 @@ def get_filesystem(
if xr_engine == "h5netcdf"
else s3fs.S3Map(root=src_path, s3=s3_filesystem)
)
elif protocol == "gs":
assert gcsfs is not None, "'gcsfs' must be installed to read dataset stored in Google Cloud Storage"
gcs_filesystem = gcsfs.GCSFileSystem()
return (
gcs_filesystem.open(src_path)
if xr_engine == "h5netcdf"
else gcs_filesystem.get_mapper(root=src_path)
)
elif protocol == "reference":
reference_args = {"fo": src_path, "remote_options": {"anon": anon}}
return fsspec.filesystem("reference", **reference_args).get_mapper("")
Expand Down