Skip to content
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

getrawfitspath() will return url; TODO listed. #5

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
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
879 changes: 879 additions & 0 deletions .ipynb_checkpoints/inline viewer demo 2-checkpoint.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 2
}
62 changes: 62 additions & 0 deletions SpectrumViewer - Copy/.ipynb_checkpoints/demo 2-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"scrolled": true
},
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'SpectrumViewer'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-6-5fc1ec971204>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;32mimport\u001b[0m \u001b[0mInlineViewer\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2\u001b[0m \u001b[0mget_ipython\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmagic\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'matplotlib notebook'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0mfileName\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'example_lite.fits'\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0mfileSource\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'SDSS'\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[0mInlineViewer\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mview\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfileName\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfileSource\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mC:\\Users\\wzuo\\Developer\\Spectrum Viewer\\SpectrumViewer\\InlineViewer.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;32mimport\u001b[0m \u001b[0mSpectrumViewer\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mSpecUtil_inline\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0minline\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mSpectrumViewer\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mSDSSDriver\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mdriver\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mview\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfilename\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfilesource\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0mcoaddObj\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mzObj\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mdriver\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mloadFITS\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfilename\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfilesource\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[0mspec\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0minline\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mSpecUtil\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfilename\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcoaddObj\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mzObj\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'SpectrumViewer'"
]
}
],
"source": [
"import InlineViewer\n",
"%matplotlib notebook\n",
"fileName = 'example_lite.fits'\n",
"fileSource = 'SDSS'\n",
"InlineViewer.view(fileName, fileSource)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.1"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
17 changes: 17 additions & 0 deletions SpectrumViewer - Copy/CoaddObj.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This class init with a fits file in the directory and store all the data in the RAM
import numpy as np
class CoaddObj:
def __init__(self,flux,loglam=None,ivar=None,andMask=None,orMask=None
,wdisp=None,sky=None,model=None):#type can be pfs
self.flux = flux
self.loglam = loglam
self.ivar =ivar
self.andMask =andMask
self.orMask = orMask
self.wdisp = wdisp
self.sky =sky
self.model = model
self.lam = np.power(10,self.loglam)



6 changes: 6 additions & 0 deletions SpectrumViewer - Copy/InlineViewer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import SpectrumViewer.SpecUtil_inline as inline
import SpectrumViewer.SDSSDriver as driver
def view(filename, filesource):
coaddObj,zObj=driver.loadFITS(filename, filesource)
spec = inline.SpecUtil(filename, coaddObj, zObj)
spec.showfig()
52 changes: 52 additions & 0 deletions SpectrumViewer - Copy/SDSSDriver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#load SDSS into workable object
from astropy.io import fits
#from py3.SciServer import Authentication, Config
#from py3.SciServer import CasJobs
from urllib.parse import urlparse
import SpectrumViewer.CoaddObj as Coadd
import SpectrumViewer.ZObj as Z
# def getSpecObjID(ra, dec, width, height, context=None, URL=True):
# leftBoundry = ra - width / 2
# rightBoundry = ra + width / 2
# upperBoundry = dec + height / 2
# lowerBoundry = dec - height / 2
# sqlQuery = 'select specObjID from dr7.specobjall Where (ra >' + str(leftBoundry) + ' and ra<' + str(
# rightBoundry) + ') and (dec>' + str(lowerBoundry) + ' and dec<' + str(upperBoundry) + ')'
# return CasJobs.executeQuery(sqlQuery, context='dr7', format='pandas')
# def getRawFITSPathInDAS(SpecObjID):
# sqlQuery = 'select dr7.fGetUrlFitsSpectrum('+SpecObjID+')'
# response = CasJobs.executeQuery(sqlQuery, context='dr7', format='pandas')
# url= response['Column1'][0]
# parseResult = urlparse(url)
# prefix = '/home/idies/workspace/sdss_das/das2'
# path = prefix+parseResult.path
# return path

def loadFITS(filename,fileSource):

if fileSource=='SDSS':
coaddData =1
zData =3
hdulist = fits.open(filename)
c=hdulist[coaddData].data
z=hdulist[zData].data
coaddObj = Coadd.CoaddObj(
flux=c['flux'],
loglam=c['loglam'],
ivar=c['ivar'],
andMask=c['and_Mask'],
orMask=c['or_Mask'],
wdisp=c['wdisp'],
sky = c['sky'],
model=c['model'])
zObj = Z.ZObj(
LINENAME=z['LINENAME'],
LINEWAVE=z['LINEWAVE'],
LINEZ=z['LINEZ'],
LINEEW=z['LINEEW'],
LINEZ_ERR=z['LINEZ_ERR'],
LINEEW_ERR=z['LINEEW_ERR'])
return coaddObj,zObj

else:
print('Sorry, we are loyal to SDSS ONLY, for the time being. ')
131 changes: 131 additions & 0 deletions SpectrumViewer - Copy/SpecUtil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# this file hold utility functions that generate the plot and actual data
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
import numpy as np
class SpecUtil:
def __init__(self,coaddObj,zObj):
self.coaddObj = coaddObj
self.zObj=zObj
# self.totalFig = plt.figure()
# self.shownFig = plt.figure()
#self.totalFig = Figure(figsize=(5, 4), dpi=100)
self.shownFig = Figure(figsize=(5, 4), dpi=100)
self.shownFig = plt.figure()
self.plotDict = {0: True,
1: True,
2: True,
3: True,
4: True}
#0 flux 1 skyline 2 emission 3 absorb 4 model
#self.totalAx = self.totalFig.add_subplot(111)
#fluxLine,=self.totalAx.plot(self.coaddObj.lam,self.coaddObj.flux)
#skyLine, = self.totalAx.plot(self.coaddObj.lam,self.coaddObj.sky)

self.shownAx = self.shownFig.add_subplot(111)
self.shownAx.set_xlabel('lambda/Å')
self.shownAx.set_ylabel('10-17 ergs/s/cm2/Å')

for key in self.plotDict.keys():
if self.plotDict[key]:
try:
self.plotLines(self.shownAx, key)
except IndexError: # dict is longer than plot numbers in totalax
pass
self.shownAx.legend()
#self.shownAx = self.totalAx
def updateFig(self):
#self.shownAx.lines=[]
self.shownAx.clear()
self.shownAx.set_xlabel('lambda/Å')
self.shownAx.set_ylabel('10-17 ergs/s/cm2/Å')
for key in self.plotDict.keys():
if self.plotDict[key]:
try:
self.plotLines(self.shownAx,key)
except IndexError:
pass
#line1, = ax.plot(x, y, 'b-')
self.shownAx.legend()
#for phase in np.linspace(0, 10 * np.pi, 100):
# line1.set_ydata(np.sin(0.5 * x + phase))
# fig.canvas.draw()
def addFlux(self):
self.plotDict[0]=True
self.updateFig()
def removeFlux(self):
self.plotDict[0] = False
self.updateFig()

def addSkyline(self):
self.plotDict[1] = True
self.updateFig()
def removeSkyline(self):
self.plotDict[1] = False
self.updateFig()
def addEmissionLine(self):
self.plotDict[2] = True
self.updateFig()
def removeEmissionLine(self):
self.plotDict[2] = False
self.updateFig()
def addAbsorbLine(self):
self.plotDict[3] = True
self.updateFig()
def removeAbsorbLine(self):
self.plotDict[3] = False
self.updateFig()
def addModel(self):
self.plotDict[4] = True
self.updateFig()
def removeModel(self):
self.plotDict[4] = False
self.updateFig()
def plotLines(self,axes,actionIndex):
if actionIndex==0:
axes.plot(self.coaddObj.lam, self.coaddObj.flux,'C0',label='flux')
elif actionIndex==1:
axes.plot(self.coaddObj.lam, self.coaddObj.sky,'C1',label='skyline')
elif actionIndex==2:
#plot emission line
self.plotSegment(axes,actionIndex)

elif actionIndex ==3:
#plot absorption line
self.plotSegment(axes,actionIndex)


elif actionIndex ==4:

#plot best fit model
axes.plot(self.coaddObj.lam, self.coaddObj.model, 'C3', label='best fit model')
else:

pass
def plotSegment(self,axes,actionIndex):

# read e/a line from zobj and plot it on axes with function from axhspan
if actionIndex==2:#emissiaon line
for lineIndex in range(0,len(self.zObj.LINENAME)):

width = self.zObj.LINEEW[lineIndex]
if width >0:
#print(width)
position = self.zObj.LINEWAVE[lineIndex]
startPostition = position-width/2
endPostition = position + width / 2
name= self.zObj.LINENAME[lineIndex]
#print(name)
axes.axvspan(xmin=startPostition,xmax=endPostition, facecolor='C4')
axes.text(position,0,name , rotation=90)
elif actionIndex==3:#absorption line
for lineIndex in range(0,len(self.zObj.LINENAME)):
width = self.zObj.LINEEW[lineIndex]
if width >0:
#print(width)
position = self.zObj.LINEWAVE[lineIndex]
startPostition = position-width/2
endPostition = position + width / 2
name= self.zObj.LINENAME[lineIndex]
#print(name)
axes.axvspan(xmin=startPostition,xmax=endPostition, facecolor='C4')
axes.text(position,0,name , rotation=90)
Loading