Calculate the wavelengths of the filter half-maximum values.
354632
def calc_halfmax_points(self):
        
        d = self._ensure_data()
        return interpolated_halfmax_points(d.wlen, d.resp)
100310
def half_duration(self):
        """"""
        if self._interval is not None:
            a, b = self._interval
            return (b - a) * .5
        else:
            return self.interval_duration * .5
255315
def _get_binned_arrays(self, wavelengths, flux_unit, area=None,
                           vegaspec=None):
        """"""
        x = self._validate_binned_wavelengths(wavelengths)
        y = self.sample_binned(wavelengths=x, flux_unit=flux_unit, area=area,
                               vegaspec=vegaspec)

        if isinstance(wavelengths, u.Quantity):
            w = x.to(wavelengths.unit, u.spectral())
        else:
            w = x

        return w, y
1310686
def process(self, frames, eod, spec_range=120.0):
        

        samples = frames[:, 0]
        nsamples = len(frames[:, 0])
        if nsamples != self.blocksize:
            self.window = self.window_function(nsamples)
        samples *= self.window

        while nsamples > self.fft_size:
            self.fft_size = 2 * self.fft_size

        zeros_p = numpy.zeros(self.fft_size / 2 - int(nsamples / 2))
        if nsamples % 2:
            zeros_n = numpy.zeros(self.fft_size / 2 - int(nsamples / 2) - 1)
        else:
            zeros_n = numpy.zeros(self.fft_size / 2 - int(nsamples / 2))
        samples = numpy.concatenate((zeros_p, samples, zeros_n), axis=0)

        fft = numpy.fft.fft(samples)
        # normalized abs(FFT) between 0 and 1
        spectrum = numpy.abs(fft[:fft.shape[0] / 2 + 1]) / float(nsamples)
        length = numpy.float64(spectrum.shape[0])

        # scale the db spectrum from [- spec_range db ... 0 db] > [0..1]
        db_spectrum = ((20 * (numpy.log10(spectrum + 1e-30)))
                       .clip(-spec_range, 0.0) + spec_range) / spec_range
        energy = spectrum.sum()
        spectral_centroid = 0

        if energy > 1e-20:
            # calculate the spectral centroid
            if self.spectrum_range is None:
                self.spectrum_range = numpy.arange(length)
            spectral_centroid = (spectrum * self.spectrum_range).sum() / \
                (energy * (length - 1)) * \
                self.samplerate * 0.5
            # clip > log10 > scale between 0 and 1
            spectral_centroid = (math.log10(self.clip(spectral_centroid,
                                                      self.lower,
                                                      self.higher)) -
                                 self.lower_log) / (self.higher_log -
                                                    self.lower_log)

        return (spectral_centroid, db_spectrum)
81036
def F(self, **kwargs):
        '''
        
        '''
        Eg = self.Eg_Gamma_0(**kwargs)
        Delta_SO = self.Delta_SO(**kwargs)
        Ep = self.Ep(**kwargs)
        meff = self.meff_e_Gamma_0(**kwargs)
        return (1./meff-1-(Ep*(Eg+2.*Delta_SO/3.))/(Eg*(Eg+Delta_SO)))/2
533861
def _wl_dist(wl_a, wl_b):
    """"""
    if isinstance(wl_a, tuple):
        # central wavelength
        wl_a = wl_a[1]
    if isinstance(wl_b, tuple):
        wl_b = wl_b[1]
    if wl_a is None or wl_b is None:
        return 1000.
    return abs(wl_a - wl_b)
943203
def nan_maximum_filter(arr, ksize):
    '''
    
    '''
    out = np.empty_like(arr)
    _calc(arr, out, ksize//2)
    return out
539167
def Planck_wavelength(l, T):
    '''
    '''
    u = hPlanck*c_light/l/kBoltzmann/T
    return 2*kBoltzmann**5*T**5/hPlanck**4/c_light**3*u**5/(exp(u)-1)
417706
def lowPassFilter(self, threshold):
        '''
        
        '''
        if not threshold:
            return
        rows, cols = self.img.shape
        tx = int(cols * threshold * 0.25)
        ty = int(rows * threshold * 0.25)
        # upper side
        self.fshift[rows - tx:rows, :] = 0
        # lower side
        self.fshift[0:tx, :] = 0
        # left side
        self.fshift[:, 0:ty] = 0
        # right side
        self.fshift[:, cols - ty:cols] = 0
674774
def convert2wavenumber(self):
        """"""
        for chname in self.rsr.keys():
            elems = [k for k in self.rsr[chname].keys()]
            for sat in elems:
                if sat == "wavelength":
                    LOG.debug("Get the wavenumber from the wavelength: sat=%s chname=%s", sat, chname)
                    wnum = 1. / (1e-4 * self.rsr[chname][sat][:])  # microns to cm
                    self.rsr[chname]['wavenumber'] = wnum[::-1]
                else:
                    if type(self.rsr[chname][sat]) is dict:
                        for name in self.rsr[chname][sat].keys():
                            resp = self.rsr[chname][sat][name][:]
                            self.rsr[chname][sat][name] = resp[::-1]
                    else:
                        resp = self.rsr[chname][sat][:]
                        self.rsr[chname][sat] = resp[::-1]

        for chname in self.rsr.keys():
            del self.rsr[chname]['wavelength']

        self.unit = 'cm-1'
595924
def find_variable_start_frequency(approximant, parameters, f_start, max_length,
                                  delta_f = 1):
    
    l = max_length + 1
    f = f_start - delta_f
    while l > max_length:
        f += delta_f
        l = pycbc.waveform.get_waveform_filter_length_in_time(approximant,
                                                      parameters, f_lower=f)
    return f
1136572
function FourierTransform(bufferSize, sampleRate) {
  this.bufferSize = bufferSize;
  this.sampleRate = sampleRate;
  this.bandwidth  = 2 / bufferSize * sampleRate / 2;

  this.spectrum   = new Float32Array(bufferSize/2);
  this.real       = new Float32Array(bufferSize);
  this.imag       = new Float32Array(bufferSize);

  this.peakBand   = 0;
  this.peak       = 0;

  /**
   * Calculates the *middle* frequency of an FFT band.
   *
   * @param {Number} index The index of the FFT band.
   *
   * @returns The middle frequency in Hz.
   */
  this.getBandFrequency = function(index) {
    return this.bandwidth * index + this.bandwidth / 2;
  };

  this.calculateSpectrum = function() {
    var spectrum  = this.spectrum,
        real      = this.real,
        imag      = this.imag,
        bSi       = 2 / this.bufferSize,
        sqrt      = Math.sqrt,
        rval, 
        ival,
        mag;

    for (var i = 0, N = bufferSize/2; i < N; i++) {
      rval = real[i];
      ival = imag[i];
      mag = bSi * sqrt(rval * rval + ival * ival);

      if (mag > this.peak) {
        this.peakBand = i;
        this.peak = mag;
      }

      spectrum[i] = mag;
    }
  };
}
909816
def rsr(self):
        """"""
        arr = np.array([self.wave.value, self.throughput]).swapaxes(0, 1)

        return arr
811052
def layer_norm_vars(filters):
  """"""
  scale = tf.get_variable(
      "layer_norm_scale", [filters], initializer=tf.ones_initializer())
  bias = tf.get_variable(
      "layer_norm_bias", [filters], initializer=tf.zeros_initializer())
  return scale, bias
262531
def apply_filter(x, filter=None, axis=0):
    """"""
    x = _as_array(x)
    if x.shape[axis] == 0:
        return x
    b, a = filter
    return signal.filtfilt(b, a, x, axis=axis)
994634
def freq_filt(bma):
    
    """
    Want to fit linear function to artifact line in freq space,
    Then mask everything near that line at distances of ~5-200 pixels, 
    Or whatever the maximum CCD artifact dimension happens to be, 
    This will depend on scaling - consult CCD map for interval
    """

    #Fill ndv with random data
    bf = malib.randomfill(bma)

    import scipy.fftpack
    f = scipy.fftpack.fft2(bf)
    ff = scipy.fftpack.fftshift(f)

    #Ben suggested a Hahn filter here, remove the low frequency, high amplitude information
    #Then do a second fft?

    #np.log(np.abs(ff))

    #perc = malib.calcperc(np.real(ff), perc=(80, 95))
    #malib.iv(numpy.real(ff), clim=perc)

    #See http://scipy-lectures.github.io/advanced/image_processing/

    #Starting at a,b, compute argmax along vertical axis for restricted range
    #Fit line to the x and y argmax values
    #Mask [argmax[y]-1:argmax[y]+1]

    #Create radial mask
    ff_dim = np.array(ff.shape)
    a,b = ff_dim/2
    n = ff_dim.max()
    y,x = np.ogrid[-a:n-a, -b:n-b]
    r1 = 40 
    r2 = 60 
    ff_mask = np.ma.make_mask(ff)
    radial_mask = (r1**2 <= x**2 + y**2) & (x**2 + y**2 < r2**2)
    #Note issues with rounding indices here
    #Hacked in +1 for testing
    ff_mask[:] = radial_mask[a-ff_dim[0]/2:a+ff_dim[0], b-ff_dim[1]/2:b+1+ff_dim[1]/2]

    #Combine radial and line mask

    #Convert mask to 0-1, then feather

    fm = ff * ff_mask

    #Inverse fft
    bf_filt = scipy.fftpack.ifft2(scipy.fftpack.ifftshift(fm))

    #Apply original mask
    bf_filt = np.ma.masked_array(bf_filt, bma.mask)
770082
function filterCoeffs(f_c) {
  if (f_c > 0.5) {  // we can't lowpass above the nyquist frequency...
    f_c = 0.5;
  }
  var wct = Math.sqrt(2) * Math.PI * f_c;
  var e = Math.exp(-wct);
  var c = e * Math.cos(wct);
  var gain = (1 - 2*c + e*e) / 2;
  return [gain, 2*c, -e*e];
}