In [1]:
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from PIL import Image
import math
import requests
from io import BytesIO
import numpy as np
import astropy.units as u
from linetools.spectralline import AbsLine
from linetools.spectra import io as lsio
from linetools.spectra.xspectrum1d import XSpectrum1D
from linetools.analysis import voigt as lav
# plots
from matplotlib import pyplot as plt
import pylab
pylab.rcParams['figure.figsize'] = (8.0, 6.0)
import matplotlib
matplotlib.rc('xtick', labelsize=20)
matplotlib.rc('ytick', labelsize=20)
In [2]:
# Define a plotting function for the Voight Profile
def plt_line(spec):
plt.clf()
plt.figure(dpi=700)
plt.plot(spec.wavelength.value, spec.flux.value, 'k-', drawstyle='steps-mid', lw=1.5)
plt.xlim(3644., 3650.)
plt.ylabel('Normalized Flux', fontsize=20.)
plt.xlabel('Wavelength', fontsize=20.)
ax = plt.gca()
ax.xaxis.set_major_locator(plt.MultipleLocator(2.))
ax.get_xaxis().get_major_formatter().set_useOffset(False)
plt.ylim(0., 1.1)
plt.show()
plt.close()
In [3]:
# Load in data
flux_data = np.load('../data/flux.npy')
wave_data = np.load('../data/wave.npy')
In [4]:
# Normalize flux data
flux_data *= 1/flux_data.max()
In [5]:
plt.clf()
plt.figure(dpi=700)
plt.plot(wave_data, flux_data, 'k-')
plt.ylabel('Normalized Flux', fontsize=20.)
plt.xlabel('Wavelength', fontsize=20.)
plt.show()
In [6]:
#Generate AbsLine
abslin = AbsLine(1215.670*u.AA)
In [7]:
# Fill Attributes
abslin.attrib['N'] = 10**14./u.cm**2 # log N
abslin.attrib['b'] = 25.*u.km/u.s
abslin.setz(2.)
In [8]:
# Load
spectra1d = XSpectrum1D.from_tuple((wave_data, flux_data))
abslin.analy['spec'] = spectra1d
In [9]:
#Generate
vmodel = abslin.generate_voigt()
In [10]:
# wv = vmodel.wavelength.value
# fx = vmodel.flux.value
In [11]:
# Plot
plt_line(vmodel)
In [12]:
abslin.attrib['N'] = 10**17.5/u.cm**2
abslin.attrib['b'] = 20.*u.km/u.s
In [13]:
wave = np.linspace(3644, 3650,5500)*u.AA
In [14]:
vmodel2 = abslin.generate_voigt(wave=wave_data[0:100]*u.AA)
In [15]:
wv2 = vmodel2.wavelength.value
fx2 = vmodel2.flux.value
In [16]:
plt_line(vmodel2)
In [8]:
cvrl = np.load('../data/model_1d_vis/conv1_relu/conv1_relu.npy')
pool1 = np.load('../data/model_1d_vis/pool1/pool1.npy')
In [9]:
def vis_feature(input):
plt.clf()
plt.figure(dpi=40)
plt.plot(input, 'k-')
plt.show()
plt.close
In [12]:
# Examine shapes with potential voigt profile match
t1 = cvrl[23]
t2 = cvrl[97]
t3 = pool1[0]
t4 = pool1[48]
In [13]:
vis_feature(t1)
vis_feature(t2)
vis_feature(t3)
vis_feature(t4)
In [16]:
con = np.concatenate((t1, t2, t3, t4))
In [19]:
np.save('../data/act_v.npy', con)
In [ ]:
In [23]:
test = np.load('../data/act_v.npy')
test.shape
Out[23]:
In [24]:
test1 = test[0:400]
test2 = test[400:800]
test3 = test[800:1200]
test4 = test[1200:]
In [25]:
vis_feature(test1)
vis_feature(test2)
vis_feature(test3)
vis_feature(test4)
In [29]:
from astropy.visualization import astropy_mpl_style
plt.style.use(astropy_mpl_style)
from astropy.io import fits
test_file = '../data/UM184_nF.fits'
test_data = fits.getdata(test_file, ext=0)
print(test_data.shape)
In [30]:
plt.figure()
plt.plot(test_data)
Out[30]:
In [ ]: