Commit f21c8952 authored by theos's avatar theos

Spaces and FieldTypes now support pre_cast and post_cast.

-> A Field on a PowerSpace can now be initialized with a spectral function.
parent aa810aa8
......@@ -490,15 +490,23 @@ class Field(object):
else:
dtype = np.dtype(dtype)
casted_x = self._actual_cast(x, dtype=dtype)
for ind, sp in enumerate(self.domain):
casted_x = sp.pre_cast(x,
axes=self.domain_axes[ind])
for ind, ft in enumerate(self.field_type):
casted_x = ft.pre_cast(casted_x,
axes=self.field_type_axes[ind])
casted_x = self._actual_cast(casted_x, dtype=dtype)
for ind, sp in enumerate(self.domain):
casted_x = sp.complement_cast(casted_x,
axes=self.domain_axes[ind])
casted_x = sp.post_cast(casted_x,
axes=self.domain_axes[ind])
for ind, ft in enumerate(self.field_type):
casted_x = ft.complement_cast(casted_x,
axes=self.field_type_axes[ind])
casted_x = ft.post_cast(casted_x,
axes=self.field_type_axes[ind])
return casted_x
......
......@@ -51,5 +51,8 @@ class FieldType(object):
return result_array
def complement_cast(self, x, axes=None):
def pre_cast(self, x, axes=None):
return x
def post_cast(self, x, axes=None):
return x
......@@ -14,7 +14,8 @@ class PowerSpace(Space):
# ---Overwritten properties and methods---
def __init__(self, harmonic_domain=RGSpace((1,)), distribution_strategy='not',
def __init__(self, harmonic_domain=RGSpace((1,)),
distribution_strategy='not',
log=False, nbin=None, binbounds=None,
dtype=np.dtype('float')):
......@@ -51,6 +52,12 @@ class PowerSpace(Space):
raise NotImplementedError(about._errors.cstring(
"ERROR: There is no k_array implementation for PowerSpace."))
def pre_cast(self, x, axes=None):
if callable(x):
return x(self.kindex)
else:
return x
# ---Mandatory properties and methods---
@property
......
......@@ -266,7 +266,10 @@ class Space(object):
"""
raise NotImplementedError
def complement_cast(self, x, axes=None):
def pre_cast(self, x, axes=None):
return x
def post_cast(self, x, axes=None):
return x
def compute_k_array(self, distribution_strategy):
......
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