-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpem.pro
35 lines (32 loc) · 847 Bytes
/
pem.pro
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
pro pem,y,n,yfit,percentile=percentile
;+
; Break a spectrum in n pieces and normalize each
; by its own mean value.
;
; IN: y -fltarr Input array
; n -integer number of pieces
;
; OUT: yfit -fltarr Output array
;
; KEYWORDS: percentile Desired percentile (0.5 for median)
;
; C. Allende Prieto, July 2011, T4 Barajas
; , January 2015, IAC -- added percentile
;-
nel=n_elements(y)
np=nel/n
y2=y
yfit=y
for i=0,n-1 do begin
if keyword_set(percentile) then mm=cmedian(y2[i*np:np*(i+1)-1],percentile=percentile) else $
mm=mean(y2[i*np:np*(i+1)-1])
yfit[i*np:np*(i+1)-1]=mm
;y2[i*np:np*(i+1)-1]=y2[i*np:np*(i+1)-1]/mm
endfor
if np*i-1 lt nel-1 then begin
if keyword_set(percentile) then mm=cmedian(y2[np*i:nel-1],percentile=percentile) else $
mm=mean(y2[np*i:nel-1])
yfit[np*i:nel-1]=mm
;y2[np*i:nel-1]=y2[np*i:nel-1]/mm
endif
end