-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspectrum.m
executable file
·127 lines (101 loc) · 3.73 KB
/
spectrum.m
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
123
124
125
126
127
# Script to plot a (calibrated) spectrum
dirname = '' # Working directory with the trailing slash, e.g. 'E:\ASTRO\Spectra\'. Leave empty for current folder
use_response_curve = 0; # Whether to use response curve, tr_final.dat
remove_continuum = 1; # Remove continuum spectrum using a polynome
n_polynome = 6; # polynome degree
show_all = 0; # show both the original spectrum, polynome fitting, and the corrected spectrum
clf;
hold on;
N = 1;
dy = [];
for i=1:N
filename = [dirname 'spectrum.dat']; # Input spectrum file
#filename = [dirname 'spectrum.dat_d' num2str(i)];
separator = '';
skipped_rows = 0;
skipped_columns = 0;
m = dlmread(filename, separator, skipped_rows, skipped_columns);
filenamep = [dirname 'params.txt']; # Calibration file
p = dlmread(filenamep, separator, skipped_rows, skipped_columns);
# Converting pixel coordinates to nanometers using calibration parameters p:
evalc('lambda = polyval (p, m(:,1))');
#y = m(:, 2);
y = log10(m(:, 2));
y = y - max(y);
if (i==1)
y0 = y;
endif
dy(i) = sum(y-y0)/rows(y); # log difference between different plots (compared to plot1)
y_copy = y;
#plot(lambda, y_copy, "r");
if (use_response_curve)
filenamec = [dirname 'tr_final.dat']; # Camera response curve polynome file
pc = dlmread(filenamec, separator, skipped_rows, skipped_columns);
lam_tr = pc(:,1);
tr = pc(:,2);
tr = tr - max(tr);
tr_interp = interp1 (lam_tr, tr, lambda, "extrap");
y = y - tr_interp; # Multiplying by inverse of the camera sensitivity, to remove the camera factor
endif
I = y;
#I = log10(y);
#I = y - dy(i);
xlim([375 725]);
x1=min(lambda);
x2=max(lambda);
xlim([x1-25 x2+25]);
xlabel('lambda, nm');
#ylabel('I');
ylabel('log10(I)');
if (show_all == 1 || remove_continuum == 0)
# plot(lambda, I, "g"); # Plotting the spectrum
plot(lambda, I, 'color', [(i-1.0)/(N-1.0) 0.5 1-(i-1.0)/(N-1.0)]);
endif
if (remove_continuum == 1)
[a s] = polyfit(lambda,I,n_polynome);
evalc('y = polyval (a, lambda)');
if (show_all == 1)
plot(lambda, y, "r");
endif
plot(lambda, I-y, "b");
# plot(lambda, 10.^(I), "b");
endif
endfor
yy=ylim();
y1=yy(1); y2=yy(2);
lam = 440;
line ("xdata",[lam,lam], "ydata",[y1,y2], "linewidth", 1, "color", "y")
lam = 680;
line ("xdata",[lam,lam], "ydata",[y1,y2], "linewidth", 1, "color", "y")
# Plotting main nebula spectral lines
lam=687.55; # O2
line ("xdata",[lam,lam], "ydata",[y1,y2], "linewidth", 1, "color", "r")
lam=656.3; # H
line ("xdata",[lam,lam], "ydata",[y1,y2], "linewidth", 1, "color", "g")
lam=628.15; # O2
line ("xdata",[lam,lam], "ydata",[y1,y2], "linewidth", 1, "color", "r")
lam=589.3; # Na
line ("xdata",[lam,lam], "ydata",[y1,y2], "linewidth", 1, "color", "y")
lam=527; # F
line ("xdata",[lam,lam], "ydata",[y1,y2], "linewidth", 1)
lam=486.1; # H
line ("xdata",[lam,lam], "ydata",[y1,y2], "linewidth", 1, "color", "g")
lam=518.4; # Mg
line ("xdata",[lam,lam], "ydata",[y1,y2], "linewidth", 1, "color", "magenta")
lam=517.3; # Mg
line ("xdata",[lam,lam], "ydata",[y1,y2], "linewidth", 1, "color", "magenta")
lam=430.8; # F
line ("xdata",[lam,lam], "ydata",[y1,y2], "linewidth", 1)
lam=393.4; # Ca
line ("xdata",[lam,lam], "ydata",[y1,y2], "linewidth", 1, "color", "cyan")
lam=576.959; #
#line ("xdata",[lam,lam], "ydata",[y1,y2], "linewidth", 1, "color", "cyan")
lam=579.065; #
#line ("xdata",[lam,lam], "ydata",[y1,y2], "linewidth", 1, "color", "cyan")
lam=546.5; #
#line ("xdata",[lam,lam], "ydata",[y1,y2], "linewidth", 1, "color", "cyan")
lam=436.6; #
#line ("xdata",[lam,lam], "ydata",[y1,y2], "linewidth", 1, "color", "cyan")
lam=611.6 ; #
#line ("xdata",[lam,lam], "ydata",[y1,y2], "linewidth", 1, "color", "green")
hold off;