Ejemplo n.º 1
0
    def out_backplot(self, fit):
        res = np.median(fit['phi'], axis=0)
        res[0:6] = 10**res[0:6]
        model = self._get_background(f, *res)

        pg = lk.Periodogram(f * u.microhertz, p * (cds.ppm**2 / u.microhertz))
        ax = pg.plot(alpha=.25, label='Data', scale='log')
        ax.plot(f, model, label='Model')
        ax.plot(f,
                self._harvey(f, res[0], res[1], 4.),
                label='Harvey 1',
                ls=':')
        ax.plot(f,
                self._harvey(f, res[2], res[3], 4.),
                label='Harvey 2',
                ls=':')
        ax.plot(f,
                self._harvey(f, res[4], res[5], 2.),
                label='Harvey 3',
                ls=':')
        ax.plot(f, self._get_apodization(f, f[-1]), label='Apod', ls='--')
        ax.plot(f, res[-4] * np.ones_like(f), label='white', ls='-.')
        plt.legend(fontsize=10)

        plt.savefig(self.dir + 'modelplot.png')
        plt.close('all')
Ejemplo n.º 2
0
    def out_modelplot(self, fit):
        model = np.ones(len(self.data['f']))
        nus = np.median(fit['nus'])
        for mode in range(len(self.data['ids'])):
            l = self.data['ids'][mode]
            for m in range(-l, l + 1):
                loc = np.median(fit['locs'].T[mode])
                H = np.median(fit['H'].T[mode])
                w = np.median(fit['w'].T[mode])
                model += self._lorentzian(f, l, m, loc, i, H, w, nus)
        fitlocs = np.median(fit['locs'], axis=0)

        pg = lk.Periodogram(data['f'] * u.microhertz,
                            data['p'] * (cds.ppm**2 / u.microhertz))
        ax = pg.plot(alpha=.5, label='Data')
        plt.scatter(fitlocs, [15] * len(fitlocs),
                    c='k',
                    s=25,
                    label='fit locs')
        plt.scatter(data['pr_locs'], [15] * len(data['pr_locs']),
                    c='r',
                    s=5,
                    label='true locs')
        plt.plot(data['f'], model, linewidth=1, label='Model')
        plt.legend()

        plt.savefig(self.dir + 'modelplot.png')
        plt.close('all')
Ejemplo n.º 3
0
def full_plot(mod, p, res, kic, idx):
    pg = lk.Periodogram(mod.f * u.microhertz,
                        p * (u.cds.ppm**2 / u.microhertz))
    ax = pg.plot(alpha=.5, label='Data')
    plt.plot(mod.f, mod.model(res, theano=False), lw=3, label='Model')
    ax.set_title(f'KIC {kic}, ID {idx}')
    plt.savefig(
        f'/home/oliver/PhD/mnt/RDS/malatium/peakbag/byeye/{kic}_full.png')
    plt.close()
Ejemplo n.º 4
0
    def out_modelplot(self):
        labels=['f0','f1','f2',
                'g0','g1','g2',
                'h0','h1','h2',
                'split','i',
                'phi']
        res_m = np.array([np.median(self.trace[label],axis=0) for label in labels])

        pg = lk.Periodogram(self.mod.f*u.microhertz, self.p*(cds.ppm**2/u.microhertz))
        ax = pg.plot(alpha=.5, label='Data')
        plt.plot(self.mod.f, self.mod.model(res_m, theano=False), lw=3, label='Model')
        plt.legend()

        plt.savefig(self.dir+'modelplot.png')
        plt.close('all')
Ejemplo n.º 5
0
    def out_modelplot(self, fit):
        labels=['loga','logb','logc','logd','logj','logk','white','numax','scale','nyq']
        res = np.array([np.median(fit[label]) for label in labels])
        res[0:6] = 10**res[0:6]
        model = self.get_background(f, *res)

        pg = lk.Periodogram(f*u.microhertz, p*(cds.ppm**2/u.microhertz))
        ax = pg.plot(alpha=.25, label='Data', scale='log')
        ax.plot(f, model, label='Model')
        ax.plot(f, self.harvey(f, res[0],res[1], 4.), label='Harvey 1', ls=':')
        ax.plot(f, self.harvey(f, res[2],res[3], 4.), label='Harvey 2', ls=':')
        ax.plot(f, self.harvey(f, res[4],res[5], 2.), label='Harvey 3', ls=':')
        ax.plot(f, self.get_apodization(f, f[-1]), label='Apod', ls='--')
        ax.plot(f, res[-4]*np.ones_like(f), label='white',ls='-.')
        plt.legend(fontsize=10)

        plt.savefig(self.dir+'modelplot.png')
        plt.close('all')
Ejemplo n.º 6
0
           f2_,                         # l2 modes
           np.ones(len(f0_)) * 2.0,     # l0 widths
           np.ones(len(f1_)) * 2.0,     # l1 widths
           np.ones(len(f2_)) * 2.0,     # l2 widths
           np.ones(len(f0_)) * 15. * 2.0 / np.pi / 2.0, # l0 amps
           np.ones(len(f1_)) * 15. * 2.0 / np.pi / 2.0, # l1 amps
           np.ones(len(f2_)) * 15. * 2.0 / np.pi / 2.0, # l2 amps
           1.0 ,                        # projected splitting
           np.pi/2.,                    # inclination angle
           phi_                         # background terms
           ]

    mod = model(f, n0_, n1_, n2_, deltanu_)

    #Plot the data
    pg = lk.Periodogram(f*u.microhertz, p*(cds.ppm**2/u.microhertz))
    ax = pg.plot(alpha=.5)
    ax.scatter(locs, [15]*len(locs),c=modeids, s=20, edgecolor='k')
    ax.plot(f, mod.model(init, theano=False), lw=2)
    plt.savefig(dir+'dataplot.png')
    # plt.show()
    plt.close()

    # Run stan
    print('About to go into Pymc3')
    run = run_pymc3(mod, p, nf_, kic, phi_, phi_cholesky, dir)
    run()

    #Print a big label
    print('#################################\n')
    print(f'DONE RUNNING KIC {str(kic)} | IDX {str(idx)} \n')
Ejemplo n.º 7
0
def job(r, save=True):
    ID = int(r['ID'])
    if CATALOGUE == "TIC":
        file = f"{PATH}/{ID}_psd_tot_nw.txt"
    elif CATALOGUE == "EPIC":
        file = f"{PATH}/{ID}/{ID}_psd_tot.txt"

    Δν = float(r['Δν'])
    ν_max = float(r['ν_max'])
    if Δν < 0:
        return

    # Read in power spectrum
    try:
        file = f"DIAMONDS/data/{CATALOGUE}{ID}.txt"
        ν, ps = np.loadtxt(file).T
    except (FileNotFoundError, OSError):
        # tqdm.write(f"PS for {CATALOGUE} {ID} not found")
        return
    except ValueError:
        print(f"PS for {CATALOGUE} {ID} malformed")
        return

    # Create periodogram object
    pg = lk.Periodogram(ν * u.uHz, u.Quantity(ps), label=f'{CATALOGUE} {ID}')

    # Make echelle diagram
    plt.close('all')
    ss = pg.to_seismology()
    ss.numax = ν_max
    ss.deltanu = Δν
    ss.plot_echelle(smooth_filter_width=Δν / 100)

    # get manual mode ID
    if isfile(f'Seed/{CATALOGUE}{ID}.pkl'):
        seed = pd.read_pickle(f'Seed/{CATALOGUE}{ID}.pkl')
        modes = seed.nu_med.values

        plt.scatter(modes % Δν, (modes // Δν) * Δν, c='green')

    # get Appourchaux frequencies
    if CATALOGUE == "KIC" and ID in app_KIC:
        modes = app[app_KIC_all == ID].Freq.astype('float')
        plt.plot(modes % Δν, (modes // Δν) * Δν,
                 'v',
                 c='red',
                 fillstyle='none')

    # get MLE estimate
    if isfile(f'mle/{CATALOGUE}{ID}.npy'):
        params = np.load(f'mle/{CATALOGUE}{ID}.npy', allow_pickle=True)
        cov = np.array([(lambda J: np.linalg.inv(J.T @ J))(j['jac'])
                        for j in params])
        ν0 = np.array([j['x'][0] for j in params])
        e_ν0 = np.array([np.sqrt(C[0, 0]) for C in cov])

        plt.errorbar(ν0 % Δν, (ν0 // Δν) * Δν,
                     fmt='^',
                     color='orange',
                     fillstyle='none')

    # Get DIAMONDS results
    def get_results(n):
        result = f"DIAMONDS/results/{CATALOGUE}{ID}/pb/{n}/peakbagging_parameterSummary.txt"
        if not isfile(result):
            return None

        res = np.loadtxt(result)
        return res.reshape((len(res) // 3, 3, -1))

    for i in range(3):
        res = get_results(i)
        if res is None:
            break

        for mode in res:
            ν = mode[0, 1]
            eν1 = mode[0, 4]
            eν2 = mode[0, 5]
            err = [[ν - eν1], [eν2 - ν]]
            plt.errorbar([ν % Δν], [(ν // Δν) * Δν],
                         xerr=err,
                         yerr=err,
                         fmt='.',
                         c='red')
            print(ν)

    if save:
        plt.savefig(f"DIAMONDS/preview/{CATALOGUE}{ID}.png")
    else:
        plt.show()