From 1578579d10472a67c925398e69015bdd430060b9 Mon Sep 17 00:00:00 2001 From: Simon Heybrock Date: Wed, 9 Apr 2025 15:33:40 +0200 Subject: [PATCH 1/2] Cache paths returned from Pooch to avoid repeated checksum in unit tests This seems to save, e.g., 0.3 seconds a whole bunch of times. Not huge but noticeable. Is it a good idea? --- src/ess/sans/data.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ess/sans/data.py b/src/ess/sans/data.py index 4e1f5201..6a9b21fb 100644 --- a/src/ess/sans/data.py +++ b/src/ess/sans/data.py @@ -1,5 +1,6 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright (c) 2023 Scipp contributors (https://github.com/scipp) +from functools import cache class Registry: @@ -25,6 +26,7 @@ def __init__( def __contains__(self, key): return key in self._registry.registry + @cache # noqa: B019 def get_path(self, name: str, unzip: bool = False) -> str: """ Get the path to a file in the registry. From 2dae5c03c6a98d9b1cf25b19816cd9cf1a660c28 Mon Sep 17 00:00:00 2001 From: Jan-Lukas Wynen Date: Fri, 8 Aug 2025 15:15:57 +0200 Subject: [PATCH 2/2] Use Pooch Registry from ESSreduce --- src/ess/isissans/data.py | 4 ++-- src/ess/loki/data.py | 6 +++--- src/ess/sans/data.py | 46 ---------------------------------------- 3 files changed, 5 insertions(+), 51 deletions(-) delete mode 100644 src/ess/sans/data.py diff --git a/src/ess/isissans/data.py b/src/ess/isissans/data.py index 589552ea..8a6f5020 100644 --- a/src/ess/isissans/data.py +++ b/src/ess/isissans/data.py @@ -1,6 +1,6 @@ # SPDX-License-Identifier: BSD-3-Clause -# Copyright (c) 2024 Scipp contributors (https://github.com/scipp) -from ess.sans.data import Registry +# Copyright (c) 2025 Scipp contributors (https://github.com/scipp) +from ess.reduce.data import Registry from ess.sans.types import ( BackgroundRun, DirectBeamFilename, diff --git a/src/ess/loki/data.py b/src/ess/loki/data.py index c0a6dc69..9cda0742 100644 --- a/src/ess/loki/data.py +++ b/src/ess/loki/data.py @@ -1,8 +1,8 @@ # SPDX-License-Identifier: BSD-3-Clause -# Copyright (c) 2023 Scipp contributors (https://github.com/scipp) +# Copyright (c) 2025 Scipp contributors (https://github.com/scipp) from pathlib import Path -from ess.sans.data import Registry +from ess.reduce.data import Registry from ess.sans.types import ( BackgroundRun, DirectBeamFilename, @@ -152,7 +152,7 @@ def loki_tutorial_mask_filenames() -> list[PixelMaskFilename]: def loki_tutorial_poly_gauss_I0() -> Path: """Analytical model for the I(Q) of the Poly-Gauss sample.""" - return Path(_registry.get_path('PolyGauss_I0-50_Rg-60.h5')) + return _registry.get_path('PolyGauss_I0-50_Rg-60.h5') def loki_tutorial_direct_beam_all_pixels() -> DirectBeamFilename: diff --git a/src/ess/sans/data.py b/src/ess/sans/data.py deleted file mode 100644 index 6a9b21fb..00000000 --- a/src/ess/sans/data.py +++ /dev/null @@ -1,46 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause -# Copyright (c) 2023 Scipp contributors (https://github.com/scipp) -from functools import cache - - -class Registry: - def __init__( - self, - instrument: str, - files: dict[str, str], - version: str, - retry_if_failed: int = 3, - ): - import pooch - - self._registry = pooch.create( - path=pooch.os_cache(f'ess/{instrument}'), - env=f'ESS_{instrument.upper()}_DATA_DIR', - base_url=f'https://public.esss.dk/groups/scipp/ess/{instrument}/' - + '{version}/', - version=version, - retry_if_failed=retry_if_failed, - registry=files, - ) - - def __contains__(self, key): - return key in self._registry.registry - - @cache # noqa: B019 - def get_path(self, name: str, unzip: bool = False) -> str: - """ - Get the path to a file in the registry. - - Parameters - ---------- - name: - Name of the file to get the path for. - unzip: - If `True`, unzip the file before returning the path. - """ - import pooch - - return self._registry.fetch(name, processor=pooch.Unzip() if unzip else None) - - -__all__ = ['Registry']