Skip to content

Commit

Permalink
Merge 75cd2b9 into ee2619c
Browse files Browse the repository at this point in the history
  • Loading branch information
megies committed Jul 11, 2016
2 parents ee2619c + 75cd2b9 commit 5359b30
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
26 changes: 17 additions & 9 deletions obspy/core/inventory/response.py
Expand Up @@ -22,7 +22,7 @@
import numpy as np

from obspy.core.util.base import ComparingObject
from obspy.core.util.obspy_types import (CustomComplex, CustomFloat,
from obspy.core.util.obspy_types import (ComplexWithUncertainties, CustomFloat,
FloatWithUncertainties,
FloatWithUncertaintiesAndUnit,
ObsPyException,
Expand Down Expand Up @@ -258,10 +258,10 @@ def zeros(self):

@zeros.setter
def zeros(self, value):
for x in value:
if not isinstance(x, CustomComplex):
msg = "Zeros must be of CustomComplex type."
raise TypeError(msg)
value = list(value)
for i, x in enumerate(value):
if not isinstance(x, ComplexWithUncertainties):
value[i] = ComplexWithUncertainties(x)
self._zeros = value

@property
Expand All @@ -270,12 +270,20 @@ def poles(self):

@poles.setter
def poles(self, value):
for x in value:
if not isinstance(x, CustomComplex):
msg = "Poles must be of CustomComplex type."
raise TypeError(msg)
value = list(value)
for i, x in enumerate(value):
if not isinstance(x, ComplexWithUncertainties):
value[i] = ComplexWithUncertainties(x)
self._poles = value

@property
def normalization_frequency(self):
return self._normalization_frequency

@normalization_frequency.setter
def normalization_frequency(self, value):
self._normalization_frequency = Frequency(value)

@property
def pz_transfer_function_type(self):
return self._pz_transfer_function_type
Expand Down
19 changes: 18 additions & 1 deletion obspy/core/tests/test_response.py
Expand Up @@ -23,10 +23,12 @@
from matplotlib import rcParams

from obspy import UTCDateTime, read_inventory
from obspy.core.inventory.response import (
_pitick2latex, PolesZerosResponseStage)
from obspy.core.util.misc import CatchOutput
from obspy.core.util.obspy_types import ComplexWithUncertainties
from obspy.core.util.testing import ImageComparison, get_matplotlib_version
from obspy.signal.invsim import evalresp
from obspy.core.inventory.response import _pitick2latex
from obspy.io.xseed import Parser


Expand Down Expand Up @@ -160,6 +162,21 @@ def test_segfault_after_error_handling(self):
inv[0][0][0].response.get_evalresp_response,
t_samp, nfft, output="DISP")

def test_custom_types_init(self):
"""
Test initializations that involve custom decimal types like
`ComplexWithUncertainties`.
"""
# initializing poles / zeros from native types should work
poles = [1+1j, 1, 1j]
zeros = [2+3j, 2, 3j]
stage = PolesZerosResponseStage(
1, 1, 1, "", "", "LAPLACE (HERTZ)", 1, zeros, poles)
self.assertEqual(type(stage.zeros[0]), ComplexWithUncertainties)
self.assertEqual(type(stage.poles[0]), ComplexWithUncertainties)
self.assertEqual(stage.poles, poles)
self.assertEqual(stage.zeros, zeros)


def suite():
return unittest.makeSuite(ResponseTestCase, 'test')
Expand Down

0 comments on commit 5359b30

Please sign in to comment.