Exemplo n.º 1
0
dr = 5.0
sphere = gal.ds.sphere(pos, (rmax, 'pc'))  # do small for now

x = sphere['spherical_radius'].convert_to_units('pc').value
y = sphere['Fe_Fraction'].value

p = yt.ProfilePlot(sphere,
                   "radius", ["Fe_Fraction", 'Fe_over_H', 'O_over_Fe'],
                   weight_field='cell_volume',
                   accumulation=False)
p.set_unit('radius', 'pc')
p.save()

bins = np.arange(0.0, rmax + dr, dr)
#acf, bins = ACF_scargle(x, y, dy = 0.0000001, n_omega = 2**12, omega_max = np.pi/5.0) #, bins = bins)
acf, err, bins = ACF_EK(x, y, dy=1.0E-8, bins=bins)

print(acf)
print(bins)
simple_plot(0.5 * (bins[1:] + bins[:-1]), acf, 'Fe_Fraction_acf.png')

print('----------------------------------------------------------')
print('----------------------------------------------------------')

x = sphere['spherical_radius'].convert_to_units('pc').value
y = sphere['Fe_over_H'].value

bins = np.arange(0.0, rmax + dr, dr)

#acf, bins = ACF_scargle(x, y, dy = 0.0001, n_omega = 2**12, omega_max = np.pi/5.0) #, bins = bins)
acf, err, bins = ACF_EK(x, y, dy=0.00001, bins=bins)
# add errors
dy = 0.1
y_obs = np.random.normal(y, dy)

#------------------------------------------------------------
# compute ACF via scargle method
C_S, t_S = ACF_scargle(t, y_obs, dy, n_omega=2**12, omega_max=np.pi / 5.0)

ind = (t_S >= 0) & (t_S <= 500)
t_S = t_S[ind]
C_S = C_S[ind]

#------------------------------------------------------------
# compute ACF via E-K method
C_EK, C_EK_err, bins = ACF_EK(t, y_obs, dy, bins=np.linspace(0, 500, 51))
t_EK = 0.5 * (bins[1:] + bins[:-1])

#------------------------------------------------------------
# Plot the results
fig = plt.figure(figsize=(5, 5))

# plot the input data
ax = fig.add_subplot(211)
ax.errorbar(t, y_obs, dy, fmt='.k', lw=1)
ax.set_xlabel('t (days)')
ax.set_ylabel('observed flux')

# plot the ACF
ax = fig.add_subplot(212)
ax.plot(t_S, C_S, '-', c='gray', lw=1, label='Scargle')
Exemplo n.º 3
0
def compute_AF():


    from astroML.time_series import lomb_scargle, generate_damped_RW
    from astroML.time_series import ACF_scargle, ACF_EK

#----------------------------------------------------------------------
# This function adjusts matplotlib settings for a uniform feel in the textbook.
# Note that with usetex=True, fonts are rendered with LaTeX.  This may
# result in an error if LaTeX is not installed on your system.  In that case,
# you can set usetex to False.
    from astroML.plotting import setup_text_plots
    setup_text_plots(fontsize=8, usetex=False)

#------------------------------------------------------------
# Generate time-series data:
#  we'll do 1000 days worth of magnitudes

    t = np.arange(0, 1E3)
    z = 2.0
    tau = 300
    tau_obs = tau / (1. + z)

    np.random.seed(6)
    y = generate_damped_RW(t, tau=tau, z=z, xmean=20)

# randomly sample 100 of these
    ind = np.arange(len(t))
    np.random.shuffle(ind)
    ind = ind[:100]
    ind.sort()
    t = t[ind]
    y = y[ind]

# add errors
    dy = 0.1
    y_obs = np.random.normal(y, dy)

#------------------------------------------------------------
# compute ACF via scargle method
    C_S, t_S = ACF_scargle(t, y_obs, dy,
                       n_omega=2 ** 12, omega_max=np.pi / 5.0)

    ind = (t_S >= 0) & (t_S <= 500)
    t_S = t_S[ind]
    C_S = C_S[ind]

#------------------------------------------------------------
# compute ACF via E-K method
    C_EK, C_EK_err, bins = ACF_EK(t, y_obs, dy, bins=np.linspace(0, 500, 51))
    t_EK = 0.5 * (bins[1:] + bins[:-1])

#------------------------------------------------------------
# Plot the results
    fig = plt.figure(figsize=(5, 5))

# plot the input data
    ax = fig.add_subplot(211)
    ax.errorbar(t, y_obs, dy, fmt='.k', lw=1)
    ax.set_xlabel('t (days)')
    ax.set_ylabel('observed flux')

# plot the ACF
    ax = fig.add_subplot(212)
    ax.plot(t_S, C_S, '-', c='gray', lw=1,
        label='Scargle')
    ax.errorbar(t_EK, C_EK, C_EK_err, fmt='.k', lw=1,
            label='Edelson-Krolik')
    ax.plot(t_S, np.exp(-abs(t_S) / tau_obs), '-k', label='True')
    ax.legend(loc=3)

    ax.plot(t_S, 0 * t_S, ':', lw=1, c='gray')

    ax.set_xlim(0, 500)
    ax.set_ylim(-1.0, 1.1)

    ax.set_xlabel('t (days)')
    ax.set_ylabel('ACF(t)')

    plt.show()