Commit 848a7b66 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

load external dependencies only when it is necessary

parent 2e1ba71f
......@@ -19,7 +19,6 @@
import numpy as np
from .slicing_transformation import SlicingTransformation
from . import lm_transformation_helper
import pyHealpix
class GLLMTransformation(SlicingTransformation):
......@@ -31,10 +30,12 @@ class GLLMTransformation(SlicingTransformation):
return False
def _transformation_of_slice(self, inp):
from pyHealpix import sharpjob_d
lmax = self.codomain.lmax
mmax = self.codomain.mmax
sjob = pyHealpix.sharpjob_d()
sjob = sharpjob_d()
sjob.set_Gauss_geometry(self.domain.nlat, self.domain.nlon)
sjob.set_triangular_alm_info(lmax, mmax)
if issubclass(inp.dtype.type, np.complexfloating):
......
......@@ -19,7 +19,6 @@
import numpy as np
from .slicing_transformation import SlicingTransformation
from . import lm_transformation_helper
import pyHealpix
class HPLMTransformation(SlicingTransformation):
......@@ -31,16 +30,18 @@ class HPLMTransformation(SlicingTransformation):
return False
def _transformation_of_slice(self, inp):
from pyHealpix import map2alm
lmax = self.codomain.lmax
mmax = lmax
if issubclass(inp.dtype.type, np.complexfloating):
rr = pyHealpix.map2alm(inp.real, lmax, mmax)
rr = map2alm(inp.real, lmax, mmax)
rr = lm_transformation_helper.buildIdx(rr, lmax=lmax)
ri = pyHealpix.map2alm(inp.imag, lmax, mmax)
ri = map2alm(inp.imag, lmax, mmax)
ri = lm_transformation_helper.buildIdx(ri, lmax=lmax)
return rr + 1j*ri
else:
rr = pyHealpix.map2alm(inp, lmax, mmax)
rr = map2alm(inp, lmax, mmax)
return lm_transformation_helper.buildIdx(rr, lmax=lmax)
......@@ -19,7 +19,6 @@
import numpy as np
from .slicing_transformation import SlicingTransformation
from . import lm_transformation_helper
import pyHealpix
class LMGLTransformation(SlicingTransformation):
......@@ -31,10 +30,12 @@ class LMGLTransformation(SlicingTransformation):
return False
def _transformation_of_slice(self, inp):
from pyHealpix import sharpjob_d
lmax = self.domain.lmax
mmax = self.domain.mmax
sjob = pyHealpix.sharpjob_d()
sjob = sharpjob_d()
sjob.set_Gauss_geometry(self.codomain.nlat, self.codomain.nlon)
sjob.set_triangular_alm_info(lmax, mmax)
if issubclass(inp.dtype.type, np.complexfloating):
......
......@@ -19,7 +19,6 @@
import numpy as np
from .slicing_transformation import SlicingTransformation
from . import lm_transformation_helper
import pyHealpix
class LMHPTransformation(SlicingTransformation):
......@@ -32,6 +31,8 @@ class LMHPTransformation(SlicingTransformation):
return False
def _transformation_of_slice(self, inp):
from pyHealpix import alm2map
nside = self.codomain.nside
lmax = self.domain.lmax
mmax = lmax
......@@ -39,10 +40,10 @@ class LMHPTransformation(SlicingTransformation):
if issubclass(inp.dtype.type, np.complexfloating):
rr = lm_transformation_helper.buildLm(inp.real, lmax=lmax)
ri = lm_transformation_helper.buildLm(inp.imag, lmax=lmax)
rr = pyHealpix.alm2map(rr, lmax, mmax, nside)
ri = pyHealpix.alm2map(ri, lmax, mmax, nside)
rr = alm2map(rr, lmax, mmax, nside)
ri = alm2map(ri, lmax, mmax, nside)
return rr + 1j*ri
else:
rr = lm_transformation_helper.buildLm(inp, lmax=lmax)
return pyHealpix.alm2map(rr, lmax, mmax, nside)
return alm2map(rr, lmax, mmax, nside)
......@@ -17,7 +17,6 @@
# and financially supported by the Studienstiftung des deutschen Volkes.
from builtins import object, range
import pyfftw
class SerialFFT(object):
......@@ -25,6 +24,8 @@ class SerialFFT(object):
The pyfftw pendant of a fft object.
"""
def __init__(self, domain, codomain):
import pyfftw
self.domain = domain
self.codomain = codomain
......@@ -48,6 +49,7 @@ class SerialFFT(object):
result : numpy.ndarray
Fourier-transformed pendant of the input field.
"""
from pyfftw.interfaces.numpy_fft import fftn, ifftn
# Check if the axes provided are valid given the shape
if axes is not None and \
......@@ -55,6 +57,6 @@ class SerialFFT(object):
raise ValueError("Provided axes does not match array shape")
if self.codomain.harmonic:
return pyfftw.interfaces.numpy_fft.fftn(val, axes=axes)
return fftn(val, axes=axes)
else:
return pyfftw.interfaces.numpy_fft.ifftn(val, axes=axes)
return ifftn(val, axes=axes)
......@@ -17,12 +17,9 @@
# and financially supported by the Studienstiftung des deutschen Volkes.
from __future__ import division
import itertools
import numpy as np
from ..space import Space
import pyHealpix
class GLSpace(Space):
......@@ -65,8 +62,6 @@ class GLSpace(Space):
------
ValueError
If input `nlat` or `nlon` is invalid.
ImportError
If the pyHealpix module is not available
See Also
--------
......@@ -87,10 +82,6 @@ class GLSpace(Space):
# ---Overwritten properties and methods---
def __init__(self, nlat, nlon=None):
if pyHealpix is None:
raise ImportError(
"The module pyHealpix is needed but not available.")
super(GLSpace, self).__init__()
self._nlat = self._parse_nlat(nlat)
......@@ -122,9 +113,10 @@ class GLSpace(Space):
nlon=self.nlon)
def weight(self, x, power=1, axes=None, inplace=False):
from pyHealpix import GL_weights
nlon = self.nlon
nlat = self.nlat
vol = pyHealpix.GL_weights(nlat, nlon) ** np.float(power)
vol = GL_weights(nlat, nlon) ** np.float(power)
weight = np.array(list(itertools.chain.from_iterable(
itertools.repeat(x, nlon) for x in vol)))
......
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