forked from fedhere/SESNspectraPCA
-
Notifications
You must be signed in to change notification settings - Fork 4
Update SNIDsn.py #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sk7372
wants to merge
17
commits into
metal-sn:master
Choose a base branch
from
sk7372:may2020_test
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
832c258
Update SNIDsn.py
sk7372 1464455
Revert "Update SNIDsn.py"
sk7372 d12559f
Update SNIDsn.py
sk7372 11ca87e
Updated SNIDsn.py and created a test case
sk7372 9d138b5
Updated SNIDsn.py and test_template.txt
sk7372 326ede7
Deleted ipynb checkpoints
sk7372 89ca2c2
Create compare_sn2004gt.ipynb
sk7372 a0384ec
Create sn04gt_knots.ipynb
sk7372 5de55ea
added sn1994D_knots
sk7372 1ce073e
edited sn1994D_knots.ipynb
sk7372 4f2ff0d
Update sn1994D_knots.ipynb
sk7372 f66f9ff
Update sn1994D_knots.ipynb
sk7372 d99c3c5
Update sn1994D_knots.ipynb
sk7372 a53dc47
added sn1994D_plot.py
sk7372 939dcbd
update loadSN()
sk7372 f13933c
cleaned up notebooks
sk7372 df57d67
Update loadSN_sn2004gt.ipynb
sk7372 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
869 changes: 869 additions & 0 deletions
869
code/.ipynb_checkpoints/SNIDdataset_SNIDsn_Tutorial-checkpoint.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "cells": [], | ||
| "metadata": {}, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 4 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -407,6 +407,7 @@ def loadSNIDlnw(self, lnwfile): | |
| ------- | ||
|
|
||
| """ | ||
| assert lnwfile[-3:] == 'lnw' #file must be .lnw | ||
| with open(lnwfile) as lnw: | ||
| lines = lnw.readlines() | ||
| lnw.close() | ||
|
|
@@ -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] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
|
@@ -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: | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.