%load_ext autoreload
%autoreload 2

class DecodeDataset[source]

DecodeDataset(path:Union[str, list], dataset_tfms:list, rate_tfms:list, bg_transform:list, num_iter:int=5000, device:str='cpu')

print_class_signature(nms)

print class signature

class TransformBase[source]

TransformBase()

All transformations optionally must be inherited from this class for nice
representations and checks if input to given transformations is a tensor

class ScaleTensor[source]

ScaleTensor(low:float=0.0, high:float=1.0) :: TransformBase


Scales given `torch.Tensor` between `low` and `high`


Parameters:

`low`     : lower bound

`high`    : upper bound

`data_min`: max value of data

`data_max`: min value of main data


Returns:

Scaled tensor

class RandScale[source]

RandScale(low:float, high:float) :: TransformBase

All transformations optionally must be inherited from this class for nice
representations and checks if input to given transformations is a tensor

class EstimateBackground[source]

EstimateBackground(smoothing_filter_size, div_factor=1) :: TransformBase

All transformations optionally must be inherited from this class for nice
representations and checks if input to given transformations is a tensor

class UniformValue[source]

UniformValue(min_val, max_val) :: TransformBase

All transformations optionally must be inherited from this class for nice
representations and checks if input to given transformations is a tensor

get_forward_scaling[source]

get_forward_scaling(img)

class RandomCrop3D[source]

RandomCrop3D(crop_sz, roi_masks) :: TransformBase

    Ramdomly Crops 3D tensor.


This class will generate random crop of `crop_sz`. This class is initialized
    with `img_sz` which should be a demension of 4 [Channel, Height, Width, Depth] and
    a `crop_sz` dimesnion of 3 [Height, Width, Depth] of desired crop. For each crop
    dimension `_get_slice` function will calculate random int ranging from 0 to (img_sz-crop_sz).
    and return tuple of containing two slice intergers. If one dimension of `img_sz` matches
    one dimension of `crop_sz` the resulting tuple will be `(None, None)` which will result
    in not croping this particular dimension.



Parameters:

`crop_sz`    : Size of the 3D crop  `(H, W, D)`


Returns:

Croped 3D image of the given `crop_sz`

class AddFoci[source]

AddFoci(n_foci_avg:float, rad_range:tuple, n_mol_range:tuple, px_size_zyx:tuple=(100, 100, 100), mode='gaussian') :: TransformBase

All transformations optionally must be inherited from this class for nice
representations and checks if input to given transformations is a tensor

get_roi_mask[source]

get_roi_mask(img, pool_size=(10, 10, 10), percentile=50)

from decode_fish.funcs.file_io import load_psf_noise_micro
from decode_fish.engine.point_process import PointProcessUniform
from decode_fish.funcs.plotting import *
pfile = '/groups/turaga/home/speisera/share_TUM/FishSIM/sim_density_fac1_1/mRNAlevel_500/random/NR/w1_HelaKyoto_Gapdh_2597_p01_cy3__Cell_CP_10__random__1.tif'
pdir = '/groups/turaga/home/speisera/share_TUM/FishSIM/sim_density_fac1_1/mRNAlevel_500/random/NR/w1*.tif'
pdir = '/groups/turaga/home/speisera/share_TUM/FishSIM/sim_foci_fac1_1/mRNAlevel_500/foci/strong/w1*.tif'
imgs_3d        = [load_tiff_image(f)[0] for f in glob.glob(pdir)]
estimate_backg = EstimateBackground(smoothing_filter_size=6, div_factor=1)
roi_masks      = [get_roi_mask(img, pool_size=(10,10,10), percentile=70) for img in imgs_3d]
rand_crop      = RandomCrop3D((48,48,48), roi_masks)
probmap_generator = ScaleTensor(low=0.00000001, 
                                high=0.005)

focifier = AddFoci(n_foci_avg=0, 
                   rad_range=(50,500), 
                   n_mol_range=(5.,20.), 
                   px_size_zyx =(100,100,300),
                   mode='gauss')

# ds = DecodeDataset(path = '/groups/turaga/home/speisera/share_TUM/FishSIM/sim_1/mRNAlevel_200/cell3D/strong/w1_HelaKyoto_Gapdh_2597_p01_cy3__Cell_CP_14__cell3D__1.tif',
#                    dataset_tfms =  [rand_crop], 
#                    rate_tfms = [probmap_generator, focifier], 
#                    bg_transform = estimate_backg, 
#                    device='cuda:0', 
#                    num_iter=100 * 4) 
ds = DecodeDataset(path = pdir,
                   dataset_tfms =  [rand_crop], 
                   rate_tfms = [estimate_backg, probmap_generator, focifier], 
                   bg_transform = estimate_backg, 
                   device='cuda:0', 
                   num_iter=100 * 4) 
20 volumes
decode_dl = DataLoader(ds, batch_size=2, num_workers=0)
x, local_rate, background = next(iter(decode_dl))
plot_3d_projections(local_rate[0,0], 'max')
plot_3d_projections(x[0,0], 'max')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-108-f79c83f96974> in <module>
----> 1 x, local_rate, background = next(iter(decode_dl))
      2 plot_3d_projections(local_rate[0,0], 'max')
      3 plot_3d_projections(x[0,0], 'max')

~/anaconda3/envs/decode2_dev/lib/python3.7/site-packages/torch/utils/data/dataloader.py in __next__(self)
    433         if self._sampler_iter is None:
    434             self._reset()
--> 435         data = self._next_data()
    436         self._num_yielded += 1
    437         if self._dataset_kind == _DatasetKind.Iterable and \

~/anaconda3/envs/decode2_dev/lib/python3.7/site-packages/torch/utils/data/dataloader.py in _next_data(self)
    473     def _next_data(self):
    474         index = self._next_index()  # may raise StopIteration
--> 475         data = self._dataset_fetcher.fetch(index)  # may raise StopIteration
    476         if self._pin_memory:
    477             data = _utils.pin_memory.pin_memory(data)

~/anaconda3/envs/decode2_dev/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py in fetch(self, possibly_batched_index)
     42     def fetch(self, possibly_batched_index):
     43         if self.auto_collation:
---> 44             data = [self.dataset[idx] for idx in possibly_batched_index]
     45         else:
     46             data = self.dataset[possibly_batched_index]

~/anaconda3/envs/decode2_dev/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py in <listcomp>(.0)
     42     def fetch(self, possibly_batched_index):
     43         if self.auto_collation:
---> 44             data = [self.dataset[idx] for idx in possibly_batched_index]
     45         else:
     46             data = self.dataset[possibly_batched_index]

<ipython-input-3-cee7f00a2963> in __getitem__(self, _)
     34 
     35     def __getitem__(self, _):
---> 36         i = random.randint(0,len(self.volumes)-1)
     37         x = self.volumes[i]
     38         x = self._compose(x, self.dataset_tfms)

~/anaconda3/envs/decode2_dev/lib/python3.7/random.py in randint(self, a, b)
    220         """
    221 
--> 222         return self.randrange(a, b+1)
    223 
    224     def _randbelow(self, n, int=int, maxsize=1<<BPF, type=type,

~/anaconda3/envs/decode2_dev/lib/python3.7/random.py in randrange(self, start, stop, step, _int)
    198             return istart + self._randbelow(width)
    199         if step == 1:
--> 200             raise ValueError("empty range for randrange() (%d,%d, %d)" % (istart, istop, width))
    201 
    202         # Non-unit step argument supplied.

ValueError: empty range for randrange() (0,0, 0)
class EstimateBackground(TransformBase):
    def __init__(self, smoothing_filter_size, div_factor=1):
        self.smoothing_filter_size = smoothing_filter_size
        self.div_factor = div_factor
    
    def __call__(self, image, **kwargs):
        background = gaussian_filter(image, self.smoothing_filter_size)/self.div_factor
        #background.clamp_min_(1.)
        return torch.tensor(background)
    
estimate_backg = EstimateBackground(smoothing_filter_size=6, div_factor=1)
import torch.fft
img_fft = torch.fft.rfftn(imgs_3d[0])
# img_fft = torch.real(img_fft)
img_fft = torch.fft.rfftn(imgs_3d[0][:,:,:])
img_fft[abs(img_fft)<5e6] = 0
rec = torch.fft.irfftn(img_fft)
plot_3d_projections(rec,'max')
array([<AxesSubplot:xlabel='x', ylabel='y'>,
       <AxesSubplot:xlabel='x', ylabel='z'>,
       <AxesSubplot:xlabel='y', ylabel='z'>], dtype=object)
plot_3d_projections(imgs_3d[0],'max')
plot_3d_projections(estimate_backg(imgs_3d[0]),'max')
array([<AxesSubplot:xlabel='x', ylabel='y'>,
       <AxesSubplot:xlabel='x', ylabel='z'>,
       <AxesSubplot:xlabel='y', ylabel='z'>], dtype=object)
!nbdev_build_lib
Converted 00_models.ipynb.
Converted 01_psf.ipynb.
Converted 02_microscope.ipynb.
Converted 03_noise.ipynb.
Converted 04_pointsource.ipynb.
Converted 05_gmm_loss.ipynb.
Converted 06_plotting.ipynb.
Converted 07_file_io.ipynb.
Converted 08_dataset.ipynb.
Converted 09_output_trafo.ipynb.
Converted 10_evaluation.ipynb.
Converted 11_emitter_io.ipynb.
Converted 12_utils.ipynb.
Converted 13_train.ipynb.
Converted 15_fit_psf.ipynb.
Converted 16_visualization.ipynb.
Converted 17_eval_routines.ipynb.
Converted 18_predict_funcs.ipynb.
Converted index.ipynb.