Commit e953a066 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

simplifications

parent 6dc4eb7f
Pipeline #25200 failed with stages
in 6 minutes and 6 seconds
...@@ -65,9 +65,7 @@ if __name__ == "__main__": ...@@ -65,9 +65,7 @@ if __name__ == "__main__":
noiseless_data = MeasurementOperator(true_sky) noiseless_data = MeasurementOperator(true_sky)
noise_amplitude = noiseless_data.val.std()*noise_level noise_amplitude = noiseless_data.val.std()*noise_level
N = ift.ScalingOperator(noise_amplitude**2, d_space) N = ift.ScalingOperator(noise_amplitude**2, d_space)
n = ift.Field.from_random( n = N.draw_sample()
domain=d_space, random_type='normal',
std=noise_amplitude, mean=0)
# Creating the mock data # Creating the mock data
d = noiseless_data + n d = noiseless_data + n
......
...@@ -66,9 +66,7 @@ if __name__ == "__main__": ...@@ -66,9 +66,7 @@ if __name__ == "__main__":
noiseless_data = MeasurementOperator(true_sky) noiseless_data = MeasurementOperator(true_sky)
noise_amplitude = noiseless_data.val.std()*noise_level noise_amplitude = noiseless_data.val.std()*noise_level
N = ift.ScalingOperator(noise_amplitude**2, d_space) N = ift.ScalingOperator(noise_amplitude**2, d_space)
n = ift.Field.from_random( n = N.draw_sample()
domain=d_space, random_type='normal',
std=noise_amplitude, mean=0)
# Creating the mock data # Creating the mock data
d = noiseless_data + n d = noiseless_data + n
......
...@@ -83,9 +83,7 @@ if __name__ == "__main__": ...@@ -83,9 +83,7 @@ if __name__ == "__main__":
noise_amplitude = noiseless_data.val.std()/signal_to_noise noise_amplitude = noiseless_data.val.std()/signal_to_noise
# Setting up the noise covariance and drawing a random noise realization # Setting up the noise covariance and drawing a random noise realization
N = ift.ScalingOperator(noise_amplitude**2, data_domain) N = ift.ScalingOperator(noise_amplitude**2, data_domain)
noise = ift.Field.from_random( noise = N.draw_sample()
domain=data_domain, random_type='normal',
std=noise_amplitude, mean=0)
data = noiseless_data + noise data = noiseless_data + noise
# Wiener filter # Wiener filter
......
...@@ -46,9 +46,7 @@ if __name__ == "__main__": ...@@ -46,9 +46,7 @@ if __name__ == "__main__":
noise_amplitude = noiseless_data.val.std()/signal_to_noise noise_amplitude = noiseless_data.val.std()/signal_to_noise
# Setting up the noise covariance and drawing a random noise realization # Setting up the noise covariance and drawing a random noise realization
N = ift.ScalingOperator(noise_amplitude**2, data_domain) N = ift.ScalingOperator(noise_amplitude**2, data_domain)
noise = ift.Field.from_random( noise = N.draw_sample()
domain=data_domain, random_type='normal',
std=noise_amplitude, mean=0)
data = noiseless_data + noise data = noiseless_data + noise
# Wiener filter # Wiener filter
......
...@@ -73,9 +73,7 @@ if __name__ == "__main__": ...@@ -73,9 +73,7 @@ if __name__ == "__main__":
noiseless_data = R(mock_signal) noiseless_data = R(mock_signal)
noise_amplitude = noiseless_data.val.std()/signal_to_noise noise_amplitude = noiseless_data.val.std()/signal_to_noise
N = ift.ScalingOperator(noise_amplitude**2, data_domain) N = ift.ScalingOperator(noise_amplitude**2, data_domain)
noise = ift.Field.from_random( noise = N.draw_sample()
domain=data_domain, random_type='normal',
std=noise_amplitude, mean=0)
data = noiseless_data + noise data = noiseless_data + noise
j = R.adjoint_times(N.inverse_times(data)) j = R.adjoint_times(N.inverse_times(data))
......
...@@ -43,10 +43,7 @@ if __name__ == "__main__": ...@@ -43,10 +43,7 @@ if __name__ == "__main__":
signal_to_noise = 1. signal_to_noise = 1.
noise_amplitude = noiseless_data.val.std()/signal_to_noise noise_amplitude = noiseless_data.val.std()/signal_to_noise
N = ift.ScalingOperator(noise_amplitude**2, s_space) N = ift.ScalingOperator(noise_amplitude**2, s_space)
n = ift.Field.from_random(domain=s_space, n = N.draw_sample()
random_type='normal',
std=noise_amplitude,
mean=0)
# Create mock data # Create mock data
d = noiseless_data + n d = noiseless_data + n
......
...@@ -134,11 +134,11 @@ class DiagonalOperator(EndomorphicOperator): ...@@ -134,11 +134,11 @@ class DiagonalOperator(EndomorphicOperator):
self._spaces) self._spaces)
def draw_sample(self): def draw_sample(self):
if self._spaces is not None: if np.issubdtype(self._ldiag.dtype, np.complexfloating):
raise ValueError("Cannot draw (yet) from this operator") raise ValueError("cannot draw sample from complex-valued operator")
res = Field.from_random(random_type="normal", res = Field.from_random(random_type="normal",
domain=self._domain, domain=self._domain,
dtype=self._diagonal.dtype) dtype=self._diagonal.dtype)
res *= sqrt(self._diagonal) res.val[()] *= np.sqrt(self._ldiag)
return res return res
...@@ -63,8 +63,9 @@ def power_analyze(field, spaces=None, binbounds=None, ...@@ -63,8 +63,9 @@ def power_analyze(field, spaces=None, binbounds=None,
---------- ----------
field : Field field : Field
The field to be analyzed The field to be analyzed
spaces : None or int or tuple of int , optional spaces : None or int or tuple of int, optional
The set of subdomains for which the powerspectrum shall be computed. The indices of subdomains for which the power spectrum shall be
computed.
If None, all subdomains will be converted. If None, all subdomains will be converted.
(default : None). (default : None).
binbounds : None or array-like, optional binbounds : None or array-like, optional
...@@ -85,7 +86,7 @@ def power_analyze(field, spaces=None, binbounds=None, ...@@ -85,7 +86,7 @@ def power_analyze(field, spaces=None, binbounds=None,
------- -------
Field Field
The output object. Its domain is a PowerSpace and it contains The output object. Its domain is a PowerSpace and it contains
the power spectrum of 'field'. the power spectrum of `field`.
""" """
for sp in field.domain: for sp in field.domain:
...@@ -133,7 +134,7 @@ def power_synthesize_nonrandom(field, spaces=None): ...@@ -133,7 +134,7 @@ def power_synthesize_nonrandom(field, spaces=None):
def power_synthesize(field, spaces=None, real_power=True, real_signal=True): def power_synthesize(field, spaces=None, real_power=True, real_signal=True):
"""Returns a sampled field with `field`**2 as its power spectrum. """Returns a sampled field with `field`\**2 as its power spectrum.
This method draws a Gaussian random field in the harmonic partner This method draws a Gaussian random field in the harmonic partner
domain of this field's domains, using this field as power spectrum. domain of this field's domains, using this field as power spectrum.
...@@ -231,12 +232,7 @@ def create_power_operator(domain, power_spectrum, space=None, dtype=None): ...@@ -231,12 +232,7 @@ def create_power_operator(domain, power_spectrum, space=None, dtype=None):
An operator that implements the given power spectrum. An operator that implements the given power spectrum.
""" """
domain = DomainTuple.make(domain) domain = DomainTuple.make(domain)
if space is None: space = utilities.infer_space(domain, space)
if len(domain) != 1:
raise ValueError("space keyword must be set")
else:
space = 0
space = int(space)
return DiagonalOperator( return DiagonalOperator(
create_power_field(domain[space], power_spectrum, dtype), create_power_field(domain[space], power_spectrum, dtype),
domain=domain, spaces=space) domain=domain, spaces=space)
......
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