Unverified Commit da7f42a3 authored by Akke Viitanen's avatar Akke Viitanen
Browse files

add agn variability notebook

parent d90ee8e2
Loading
Loading
Loading
Loading
Loading
+185 −0
Original line number Diff line number Diff line
%% Cell type:markdown id:f62f241b-275b-43fe-8b6c-079ac7126770 tags:

# Explore AGN lightcurve 1 + z

This notebook explores the AGN lightcurves with and without the (1 + z) term on the structure function. For AGILE DR1 the (1 + z) term was included, which it could be reasoned to omit the term.

Here we aim to quantify the effect of (1 + z) on the structure function in terms of AGN physical parameters and the lightcurve RMS.

%% Cell type:code id:6ee80f74-7bc1-4980-a87c-11e3d016f5a2 tags:

``` python
from lsst_inaf_agile.lightcurve import get_lightcurve_agn
```

%% Cell type:code id:c9d27682-7c1b-4bd4-9d2a-39324edec2c4 tags:

``` python
def lc_mag(*args, **kwargs):
    lc = get_lightcurve_agn(*args, **kwargs)
    return -2.5 * np.log10(lc) + 23.9
```

%% Cell type:code id:0dcc5604-f0e5-4d43-8c02-1c1f33c2a94c tags:

``` python
def calc_stats(mag):
    return {
        "min": mag.min(),
        "max": mag.max(),
        "mean": mag.mean(),
        "rmse": np.sqrt(np.mean((mag - np.mean(mag)) ** 2)),
    }
```

%% Cell type:code id:f4bd35d2-4ffa-423d-8cef-e2af31bb376a tags:

``` python
kwargs = dict(
    mjd0=0,
    mjd=np.arange(365.25 * 10),
    flux=1.0,
    band="lsst-r",
    z=1.0,
    mag_i=-26,
    logMbh=8,
    type2=False,
    seed=2026,
)
```

%% Cell type:markdown id:85339944-a14b-4080-b4d9-699c6abbb307 tags:

# Plot a single lightcurve with and without 1 + z

%% Cell type:code id:a2cc1454-efcb-46f9-bba0-634c09291a0e tags:

``` python
plt.figure(dpi=100)
for divide_1z in False, True:
    lc = lc_mag(divide_sf_inf_by_z1=divide_1z, **kwargs)
    stats = calc_stats(lc)
    text = "\n".join(
        [
            f"{divide_1z=}",
        ]
        + [f"{k}: {v:.4f}" for k, v in stats.items()]
    )
    print(calc_stats(lc))
    plt.plot(lc, label=text)
plt.title(f"z = {kwargs['z']}")
plt.legend(frameon=True)
plt.xlim(0, 4000)
plt.xlabel("mjd")
plt.ylabel("mag")
```

%% Cell type:markdown id:2cbcef2e-0135-4d62-9f27-1e1c7da08a54 tags:

# Plot a differential lightcurve with and without 1 + z

%% Cell type:code id:5be3601c-1b6c-4f5f-aad5-51c8fbc8b21d tags:

``` python
plt.figure(dpi=100)
lc1 = lc_mag(divide_sf_inf_by_z1=True, **kwargs)
lc2 = lc_mag(divide_sf_inf_by_z1=False, **kwargs)
stats = calc_stats(lc1 - lc2)
text = "\n".join([f"{k}: {v:.4f}" for k, v in stats.items()])
print(text)
plt.plot(lc1 - lc2, label=text)
plt.title(f"z = {kwargs['z']}")
plt.xlim(0, 4000)
plt.xlabel("mjd")
plt.ylabel("mag_with - mag_without")
plt.legend()
```

%% Cell type:markdown id:60668bcf-032a-4b49-950d-5ec1b93bee1a tags:

# Plot the redshift-dependence

%% Cell type:code id:e20cbcbb-c347-47de-a852-c5adea52ffad tags:

``` python
plt.figure(dpi=100)
for z in 0.1, 1, 2, 3:
    _kwargs = kwargs.copy()
    _kwargs["z"] = z
    lc = lc_mag(divide_sf_inf_by_z1=True, **_kwargs)
    stats = calc_stats(lc)
    text = "\n".join(
        [
            f"z={_kwargs['z']}",
        ]
        + [f"{k}: {v:.4f}" for k, v in stats.items()]
    )
    print(calc_stats(lc))
    plt.plot(lc, label=text)
plt.legend(frameon=True)
plt.xlim(0, 4000)
plt.xlabel("mjd")
plt.ylabel("mag")
```

%% Cell type:markdown id:a49baef6-8095-4609-9ecc-61ce6f3d6f8e tags:

# Plot a very high redshift example z=0.1 vs. z=7.0

%% Cell type:code id:8320c96e-79b2-4f43-a945-e09681a9cc13 tags:

``` python
plt.figure(dpi=100)
for z in 0.1, 7:
    _kwargs = kwargs.copy()
    _kwargs["z"] = z
    lc = lc_mag(divide_sf_inf_by_z1=True, **_kwargs)
    stats = calc_stats(lc)
    text = "\n".join(
        [
            f"z={_kwargs['z']}",
        ]
        + [f"{k}: {v:.4f}" for k, v in stats.items()]
    )
    print(calc_stats(lc))
    plt.plot(lc, label=text)
plt.legend(frameon=True)
plt.xlim(0, 4000)
plt.xlabel("mjd")
plt.ylabel("mag")
```

%% Cell type:markdown id:2e55fe1b-0b8d-44e9-ad72-06b4b8efcb4a tags:

# Show scaling with MBH

%% Cell type:code id:1b7a5388-bff5-4f4d-8dc1-ddb8a3965d80 tags:

``` python
plt.figure(dpi=100)

for divide_1z in False, True:
    mbhs = []
    rmses = []
    for logMbh in np.linspace(5, 10):
        _kwargs = kwargs.copy()
        _kwargs["z"] = 1.0
        _kwargs["logMbh"] = logMbh
        lc = lc_mag(divide_sf_inf_by_z1=divide_1z, **_kwargs)
        stats = calc_stats(lc)

        mbhs.append(logMbh)
        rmses.append(stats["rmse"])

    plt.plot(mbhs, rmses, ls="solid" if divide_1z else "dotted", label=f"{divide_1z=}")

plt.title("z = 1")
plt.xlabel("logMBH")
plt.ylabel("RMSE")
plt.legend()
```

%% Cell type:code id:6302eaf8-1c3d-4e8e-a6b2-f63044b25247 tags:

``` python
```