コード例 #1
0
ファイル: rebin_hdf5.py プロジェクト: mxhf/hetdex_cube
def get_rebinned(ww, ff, start = 3494.74, step =  1.9858398, stop = 5500.):
    N = int( np.ceil( (stop - start)/step ) )
    _lw, _lf = srebin.linlin(ww, ff, start, step, stop, dowarn=False)
    
    lw = (np.arange(N) * step) + start
    lf = np.zeros_like(lw)
    
    lf[:min(N, len(_lf))] = _lf[:min(N, len(_lf))]

    if not _lw[0] == lw[0]:
        print("Binning is broken, please check.")
        return np.nan
    
    return lw, lf
コード例 #2
0
ファイル: new_rebinning.py プロジェクト: mlujnie/Spielereien
def get_rebinned(ff,exposures, ifuslots, amps, exp, ifuslot, amp, extensions=['spectrum', 'sky_spectrum', 'fiber_to_fiber'], start = 3494.74, step =  1.9858398, stop = 5500.):
    
    #global exposures, ifuslots, amps#, ff
 
    ii = (exposures == exp) * (ifuslots == ifuslot) * (amps == amp)
    if not sum(ii) == 1:
        print('ValueError in Rebinning')
        raise ValueError("Error: Could not identify file for exposure {} slot {} and amp {}.".format(exp, ifuslot, amp))
        return
  
    fin = ff[ii][0]
    print("Reading {}".format(fin))
    hdu = fits.open(fin)
  
    wl = hdu['wavelength'].data
    #spectrum       = hdu['spectrum'].data
    #sky_spectrum   = hdu['sky_spectrum'].data
    #sky_subtracted = hdu['sky_subtracted'].data

    #start,stop = 3503.9716796, 5396.477
    N = int( np.ceil( (stop - start)/step ) )
    
    rebinned = {}
    for ext in extensions:
        #for j in range(hdu[ext].data.shape[1]): # This might cause big errors...
            #isnull = np.unique(hdu[ext].data[:,j])
            #isnull = isnull[np.where(isnull != 0)]
            #if len(isnull)==0:
            #    hdu[ext].data[:, j] = np.ones(hdu[ext].data.shape[0])*np.nan
        print("Rebinning {}".format(ext))
        
        new = np.zeros([wl.shape[0], N])
        hduextdata = hdu[ext].data 
        for i in range(wl.shape[0]):
            w = wl[i,:]
            f = hduextdata[i,:]
            start = start
            step =  step
            stop = stop
            lw, lf = linlin(w, f, start, step, stop, dowarn=False)
            #lw = np.arange(start, stop, step)
            #lf = model_resampled_10A = spectres(lw, w, f)
            
            # hack as they may not all necessareyly have the same length
            new[i,:min(N, len(lf))] = lf[:min(N, len(lf))]

        rebinned[ext] = new
    return lw, rebinned
コード例 #3
0
def get_rebinned(hdu, extensions, start=3494.74, step=1.9858398, stop=5500.):
    #start,stop = 3503.9716796, 5396.477
    N = int(np.ceil((stop - start) / step))

    rebinned = {}
    wl = hdu['wavelength'].data
    for ext in extensions:
        new = np.zeros([wl.shape[0], N])

        for i in range(wl.shape[0]):
            w = wl[i, :]
            f = hdu[ext].data[i, :]
            start = start
            step = step
            stop = stop
            lw, lf = srebin.linlin(w, f, start, step, stop, dowarn=False)

            # hack as they may not all necessareyly have the same length
            new[i, :min(N, len(lf))] = lf[:min(N, len(lf))]

        rebinned[ext] = new
    return lw, rebinned