예제 #1
0
    def update(self, z):
        if self.opt.f26 is not None:
            wa, nfl, ner, nco, model, artists, options = (
                self.wa, self.nfl, self.ner, self.co, self.model,
                self.artists, self.opt)
        else:
            wa, nfl, ner, nco, artists, options = (
                self.wa, self.nfl, self.ner, self.co,
                self.artists, self.opt)

        self.z = z

        zp1 = z + 1
        betamin = self.vmin / c_kms
        betamax = self.vmax / c_kms

        for t in artists['ticklabels']:
            t.remove()
        for t in artists['ticks']:
            t.remove()
        artists['ticklabels'] = []
        artists['ticks'] = []
        if artists['ew'] is not None:
            artists['ew'].remove()
            artists['ew'] = None
        for r in artists['regions']:
            r.remove()
        for s in artists['sky']:
            s.remove()
        artists['regions'] = []
        artists['sky'] = []

        # want plots to appear from  top down, so we need reversed()
        for i, trans in enumerate(reversed(options.linelist)):
            ax = self.axes[0]
            offset = i * 1.5
            if i >= self.num_per_panel:
                offset = (i - self.num_per_panel) * 1.5
                ax = self.axes[1]

            watrans = trans['wa']
            obswa = watrans * zp1
            wmin = obswa * (1 + 3*betamin)
            wmax = obswa * (1 + 3*betamax)
            if self.opt.showticks and len(self.allticks) > 0:
                ticks = self.allticks
                tickwmin = obswa * (1 + betamin)
                tickwmax = obswa * (1 + betamax)
                wticks = ticks.wa
                cond = between(wticks, tickwmin, tickwmax)
                if cond.any():
                    vel = (wticks[cond] / obswa - 1) * c_kms
                    for j,t in enumerate(ticks[cond]):
                        T,Tlabels = plot_tick_vel(ax, vel[j], offset, t,
                                                  tickz=options.tickz)
                        artists['ticklabels'].extend(Tlabels)
                        artists['ticks'].extend(T)
            if options.f26 is not None and options.f26.regions is not None:
                artists['regions'].extend(plot_velocity_regions(
                    wmin, wmax, options.f26.regions.wmin,
                    options.f26.regions.wmax,
                    obswa, ax, offset))

            cond = between(wa, wmin, wmax)
            #good = ~np.isnan(fl) & (er > 0) & ~np.isnan(co)

            # remove ultra-low S/N regions to help plotting
            cond &= ner < 1.5
                
            fl = nfl[cond]
            co = nco[cond]

            vel = (wa[cond] / obswa - 1) * c_kms
            vranges = []
            for w0, w1 in unrelated:
                c0 = between(wa[cond], w0, w1)
                if c0.any():
                    vranges.append(c0)

            for w0, w1 in ATMOS:
                c0 = between(wa[cond], w0, w1)
                if c0.any():
                    artists['sky'].append(
                        ax.fill_between(vel[c0], offset,
                                        offset + 1.5, facecolor='0.9', lw=0))

            if self.smoothby > 1:
                if len(fl) > 3 * self.smoothby:
                    fl = convolve_psf(fl, self.smoothby)

            artists['fl'][i].set_xdata(vel)
            artists['fl'][i].set_ydata(fl + offset)

            artists['co'][i].set_xdata(vel)
            artists['co'][i].set_ydata(co + offset)

            #pdb.set_trace()

            if self.opt.residuals:
                resid = (fl - model[cond]) / ner[cond]
                c0 = np.abs(resid) < 5
                artists['resid'][i].set_xdata(vel[c0])
                artists['resid'][i].set_ydata(resid[c0] * 0.05 + offset - 0.1)

            if self.opt.f26 is not None:
                artists['model'][i].set_xdata(vel)
                artists['model'][i].set_ydata(model[cond] + offset)

        for ax in self.axes:
            ax.set_xlim(self.vmin, self.vmax)
            ax.set_ylim(-0.5, self.num_per_panel * 1.5)
        self.artists['title'].set_text('$z = %.5f$' % self.z)

        if not self.opt.ticklabels:
            for t in artists['ticklabels']:
                t.set_visible(False)

        self.fig.canvas.draw()

        self.artists = artists
예제 #2
0
    def update(self, z):
        if self.opt.f26 is not None:
            wa, nfl, ner, nco, model, artists, options = (self.wa, self.nfl,
                                                          self.ner, self.co,
                                                          self.model,
                                                          self.artists,
                                                          self.opt)
        else:
            wa, nfl, ner, nco, artists, options = (self.wa, self.nfl, self.ner,
                                                   self.co, self.artists,
                                                   self.opt)

        self.z = z

        ymult = self.ymult

        zp1 = z + 1
        betamin = self.vmin / c_kms
        betamax = self.vmax / c_kms

        for t in artists['ticklabels']:
            t.remove()
        for t in artists['ticks']:
            t.remove()
        artists['ticklabels'] = []
        artists['ticks'] = []
        if artists['ew'] is not None:
            artists['ew'].remove()
            artists['ew'] = None

        for r in artists['regions']:
            r.remove()
        for s in artists['sky']:
            s.remove()
        for s in artists['aod']:
            s.remove()
        artists['regions'] = []
        artists['sky'] = []
        artists['aod'] = []

        # want plots to appear from  top down, so we need reversed()
        for i, trans in enumerate(reversed(options.linelist)):
            atom, ion = split_trans_name(trans['name'].split()[0])
            iax, ioff = divmod(i, self.num_per_panel)
            ax = self.axes[iax]
            offset = ioff * 1.5
            #if i >= self.num_per_panel:
            #    offset = (i - self.num_per_panel) * 1.5
            #    ax = self.axes[1]

            watrans = trans['wa']
            obswa = watrans * zp1
            wmin = obswa * (1 + 3 * betamin)
            wmax = obswa * (1 + 3 * betamax)
            if self.opt.showticks and len(self.allticks) > 0:
                ticks = self.allticks
                tickwmin = obswa * (1 + betamin)
                tickwmax = obswa * (1 + betamax)
                wticks = ticks.wa
                cond = between(wticks, tickwmin, tickwmax)
                if cond.any():
                    vel = (wticks[cond] / obswa - 1) * c_kms
                    for j, t in enumerate(ticks[cond]):
                        T, Tlabels = plot_tick_vel(ax,
                                                   vel[j],
                                                   offset,
                                                   t,
                                                   tickz=options.tickz)
                        artists['ticklabels'].extend(Tlabels)
                        artists['ticks'].extend(T)

            cond = between(wa, wmin, wmax)
            #good = ~np.isnan(fl) & (er > 0) & ~np.isnan(co)

            # remove ultra-low S/N regions to help plotting
            cond &= ner < 1.5
            cond &= ymult * (nfl - 1) + 1 > -0.1

            fl = nfl[cond]
            co = nco[cond]

            vel = (wa[cond] / obswa - 1) * c_kms

            if options.f26 is not None and options.f26.regions is not None:
                artists['regions'].extend(
                    plot_velocity_regions(wmin, wmax, options.f26.regions.wmin,
                                          options.f26.regions.wmax, obswa, ax,
                                          offset, vel,
                                          ymult * (fl - 1) + 1))

            #import pdb; pdb.set_trace()
            if hasattr(options, 'aod'):
                # print ranges used for AOD calculation.
                # find the right transition
                c0 = ((np.abs(options.aod['wrest'] - trans['wa']) < 0.01) &
                      (options.aod['atom'] == atom))
                itrans = np.flatnonzero(c0)
                for row in options.aod[itrans]:
                    c0 = between(wa[cond], row['wmin'], row['wmax'])
                    if np.any(c0):
                        artists['aod'].append(
                            ax.fill_between(vel[c0],
                                            offset,
                                            offset + 1.5,
                                            facecolor='0.8',
                                            lw=0,
                                            zorder=0))

            vranges = []
            for w0, w1 in unrelated:
                c0 = between(wa[cond], w0, w1)
                if c0.any():
                    vranges.append(c0)

            for w0, w1 in ATMOS:
                c0 = between(wa[cond], w0, w1)
                if c0.any():
                    artists['sky'].append(
                        ax.fill_between(vel[c0],
                                        offset,
                                        offset + 1.5,
                                        facecolor='0.9',
                                        lw=0))

            if self.smoothby > 1:
                if len(fl) > 3 * self.smoothby:
                    fl = convolve_psf(fl, self.smoothby)

            artists['fl'][i].set_xdata(vel)
            artists['fl'][i].set_ydata(ymult * (fl - 1) + 1 + offset)

            artists['co'][i].set_xdata(vel)
            artists['co'][i].set_ydata(ymult * (co - 1) + 1 + offset)

            #pdb.set_trace()

            if self.opt.residuals:
                resid = (fl - model[cond]) / ner[cond]
                c0 = np.abs(resid) < 5
                artists['resid'][i].set_xdata(vel[c0])
                artists['resid'][i].set_ydata(resid[c0] * 0.05 + offset - 0.1)

            if self.opt.f26 is not None:
                artists['model'][i].set_xdata(vel)
                artists['model'][i].set_ydata(ymult * (model[cond] - 1) + 1 +
                                              offset)

            tr_id = trans['name'], tuple(trans['tr'])
            #import pdb; pdb.set_trace()
            art = self.artists['models'][tr_id]
            for line in self.models:
                m = self.models[line]
                if line not in art:
                    art[line] = ax.plot(vel,
                                        ymult * (m[cond] - 1) + 1 + offset,
                                        'k',
                                        lw=0.2)[0]
                else:
                    art[line].set_xdata(vel)
                    art[line].set_ydata(ymult * (m[cond] - 1) + 1 + offset)

        for ax in self.axes:
            ax.set_xlim(self.vmin, self.vmax)
            ax.set_ylim(-0.5, self.num_per_panel * 1.5)
        self.artists['title'].set_text('$z = %.5f$' % self.z)

        if not self.opt.ticklabels:
            for t in artists['ticklabels']:
                t.set_visible(False)

        self.fig.canvas.draw()

        self.artists = artists
예제 #3
0
    def update(self, z):
        if self.opt.f26 is not None:
            wa, nfl, ner, nco, model, artists, options = (
                self.wa, self.nfl, self.ner, self.co, self.model,
                self.artists, self.opt)
        else:
            wa, nfl, ner, nco, artists, options = (
                self.wa, self.nfl, self.ner, self.co,
                self.artists, self.opt)

        self.z = z

        ymult = self.ymult

        zp1 = z + 1
        betamin = self.vmin / c_kms
        betamax = self.vmax / c_kms

        for t in artists['ticklabels']:
            t.remove()
        for t in artists['ticks']:
            t.remove()
        artists['ticklabels'] = []
        artists['ticks'] = []
        if artists['ew'] is not None:
            artists['ew'].remove()
            artists['ew'] = None


        for r in artists['regions']:
            r.remove()
        for s in artists['sky']:
            s.remove()
        for s in artists['aod']:
            s.remove()
        artists['regions'] = []
        artists['sky'] = []
        artists['aod'] = []

        # want plots to appear from  top down, so we need reversed()
        for i, trans in enumerate(reversed(options.linelist)):
            atom, ion = split_trans_name(trans['name'].split()[0])
            iax, ioff = divmod(i, self.num_per_panel)
            ax = self.axes[iax]
            offset = ioff * 1.5
            #if i >= self.num_per_panel:
            #    offset = (i - self.num_per_panel) * 1.5
            #    ax = self.axes[1]

            watrans = trans['wa']
            obswa = watrans * zp1
            wmin = obswa * (1 + 3*betamin)
            wmax = obswa * (1 + 3*betamax)
            if self.opt.showticks and len(self.allticks) > 0:
                ticks = self.allticks
                tickwmin = obswa * (1 + betamin)
                tickwmax = obswa * (1 + betamax)
                wticks = ticks.wa
                cond = between(wticks, tickwmin, tickwmax)
                if cond.any():
                    vel = (wticks[cond] / obswa - 1) * c_kms
                    for j,t in enumerate(ticks[cond]):
                        T,Tlabels = plot_tick_vel(ax, vel[j], offset, t,
                                                  tickz=options.tickz)
                        artists['ticklabels'].extend(Tlabels)
                        artists['ticks'].extend(T)


            cond = between(wa, wmin, wmax)
            #good = ~np.isnan(fl) & (er > 0) & ~np.isnan(co)

            # remove ultra-low S/N regions to help plotting
            cond &= ner < 1.5
            cond &= ymult*(nfl-1) + 1 > -0.1
                
            fl = nfl[cond]
            co = nco[cond]

            vel = (wa[cond] / obswa - 1) * c_kms

            if options.f26 is not None and options.f26.regions is not None:
                artists['regions'].extend(plot_velocity_regions(
                    wmin, wmax, options.f26.regions.wmin,
                    options.f26.regions.wmax,
                    obswa, ax, offset, vel, ymult*(fl-1) + 1))

            #import pdb; pdb.set_trace()
            if hasattr(options, 'aod'):
                # print ranges used for AOD calculation.
                # find the right transition
                c0 = ((np.abs(options.aod['wrest'] - trans['wa']) < 0.01) &
                      (options.aod['atom'] == atom))
                itrans = np.flatnonzero(c0)
                for row in options.aod[itrans]:
                    c0 = between(wa[cond], row['wmin'], row['wmax'])
                    if np.any(c0):
                        artists['aod'].append(
                            ax.fill_between(vel[c0], offset, offset+1.5, facecolor='0.8', lw=0,
                                            zorder=0)
                            )
                    

            vranges = []
            for w0, w1 in unrelated:
                c0 = between(wa[cond], w0, w1)
                if c0.any():
                    vranges.append(c0)

            for w0, w1 in ATMOS:
                c0 = between(wa[cond], w0, w1)
                if c0.any():
                    artists['sky'].append(
                        ax.fill_between(vel[c0], offset,
                                        offset + 1.5, facecolor='0.9', lw=0))

            if self.smoothby > 1:
                if len(fl) > 3 * self.smoothby:
                    fl = convolve_psf(fl, self.smoothby)


            artists['fl'][i].set_xdata(vel)
            artists['fl'][i].set_ydata(ymult*(fl-1) + 1 + offset)

            artists['co'][i].set_xdata(vel)
            artists['co'][i].set_ydata(ymult*(co-1) + 1 + offset)

            #pdb.set_trace()

            if self.opt.residuals:
                resid = (fl - model[cond]) / ner[cond]
                c0 = np.abs(resid) < 5
                artists['resid'][i].set_xdata(vel[c0])
                artists['resid'][i].set_ydata(resid[c0] * 0.05 + offset - 0.1)

            if self.opt.f26 is not None:
                artists['model'][i].set_xdata(vel)
                artists['model'][i].set_ydata(ymult*(model[cond]-1) + 1 + offset)

            tr_id = trans['name'], tuple(trans['tr'])
            #import pdb; pdb.set_trace()
            art = self.artists['models'][tr_id]
            for line in self.models:                
                m  = self.models[line]
                if line not in art:
                    art[line] = ax.plot(vel, ymult*(m[cond]-1) + 1 + offset, 'k', lw=0.2)[0]
                else:
                    art[line].set_xdata(vel)
                    art[line].set_ydata(ymult*(m[cond]-1) + 1 + offset)

        for ax in self.axes:
            ax.set_xlim(self.vmin, self.vmax)
            ax.set_ylim(-0.5, self.num_per_panel * 1.5)
        self.artists['title'].set_text('$z = %.5f$' % self.z)

        if not self.opt.ticklabels:
            for t in artists['ticklabels']:
                t.set_visible(False)

        self.fig.canvas.draw()

        self.artists = artists