Skip to content
Snippets Groups Projects
Commit fce5b237 authored by Felipe Reyes Osorio's avatar Felipe Reyes Osorio
Browse files

First attempt at animation and code

parent a2c6ef77
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id: tags:
``` python
import numpy as np
from matplotlib.pyplot import *
import matplotlib.animation as an
%matplotlib inline
giants = np.loadtxt("./data/giants.txt",skiprows=1)
supGiants = np.loadtxt("./data/supergiants.txt",skiprows=1)
dwarfs = np.loadtxt("./data/dwarfs.csv",skiprows=1,delimiter=",")
ms = np.loadtxt("./data/ms.csv",skiprows=1,delimiter=",")
def tRange(listOfLists):
ans=[]
for i in range(len(listOfLists)):
ans.append([min(listOfLists[i]), max(listOfLists[i])])
ans = np.array(ans)
return min(ans[:,0]),max(ans[:,1])
bigListT=[ms[:,1],giants[:,1],supGiants[:,1],dwarfs[:,1]]
temps = tRange(bigListT)
```
%% Cell type:code id: tags:
``` python
fig1, ax1= subplots(figsize=(9,6))
ax1.tick_params(axis='both', which='major', labelsize=14)
vmin, vmax = tRange(bigListT)
cm = "RdYlBu"
ylabel("Luminosity [L$_\odot$]", fontsize=20)
ax1.set_yscale('log')
ax1.set_ylim(0.3e-4, 5e7)
xlabel("$T$ [K]", fontsize=20)
ax1.set_xlim(vmin-900, vmax+500);
```
%% Output
%% Cell type:code id: tags:
``` python
from celluloid import Camera
cam = Camera(fig1)
```
%% Cell type:code id: tags:
``` python
dMs = len(ms[:,0])
for j in range(dMs):
msTrash = np.delete(ms, slice(j+1, dMs-1), 0)
ax1.scatter(msTrash[:,1], msTrash[:,0], c=-msTrash[:,1], vmin=-vmax, vmax=0, s=1.7*msTrash[:,2]**1.5, cmap=cm, lw=0.8, ec="k")
if j%3==0: cam.snap()
```
%% Cell type:code id: tags:
``` python
animation = cam.animate()
animation.save('animation.gif', writer='Pillow', fps=10)
```
%% Output
MovieWriter Pillow unavailable; using Pillow instead.
%% Cell type:code id: tags:
``` python
dGs = len(giants[:,0])
for j in range(dGs):
gsTrash = np.delete(giants, slice(j+1, dMs-1), 0)
ax1.scatter(ms[:,1], ms[:,0], c=-ms[:,1], vmin=-vmax, vmax=0, s=1.7*ms[:,2]**1.5, cmap=cm, lw=0.8, ec="k")
ax1.scatter(gsTrash[:,1], gsTrash[:,0], c=-gsTrash[:,1], vmin=-vmax, vmax=0, s=1.7*gsTrash[:,2]**1.5, cmap=cm, lw=2, ec="k")
cam.snap()
```
%% Cell type:code id: tags:
``` python
dSg = len(supGiants[:,0])
for j in range(dSg):
sgTrash = np.delete(supGiants, slice(j+1, dMs-1), 0)
ax1.scatter(ms[:,1], ms[:,0], c=-ms[:,1], vmin=-vmax, vmax=0, s=1.7*ms[:,2]**1.5, cmap=cm, lw=0.8, ec="k")
ax1.scatter(giants[:,1], giants[:,0], c=-giants[:,1], vmin=-vmax, vmax=0, s=1.7*giants[:,2]**1.5, cmap=cm, lw=2, ec="k")
ax1.scatter(sgTrash[:,1], sgTrash[:,0], c=-sgTrash[:,1], vmin=-vmax, vmax=0, s=1.7*sgTrash[:,2]**1.5, cmap=cm, lw=2, ec="k")
cam.snap()
```
%% Cell type:code id: tags:
``` python
dDw = len(dwarfs[:,0])
for j in range(dDw):
dwTrash = np.delete(dwarfs, slice(j+1, dMs-1), 0)
ax1.scatter(ms[:,1], ms[:,0], c=-ms[:,1], vmin=-vmax, vmax=0, s=1.7*ms[:,2]**1.5, cmap=cm, lw=0.8, ec="k")
ax1.scatter(giants[:,1], giants[:,0], c=-giants[:,1], vmin=-vmax, vmax=0, s=1.7*giants[:,2]**1.5, cmap=cm, lw=2, ec="k")
ax1.scatter(supGiants[:,1], supGiants[:,0], c=-supGiants[:,1], vmin=-vmax, vmax=0, s=1.7*supGiants[:,2]**1.5, cmap=cm, lw=2, ec="k")
ax1.scatter(dwTrash[:,1], dwTrash[:,0], c=-dwTrash[:,1], vmin=-vmax, vmax=0, s=1.7*dwTrash[:,2]**1.5, cmap=cm, lw=0.8, ec="k")
cam.snap()
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
animation.gif

601 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment