Commit 3c771b2f authored by Theo Steininger's avatar Theo Steininger
Browse files

Merge branch 'master' of gitlab.mpcdf.mpg.de:ift/NIFTy

parents 9ee541a0 1c1b6377
Pipeline #17228 passed with stages
in 25 minutes and 7 seconds
...@@ -16,9 +16,9 @@ ...@@ -16,9 +16,9 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik # NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes. # and financially supported by the Studienstiftung des deutschen Volkes.
from nifty.minimization import ConjugateGradient from builtins import object
from ...minimization import ConjugateGradient
from nifty.field import Field from ...field import Field
class InvertibleOperatorMixin(object): class InvertibleOperatorMixin(object):
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from laplace_operator import LaplaceOperator from .laplace_operator import LaplaceOperator
...@@ -17,11 +17,11 @@ ...@@ -17,11 +17,11 @@
# and financially supported by the Studienstiftung des deutschen Volkes. # and financially supported by the Studienstiftung des deutschen Volkes.
import numpy as np import numpy as np
from nifty.field import Field from ...field import Field
from nifty.spaces.power_space import PowerSpace from ...spaces.power_space import PowerSpace
from nifty.operators.endomorphic_operator import EndomorphicOperator from ..endomorphic_operator import EndomorphicOperator
from nifty import sqrt from ... import sqrt
import nifty.nifty_utilities as utilities from ... import nifty_utilities as utilities
class LaplaceOperator(EndomorphicOperator): class LaplaceOperator(EndomorphicOperator):
......
...@@ -16,4 +16,4 @@ ...@@ -16,4 +16,4 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik # NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes. # and financially supported by the Studienstiftung des deutschen Volkes.
from linear_operator import LinearOperator from .linear_operator import LinearOperator
...@@ -16,15 +16,17 @@ ...@@ -16,15 +16,17 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik # NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes. # and financially supported by the Studienstiftung des deutschen Volkes.
from builtins import str
import abc import abc
from nifty.nifty_meta import NiftyMeta from ...nifty_meta import NiftyMeta
from keepers import Loggable from keepers import Loggable
from nifty.field import Field from ...field import Field
import nifty.nifty_utilities as utilities from ... import nifty_utilities as utilities
from future.utils import with_metaclass
class LinearOperator(Loggable, object): class LinearOperator(with_metaclass(NiftyMeta, type('NewBase', (Loggable, object), {}))):
"""NIFTY base class for linear operators. """NIFTY base class for linear operators.
The base NIFTY operator class is an abstract class from which The base NIFTY operator class is an abstract class from which
...@@ -70,8 +72,6 @@ class LinearOperator(Loggable, object): ...@@ -70,8 +72,6 @@ class LinearOperator(Loggable, object):
""" """
__metaclass__ = NiftyMeta
def __init__(self, default_spaces=None): def __init__(self, default_spaces=None):
self._default_spaces = default_spaces self._default_spaces = default_spaces
......
...@@ -16,4 +16,4 @@ ...@@ -16,4 +16,4 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik # NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes. # and financially supported by the Studienstiftung des deutschen Volkes.
from projection_operator import ProjectionOperator from .projection_operator import ProjectionOperator
...@@ -16,11 +16,11 @@ ...@@ -16,11 +16,11 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik # NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes. # and financially supported by the Studienstiftung des deutschen Volkes.
from builtins import range
import numpy as np import numpy as np
from nifty.field import Field from ...field import Field
from ..endomorphic_operator import EndomorphicOperator
from nifty.operators.endomorphic_operator import EndomorphicOperator
class ProjectionOperator(EndomorphicOperator): class ProjectionOperator(EndomorphicOperator):
...@@ -99,7 +99,7 @@ class ProjectionOperator(EndomorphicOperator): ...@@ -99,7 +99,7 @@ class ProjectionOperator(EndomorphicOperator):
# the one of x, reshape the local data of self and apply it directly # the one of x, reshape the local data of self and apply it directly
active_axes = [] active_axes = []
if spaces is None: if spaces is None:
active_axes = range(len(x.shape)) active_axes = list(range(len(x.shape)))
else: else:
for space_index in spaces: for space_index in spaces:
active_axes += x.domain_axes[space_index] active_axes += x.domain_axes[space_index]
...@@ -124,10 +124,10 @@ class ProjectionOperator(EndomorphicOperator): ...@@ -124,10 +124,10 @@ class ProjectionOperator(EndomorphicOperator):
local_x = x.val.get_local_data(copy=False) local_x = x.val.get_local_data(copy=False)
l = len(local_projection_vector.shape) l = len(local_projection_vector.shape)
sublist_projector = range(l) sublist_projector = list(range(l))
sublist_x = np.arange(len(local_x.shape)) + l sublist_x = np.arange(len(local_x.shape)) + l
for i in xrange(l): for i in range(l):
a = active_axes[i] a = active_axes[i]
sublist_x[a] = i sublist_x[a] = i
......
from response_operator import ResponseOperator from .response_operator import ResponseOperator
from builtins import range
import numpy as np import numpy as np
from nifty import Field,\ from ... import Field,\
FieldArray FieldArray
from nifty.operators.linear_operator import LinearOperator from ..linear_operator import LinearOperator
from nifty.operators.smoothing_operator import SmoothingOperator from ..smoothing_operator import SmoothingOperator
from nifty.operators.composed_operator import ComposedOperator from ..composed_operator import ComposedOperator
from nifty.operators.diagonal_operator import DiagonalOperator from ..diagonal_operator import DiagonalOperator
class ResponseOperator(LinearOperator): class ResponseOperator(LinearOperator):
...@@ -79,8 +80,8 @@ class ResponseOperator(LinearOperator): ...@@ -79,8 +80,8 @@ class ResponseOperator(LinearOperator):
raise ValueError("Length of smoothing kernel and length of" raise ValueError("Length of smoothing kernel and length of"
"exposure do not match") "exposure do not match")
for ii in xrange(len(kernel_smoothing)): for ii in range(len(kernel_smoothing)):
kernel_smoothing[ii] = SmoothingOperator(self._domain[ii], kernel_smoothing[ii] = SmoothingOperator.make(self._domain[ii],
sigma=sigma[ii]) sigma=sigma[ii])
kernel_exposure[ii] = DiagonalOperator(self._domain[ii], kernel_exposure[ii] = DiagonalOperator(self._domain[ii],
diagonal=exposure[ii]) diagonal=exposure[ii])
......
# -*- coding: utf8 -*- # -*- coding: utf8 -*-
from __future__ import division
from builtins import range
import numpy as np import numpy as np
from d2o import STRATEGIES from d2o import STRATEGIES
...@@ -71,7 +73,7 @@ class DirectSmoothingOperator(SmoothingOperator): ...@@ -71,7 +73,7 @@ class DirectSmoothingOperator(SmoothingOperator):
return power[startindex:endindex] return power[startindex:endindex]
p_smooth = np.zeros(endindex-startindex, dtype=power.dtype) 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]) imin = max(startindex, ibegin[i])
imax = min(endindex, ibegin[i]+nval[i]) imax = min(endindex, ibegin[i]+nval[i])
p_smooth[imin:imax] += (power[i] * p_smooth[imin:imax] += (power[i] *
...@@ -95,7 +97,7 @@ class DirectSmoothingOperator(SmoothingOperator): ...@@ -95,7 +97,7 @@ class DirectSmoothingOperator(SmoothingOperator):
ind = np.zeros(nd-1, dtype=np.int) ind = np.zeros(nd-1, dtype=np.int)
i = np.zeros(nd, dtype=object) i = np.zeros(nd, dtype=object)
shape = arr.shape shape = arr.shape
indlist = np.asarray(range(nd)) indlist = np.asarray(list(range(nd)))
indlist = np.delete(indlist, axis) indlist = np.delete(indlist, axis)
i[axis] = slice(None, None) i[axis] = slice(None, None)
outshape = np.asarray(shape).take(indlist) outshape = np.asarray(shape).take(indlist)
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from builtins import range
import numpy as np import numpy as np
from nifty.operators.fft_operator import FFTOperator from nifty.operators.fft_operator import FFTOperator
...@@ -47,7 +49,7 @@ class FFTSmoothingOperator(SmoothingOperator): ...@@ -47,7 +49,7 @@ class FFTSmoothingOperator(SmoothingOperator):
local_kernel = kernel.get_local_data(copy=False) local_kernel = kernel.get_local_data(copy=False)
reshaper = [local_transformed_x.shape[i] if i in coaxes else 1 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) local_kernel = np.reshape(local_kernel, reshaper)
# apply the kernel # apply the kernel
......
...@@ -89,51 +89,44 @@ class SmoothingOperator(EndomorphicOperator): ...@@ -89,51 +89,44 @@ class SmoothingOperator(EndomorphicOperator):
""" """
_fft_smoothing_spaces = [RGSpace, @staticmethod
GLSpace, def make(domain, sigma, log_distances=False, default_spaces=None):
HPSpace] _fft_smoothing_spaces = [RGSpace,
_direct_smoothing_spaces = [PowerSpace] GLSpace,
HPSpace]
def __new__(cls, domain, *args, **kwargs): _direct_smoothing_spaces = [PowerSpace]
if cls is SmoothingOperator:
domain = cls._parse_domain(domain) domain = SmoothingOperator._parse_domain(domain)
if len(domain) != 1: if len(domain) != 1:
raise ValueError("SmoothingOperator only accepts exactly one " raise ValueError("SmoothingOperator only accepts exactly one "
"space as input domain.") "space as input domain.")
if np.any([isinstance(domain[0], sp) if np.any([isinstance(domain[0], sp)
for sp in cls._fft_smoothing_spaces]): for sp in _fft_smoothing_spaces]):
from .fft_smoothing_operator import FFTSmoothingOperator from .fft_smoothing_operator import FFTSmoothingOperator
return super(SmoothingOperator, cls).__new__( return FFTSmoothingOperator (domain, sigma, log_distances,\
FFTSmoothingOperator, domain, *args, **kwargs) default_spaces)
elif np.any([isinstance(domain[0], sp) elif np.any([isinstance(domain[0], sp)
for sp in cls._direct_smoothing_spaces]): for sp in _direct_smoothing_spaces]):
from .direct_smoothing_operator import DirectSmoothingOperator from .direct_smoothing_operator import DirectSmoothingOperator
return super(SmoothingOperator, cls).__new__( return DirectSmoothingOperator (domain, sigma, log_distances,\
DirectSmoothingOperator, domain, *args, **kwargs) default_spaces)
else:
raise NotImplementedError("For the given Space smoothing "
" is not available.")
else: else:
return super(SmoothingOperator, cls).__new__(cls, raise NotImplementedError("For the given Space smoothing "
domain, " is not available.")
*args,
**kwargs)
# ---Overwritten properties and methods--- # ---Overwritten properties and methods---
def __init__(self, domain, sigma, log_distances=False, def __init__(self, domain, sigma, log_distances=False,
default_spaces=None): default_spaces=None):
super(SmoothingOperator, self).__init__(default_spaces) 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) 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._sigma = sigma
self._log_distances = log_distances self._log_distances = log_distances
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from smoothness_operator import SmoothnessOperator from .smoothness_operator import SmoothnessOperator
from ...spaces.power_space import PowerSpace
from nifty.spaces.power_space import PowerSpace from ..endomorphic_operator import EndomorphicOperator
from nifty.operators.endomorphic_operator import EndomorphicOperator from ..laplace_operator import LaplaceOperator
from nifty.operators.laplace_operator import LaplaceOperator
class SmoothnessOperator(EndomorphicOperator): class SmoothnessOperator(EndomorphicOperator):
......
from descriptors import * from .descriptors import *
from plots import * from .plots import *
from figures import * from .figures import *
from colormap import * from .colormap import *
from plotter import * from .plotter import *
from colormap import Colormap from .colormap import Colormap
import colormaps from . import colormaps
\ No newline at end of file
from nifty.plotting.plotly_wrapper import PlotlyWrapper from __future__ import division
from builtins import str
from ..plotly_wrapper import PlotlyWrapper
class Colormap(PlotlyWrapper): class Colormap(PlotlyWrapper):
......
from nifty.plotting.colormap.colormap import Colormap from ..colormap.colormap import Colormap
def HighEnergyCmap(): def HighEnergyCmap():
......
from axis import Axis from .axis import Axis
from line import Line from .line import Line
from marker import Marker from .marker import Marker
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from nifty.plotting.plotly_wrapper import PlotlyWrapper from ..plotly_wrapper import PlotlyWrapper
class Axis(PlotlyWrapper): class Axis(PlotlyWrapper):
......
Supports Markdown
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