Update SNIDsn.py#9
Conversation
| continuum[ind - 1] = np.array([float(x) for x in cont_line]) | ||
| self.continuum = continuum | ||
| return | ||
| if len(header_lines) == 10: #if file matches tutorial data format |
There was a problem hiding this comment.
This is hard for users to understand. Use '.lnw' for SNID templates. If suffix of the user specified file isn't lnw, then check to see if the file has two columns, one for wavelength and one for flux. If it does, make a SNIDsn object, otherwise, raise an assert.
There was a problem hiding this comment.
Maybe allow ascii files with at least 2 columns. Require a header line first that names the columns.
There was a problem hiding this comment.
your new function should have a phaseType argument for the user to specify whether phases are defined relative to max or not.
| @@ -410,59 +410,86 @@ def loadSNIDlnw(self, lnwfile): | |||
| with open(lnwfile) as lnw: | |||
There was a problem hiding this comment.
Write a new function within this class: loadSN(self, file, phaseType)
marxwillia
left a comment
There was a problem hiding this comment.
It's very important to include a test with your PR to show that your new code works.
|
Use git checkout SNIDsn.py to throw away your changes. |
| assert file[-3:] != 'lnw' #file cannot be .lnw | ||
| self.phaseType = phaseType | ||
|
|
||
| all_data = np.loadtxt(file, skiprows = 1) |
There was a problem hiding this comment.
this is assuming that header line is not marked with a '#' i think?
|
|
||
| all_data = np.loadtxt(file, skiprows = 1) | ||
|
|
||
| header_line = all_data[0] |
There was a problem hiding this comment.
Didn't you skip the header line in the line above?
| all_data = np.loadtxt(file, skiprows = 1) | ||
|
|
||
| header_line = all_data[0] | ||
| phases = header_line[1:len(header_line)] |
| for row in all_data: | ||
| wvl.append(row[0]) | ||
| wvl.pop(0) | ||
| wvl = np.array(wvl) | ||
| self.wavelengths = wvl |
There was a problem hiding this comment.
np.loadtxt already gives you an ndarray with array slicing ability.
self.wavelengths = all_data[:, 0] grabs entries in every row of the 0th column.
There was a problem hiding this comment.
self.wavelengths = all_data[1:, 0] skips the first row
There was a problem hiding this comment.
self.wavelengths = all_data[[1,2,3,4], 0] which gives you the wavelengths in rows 1,2,3,4
Added dictionary for self.header and removed title line in test_template
Compared outputs for an object using sn2004gt.lnw and another object using test_template.txt
added if/else statements to account for when data files only have phases, wavelengths, and spectra.