Commit 1297585d authored by Theo Steininger's avatar Theo Steininger
Browse files

Merge branch 'python3' into 'master'

Add Python3 compatibility

See merge request !156
parents da29a8f4 a476b875
Pipeline #17025 passed with stages
in 24 minutes and 49 seconds
from builtins import range
import numpy as np
from nifty import Field,\
FieldArray
......@@ -79,8 +80,8 @@ class ResponseOperator(LinearOperator):
raise ValueError("Length of smoothing kernel and length of"
"exposure do not match")
for ii in xrange(len(kernel_smoothing)):
kernel_smoothing[ii] = SmoothingOperator(self._domain[ii],
for ii in range(len(kernel_smoothing)):
kernel_smoothing[ii] = SmoothingOperator.make(self._domain[ii],
sigma=sigma[ii])
kernel_exposure[ii] = DiagonalOperator(self._domain[ii],
diagonal=exposure[ii])
......
# -*- coding: utf8 -*-
from __future__ import division
from builtins import range
import numpy as np
from d2o import STRATEGIES
......@@ -71,7 +73,7 @@ class DirectSmoothingOperator(SmoothingOperator):
return power[startindex:endindex]
p_smooth = np.zeros(endindex-startindex, dtype=power.dtype)
for i in xrange(startindex, endindex):
for i in range(startindex, endindex):
imin = max(startindex, ibegin[i])
imax = min(endindex, ibegin[i]+nval[i])
p_smooth[imin:imax] += (power[i] *
......@@ -95,7 +97,7 @@ class DirectSmoothingOperator(SmoothingOperator):
ind = np.zeros(nd-1, dtype=np.int)
i = np.zeros(nd, dtype=object)
shape = arr.shape
indlist = np.asarray(range(nd))
indlist = np.asarray(list(range(nd)))
indlist = np.delete(indlist, axis)
i[axis] = slice(None, None)
outshape = np.asarray(shape).take(indlist)
......
# -*- coding: utf-8 -*-
from builtins import range
import numpy as np
from nifty.operators.fft_operator import FFTOperator
......@@ -47,7 +49,7 @@ class FFTSmoothingOperator(SmoothingOperator):
local_kernel = kernel.get_local_data(copy=False)
reshaper = [local_transformed_x.shape[i] if i in coaxes else 1
for i in xrange(len(transformed_x.shape))]
for i in range(len(transformed_x.shape))]
local_kernel = np.reshape(local_kernel, reshaper)
# apply the kernel
......
......@@ -89,51 +89,44 @@ class SmoothingOperator(EndomorphicOperator):
"""
_fft_smoothing_spaces = [RGSpace,
GLSpace,
HPSpace]
_direct_smoothing_spaces = [PowerSpace]
def __new__(cls, domain, *args, **kwargs):
if cls is SmoothingOperator:
domain = cls._parse_domain(domain)
if len(domain) != 1:
raise ValueError("SmoothingOperator only accepts exactly one "
"space as input domain.")
if np.any([isinstance(domain[0], sp)
for sp in cls._fft_smoothing_spaces]):
from .fft_smoothing_operator import FFTSmoothingOperator
return super(SmoothingOperator, cls).__new__(
FFTSmoothingOperator, domain, *args, **kwargs)
elif np.any([isinstance(domain[0], sp)
for sp in cls._direct_smoothing_spaces]):
from .direct_smoothing_operator import DirectSmoothingOperator
return super(SmoothingOperator, cls).__new__(
DirectSmoothingOperator, domain, *args, **kwargs)
else:
raise NotImplementedError("For the given Space smoothing "
" is not available.")
@staticmethod
def make(domain, sigma, log_distances=False, default_spaces=None):
_fft_smoothing_spaces = [RGSpace,
GLSpace,
HPSpace]
_direct_smoothing_spaces = [PowerSpace]
domain = SmoothingOperator._parse_domain(domain)
if len(domain) != 1:
raise ValueError("SmoothingOperator only accepts exactly one "
"space as input domain.")
if np.any([isinstance(domain[0], sp)
for sp in _fft_smoothing_spaces]):
from .fft_smoothing_operator import FFTSmoothingOperator
return FFTSmoothingOperator (domain, sigma, log_distances,\
default_spaces)
elif np.any([isinstance(domain[0], sp)
for sp in _direct_smoothing_spaces]):
from .direct_smoothing_operator import DirectSmoothingOperator
return DirectSmoothingOperator (domain, sigma, log_distances,\
default_spaces)
else:
return super(SmoothingOperator, cls).__new__(cls,
domain,
*args,
**kwargs)
raise NotImplementedError("For the given Space smoothing "
" is not available.")
# ---Overwritten properties and methods---
def __init__(self, domain, sigma, log_distances=False,
default_spaces=None):
super(SmoothingOperator, self).__init__(default_spaces)
# # the _parse_domain is already done in the __new__ method
# self._domain = self._parse_domain(domain)
# if len(self.domain) != 1:
# raise ValueError("SmoothingOperator only accepts exactly one "
# "space as input domain.")
self._domain = self._parse_domain(domain)
if len(self._domain) != 1:
raise ValueError("SmoothingOperator only accepts exactly one "
"space as input domain.")
self._sigma = sigma
self._log_distances = log_distances
......
# -*- coding: utf-8 -*-
from smoothness_operator import SmoothnessOperator
from .smoothness_operator import SmoothnessOperator
from descriptors import *
from plots import *
from figures import *
from colormap import *
from plotter import *
from .descriptors import *
from .plots import *
from .figures import *
from .colormap import *
from .plotter import *
from colormap import Colormap
import colormaps
\ No newline at end of file
from .colormap import Colormap
from . import colormaps
from __future__ import division
from builtins import str
from nifty.plotting.plotly_wrapper import PlotlyWrapper
......
from axis import Axis
from line import Line
from marker import Marker
from .axis import Axis
from .line import Line
from .marker import Marker
from figure_2D import Figure2D
from figure_3D import Figure3D
from multi_figure import MultiFigure
from .figure_2D import Figure2D
from .figure_3D import Figure3D
from .multi_figure import MultiFigure
# -*- coding: utf-8 -*-
from figure_from_plot import FigureFromPlot
from .figure_from_plot import FigureFromPlot
from nifty.plotting.plots import Heatmap, HPMollweide, GLMollweide
......
# -*- coding: utf-8 -*-
from figure_from_plot import FigureFromPlot
from .figure_from_plot import FigureFromPlot
class Figure3D(FigureFromPlot):
......
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from figure_base import FigureBase
from .figure_base import FigureBase
class FigureFromPlot(FigureBase):
......
# -*- coding: utf-8 -*-
from builtins import map
from builtins import str
import numpy as np
from nifty import dependency_injector as gdi
from figure_base import FigureBase
from figure_3D import Figure3D
from .figure_base import FigureBase
from .figure_3D import Figure3D
plotly = gdi.get('plotly')
......
from builtins import object
from abc import ABCMeta, abstractmethod
from nifty.nifty_meta import NiftyMeta
from future.utils import with_metaclass
class PlotlyWrapper(object):
__metaclass__ = NiftyMeta
class PlotlyWrapper(with_metaclass(NiftyMeta, object)):
@abstractmethod
def to_plotly(self):
return {}
from scatter_plots import *
from heatmaps import *
from .scatter_plots import *
from .heatmaps import *
# -*- coding: utf-8 -*-
from hpmollweide import HPMollweide
from glmollweide import GLMollweide
from heatmap import Heatmap
from .hpmollweide import HPMollweide
from .glmollweide import GLMollweide
from .heatmap import Heatmap
# -*- coding: utf-8 -*-
from nifty import dependency_injector as gdi
from heatmap import Heatmap
from .heatmap import Heatmap
import numpy as np
from nifty.plotting.descriptors import Axis
......
# -*- coding: utf-8 -*-
from __future__ import division
from nifty import dependency_injector as gdi
from heatmap import Heatmap
from .heatmap import Heatmap
import numpy as np
from nifty.plotting.descriptors import Axis
......@@ -41,7 +42,7 @@ class HPMollweide(Heatmap):
ptg = np.empty((phi.size, 2), dtype=np.float64)
ptg[:, 0] = theta
ptg[:, 1] = phi
base = pyHealpix.Healpix_Base(int(np.sqrt(x.size/12)), "RING")
base = pyHealpix.Healpix_Base(int(np.sqrt(x.size//12)), "RING")
res[mask] = x[base.ang2pix(ptg)]
return res
......
# -*- coding: utf-8 -*-
from __future__ import division
import numpy as np
def mollweide_helper(xsize):
xsize = int(xsize)
ysize = int(xsize/2)
ysize = xsize//2
res = np.full(shape=(ysize, xsize), fill_value=np.nan,
dtype=np.float64)
xc = (xsize-1)*0.5
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment