zkbt / chromatic

Tools for visualizing spectrosopic light curves, with flux as a function of wavelength and time.
MIT License
14 stars 4 forks source link

Make it easier to include models in `.plot()` function. #139

Closed zkbt closed 2 years ago

zkbt commented 2 years ago

Right now, the .plot() function (which by default quietly calls .plot_lightcurves()) can make plots like this:

from chromatic import *

r = (SimulatedRainbow(wlim=[1,5]*u.micron)
     .inject_transit()
     .inject_noise())

r.bin(dw=1*u.micron).plot()

image

We need to add some abilities to make it just as easy to include models along with these too, to plot residuals, and to plot their histograms. There are a couple things already in the works: @mone0982 is drafting a "plot a histogram of the residuals for this wavelength" function in #115 and @zkbt recently added a RainbowWithModel object that does automatic calculation of a residual array based on an attached model. The remaining things that we should might include:

@erinmmay , to help with this, a really helpful first step would be to describe exactly what you'd like for this plot and/or point to some examples you like? I remember the MOPPS plots being really nice! I have a little bit of work to do to tidy up the model management going on in the background, but then I think we can start iterating on versions of this?

zkbt commented 2 years ago

@erinmmay, here's what the some options for the plot_lightcurves_and_residuals_with_models look like. (These are all the same function, just with different keyword arguments supplied.)

def test_plot_lightcurves_and_residuals_with_models():
    s = SimulatedRainbow(R=3, dt=3 * u.minute)
    r = s.inject_transit(
        limb_dark="quadratic",
        u=np.transpose(
            [np.linspace(1.0, 0.0, s.nwave), np.linspace(0.5, 0.0, s.nwave)]
        ),
    ).inject_noise(signal_to_noise=1000)
    for i, options in enumerate(
        [
            dict(),
            dict(errorbar=True),
            dict(cmap=one2another("skyblue", "sienna")),
            dict(data_plotkw=dict(alpha=0.5), cmap="magma_r"),
            dict(figsize=(8, 4), cmap=one2another("orchid", "indigo")),
        ]
    ):
        r.plot_lightcurves_and_residuals_with_models(**options)
        plt.savefig(
            os.path.join(
                test_directory, f"rainbow-of-lightcurves-and-residuals-example{i}.png"
            )
        )

rainbow-of-lightcurves-and-residuals-example0 rainbow-of-lightcurves-and-residuals-example1 rainbow-of-lightcurves-and-residuals-example2 rainbow-of-lightcurves-and-residuals-example3 rainbow-of-lightcurves-and-residuals-example4

Thoughts on these? They should be easy to produce as long as we have wavelength, time, flux, uncertainty, model defined.

erinmmay commented 2 years ago

These look great! I'm partial to including the errorbars :) I think what we'll want for the paper version is the ability to grab every X light curves from that wavelength/time/flux/uncertainty/model rainbow so that we don't have to plot them all.