<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Let us start with a standard light curve simulation with the Timmer & Koenig method
Step1:  Simulating event times with the inverse CDF method
Given a positive-definite light curve (generated, e.g., with the method by Timmer & Koenig), we treat it as a probability distribution
Step2:  The same method can be used, in principle, to simulate variates from any probability distribution. The only requirement is that the input distribution is positive definite.
Stingray implements this method in stingray.simulator.base
<ASSISTANT_TASK:>
Python Code:
from astropy.modeling import models
pds_model = \
    models.PowerLaw1D(x_0=1, alpha=1, amplitude=1)
nyq = 100.
freq = np.linspace(0, nyq, 1000)[1:]
pds_shape = pds_model(freq)
mean = 10
rms = 0.3
dt = 0.5 / nyq
flux = timmerkoenig(pds_shape, mean, rms)
times = dt * np.arange(flux.size)
plt.plot(times, flux)
Explanation: Let us start with a standard light curve simulation with the Timmer & Koenig method:
End of explanation
from scipy.interpolate import interp1d
def cdf_from_lc(lc, dt):
    cdf = np.cumsum(lc)
    cdf = np.concatenate([[0], cdf])
    cdf /= cdf.max()
    return cdf    
# cdf_times = np.concatenate([[0], dt / 2 + time])
cdf_values = cdf_from_lc(flux, dt)
cdf_times = np.arange(cdf_values.size) * dt
cdf_inverse = interp1d(cdf_values, cdf_times)
plt.plot(times, flux / flux.max(), color="grey", label="Light curve")
plt.plot(cdf_times, cdf_values, color="k", label="CDF")
for prob_val in np.linspace(0, 1, 100):
    time = cdf_inverse(prob_val)
    plt.plot([0, time], [prob_val, prob_val], color="r", lw=0.3)
    plt.plot([time, time], [0, prob_val], color="r", lw=0.3)
    
plt.xlabel("Time")
plt.ylabel("Probability")
plt.ylim([0, 1])
plt.xlim([0, 10])
plt.legend(loc="lower right");
plt.tight_layout()
plt.savefig("CDF_lc.jpg")
Explanation: Simulating event times with the inverse CDF method
Given a positive-definite light curve (generated, e.g., with the method by Timmer & Koenig), we treat it as a probability distribution: we calculate the cumulative distribution function by calculating its cumulative sum and normalizing to 1. Then, we generate random numbers uniformly distributed between 0 and 1 (horizontal lines) and take the event times at the corresponding values of the CDF (vertical lines).
End of explanation
from stingray.simulator.base import simulate_with_inverse_cdf
event_times = simulate_with_inverse_cdf(flux, 10)
event_times
Explanation: The same method can be used, in principle, to simulate variates from any probability distribution. The only requirement is that the input distribution is positive definite.
Stingray implements this method in stingray.simulator.base:
End of explanation
<END_TASK>