/
seds.py
50 lines (42 loc) · 1.56 KB
/
seds.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from astropy.io import fits
import pylab as pl
import idlsave
import itertools
import scipy.ndimage
from astropy.nddata.convolution import make_kernel,convolve
import numpy as np
import sys
import os
sys.path.append(os.path.split(os.getcwd())[0])
from convolve_match_makefits import convolve_and_match
from sed_from_dict import sed_from_dict,plot_sed
from viewer import load_data
def make_plots(dirname, fnames):
# get the highest-level directory, assume it is the target source ID
obj = os.path.split(dirname)[-1]
for fn in fnames:
# each band gets listed...
if 'band0' not in fn or '.sav' not in fn:
continue
# templates:
# coadd_cleanband0in_clean_music_20130815_jk000.sav
# 130820_ob1_band0i_clean_music_20130815_map.sav
obs = "_".join(fn.split("_")[:2])
#obs = fn[:11]
print "Working on file ",os.path.join(dirname,obs)
data = load_data(os.path.join(dirname,obs))
sm,us = convolve_and_match(data,obj,writefits=False)
flux,bg,err = sed_from_dict(sm)
pl.clf()
plot_sed(flux,bg,err, label='Smooth')
flux,bg,err = sed_from_dict(us)
plot_sed(flux,bg,err, label='Unsharp')
pl.title(obj)
pl.legend(loc='best')
pl.savefig(os.path.join(dirname,obj+obs)+"_SED.png",bbox_inches='tight')
if __name__ == "__main__":
for dirpath, dirnames, filenames in os.walk('./'):
if dirpath != './':
if 'neptune' in dirpath or 'g34.3' in dirpath:
continue
make_plots(dirpath,filenames)