Commit 6c8dc290 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

more cleanups

parent 32078eba
......@@ -248,7 +248,7 @@ class Field(object):
parts_val = self._hermitian_decomposition(
val=self.val,
preserve_gaussian_variance=False)
parts = [self.copy_empty().set_val(part_val, copy=False)
parts = [Field(self.domain, part_val, self.dtype, copy=False)
for part_val in parts_val]
else:
parts = [self]
......@@ -563,19 +563,6 @@ class Field(object):
"""
return self._val.size
@property
def dof(self):
""" Returns the total number of degrees of freedom the Field has. For
real Fields this is equal to `self.dim`. For complex Fields it is
2*`self.dim`.
"""
dof = self.dim
if issubclass(self.dtype.type, np.complexfloating):
dof *= 2
return dof
@property
def total_volume(self):
""" Returns the total volume of all spaces in the domain.
......@@ -620,50 +607,12 @@ class Field(object):
out : Field
The output object. An identical copy of 'self'.
See Also
--------
copy_empty
"""
if domain is None:
domain = self.domain
return Field(domain=domain, val=self._val, dtype=dtype, copy=True)
def copy_empty(self, domain=None, dtype=None):
""" Returns an empty copy of the Field.
If no keyword arguments are given, the returned object will be an
identical copy of the original Field. The memory for the data array
is only allocated but not actively set to any value
(c.f. numpy.ndarray.copy_empty). By explicit specification one is able
to change the domain and the dtype of the returned Field.
Parameters
----------
domain : DomainObject
The new domain the Field shall have.
dtype : type
The new dtype the Field shall have.
Returns
-------
out : Field
The output object.
See Also
--------
copy
"""
if domain is None:
domain = self.domain
if dtype is None:
dtype = self.dtype
return Field(domain=domain, dtype=dtype)
def weight(self, power=1, inplace=False, spaces=None):
""" Weights the pixels of `self` with their invidual pixel-volume.
......@@ -702,7 +651,7 @@ class Field(object):
wgt = wgt.reshape(new_shape)
new_val *= wgt**power
fct = fct**power
if fct!=1:
if fct != 1.:
new_val *= fct
return Field(self.domain, new_val, self.dtype)
......
......@@ -16,7 +16,7 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from ... import nifty_utilities as utilities
from ... import Field, nifty_utilities as utilities
from ...spaces import RGSpace,\
GLSpace,\
HPSpace,\
......@@ -143,12 +143,7 @@ class FFTOperator(LinearOperator):
result_domain = list(x.domain)
result_domain[spaces[0]] = self.target[0]
result_dtype = new_val.dtype
result_field = x.copy_empty(domain=result_domain,
dtype=result_dtype)
result_field.set_val(new_val=new_val, copy=True)
return result_field
return Field(result_domain, new_val, copy=False)
def _adjoint_times(self, x, spaces):
spaces = utilities.cast_axis_to_tuple(spaces, len(x.domain))
......@@ -168,13 +163,7 @@ class FFTOperator(LinearOperator):
result_domain = list(x.domain)
result_domain[spaces[0]] = self.domain[0]
result_dtype = new_val.dtype
result_field = x.copy_empty(domain=result_domain,
dtype=result_dtype)
result_field.set_val(new_val=new_val, copy=True)
return result_field
return Field(result_domain, new_val, copy=False)
# ---Mandatory properties and methods---
......
......@@ -111,9 +111,7 @@ class ProjectionOperator(EndomorphicOperator):
remultiplied = np.einsum(local_projection_vector, sublist_projector,
dotted, sublist_dotted,
sublist_x)
result_field = x.copy_empty(dtype=remultiplied.dtype)
result_field.val=remultiplied
return result_field
return Field(x.domain, remultiplied, x.dtype)
def _inverse_times(self, x, spaces):
raise NotImplementedError("The ProjectionOperator is a singular "
......
from ...spaces.power_space import PowerSpace
from ..endomorphic_operator import EndomorphicOperator
from ..laplace_operator import LaplaceOperator
from ... import Field
class SmoothnessOperator(EndomorphicOperator):
......@@ -76,8 +77,7 @@ class SmoothnessOperator(EndomorphicOperator):
spaces)
result *= self._strength**2
else:
result = x.copy_empty()
result.val[:] = 0
result = Field(x.domain, 0., x.dtype)
return result
# ---Added properties and methods---
......
......@@ -45,7 +45,6 @@ class Test_Interface(unittest.TestCase):
['val', np.ndarray],
['shape', tuple],
['dim', np.int],
['dof', np.int],
['total_volume', np.float]]))
def test_return_types(self, domain, attribute_desired_type):
attribute = attribute_desired_type[0]
......
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