After what could be described as a cautious approach to opening my notebook to the world, I've finally decided to take the plunge into IPython notebooks. It will be primarily used for research purposes, but perhaps it will become a larger repository for my thoughts and ideas over time. Since this is my first "official" notebook, some trials are in order.
Let's first try to create and then plot some data. A useful first test is to plot a sine wave.
In [9]:
# start by directing figure outputs to be inline & import numpy
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
# create domain and range (for two plots)
t = np.arange(0.0, 1.0, 0.01)
y1 = np.sin(2.0*np.pi*t)
y2 = np.sin(4.0*np.pi*t)
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 5))
# properties of 1st frame
ax1.plot(t, y1, '-', lw=2, color='#4682B4')
ax1.grid(True)
ax1.set_xlabel('Time (unit)')
ax1.set_ylabel('Intensity (arbitrary)')
ax1.set_xlim((0, 1))
ax1.set_ylim((-1.5, 1.5))
# properties of 2nd frame
ax2.plot(t, y2, '--', lw=2, color='#800000')
ax2.grid(True)
ax2.set_xlabel('Time (unit)')
ax2.set_xlim((0, 1))
ax2.set_ylim((-1.5, 1.5))
Out[9]:
Cool! That was actually super easy and very convenient. In hindsight, I may not be regretting not switching to IPython notebook sooner. I was always under the impression that this all had to be carefully and meticulously crafted from the command line, meaning you had to execute all python commands properly with militaristic precision. Dauting, to say the least! I am not quite sure why it was that I thought this, as clearly it is not the case. The interface set in the browser is convenient and very forgiving! However, I wonder how that the notebook will eventually reflect changes and alterations made to various notebooks and such over time. I shall have to find out!
Now for something slightly more advanced: stellar evolution mass tracks. Just a quick plot or two, however. Nothing too advanced. I'll save that for another notebook. Let's start with a Hertzsprung-Russell Diagram with some of my latest models.
In [28]:
fig, ax = plt.subplots(1, 1, figsize=(8, 8))
# define mass interval for mass tracks
masses = np.arange(0.1, 1.21, 0.1)
# load and plot mass tracks from 1 Myr to ZAMS
for mass in masses:
trk = np.genfromtxt('../../evolve/dmestar/trk/gas07/p000/a0/amlt2202/m{:04.0f}_GAS07_p000_p0_y26_mlt2.202.trk'.format(
mass*1000.0), comments='#', usecols=(0, 1, 3, 9))
trk = np.array([x for x in trk if 1.0e9 > x[0] > 1.0e6 and x[3]/10.0**x[2] < 0.99])
ax.plot(10.0**trk[:, 1], trk[:, 2], '-', lw=2, color='#4682B4')
# add ZAMS line
zams_line = np.genfromtxt('../../evolve/dmestar/src/zams_ages.txt', comments='#')
ax.plot(10.0**zams_line[:, 1], zams_line[:, 3], '--', lw=3, color='#800000')
ax.set_xlabel('Effective Temperature (K)')
ax.set_ylabel('$\log_{10}(L / L_{\odot})$')
ax.set_xlim((6500, 2500))
ax.set_ylim((-3.5, 0.5))
Out[28]:
In [ ]: