Skip to content

Commit

Permalink
Merge pull request #369 from jakirkham/python3_support
Browse files Browse the repository at this point in the history
Python 3 support
  • Loading branch information
jakirkham committed Feb 29, 2016
2 parents d41b7b9 + 2a22252 commit 718f518
Show file tree
Hide file tree
Showing 49 changed files with 592 additions and 444 deletions.
20 changes: 10 additions & 10 deletions nanshe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,13 @@
# "viewer"
]

import box
import converter
import io
import imp
import learner
import registerer
import syn
import util
# import viewer # Must be commented as there is some segfault
# coming from Volumina.
from nanshe import box
from nanshe import converter
from nanshe import io
from nanshe import imp
from nanshe import learner
from nanshe import registerer
from nanshe import syn
from nanshe import util
# from nanshe import viewer # Must be commented as there is some segfault
# coming from Volumina.
2 changes: 1 addition & 1 deletion nanshe/box/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
__all__ = ["spams_sandbox"]


import spams_sandbox
from nanshe.box import spams_sandbox
8 changes: 4 additions & 4 deletions nanshe/imp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

__all__ = ["filters", "registration", "renorm", "segment"]

import filters
import registration
import renorm
import segment
from nanshe.imp import filters
from nanshe.imp import registration
from nanshe.imp import renorm
from nanshe.imp import segment
6 changes: 3 additions & 3 deletions nanshe/imp/filters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@

__all__ = ["noise", "masks", "wavelet"]

import masks
import noise
import wavelet
from nanshe.imp.filters import masks
from nanshe.imp.filters import noise
from nanshe.imp.filters import wavelet
8 changes: 4 additions & 4 deletions nanshe/imp/filters/noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ def estimate_noise(input_array, significance_threshold=3.0):
>>> estimate_noise(numpy.eye(2), 3)
0.5
>>> round(estimate_noise(numpy.eye(3), 3), 3)
>>> round(float(estimate_noise(numpy.eye(3), 3)), 3)
0.471
>>> numpy.random.seed(10)
>>> round(estimate_noise(numpy.random.random((2000,2000)), 1), 3)
>>> round(float(estimate_noise(numpy.random.random((2000,2000)), 1)), 3)
0.167
>>> numpy.random.seed(10)
>>> round(estimate_noise(numpy.random.random((2000,2000)), 2), 3)
>>> round(float(estimate_noise(numpy.random.random((2000,2000)), 2)), 3)
0.289
>>> numpy.random.seed(10)
>>> round(estimate_noise(numpy.random.random((2000,2000)), 3), 3)
>>> round(float(estimate_noise(numpy.random.random((2000,2000)), 3)), 3)
0.289
"""

Expand Down
7 changes: 4 additions & 3 deletions nanshe/imp/filters/wavelet.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import vigra

from nanshe.io import hdf5
from nanshe.util.iters import irange
from nanshe.util.xnumpy import binomial_coefficients


Expand Down Expand Up @@ -163,7 +164,7 @@ def binomial_1D_vigra_kernel(i, n=4, border_treatment=vigra.filters.BorderTreatm
h_kern = binomial_1D_array_kernel(i, n)

# Determine the kernel center
h_kern_half_width = (h_kern.size - 1) / 2
h_kern_half_width = (h_kern.size - 1) // 2

# Default kernel
k = vigra.filters.Kernel1D()
Expand Down Expand Up @@ -405,7 +406,7 @@ def transform(im0,
imCur = im0.astype(numpy.float32)


for i in xrange(1, scale.max() + 1):
for i in irange(1, scale.max() + 1):
if include_intermediates:
imPrev = imCur
imOut[i] = imOut[i - 1]
Expand All @@ -415,7 +416,7 @@ def transform(im0,

h_ker = binomial_1D_vigra_kernel(i)

for d in xrange(len(scale)):
for d in irange(len(scale)):
if i <= scale[d]:
vigra.filters.convolveOneDimension(imCur, d, h_ker, out=imCur)

Expand Down
8 changes: 4 additions & 4 deletions nanshe/imp/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def register_mean_offsets(frames2reg,
space_shift_min[space_shift_min == 0] = None
space_shift_min = tuple(space_shift_min)
reg_frames_slice = tuple(
slice(_1, _2) for _1, _2 in itertools.izip(
slice(_1, _2) for _1, _2 in iters.izip(
space_shift_max, space_shift_min
)
)
Expand Down Expand Up @@ -502,7 +502,7 @@ def translate_fourier(frame_fft, shift):
array([[ 0., 1., 2., 3.],
[ 4., 5., 6., 7.],
[ 8., 9., 10., 11.]])
>>> af = fft.fftn(a, axes=tuple(xrange(a.ndim)))
>>> af = fft.fftn(a, axes=tuple(iters.irange(a.ndim)))
>>> numpy.around(af, decimals=10)
array([[ 66. +0.j , -6. +6.j , -6. +0.j , -6. -6.j ],
[-24.+13.85640646j, 0. +0.j , 0. +0.j , 0. +0.j ],
Expand All @@ -517,7 +517,7 @@ def translate_fourier(frame_fft, shift):
[ 24.-13.85640646j, 0. -0.j , 0. +0.j , 0. +0.j ]])
>>> fft.ifftn(
... atf, axes=tuple(xrange(a.ndim))
... atf, axes=tuple(iters.irange(a.ndim))
... ).real.round().astype(int).astype(float)
array([[ 9., 10., 11., 8.],
[ 1., 2., 3., 0.],
Expand All @@ -532,7 +532,7 @@ def translate_fourier(frame_fft, shift):
>>> fft.ifftn(
... atf, axes=tuple(xrange(1, a.ndim))
... atf, axes=tuple(iters.irange(1, a.ndim))
... ).real.round().astype(int).astype(float)
array([[[ 9., 10., 11., 8.],
[ 1., 2., 3., 0.],
Expand Down
4 changes: 3 additions & 1 deletion nanshe/imp/renorm.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
# Generally useful and fast to import so done immediately.
import numpy

from nanshe.util import iters

# Need in order to have logging information no matter what.
from nanshe.util import prof

Expand Down Expand Up @@ -225,7 +227,7 @@ def renormalized_images(input_array, ord=2, output_array=None):
# does not support the axis keyword. So, we must use a for loop.
# Take each image at each time and turn the image into a vector.
# Then, find the norm and divide each image by this norm.
for i in xrange(output_array.shape[0]):
for i in iters.irange(output_array.shape[0]):
output_array_i = output_array[i]
output_array_i_norm = numpy.linalg.norm(
output_array_i.ravel(), ord=ord
Expand Down
Loading

0 comments on commit 718f518

Please sign in to comment.