From 82bf4c52c1265942b47c377e0320b8b9c89c26b7 Mon Sep 17 00:00:00 2001 From: Joshua Gould Date: Thu, 22 Jan 2026 13:25:28 -0500 Subject: [PATCH] remove crick package --- pyproject.toml | 1 - requirements.txt | 1 - scallops/tests/test_xr.py | 14 +------- scallops/xr.py | 70 --------------------------------------- 4 files changed, 1 insertion(+), 85 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 763ab7c..e143159 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,7 +37,6 @@ dependencies = [ "bioio-tifffile", "centrosome", "cp-measure", - "crick", "dask-image", "dask", "decorator", diff --git a/requirements.txt b/requirements.txt index b34d110..a5128fa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,6 @@ bioio-base==1.0.7 bioio==1.6.1 centrosome==1.3.3 cp-measure==0.1.13 -crick==0.0.8 cython==3.2.4 dask-image==2025.11.0 dask==2025.11.0 diff --git a/scallops/tests/test_xr.py b/scallops/tests/test_xr.py index aec61bd..b831452 100644 --- a/scallops/tests/test_xr.py +++ b/scallops/tests/test_xr.py @@ -1,8 +1,7 @@ -import numpy as np import pytest import xarray as xr -from scallops.xr import apply_data_array, dask_grouped_quantiles +from scallops.xr import apply_data_array @pytest.fixture @@ -12,17 +11,6 @@ def image(array_A1_102_aln): ) # ops swaps z and t in saved tif -@pytest.mark.io -def test_dask_grouped_quantiles(image): - dask_image = image.squeeze() # ops swaps z and t in saved tif - dask_image = dask_image.chunk(dict(t=1, y=256, x=256)) - q = [0.5, 0.75] - dask_results = dask_grouped_quantiles(dask_image, dims=["t", "c"], q=q).compute() - results = image.squeeze().quantile(dim=["y", "x"], q=q) - assert np.abs(dask_results.isel(quantile=0) - results.isel(quantile=0)).max() < 0.8 - assert np.abs(dask_results.isel(quantile=1) - results.isel(quantile=1)).max() < 1.75 - - @pytest.mark.io def test_data_array(image): def add_data_array(x: xr.DataArray, y: float): diff --git a/scallops/xr.py b/scallops/xr.py index f5818af..ebf9e98 100644 --- a/scallops/xr.py +++ b/scallops/xr.py @@ -8,13 +8,10 @@ - The SCALLOPS development team """ -import importlib import itertools from collections.abc import Callable, Sequence from typing import Any, Literal, Union -import dask -import dask.array as da import numpy as np import xarray as xr @@ -92,73 +89,6 @@ def _get_dims( return _dims -def dask_grouped_quantiles( - array: xr.DataArray, dims: list[str], q: list[float] -) -> xr.DataArray: - """Compute quantiles for grouped data using Dask. - - This function calculates the specified quantiles for the given dimensions in a - Dask-backed Xarray DataArray. It uses Dask's percentile computation to handle - large datasets efficiently. - - :param array: The input DataArray containing the data. - :param dims: List of dimensions over which to compute the quantiles. - :param q: List of quantiles to compute, each value should be between 0 and 1. - :return: A DataArray containing the computed quantiles for the specified dimensions. - - :raises AssertionError: - If no quantiles are provided in the `q` list. - :raises ValueError: - If a specified dimension is not found in the DataArray and `missing_dims` - is set to "error". - - :example: - - .. code-block:: python - - import xarray as xr - import numpy as np - import dask.array as da - - data = da.random.random((10, 20, 30), chunks=(5, 10, 15)) - array = xr.DataArray(data, dims=["x", "y", "z"]) - - # Compute quantiles for dimensions 'x' and 'y' - quantiles = dask_grouped_quantiles(array, ["x", "y"], [0.25, 0.5, 0.75]) - print(quantiles) - """ - assert len(q) > 0, "No quantiles provided" - dims = _get_dims(array, dims) - - coords = {d: array.coords[d] for d in dims} - coords["quantile"] = q - - quantiles = [_q * 100 for _q in q] - results = xr.DataArray( - da.zeros((len(q),) + tuple([array.sizes[d] for d in dims])), - dims=["quantile"] + dims, - coords=coords, - ) - - dim_vals = [array[d].values for d in dims] - internal_method = "tdigest" - - try: - importlib.import_module("crick") - except ModuleNotFoundError: - internal_method = "default" - with dask.config.set(**{"array.slicing.split_large_chunks": True}): - for dim_val in itertools.product(*dim_vals): - sel = dict(zip(dims, dim_val)) - values = da.percentile( - array.sel(sel).data.reshape(-1), - quantiles, - internal_method=internal_method, - ) - results.loc[sel] = values - return results - - def apply_data_array( array: xr.DataArray, dims: list[str],