Пример #1
0
def test_czml_add_orbit():
    start_epoch = iss.epoch
    end_epoch = iss.epoch + molniya.period

    sample_points = 10

    extractor = CZMLExtractor(start_epoch, end_epoch, sample_points)

    extractor.add_orbit(molniya,
                        label_text="Molniya",
                        label_fill_color=[125, 80, 120, 255])
    extractor.add_orbit(iss, label_text="ISS", path_show=False)

    cords_iss = extractor.czml[1]["position"]["cartesian"]

    h_iss = (end_epoch - iss.epoch).to(u.second) / sample_points

    for i in range(sample_points):
        position_iss_test = propagate(iss, TimeDelta(i * h_iss))
        cords_iss_test = (
            position_iss_test.represent_as(CartesianRepresentation).xyz.to(
                u.meter).value)
        cords_iss_test = np_insert(cords_iss_test, 0, h_iss.value * i, axis=0)

        for j in range(4):
            assert_allclose(cords_iss[4 * i + j], cords_iss_test[j], rtol=1e-5)

    # Test label params and that the values between the two objects are not overwritten
    assert extractor.czml[0]["label"]["text"] == "Molniya"
    assert extractor.czml[1]["label"]["text"] == "ISS"
    assert extractor.czml[0]["label"]["fillColor"]["rgba"] == [
        125, 80, 120, 255
    ]

    assert extractor.czml[1]["path"]["show"]["boolean"] is False
Пример #2
0
    def insert(self, index: int, to_add: Any) -> 'NoteSequence':
        validate_type('index', index, int)

        new_notes = to_add.note_attr_vals
        if len(new_notes.shape) == 1:
            new_notes_num_attributes = new_notes.shape[0]
        else:
            new_notes_num_attributes = new_notes.shape[1]
        if len(self.note_attr_vals):
            num_attributes = self.note_attr_vals.shape[1]
        else:
            num_attributes = 0
        if num_attributes and num_attributes != new_notes_num_attributes:
            raise NoteSequenceInvalidAppendException(
                    'NoteSequence inserted into a NoteSequence must have the same number of attributes')

        if len(self.note_attr_vals):
            self.note_attr_vals = np_insert(self.note_attr_vals, index, new_notes, axis=0)
        else:
            # Must copy the list of the underlying note array to initialize storage for a NoteSequence
            # because NoteSequence arrays are 2D
            if len(new_notes.shape) == 1:
                new_notes = [new_notes]
            self.note_attr_vals = np_copy(new_notes)

        self.update_range_map()
        return self
Пример #3
0
    def execute(self):
        """Execute the command"""

        if self.file_type == 'hdf':
            self.data.dw_io=dwio.HdfIO()
        elif self.file_type == 'hdf_pola':
            self.data.dw_io=dwio.HdfPolaIO()
        elif self.file_type == 'fits':
            self.data.dw_io=dwio.FitsIO()
        else:
            raise NotImplemented
        self.data.fileh = self.data.dw_io.data_open(self.file_name)
        try:
            self.data.data_type_dict = self.data.dw_io.check_data_type(self.data.fileh)
        except:
            pass
        self.data.datasets = self.data.dw_io.get_datasets(self.data.fileh)

        for i_dataset in xrange(len(self.data.datasets)):
            time = integration_to_seconds(np_cumsum(
                    self.data.dw_io.get_integration(self.data.datasets[i_dataset].th)),
                    self.file_type)
            self.data.datasets[i_dataset].time_scale = np_insert(time, 0, 0)

            self.data.datasets[i_dataset].local_osc = self.data.dw_io.get_first_osc(self.data.datasets[i_dataset].th)
            self.data.datasets[i_dataset].frequency = self.data.dw_io.get_frequency(self.data.datasets[i_dataset].th)

            self.data.datasets[i_dataset].freq_scale = np_linspace(self.data.datasets[i_dataset].frequency,
                                            self.data.datasets[i_dataset].frequency+self.data.datasets[i_dataset].bandwidth,
                                            self.data.datasets[i_dataset].n_channels+1)
            self.data.datasets[i_dataset].feed_section = self.data.dw_io.get_feed_section(self.data.fileh, self.data.datasets[i_dataset].th)
            try:
                self.data.datasets[i_dataset].t = "Feed"+str(self.data.datasets[i_dataset].feed_section[0])+" - Section"+str(self.data.datasets[i_dataset].feed_section[1])
            except:
                pass
            self.data.datasets[i_dataset].flagsets = {}
Пример #4
0
def gammatone(freq, k=5, fs=48000, is_plot=False):
    """
    ECMA-418-2 Gammatone filter design

    This function computes the coefficients of a gammatone digital filter according to ECMA-418-2 section 5.1.3.

    Parameters
    ----------
    freq: float
        Center frequency of the filter ['Hz'].

    k: int, optional
        The order of the filter. Default is "5" according to ECMA-418.2.

    fs: float, optional
        The sampling frequency of the signal. Default is 48000 Hz.

    Returns
    -------
    bm_prim, am_prim: ndarray, ndarray
        Numerator (b) and denominator (a) polynomials of the filter.

    """

    # ECMA-418-2 constants
    af_f0 = 81.9289
    c = 0.1618

    # Bandwidth (ECMA 418-2 equation 7)
    delta_f = sqrt((af_f0 ** 2) + ((c * freq) ** 2))

    # Time constant, delay (ECMA 418-2 equation 5)
    binom = comb(2 * k - 2, k - 1, exact=True)
    tau = (1 / (2 ** (2 * k - 1))) * binom * (1.0 / delta_f)

    # "d" coefficient
    d = exp(-1 / (fs * tau))

    # coeff am (ECMA 418-2 equation 11)
    m = arange(5) + 1
    am = np_power((-d), m) * comb(5, m)
    am = np_insert(am, 0, 1)

    # coeff bm (ECMA 418-2 equation 12)
    em = np_array([0, 1, 11, 11, 1])
    i = arange(4) + 1
    denom = np_sum(em[i] * d ** i)
    m = arange(5)
    bm = ((1 - d) ** k) / denom * (d ** m) * em[m]

    # band pass filter coefficients (ECMA 418-2 equation 13 & 14)
    # [by modifying the filter ceofficients with a negative exponential,
    # the filter is a low-pass filter instead of the expected bandpass
    # filter]
    m = arange(6)
    exponential = exp(-1j * 2 * pi * freq * m / fs)
    am_prim_ecma = am * exponential
    bm_prim_ecma = bm * exponential[:-1]

    # band pass filter coefficients (ECMA 418-2 from equation 13 & 14)
    # [corrected to get a bandpass filter, to be validated]
    m = arange(6)
    exponential = exp(1j * 2 * pi * freq * m / fs)
    am_prim = am * exponential
    bm_prim = bm * exponential[:-1]

    if is_plot:
        w, h = freqz(bm, am, worN=round(fs / 2), fs=fs)
        h_db = 20.0 * log10(np_abs(h))
        plt.semilogx(w, h_db, label="am, bm from eq. 11 and 12")

        w, h = freqz(bm_prim_ecma, am_prim_ecma, worN=round(fs / 2), fs=fs)
        h_db = 20.0 * log10(np_abs(h))
        plt.semilogx(w, h_db, label="am', bm' from eq. 13 and 14")

        w, h = freqz(bm_prim, am_prim, worN=round(fs / 2), fs=fs)
        h_db = 20.0 * log10(np_abs(h))
        plt.semilogx(w, h_db, label="am', bm' with positive exp")

        plt.xlabel("Frequency [Hz]")
        plt.ylabel("Amplitude [dB]")
        plt.grid(which="both", axis="both")
        plt.legend()

    return bm_prim, am_prim