- Notifications
You must be signed in to change notification settings - Fork2
Denoising via adaptive binning.
License
NotificationsYou must be signed in to change notification settings
maurosilber/binlets
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
binlets
requires an array of data,and a test function to compare two data points.
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
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)
Binlets can be installed from PyPI:
pip install binlets
or conda-forge:
conda installl -c conda-forge binlets
To set up a development environment in a new conda environment, run the following commands:
git clone https://github.com/maurosilber/binletscd binletsconda env create -f environment.ymlconda activate binletspre-commit install
About
Denoising via adaptive binning.
Resources
License
Stars
Watchers
Forks
Packages0
No packages published