Skip to content

Commit

Permalink
february update
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanCantatGaudin committed Feb 27, 2014
1 parent 46011e3 commit 37c6b1c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 15 deletions.
9 changes: 7 additions & 2 deletions cutSpec.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# ./cutSpec.py spec.fits[1] 4800 5800 specL.fits
#
#NB: the output will be in 32 bit, whatever the input!
# the code can easily be modified to output 64bits.
# (the code can easily be modified to output 64bit though)


try:
Expand All @@ -28,12 +28,17 @@
infile = sys.argv[1]
minWAV = float(sys.argv[2])
maxWAV = float(sys.argv[3])
outfile = sys.argv[4]
except IndexError:
print 'The syntax is:'
print sys.argv[0], "file.txt -options"
sys.exit()

#find the requested output file name, or set a default name if nothing specified:
try:
outfile = sys.argv[4]
except:
outfile = infile.replace('.fits','_cut.fits')

#find in requested a specific extension, ext=0 if not:
try:
ext=infile[-3:]
Expand Down
15 changes: 10 additions & 5 deletions plotSpec.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
c=299792.458

dark = '-dark' in sys.argv
if '-steps' in sys.argv:
drawstyle='steps-mid'
else:
drawstyle=''


#function that takes the arguments, reads the files and plots:
Expand Down Expand Up @@ -161,8 +165,8 @@ def actualseefits(argumentsList):


######### Plot it:
plt.plot(waveobs, flux, color=colors[i], label=labels[i])

plt.plot(waveobs, flux, color=colors[i], label=labels[i],drawstyle=drawstyle)
return files[0] #return the name of the first file



Expand All @@ -188,9 +192,9 @@ def actualseefits(argumentsList):
argumentsList=[sys.argv[0]]+content[i]
plt.ion()
plt.clf()
actualseefits(argumentsList)
title = actualseefits(argumentsList)
plt.draw()
spam=raw_input('Press ENTER for next plot.')
spam=raw_input(title+'\t Press ENTER for next plot.')
if spam=='b':
i=i-1 #to step back
elif spam=='q':
Expand All @@ -213,9 +217,10 @@ def actualseefits(argumentsList):
mpl.rc('savefig',facecolor='black',edgecolor='black')
else:
fig=plt.figure(1)
actualseefits(sys.argv)
title = actualseefits(sys.argv)
plt.ylabel('flux')
plt.xlabel('wavelength')
plt.title(title)
if labelOn==True:
plt.legend()
plt.show()
36 changes: 28 additions & 8 deletions txt2fits.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# cdelt=0.0147 to resample with a step of 0.0147*
# rv=150 to add a 150km/h radial velocity (this increases the wavelength)
# -col3 to read flux from column 3 instead of 1 (nb: Python indices start at 0!)
# -usehead=/home/user/somefile.fits[3] to insert the header of another file
#
# *fits spectra assume a constant wavelength step, so if your original ascii is not on a
# constant step you NEED to resample.
Expand Down Expand Up @@ -48,6 +49,7 @@
resample=False
radvel=0
colFlux=1
usehead=False
for el in options:
if '-h' in el:
linesToRemove = int(el.split('-h')[1])
Expand Down Expand Up @@ -76,7 +78,8 @@
radvel=float(el[3:])
if '-col' in el:
colFlux=int(el[4:])

if '-usehead' in el:
usehead=el.split('=')[1]



Expand Down Expand Up @@ -223,13 +226,30 @@
os.system('rm -f '+outputSpectrum)
pyfits.writeto(outputSpectrum,flux)

header = pyfits.getheader(outputSpectrum)
header.update('CRVAL1', wave_base, "wavelength zeropoint")
header.update('CD1_1', wave_step, "wavelength step")
header.update('CDELT1', wave_step, "wavelength step")
header.update('CRPIX1', 1.0, "Pixel zeropoint")
header.update('NAXIS', 1, "Number of axes")
header.update('NAXIS1', len(flux), "Axis length")
#insert a header:
if usehead==False:
header = pyfits.getheader(outputSpectrum)
header.update('CRVAL1', wave_base, "wavelength zeropoint")
header.update('CD1_1', wave_step, "wavelength step")
header.update('CDELT1', wave_step, "wavelength step")
header.update('CRPIX1', 1.0, "Pixel zeropoint")
header.update('NAXIS', 1, "Number of axes")
header.update('NAXIS1', len(flux), "Axis length")
else: #take the header of another file:
if usehead[-1]==']':
ext = int( usehead.split('[')[1][:-1] )
otherfile = usehead.split('[')[0]
else:
ext = 0
otherfile = usehead
header = pyfits.getheader(otherfile,ext)
header.update('CRVAL1', wave_base, "wavelength zeropoint")
header.update('CD1_1', wave_step, "wavelength step")
header.update('CDELT1', wave_step, "wavelength step")
header.update('CRPIX1', 1.0, "Pixel zeropoint")
header.update('NAXIS', 1, "Number of axes")
header.update('NAXIS1', len(flux), "Axis length")


os.system('rm -f '+outputSpectrum)
pyfits.writeto(outputSpectrum,flux,header)

0 comments on commit 37c6b1c

Please sign in to comment.