Definition of the classes and modules we use to model PSFs
%load_ext autoreload
%autoreload 2

class LinearInterpolatedPSF[source]

LinearInterpolatedPSF(size_zyx=[21, 21, 21], device='cuda') :: Module

Base class for all neural network modules.

Your models should also subclass this class.

Modules can also contain other Modules, allowing to nest them in
a tree structure. You can assign the submodules as regular attributes::

    import torch.nn as nn
    import torch.nn.functional as F

    class Model(nn.Module):
        def __init__(self):
            super(Model, self).__init__()
            self.conv1 = nn.Conv2d(1, 20, 5)
            self.conv2 = nn.Conv2d(20, 20, 5)

        def forward(self, x):
            x = F.relu(self.conv1(x))
            return F.relu(self.conv2(x))

Submodules assigned in this way will be registered, and will have their
parameters converted too when you call :meth:`to`, etc.

:ivar training: Boolean represents whether this module is in training or
                evaluation mode.
:vartype training: bool
psf_state = torch.load('/groups/turaga/home/speisera/Mackebox/Artur/WorkDB/deepstorm/models/fishcod/msp300_smFISH/nb_run/msp300_smFISH_3_3/psf_init.pkl')
shape_zyx = psf_state['psf_volume'][:,].shape[-3:]
psf = LinearInterpolatedPSF((21,21,21))
psf.load_state_dict({'psf_volume':psf_state['psf_volume']}, strict=False)
_IncompatibleKeys(missing_keys=['x', 'y', 'z'], unexpected_keys=[])
psf.get_com()
(tensor(10., device='cuda:0', grad_fn=<DivBackward0>),
 tensor(10., device='cuda:0', grad_fn=<DivBackward0>),
 tensor(10., device='cuda:0', grad_fn=<DivBackward0>))
shift = psf(torch.tensor([-2,0.,+2]).cuda(),0.+torch.zeros(3).cuda(),0.+torch.zeros(3).cuda())
# First output is the volume shifted 2 pixels to the left.
plot_3d_projections(cpu(shift)[0,0])
shift.shape
torch.Size([3, 1, 21, 21, 21])

crop_psf[source]

crop_psf(psf, extent_zyx)

Returns a cropped version of a PSF
cropped_psf = crop_psf(psf,[11,21,21])
plot_3d_projections(cropped_psf.psf_volume)
(<Figure size 701.486x658.286 with 6 Axes>,
 [<AxesSubplot:ylabel='y'>,
  <AxesSubplot:xlabel='x', ylabel='z'>,
  <AxesSubplot:xlabel='z'>])
!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.