Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GIF for evolution of live points #346

Open
slegner opened this issue Oct 6, 2023 · 0 comments
Open

GIF for evolution of live points #346

slegner opened this issue Oct 6, 2023 · 0 comments

Comments

@slegner
Copy link

slegner commented Oct 6, 2023

Hi!
My computer doesn't load the interactive GUI for anesthetic very well, so I created a python file that makes a gif illustrating the evolution of live points. (It is heavily based on the python file that Adam has made in the past.)

It makes a gif of corner plots, like this:
pc_250_2
(This animates 100 frames and takes about 2mins to generate on my computer, it can have more parameters but will significantly increase the time to generate)

Will recommended that I suggest to add this as a feature on the Anesthetic Github repository, but I'm not sure if this is the correct way to do so. I'm not sure how to upload the python file, but here is the script:

import sys
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation
from anesthetic import read_chains, make_2d_axes

def clustering_animation(chains):
    ns = read_chains(f"chains/{chains}")
    fig, axes = make_2d_axes(['x0', 'x1'])
    axesln = len(axes)

    def animate(i):
        for y, row in axes.iterrows():
            for x, ax in row.items():
                if x == y:
                    if len(ax.twin.lines)>0:
                        ax.twin.lines[0].remove()
                else:
                    ax.clear()
                    ax.set(xlim = [min(ns[f'{x}']),max(ns[f'{x}'])], ylim = [min(ns[f'{y}']), max(ns[f'{y}'])])
        fig.suptitle(f"{chains}_{i}_/{len(ns)}")
        lp = ns.live_points(i)
        lp.plot_2d(axes, kinds=dict(diagonal='kde_1d', lower='kde_2d', upper='scatter_2d'))	
        for i in range(axesln):
            np.diag(axes)[i].twin.lines[0].set_color('k')

    ani = animation.FuncAnimation(fig, animate, frames=np.arange(0, len(ns), round(len(ns)/100)), interval=10)

    writer = animation.PillowWriter(fps = 10, metadata = None, bitrate=1800)
    ani.save(f'{chains}.gif', writer = writer)

for chains in sys.argv[1:]:
    clustering_animation(chains)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant