Skip to content

Commit

Permalink
Add zero_black_quantiles parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
blowekamp committed Nov 13, 2023
1 parent 2fa6203 commit 9019955
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pytools/HedwigZarrImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ def _neuroglancer_shader_parameters_multichannel(

upper_quantile = 0.9999
stats = self._image_statistics(
quantiles=[*middle_quantile, upper_quantile] if middle_quantile else [upper_quantile], channel=c
quantiles=[*middle_quantile, upper_quantile] if middle_quantile else [upper_quantile],
channel=c,
zero_black_quantiles=True,
)
if middle_quantile:
range = (stats["quantiles"][middle_quantile[0]], stats["quantiles"][middle_quantile[1]])
Expand Down Expand Up @@ -340,7 +342,7 @@ def _chunk_logic_dim(drequest: int, dshape: int) -> int:
return drequest
return dshape

def _image_statistics(self, quantiles=None, channel=None) -> Dict[str, List[int]]:
def _image_statistics(self, quantiles=None, channel=None, *, zero_black_quantiles=False) -> Dict[str, List[int]]:
"""Processes the full resolution Zarr image. Dask is used for parallel reading and statistics computation. The
global scheduler is used for all operations which can be changed with standard Dask configurations.
Expand Down Expand Up @@ -383,7 +385,9 @@ def _image_statistics(self, quantiles=None, channel=None) -> Dict[str, List[int]
stats.update(histogram_stats(h, bins))
stats["min"], stats["max"] = weighted_quantile(mids, quantiles=[0.0, 1.0], sample_weight=h, values_sorted=True)
if quantiles:
h[0] = 0
if zero_black_quantiles:
h[0] = 0

quantile_value = weighted_quantile(mids, quantiles=quantiles, sample_weight=h, values_sorted=True)
stats["quantiles"] = {q: v for q, v in zip(quantiles, quantile_value)}
logger.debug(f"stats: {stats}")
Expand Down

0 comments on commit 9019955

Please sign in to comment.