Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added code/.DS_Store
Binary file not shown.
869 changes: 869 additions & 0 deletions code/.ipynb_checkpoints/SNIDdataset_SNIDsn_Tutorial-checkpoint.ipynb

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions code/.ipynb_checkpoints/Test_Case-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 4
}
42 changes: 4 additions & 38 deletions code/SNIDdataset_SNIDsn_Tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 13,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -277,7 +277,9 @@
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -782,42 +784,6 @@
"SNIDdataset.plotDataset(SNIDset, (15,50))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
73 changes: 73 additions & 0 deletions code/SNIDsn.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ def loadSNIDlnw(self, lnwfile):
-------

"""
assert lnwfile[-3:] == 'lnw' #file must be .lnw
with open(lnwfile) as lnw:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write a new function within this class: loadSN(self, file, phaseType)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add other arguments as necessary.

lines = lnw.readlines()
lnw.close()
Expand Down Expand Up @@ -463,7 +464,78 @@ def loadSNIDlnw(self, lnwfile):
continuum[ind - 1] = np.array([float(x) for x in cont_line])
self.continuum = continuum
return

def loadSN(self, file, phaseType, TypeInt, SubTypeInt, TypeStr, SN, redshift):
"""
Loads an ascii SNID template file specified by the path file into
a SNIDsn object. The file must only have wavelengths in the first column
and fluxes in subsequent columns. The first line must also have the phases,
with the first entry in the first line being the phase type.

Parameters
----------
file : string
path to SNID template file produced by logwave.
phaseType : integer
integer value that specifies whether phases are defined relative to max
TypeInt : integer
integer value that specifies the type of the supernova
SubTypeInt : integer
integer value that specifies the subtype of the supernova
TypeStr : string
specifies the type and subtype of the supernova
SN : string
name of the supernova

Returns
-------

"""

assert file[-3:] != 'lnw' #file cannot be .lnw

self.phaseType = phaseType

header = dict()
header['Nspec'] = len(np.loadtxt(file).tolist()[0]) - 1
header['Nbins'] = len(np.loadtxt(file, skiprows = 1, usecols = 0).tolist())
header['WvlStart'] = np.loadtxt(file, skiprows = 1, usecols = 0).min()
header['WvlEnd'] = np.loadtxt(file, skiprows = 1, usecols = 0).max()
header['SN'] = SN
header['TypeStr'] = TypeStr
header['TypeInt'] = TypeInt
header['SubTypeInt'] = SubTypeInt
self.header = header

tp, subtp = getType(header['TypeInt'], header['SubTypeInt'])
self.type = tp
self.subtype = subtp

all_data = np.loadtxt(file)

header_line = all_data[0]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't you skip the header line in the line above?

phases = header_line[1:]
self.phases = phases

self.wavelengths = all_data[1:, 0] / (1 + redshift)

filedtype = []
colnames = []
for ph in self.phases:
colname = 'Ph'+str(ph)
if colname in colnames:
colname = colname + 'v1'
count = 2
while(colname in colnames):
colname = colname[0:-2] + 'v'+str(count)
count = count + 1
colnames.append(colname)
dt = (colname, 'f4')
filedtype.append(dt)
data = np.loadtxt(file, dtype=filedtype, skiprows=1, usecols=range(1,len(self.phases) + 1))
self.data = data
return

def preprocess(self, phasekey):
"""
Zeros the mean and scales std to 1 for the spectrum indicated.
Expand Down Expand Up @@ -499,6 +571,7 @@ def restoreContinuum(self, verbose=False, spl_a_ind=0, spl_b_ind=-1):
-------

"""

continuum_header = self.continuum[0]
continuum = self.continuum[1:]
if verbose:
Expand Down
Loading