-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinning_single.py
More file actions
123 lines (62 loc) · 1.79 KB
/
binning_single.py
File metadata and controls
123 lines (62 loc) · 1.79 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 5 09:59:52 2019
@author: Heitor
"""
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import sys
import math
def Resize(source, length):
step = float(len(source) - 1) / (length - 1)
for i in range(length):
key = i * step
low = source[int(math.floor(key))]
high = source[int(math.ceil(key))]
ratio = key % 1
yield (1 - ratio) * low + ratio * high
def save(wl,fl,NAME):
FNAME=NAME+str(pace)+'.B'
file = open(FNAME, 'w')
file.write(NAME[12:25]+'\n')
file.write('# Wavelength(A) Flux \n')
n=0
for i in fl:
flu = float(fl[n])
wave = float(wl[n])
file.write('%7.5f %10.7f\n'%(wave,flu))
n=n+1
print(NAME+' saved as ' + FNAME)
#-----------------------------------------
sns.set_style("white")
sns.set_context("paper", font_scale=2.0, rc={"lines.linewidth": 2.5})
#-----------------------------------------
INPUT_spec = sys.argv[1]
pace = float(sys.argv[2])
#INPUT_spec ='flux_G_m3_p10.norm.nulbad.0.150'
print('Input file: '+str(INPUT_spec))
#-----------------------------------------
#spectrum
#CUBES
wl11,flux11 = np.genfromtxt(INPUT_spec, skip_header=2, unpack=True)
#wlfl11 = numpy.delete(wlfl11, (14990), axis=1)
#-----------------------------------------
#REBIN
#CUBES
#pace=0.06
#UVES
#pace=0.03
#10k
#pace=0.12
x= int((wl11[len(wl11)-1]-wl11[0] )/pace)
wl11b=list(Resize(wl11, x))
flux11b=list(Resize(flux11, x))
#-----------------------------------------
plt.plot(wl11,flux11, 'k')
plt.plot(wl11b, flux11b, 'red')
#-----------------------------------------
#CUBES SAVE
save(wl11b,flux11b,INPUT_spec)
#-----------------------------------------