Project

General

Profile

Bug #3728

Updated by Brian Nord almost 7 years ago


Execute the following (see Sim_Gal_Spec_Observed_Cunha/test_kbinspec_ben.py). The rebinning from k_binspec_new does not agree with the original function.

<pre>
## Bins a spectrum by just integrating over the pixel edges.
## Note that this will change a flux density to a flux.
import sys
sys.path.append('../../Wrapper/')
sys.path.append('../../Plotters/')
sys.path.append('kcorrect_python_rewrite/')
sys.path.append('../../Utilities/')
import Utilities
import k_binspec_new as k_binspec
import numpy
import pylab
import subprocess
import scipy.integrate
import archive
import scipy.interpolate as interpolate

# import data
with archive.archive('../../../data/data_bank.h5','r') as ar:
abswave = numpy.array(ar['/sky/extinction/wave'])
abstemp = numpy.array(ar['/sky/extinction/power'])
Nwave = ar['/Sim_Gal_Spec_Observed/number_of_pixels']
wavelength_min = ar['/Sim_Gal_Spec_Observed/min_wavelength']
wavelength_max = ar['/Sim_Gal_Spec_Observed/max_wavelength']

# create survey grid (copied from SGSO_Cunha)
dellam = float(wavelength_max - wavelength_min)/Nwave
lambda_survey = numpy.zeros(Nwave, dtype='float64')
lambda_survey[0] = wavelength_min

for i in numpy.arange(1,Nwave):
lambda_survey[i] = lambda_survey[i-1]+dellam

for i in numpy.arange(1,Nwave-1):
lambda_survey[i] = lambda_survey[i] + (lambda_survey[i+1]-lambda_survey[i])/2.

# rebin with k_binspec
abstemp_rebinned = numpy.zeros(lambda_survey.shape)
k_binspec.k_binspec(abswave,abstemp,lambda_survey,abstemp_rebinned)

# rebin with interp1d
abstemp_function = interpolate.interp1d(abswave,abstemp)
abstemp_rebinned2 = abstemp_function(lambda_survey)

# plot original data
f1 = pylab.figure()
pylab.plot(abswave,abstemp,'.')
pylab.xlabel('wavelength')
pylab.ylabel('abstemp (original)')

# plot rebin with k_binspec
f2 = pylab.figure()
pylab.plot(lambda_survey,abstemp_rebinned,'.')
pylab.xlabel('wavelength')
pylab.ylabel('abstemp (k_binspec)')

# plot rebin with interp1d
f3 = pylab.figure()
pylab.plot(lambda_survey,abstemp_rebinned2,'.')
pylab.xlabel('wavelength')
pylab.ylabel('abstemp (interp1d)')

pylab.show()

</pre>

Back