<jupyter_start><jupyter_text>jammer 02 Explore the Marley models I- How to read them in<NAME>  Friday, March 31, 2017<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
% matplotlib inline
% config InlineBackend.figure_format = 'retina'
import seaborn as sns
import pandas as pd
from os import listdir
import astropy.units as u
! cat ../../Starfish/libraries/raw/marley/parameters
! ls ../../Starfish/libraries/raw/marley/ | head -n 16
all_files = listdir('../../Starfish/libraries/raw/marley/')
files = all_files[1:]
temps = np.array([np.float(val[val.index('t')+1:val.index('g')]) for val in files])
surfs = np.array([np.float(val[val.index('g')+1:val.index('n')]) for val in files])
np.unique(temps)
gravs = np.unique(surfs)
np.log10((gravs*u.m/u.s**2).to(u.cm/u.s**2).value)
surfs = surfs*100.0 # convert to cgs units
plt.plot(temps, np.log10(surfs), 'o')
plt.ylabel('$\log{g}$')
plt.xlabel('$T_{\mathrm{eff}}$');<jupyter_output><empty_output><jupyter_text>The sampling is $\Delta T = 25$ K below 600 K, and $\Delta T = 50$ K above 600 K.<jupyter_code>! head -n4 ../../Starfish/libraries/raw/marley/sp_t500g1000nc_m0.0
! head -n4 ../../Starfish/libraries/raw/marley/sp_t800g3160nc_m0.0<jupyter_output>800.     3160.   0.28  0.00  1.0000E+05   0.00   1.00  0.00    Teff,
    microns  Flux (erg/cm^2/s/Hz)

   50.0000000     1.10384E-08<jupyter_text>It looks like Teff and **g** change, but all other properties are held fixed. It looks like the range in $\log{g}$ is 3.0 - 5.5, so an extra data point than what <NAME> said in the email:> spectra for Teff=500-1000K, log g=3.25 - 5.5, solar composition, cloudless.<jupyter_code>dat = pd.read_csv('../../Starfish/libraries/raw/marley/sp_t1000g1000nc_m0.0', 
                  names=['wavelength', 'flux'],
                  skiprows=3, 
                  delim_whitespace=True)
dat.head()<jupyter_output><empty_output><jupyter_text>The units are : - wavelength: **micron**- flux density: **erg/cm^2/s/Hz**There's no solid angle, so I suppose this must be at the (sub)stellar surface?  Let's make a new column for Starfish units.  $\frac{d f}{d\lambda} = \frac{d f}{d \nu} \cdot \frac{d \nu}{d\lambda}$$\nu = c \lambda^{-1}$$\frac{d \nu}{d\lambda} = (-1) c \lambda^{-2} = (-1) \nu \lambda^{-1}$<jupyter_code>import astropy.constants as C
c_val = C.c.to(u.cm/u.s).value
c_val
x = dat.wavelength.values*u.micron
x_Hz = x.to(u.Hz, equivalencies=u.spectral())
x_Ang = x.to(u.Angstrom)


y0 = dat.flux.values*u.erg/u.cm**2/u.s/u.Hz
y = y0.to(u.erg/u.cm**2/u.s/u.Angstrom, 
          equivalencies=u.spectral_density(dat.wavelength.values*u.micron))
y2 = dat.flux.values * c_val * dat.wavelength.values**-2  ##units are funky, but still works?
y3 = dat.flux.values * x_Hz.value / x_Ang.value
plt.plot(x, y)
plt.plot(x, y2*0.8)
plt.plot(x, y3*0.8**2)
plt.yscale('log')
plt.xscale('log')
plt.xlim(0.5, 5)
plt.ylim(1.0E-6*np.nanmax(y.value), 3.0*np.nanmax(y.value))
plt.xlabel('$\lambda \;(\mu \mathrm{m})$')
plt.ylabel('$f_\lambda \;(\mathrm{erg/s/cm}^2/\AA)$ ')<jupyter_output><empty_output><jupyter_text>They're all dead-on, right on top of each other!<jupyter_code>plt.plot(x, y)
plt.yscale('log')
plt.xscale('log')
plt.xlim(0.5, 5)
plt.ylim(1.0E-6*np.nanmax(y.value), 3.0*np.nanmax(y.value))
plt.xlabel('$\lambda \;(\mu \mathrm{m})$')
plt.ylabel('$f_\lambda \;(\mathrm{erg/s/cm}^2/\AA)$ ')
plt.plot(x, dat.flux)
plt.yscale('log')
plt.xscale('log')
plt.xlim(0.5, 5)
plt.ylim(1.0E-6*np.nanmax(dat.flux.values), 3.0*np.nanmax(dat.flux.values))
plt.xlabel('$\lambda \;(\mu \mathrm{m})$')
plt.ylabel('$f_ν \;(\mathrm{erg/s/cm}^2/\mathrm{Hz})$ ')<jupyter_output><empty_output><jupyter_text>Notice the difference between the flux densities per $\nu$ and per Angstrom.  Compare to another model<jupyter_code>dat2 = pd.read_csv('../../Starfish/libraries/raw/marley/sp_t500g1000nc_m0.0', 
                  names=['wavelength', 'flux'],
                  skiprows=3, 
                  delim_whitespace=True)
plt.plot(x, dat.flux)
plt.plot(dat.wavelength, dat2.flux)
plt.yscale('log')
plt.xscale('log')
plt.xlim(0.5, 5)
plt.ylim(1.0E-6*np.nanmax(dat.flux.values), 3.0*np.nanmax(dat.flux.values))
plt.xlabel('$\lambda \;(\mu \mathrm{m})$')
plt.ylabel('$f_ν \;(\mathrm{erg/s/cm}^2/\mathrm{Hz})$ ')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19990647650222118, 'fraction_numerical': 0.04559270516717325, 'mean_word_length': 3.9628770301624128, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '521524', 'license': 'MIT', 'n_tokens_mistral': 1932, 'n_tokens_neox': 1767, 'n_words': 333, 'path': 'notebooks/jammer_02-01_Explore_Marley_models.ipynb', 'repo_name': 'gully/jammer-Gl570D', 'size': '4300'}