You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
binlets requires an array of data,and a test function to compare two data points.
Single-channel with Poisson statistics
For instance,for single-channel signal with Poisson statistics:
defchi2_test(x:NDArray,y:NDArray)->NDArray[bool]:"""Compares two values with Poisson noise using a χ² test."""diff=x-yvar_diff=x+y# Poisson variancereturndiff**2<=var_diffdenoised=binlets(data,test=chi2_test,levels=None,# max averaging area is 2**levels. By default, floor(log2(min(data.shape)))linear=True,# the transformation is linear (x - y))
We recomend wrapping this in a function,and providing an extra parameter to adjust the significance level:
defpoisson_binlets(data:NDArray,*,n_sigma:float,levels:int|None=None):defchi2_test(x:NDArray,y:NDArray)->NDArray[bool]:"""Compares two values with Poisson noise using a χ² test."""diff=x-yvar_diff=x+y# Poisson variancereturndiff**2<=n_sigma**2*var_diffdenoised=binlets(data,test=chi2_test,linear=True, )returndenoised
Ratio of multichannel-data
For multichannel data,binlets expects channels to be in the first dimension of the data array.That is,data.shape should be(N_CHANNELS, *spatial_dimensions).
defratio(channels):"""Statistic of interest."""returnchannels[1]/channels[0]deftest(x,y):# The test of your choice. For instance, a χ² test.diff=ratio(x)-ratio(y)var_diff=ratio_var(x)+ratio_var(y)returndiff**2<=var_diffdenoised=binlets(data,test=test, ...)# the same as beforedenoised_ratio=ratio(denoised)
Installation
Binlets can be installed from PyPI:
pip install binlets
or conda-forge:
conda installl -c conda-forge binlets
Development
To set up a development environment in a new conda environment, run the following commands: