Ejemplo n.º 1
0
    def reddening_spectrum(self,
                           wave,
                           flux,
                           reddening_curve,
                           cHbeta=None,
                           E_BV=None,
                           R_v=None):

        # cHbeta format
        if isinstance(cHbeta, float):
            cHbeta_mag = cHbeta

        elif isinstance(cHbeta, UFloat):
            cHbeta_mag = cHbeta

        # If it is negative we set it to zero
        if cHbeta_mag < 0.0:
            cHbeta_mag = 0.0

        # By default we perform the calculation using the colour excess
        E_BV = E_BV if E_BV != None else self.Ebv_from_cHbeta(
            cHbeta, reddening_curve, R_v)

        # Perform dereddening
        wavelength_range_Xx = self.reddening_Xx(wave, reddening_curve, R_v)
        flux_range_red = flux * np_power(10, -0.4 * wavelength_range_Xx * E_BV)

        return flux_range_red
Ejemplo n.º 2
0
    def X_x_Cardelli1989(self):

        x_true = 1.0 / (self.wavelength_rc / 10000.0)
        y = x_true - 1.82

        y_coeffs = array([
            ones(len(y)), y,
            np_power(y, 2),
            np_power(y, 3),
            np_power(y, 4),
            np_power(y, 5),
            np_power(y, 6),
            np_power(y, 7)
        ])
        a_coeffs = array([
            1, 0.17699, -0.50447, -0.02427, 0.72085, 0.01979, -0.77530, 0.32999
        ])
        b_coeffs = array([
            0, 1.41338, 2.28305, 1.07233, -5.38434, -0.62251, 5.30260, -2.09002
        ])

        a_x = dot(a_coeffs, y_coeffs)
        b_x = dot(b_coeffs, y_coeffs)

        X_x = a_x + b_x / self.R_v

        return X_x
Ejemplo n.º 3
0
 def inner(start_time, end_time):
     data = pitcache_getter(lnmkvdata_name,
                            10).get_tsdata(start_time, end_time)
     data = np_power(data, exponent)
     return data
Ejemplo n.º 4
0
def gaussian(x, mu, sig):
    return np_exp(-np_power(x - mu, 2.) / (2 * np_power(sig, 2.)))
Ejemplo n.º 5
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
Ejemplo n.º 6
0
si  =   (dl-Data_Dict['dg'][ilo])   / (Data_Dict['dg'][ilo+1]-Data_Dict['dg'][ilo])
tj  =   (tl-Data_Dict['Tg'][jlo])   / (Data_Dict['Tg'][jlo+1]-Data_Dict['Tg'][jlo])
uk  =   (op-Data_Dict['taug'][klo]) / (Data_Dict['taug'][klo+1]-Data_Dict['taug'][klo])

Data_Dict['ilo'] = ilo
Data_Dict['jlo'] = jlo
Data_Dict['klo'] = klo
Data_Dict['si']  = si
Data_Dict['tj']  = tj
Data_Dict['uk']  = uk

#Check the coordinates calculation
manage_warnings('Check coordinates', Data_Dict)

#Need to include density multiplications since precomputed level populations do not have density divided out...
dd1     = np_power(10, Data_Dict['dg'][ilo])
dd1     = dd1 * dd1 * Data_Dict['AHe']
dd2     = np_power(10, Data_Dict['dg'][ilo + 1])
dd2     = dd2 * dd2 * Data_Dict['AHe']
       
#Trilinear interpolation (8 vertices)
v1      = (1-si) * (1-tj) * (1-uk) * Data_Dict['pg'][ku2, ilo, jlo, klo]
v2      = si * (1-tj) * (1-uk) * Data_Dict['pg'][ku2, ilo+1, jlo, klo]
v3      = (1-si) * tj * (1-uk) * Data_Dict['pg'][ku2, ilo, jlo+1, klo]
v4      = si  *  tj   * (1-uk) * Data_Dict['pg'][ku2, ilo+1, jlo+1, klo]
v5      = (1-si) * (1-tj) * uk * Data_Dict['pg'][ku2, ilo, jlo  , klo+1]
v6      = si * (1-tj) *  uk  * Data_Dict['pg'][ku2,ilo+1,jlo  ,klo+1]
v7      = (1-si) *  tj  *  uk  * Data_Dict['pg'][ku2,ilo  ,ilo+1,klo+1]
v8      = si *  tj  *  uk  * Data_Dict['pg'][ku2,ilo+1,jlo+1,klo+1]
uppop   = (1e10/dd1) * (v1+v3+v5+v7) + (1e10/dd2) * (v2+v4+v6+v8)
uppop   = uppop * (den * Data_Dict['denHe']/1e10)