コード例 #1
0
ファイル: states.py プロジェクト: jhkoivis/peri
import os
import re
import copy
import json
import numpy as np
import cPickle as pickle

from functools import partial
from contextlib import contextmanager

from peri import util, comp, models
from peri.logger import log as baselog
log = baselog.getChild('states')


class UpdateError(Exception):
    pass


def sample(field, inds=None, slicer=None, flat=True):
    """
    Take a sample from a field given flat indices or a shaped slice

    Parameters
    -----------
    inds : list of indices
        One dimensional (raveled) indices to return from the field

    slicer : slice object
        A shaped (3D) slicer that returns a section of image
コード例 #2
0
ファイル: models.py プロジェクト: jhkoivis/peri
import re

from peri.comp import (
    ComponentCollection, GlobalScalar, ilms, psfs, objs, exactpsf
)
from peri.logger import log as baselog
log = baselog.getChild('models')

allfields = {
    'const': GlobalScalar,
    'poly3d': ilms.Polynomial3D,
    'leg3d': ilms.LegendrePoly3D,
    'poly2p1d': ilms.Polynomial2P1D,
    'leg2p1d': ilms.LegendrePoly2P1D,
    'cheb2p1d': ilms.ChebyshevPoly2P1D,
    'barnesleg2p1d': ilms.BarnesStreakLegPoly2P1D,
    'combo': ComponentCollection,
}

allpsfs = {
    'identity': psfs.IdentityPSF,
    'gauss2d': psfs.AnisotropicGaussian,
    'gauss3d': psfs.AnisotropicGaussianXYZ,
    'gauss4d': psfs.Gaussian4DPoly,
    'gauss4d-leg': psfs.Gaussian4DLegPoly,
    'gauss4d-mom': psfs.GaussianMomentExpansion,
    'linescan': exactpsf.ExactLineScanConfocalPSF,
    'cheb-linescan': exactpsf.ChebyshevLineScanConfocalPSF,
    'cheb-linescan-fixedss': exactpsf.FixedSSChebLinePSF,
}
コード例 #3
0
arguments::

    from peri.fft import fft, fftkwargs
    fft.fftn(image_array, **fftkwargs)

"""
import atexit
import pickle
import numpy as np

from multiprocessing import cpu_count

from peri import conf
from peri.util import Tile
from peri.logger import log
log = log.getChild('fft')

try:
    import pyfftw
    hasfftw = True
except ImportError as e:
    log.warning(
        'FFTW not found, which can improve speed by 20x. '
        'Try `pip install pyfftw`.'
    )
    hasfftw = False
    
FFTW_PLAN_FAST = 'FFTW_ESTIMATE'
FFTW_PLAN_NORMAL = 'FFTW_MEASURE'
FFTW_PLAN_SLOW = 'FFTW_PATIENT'
コード例 #4
0
ファイル: util.py プロジェクト: jhkoivis/peri
from __future__ import print_function

import os
import sys
import time
import inspect
import itertools
import numpy as np
from contextlib import contextmanager

from peri import initializers
from peri.logger import log
log = log.getChild('util')

#=============================================================================
# Tiling utilities
#=============================================================================
def oddify(num):
    """
    Return the next odd number if ``num`` is even.

    Examples
    --------
    >>> oddify(1)
    1

    >>> oddify(4)
    5
    """
    return num + (num % 2 == 0)
コード例 #5
0
ファイル: addsubtract.py プロジェクト: yangyushi/peri
from builtins import range, zip

import numpy as np
import scipy.ndimage as nd

import peri
from peri import initializers
from peri.util import Tile
import peri.opt.optimize as opt

from peri.logger import log
CLOG = log.getChild('addsub')


def feature_guess(st,
                  rad,
                  invert='guess',
                  minmass=None,
                  use_tp=False,
                  trim_edge=False,
                  **kwargs):
    """
    Makes a guess at particle positions using heuristic centroid methods.

    Parameters
    ----------
    st : :class:`peri.states.State`
        The state to check adding particles to.
    rad : Float
        The feature size for featuring.
    invert : {'guess', True, False}, optional
コード例 #6
0
from builtins import str, range

import os
import sys
import tempfile
import pickle

import numpy as np

from peri import states, util
from peri.mc import samplers, engines, observers

from peri.logger import log

log = log.getChild("mc.sample")


#=============================================================================
# Sampling methods that run through blocks and sample
#=============================================================================
def sample_state(state,
                 blocks,
                 stepout=1,
                 slicing=True,
                 N=1,
                 doprint=False,
                 procedure='uniform'):
    eng = engines.SequentialBlockEngine(state)
    opsay = observers.Printer()
    ohist = observers.HistogramObserver(block=blocks)
    eng.add_samplers([
コード例 #7
0
ファイル: initializers.py プロジェクト: yangyushi/peri
from builtins import range

import glob
import itertools
from PIL import Image

import numpy as np
import scipy.ndimage as nd

from peri.logger import log

log = log.getChild("initializers")


#=======================================================================
# Image loading functions
#=======================================================================
def _sliceiter(img):
    i = 0
    while True:
        try:
            img.seek(i)
            yield np.array(img)
            i += 1
        except EOFError as e:
            break


def load_tiff(filename):
    img = Image.open(filename)
    return np.array(list(_sliceiter(img)))
コード例 #8
0
ファイル: interaction.py プロジェクト: yangyushi/peri
from builtins import range, object

import numpy as np
import matplotlib as mpl
import matplotlib.pylab as pl
from matplotlib.gridspec import GridSpec

import peri.opt.optimize as opt
from peri.util import Tile

from peri.logger import log
log = log.getChild('interaction')


def make_clean_figure(figsize,
                      remove_tooltips=False,
                      remove_keybindings=False):
    """
    Makes a `matplotlib.pyplot.Figure` without tooltips or keybindings

    Parameters
    ----------
    figsize : tuple
        Figsize as passed to `matplotlib.pyplot.figure`
    remove_tooltips, remove_keybindings : bool
        Set to True to remove the tooltips bar or any key bindings,
        respectively. Default is False

    Returns
    -------
    fig : `matplotlib.pyplot.Figure`