Example #1
0
def test_kcorr():
    filters = ['u', 'B', 'V', 'r', 'i', 'Y', 'J', 'H']

    wave0, flux0 = getSED(0, version="H3")
    # redden the flux a bit
    rflux = kcorr.redden(wave0, flux0, 0.1, 0.0, 0.0)
    # generate artificial photometry at redshift 0.1:
    mag0s = []
    magzs = []
    for f in filters:
        mag0s.append(fset[f].synth_mag(wave0, rflux, z=0.))
        magzs.append(fset[f].synth_mag(wave0, rflux, z=0.1) + 2.5 * log10(1.1))

    mag0s = array([mag0s])
    magzs = array([magzs])
    masks = greater(magzs, 0)
    k0s = array([kcorr.kcorr([0], f, f, 0.1)[0][0] for f in filters])
    ks, mask, Rts, m_opts = kcorr.kcorr_mangle([0],
                                               filters,
                                               magzs,
                                               masks,
                                               filters,
                                               0.1,
                                               version='H3',
                                               full_output=True,
                                               gradient=True,
                                               normfilter='H')
    # difference in kcorrs with no mangling:
    delta1 = absolute((magzs[0, :] - mag0s)[0] - k0s)
    # difference in kcorrs with mangling:
    delta2 = absolute((magzs[0, :] - mag0s)[0] - ks[0])

    # The mangling should be better and precise
    assert alltrue(delta2 < delta1) and alltrue(delta2 < 0.01)
Example #2
0
def test_kcorr():
   filters = ['u','B','V','r','i','Y','J','H']

   wave0,flux0 = getSED(0, version="H3")
   # redden the flux a bit
   rflux = kcorr.redden(wave0,flux0, 0.1, 0.0, 0.0)
   # generate artificial photometry at redshift 0.1:
   mag0s = []
   magzs = []
   for f in filters:
      mag0s.append(fset[f].synth_mag(wave0, rflux, z=0.))
      magzs.append(fset[f].synth_mag(wave0, rflux, z=0.1)+2.5*log10(1.1))
   
   mag0s = array([mag0s])
   magzs = array([magzs])
   masks = greater(magzs, 0)
   k0s = array([kcorr.kcorr([0], f, f, 0.1)[0][0] for f in filters])
   ks,mask,Rts,m_opts = kcorr.kcorr_mangle([0], filters, magzs, masks, filters, 
         0.1, version='H3', full_output=True, gradient=True, normfilter='H')
   # difference in kcorrs with no mangling:
   delta1 = absolute((magzs[0,:]-mag0s)[0] - k0s)
   # difference in kcorrs with mangling:
   delta2 = absolute((magzs[0,:]-mag0s)[0] - ks[0])

   # The mangling should be better and precise
   assert alltrue(delta2 < delta1) and alltrue(delta2 < 0.01)
Example #3
0
def plot_kcorrs(self, device='13/XW', colors=None, symbols=None):
   '''Plot the k-corrections, both mangled and un-mangled.'''
   # See  what filters we're going to use:
   bands = self.ks.keys()
   if len(bands) == 0:
      return

   if colors is None:  colors = default_colors
   if symbols is None:  symbols = default_symbols

   eff_wavs = []
   for filter in bands:
      eff_wavs.append(fset[filter].ave_wave)
   eff_wavs = asarray(eff_wavs)
   ids = argsort(eff_wavs)
   bands = [bands[i] for i in ids]
   minx = Inf
   maxx = -Inf
   for b in bands:
      if b not in colors:  colors[b] = 1
      if b not in symbols:  symbols[b] = 4
      minx = min(minx, self.data[b].t.min())
      maxx = max(maxx, self.data[b].t.max())
   n_plots = len(bands)
   cols = int(round(sqrt(n_plots)))
   rows = (n_plots / cols)
   if n_plots % cols:  rows += 1
   p = pygplot.Panel(1, n_plots, device=device, aspect=1.0/6*n_plots)

   for b in bands:
      x = self.data[b].MJD - self.Tmax
      days = arange(int(x[0]), int(x[-1]), 1)
      rest_days = days/(1+self.z)/self.ks_s
      k,k_m = map(array, kcorr.kcorr(rest_days.tolist(), self.restbands[b], b, 
         self.z, self.EBVgal, 0.0, version=self.k_version))
      k_m = equal(k_m, 1)
      pp = pygplot.Plot(fsize=1, font=2, xlabel='Epoch (days)',
            leftpad=0.1, rotylab=1, xrange=[minx,maxx])
      pp.filter = b
      pp.inst = self
      p.add(pp)
      pp.line(days[k_m],k[k_m], color=colors[b])
      pp.point(x[self.ks_mask[b]], self.ks[b][self.ks_mask[b]], 
            symbol=symbols[b], color=colors[b], fillcolor=colors[b],
            fsize=2)
      pp.label(0.9, 0.9, b, just=1, vjust=1, reference='relative')

   p.plots[n_plots/2].ylabel = 'K-correction'
   p.plot()
   p.interact(bindings={'A':plot_mangled_SED})
   p.close()
   return(p)
Example #4
0
def plot_kcorrs(self, colors=None, symbols=None, outfile=None):
   '''Plot the k-corrections, both mangled and un-mangled.'''
   # See  what filters we're going to use:
   bands = self.ks.keys()
   if len(bands) == 0:
      return

   if colors is None:  colors = color_dict()
   if symbols is None:  symbols = symbol_dict()

   eff_wavs = []
   for filt in bands:
      eff_wavs.append(fset[filt].ave_wave)
   eff_wavs = asarray(eff_wavs)
   ids = argsort(eff_wavs)
   bands = [bands[i] for i in ids]
      
   n_plots = len(bands)
   p = myplotlib.PanelPlot(1, n_plots, num=112, figsize=(6,n_plots),
        nymax=5, prunex=None)
   p.title("Use 'm' to plot mangled SED for any point")
   p.xlabel('Epoch (days)')
   p.ylabel('K-corrections')

   for i in range(len(bands)):
      #p.axes[i].yaxis.set_major_locator(MaxNLocator(5))
      b = bands[i]
      x = self.data[b].MJD - self.Tmax
      days = (arange(int(x[0]), int(x[-1]), 1)) #/(1+self.z)/self.ks_s
      rest_days = days/(1+self.z)/self.ks_s
      k,k_m = map(array, kcorr.kcorr(rest_days.tolist(), self.restbands[b], 
         b, self.z, self.EBVgal, 0.0, version=self.k_version))
      k_m = equal(k_m, 1)
      p.axes[i].filt = b
      p.axes[i].inst = self
      p.axes[i].plot(days[k_m],k[k_m], '-', color=colors[b])
      p.axes[i].plot(x[self.ks_mask[b]], self.ks[b][self.ks_mask[b]], 
            symbols[b], color=colors[b])
      p.axes[i].text(0.9, 0.9, b, transform=p.axes[i].transAxes,
            verticalalignment='top', horizontalalignment='right')

   p.set_limits(all_equal=0)
   p.draw()
   p.bc = ButtonClick(p.fig, bindings={'m':plot_mangled_SED})
   p.bc.connect()
   if outfile is not None:
      p.fig.savefig(outfile)
   return(p)
Example #5
0
def plot_kcorrs(self, colors=None, symbols=None, outfile=None):
   '''Plot the k-corrections, both mangled and un-mangled.'''
   # See  what filters we're going to use:
   bands = list(self.ks.keys())
   if len(bands) == 0:
      return

   if colors is None:  colors = color_dict()
   if symbols is None:  symbols = symbol_dict()

   eff_wavs = []
   for filt in bands:
      eff_wavs.append(fset[filt].ave_wave)
   eff_wavs = asarray(eff_wavs)
   ids = argsort(eff_wavs)
   bands = [bands[i] for i in ids]
      
   n_plots = len(bands)
   p = myplotlib.PanelPlot(1, n_plots, num=112, figsize=(6,n_plots))
        
   p.title("Use 'm' to plot mangled SED for any point")
   p.xlabel('Epoch (days)')
   p.ylabel('K-corrections')

   for i in range(len(bands)):
      #p.axes[i].yaxis.set_major_locator(MaxNLocator(5))
      b = bands[i]
      x = self.data[b].MJD - self.Tmax
      days = (arange(int(x[0]), int(x[-1]), 1)) #/(1+self.z)/self.ks_s
      rest_days = days/(1+self.z)/self.ks_s
      k,k_m = list(map(array, kcorr.kcorr(rest_days.tolist(), self.restbands[b], 
         b, self.z, self.EBVgal, 0.0, version=self.k_version)))
      k_m = equal(k_m, 1)
      p.axes[i].filt = b
      p.axes[i].inst = self
      p.axes[i].plot(days[k_m],k[k_m], '-', color=colors[b])
      p.axes[i].plot(x[self.ks_mask[b]], self.ks[b][self.ks_mask[b]], 
            symbols[b], color=colors[b])
      p.axes[i].text(0.9, 0.9, b, transform=p.axes[i].transAxes,
            verticalalignment='top', horizontalalignment='right')

   p.set_limits(all_equal=0)
   p.draw()
   p.bc = ButtonClick(p.fig, bindings={'m':plot_mangled_SED})
   p.bc.connect()
   if outfile is not None:
      p.fig.savefig(outfile)
   return(p)
Example #6
0
def plot_kcorrs(self, device='13/XW', colors=None, symbols=None):
    '''Plot the k-corrections, both mangled and un-mangled.'''
    # See  what filters we're going to use:
    bands = list(self.ks.keys())
    if len(bands) == 0:
        return

    if colors is None: colors = default_colors
    if symbols is None: symbols = default_symbols

    eff_wavs = []
    for filter in bands:
        eff_wavs.append(fset[filter].ave_wave)
    eff_wavs = asarray(eff_wavs)
    ids = argsort(eff_wavs)
    bands = [bands[i] for i in ids]
    minx = Inf
    maxx = -Inf
    for b in bands:
        if b not in colors: colors[b] = 1
        if b not in symbols: symbols[b] = 4
        minx = min(minx, self.data[b].t.min())
        maxx = max(maxx, self.data[b].t.max())
    n_plots = len(bands)
    cols = int(round(sqrt(n_plots)))
    rows = (n_plots / cols)
    if n_plots % cols: rows += 1
    p = pygplot.Panel(1, n_plots, device=device, aspect=1.0 / 6 * n_plots)

    for b in bands:
        x = self.data[b].MJD - self.Tmax
        days = arange(int(x[0]), int(x[-1]), 1)
        rest_days = days / (1 + self.z) / self.ks_s
        k, k_m = list(
            map(
                array,
                kcorr.kcorr(rest_days.tolist(),
                            self.restbands[b],
                            b,
                            self.z,
                            self.EBVgal,
                            0.0,
                            version=self.k_version)))
        k_m = equal(k_m, 1)
        pp = pygplot.Plot(fsize=1,
                          font=2,
                          xlabel='Epoch (days)',
                          leftpad=0.1,
                          rotylab=1,
                          xrange=[minx, maxx])
        pp.filter = b
        pp.inst = self
        p.add(pp)
        pp.line(days[k_m], k[k_m], color=colors[b])
        pp.point(x[self.ks_mask[b]],
                 self.ks[b][self.ks_mask[b]],
                 symbol=symbols[b],
                 color=colors[b],
                 fillcolor=colors[b],
                 fsize=2)
        pp.label(0.9, 0.9, b, just=1, vjust=1, reference='relative')

    p.plots[n_plots / 2].ylabel = 'K-correction'
    p.plot()
    p.interact(bindings={'A': plot_mangled_SED})
    p.close()
    return (p)