1# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 2# SPDX-License-Identifier: Apache-2.0 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16importos 17fromconcurrent.futuresimportThreadPoolExecutor,as_completed 18fromtypingimportTYPE_CHECKING,Any,Iterator,Mapping,Optional,Sequence,Tuple 19 20importzarras_zarr 21fromzarr.storageimportBaseStore 22 23from..shortcutsimportresolve_storage_client 24from..typesimportMSC_PROTOCOL 25importnumpyasnp 26 27ifTYPE_CHECKING: 28from..clientimportStorageClient 29 30
[docs] 31defopen_consolidated(*args:Any,**kwargs:Any)->_zarr.Group: 32""" 33 Adapt ``zarr.open_consolidated`` to use :py:class:`LazyZarrStore` when path matches the ``msc`` protocol. 34 35 If the path starts with the MSC protocol, it uses :py:class:`LazyZarrStore` with a resolved 36 storage client and prefix, passing ``msc_max_workers`` if provided. Otherwise, it 37 directly calls ``zarr.open_consolidated``. 38 """ 39args_list=list(args) 40path=args_list[0]ifargs_listelsekwargs.get("store") 41msc_max_workers=kwargs.pop("msc_max_workers",None) 42ifisinstance(path,str)andpath.startswith(MSC_PROTOCOL): 43storage_client,prefix=resolve_storage_client(path) 44zarr_store=LazyZarrStore(storage_client,prefix=prefix,msc_max_workers=msc_max_workers) 45ifpath==args_list[0]: 46args_list[0]=zarr_store 47else: 48kwargs["store"]=zarr_store 49return_zarr.open_consolidated(*args_list,**kwargs)# pyright: ignore [reportReturnType] 50return_zarr.open_consolidated(*args,**kwargs)# pyright: ignore [reportReturnType]