示例#1
0
    def __init__(self,
                 frequencies,
                 rcomplex=None,
                 ccomplex=None,
                 rmag=None,
                 rpha=None):
        """

        Parameters
        ----------
        frequencies : :class:`numpy.ndarray`
            Array of size N containing N frequencies in ascending order
        rcomplex : :class:`numpy.ndarray`, optional
            Complex values resistance/resistivity values (size N)
        ccomplex : :class:`numpy.ndarray`, optional
            Complex values conductance/conductivity values (size N)
        rmag : :class:`numpy.ndarray`, optional
            Real valued resistance/resistivity magnitude values (size N)
        rpha : :class:`numpy.ndarray`, optional
            Real valued resistance/resistivity phase values (size N)

        """
        if rcomplex is None and ccomplex is None and (rmag is None
                                                      or rpha is None):
            raise Exception('One initialization array is allowed!')
        if rcomplex is not None and ccomplex is not None:
            raise Exception('Only one initialization array is allowed!')

        self.frequencies = frequencies

        if rcomplex is not None:
            self.rcomplex = rcomplex
            self.ccomplex = convert('rcomplex', 'ccomplex', rcomplex)
        elif ccomplex is not None:
            self.ccomplex = ccomplex
            self.rcomplex = convert('ccomplex', 'rcomplex', ccomplex)
        elif rmag is not None and rpha is not None:
            self.rcomplex = rmag * np.exp(1j * rpha / 1000.0)
            self.ccomplex = convert('rcomplex', 'ccomplex', self.rcomplex)

        self.rmag = np.abs(self.rcomplex)
        self.rpha = np.arctan2(np.imag(self.rcomplex), np.real(
            self.rcomplex)) * 1000
        self.cmag = np.abs(self.ccomplex)
        self.cpha = np.arctan2(np.imag(self.ccomplex), np.real(
            self.ccomplex)) * 1000

        self.rmag_rpha = np.vstack((self.rmag, self.rpha)).T
        self.cmag_cpha = np.vstack((self.cmag, self.cpha)).T

        self.rre = np.real(self.rcomplex)
        self.rim = np.imag(self.rcomplex)
        self.cre = np.real(self.ccomplex)
        self.cim = np.imag(self.ccomplex)

        self.rre_rim = np.vstack((self.rre, self.rim)).T
        self.cre_cim = np.vstack((self.cre, self.cim)).T
示例#2
0
    def test_convert(self):
        """
        We test by converting to all values, from all values. This is a chain
        test, i.e. we only provide the first input data, and then we use the
        output of this conversion to feed the next conversion. The last
        conversion then converts back to the initial data format, and thus we
        can compare those outputs to the hardcoded values.
        """
        from_keys = list(sorted(sip_convert.from_converters.keys()))

        # we know (require) that the first key is rmag_rpha
        initial_values = np.hstack((self.rmag, self.rpha))
        start_values = initial_values.copy()

        for nr, from_key in enumerate(from_keys):
            to = (nr + 1) % len(from_keys)
            output_data = sip_convert.convert(from_keys[nr], from_keys[to],
                                              start_values)
            start_values = output_data

        diffs = start_values - initial_values

        for term in diffs.flatten():
            # check to within 3 places
            # assert_almost_equal(term, 0, 3)
            assert term == pytest.approx(0, abs=1e-3)
示例#3
0
    def test_input_styles(self):
        # prepare test styles
        data_1d = np.hstack((self.cmag, self.cpha))
        data_2d_one_spec = np.vstack((self.cmag, self.cpha))
        data_2d_multi_specs = np.vstack((data_1d, data_1d))

        for data, one_spec in zip(
            (data_1d, data_2d_one_spec, data_2d_multi_specs),
            (False, True, False)):
            data_converted = sip_convert.convert('cmag_cpha', 'rmag_rpha',
                                                 data, one_spec)
            assert data.shape == data_converted.shape
            data_backconverted = sip_convert.convert('rmag_rpha', 'cmag_cpha',
                                                     data_converted, one_spec)
            numpy.testing.assert_almost_equal(data,
                                              data_backconverted,
                                              decimal=4)