Ejemplo n.º 1
0
    def test_init_from_attenuation_VF_array_att(self):
        """
        Test passing array as attenuation in the Coaxial classmethod
        `from_attenuation_VF_units`.
        """
        # create a Coaxial media for frequency-dependant attenuation and
        # test the resulting alpha values (real part of gamma)
        frequency = rf.Frequency(start=1, stop=2, unit='GHz', npoints=101)
        # k0k1k2 attenuation model
        # values taken for HUBER+SUHNER DATA SHEET Coaxial Cable S_10172_B-1
        # attenuation in dB/m for frequency in GHz
        att = 0 + 0.0826 * npy.sqrt(
            frequency.f_scaled) + 0.0129 * frequency.f_scaled

        coax = Coaxial.from_attenuation_VF(frequency=frequency,
                                           att=att,
                                           unit='dB/m')
        # check alpha in gamma
        assert_array_almost_equal(rf.db_2_np(att), coax.gamma.real)

        # if the attenuation array length does not match the frequency,
        # should raise a ValueError
        frequency2 = rf.Frequency(start=1, stop=2, unit='GHz', npoints=10)
        with self.assertRaises(ValueError):
            coax = Coaxial.from_attenuation_VF(frequency=frequency2, att=att)
Ejemplo n.º 2
0
 def test_init_from_attenuation_VF_units(self):
     """
     Test the attenuation unit conversions in the Coaxial classmethod
     `from_attenuation_VF_units`.
     """
     # create a dummy Coaxial media for various attenuation and test the
     # resulting alpha values (real part of gamma)
     frequency = rf.Frequency(npy.random.rand(), unit='GHz', npoints=1)
     _att = npy.random.rand()
     # dB/m
     coax = Coaxial.from_attenuation_VF(frequency=frequency,
                                        VF=1,
                                        att=_att,
                                        unit='dB/m')
     assert_almost_equal(coax.gamma.real, rf.db_2_np(_att))
     # dB/100m
     coax = Coaxial.from_attenuation_VF(frequency=frequency,
                                        VF=1,
                                        att=_att,
                                        unit='dB/100m')
     assert_almost_equal(coax.gamma.real, rf.db_2_np(_att) / 100)
     # dB/feet
     coax = Coaxial.from_attenuation_VF(frequency=frequency,
                                        VF=1,
                                        att=_att,
                                        unit='dB/feet')
     assert_almost_equal(coax.gamma.real,
                         rf.db_2_np(_att) * rf.meter_2_feet())
     # dB/100m
     coax = Coaxial.from_attenuation_VF(frequency=frequency,
                                        VF=1,
                                        att=_att,
                                        unit='dB/100feet')
     assert_almost_equal(coax.gamma.real,
                         rf.db_2_np(_att) / 100 * rf.meter_2_feet())
     # Neper/m
     coax = Coaxial.from_attenuation_VF(frequency=frequency,
                                        VF=1,
                                        att=_att,
                                        unit='Np/m')
     assert_almost_equal(coax.gamma.real, _att)
     # Neper/feet
     coax = Coaxial.from_attenuation_VF(frequency=frequency,
                                        VF=1,
                                        att=_att,
                                        unit='Np/feet')
     assert_almost_equal(coax.gamma.real, _att * rf.meter_2_feet())
Ejemplo n.º 3
0
 def test_db_2_np(self):
     """
     Test dB to Np conversion with: 
         1 [dB] = ln(10)/20 [Np]
     """
     assert_almost_equal(rf.db_2_np(1), log(10) / 20)