11var Opt = require ( "ml-optimize-lorentzian" ) ;
2-
2+ var stats = require ( "ml-stat" ) ;
33function gsd ( x , y , options ) {
44 var options = Object . create ( options || { } ) ;
55 if ( options . minMaxRatio === undefined ) options . minMaxRatio = 0.00025 ;
66 if ( options . broadRatio === undefined ) options . broadRatio = 0.00 ;
77 if ( options . noiseLevel === undefined ) options . noiseLevel = 0 ;
88 if ( options . maxCriteria === undefined ) options . maxCriteria = true ;
99 if ( options . smoothY === undefined ) options . smoothY = true ;
10+ if ( options . realTopDetection === undefined ) options . realTopDetection = false ;
1011
1112
12- if ( options . noiseLevel > 0 ) {
13+ //Transform y to use the standard algorithm.
14+ var yCorrection = { m :1 , b :0 } ;
15+ if ( ! options . maxCriteria || options . noiseLevel > 0 ) {
1316 y = [ ] . concat ( y ) ;
14- for ( var i = 0 ; i < y . length ; i ++ ) {
15- if ( Math . abs ( y [ i ] ) < options . noiseLevel ) {
16- y [ i ] = 0 ;
17+ var yCorrection = { m :- 1 , b :stats . array . max ( y ) } ;
18+ if ( ! options . maxCriteria ) {
19+ for ( var i = 0 ; i < y . length ; i ++ ) {
20+ y [ i ] = - y [ i ] + yCorrection . b ;
21+ }
22+ options . noiseLevel = - options . noiseLevel + yCorrection . b ;
23+ }
24+ if ( options . noiseLevel > 0 ) {
25+ for ( var i = 0 ; i < y . length ; i ++ ) {
26+ if ( Math . abs ( y [ i ] ) < options . noiseLevel ) {
27+ y [ i ] = 0 ;
28+ }
1729 }
1830 }
1931 }
20-
2132 // fill convolution frequency axis
2233 var X = [ ] ; //x[2:(x.length-2)];
2334
@@ -78,34 +89,21 @@ function gsd(x, y, options){
7889 intervals . push ( [ lastMax , lastMin ] ) ;
7990 }
8091 }
81-
82- if ( options . maxCriteria ) {
83- if ( ( ddY [ i ] < ddY [ i - 1 ] ) && ( ddY [ i ] < ddY [ i + 1 ] ) ) {
84- minddY . push ( [ X [ i ] , Y [ i ] , i ] ) ; // TODO should we change this to have 3 arrays ? Huge overhead creating arrays
85- if ( Math . abs ( ddY [ i ] ) > options . broadRatio * maxDdy ) { // TODO should this be a parameter =
86- broadMask . push ( false ) ;
87- }
88- else {
89- broadMask . push ( true ) ;
90- }
92+ if ( ( ddY [ i ] < ddY [ i - 1 ] ) && ( ddY [ i ] < ddY [ i + 1 ] ) ) {
93+ minddY . push ( [ X [ i ] , Y [ i ] , i ] ) ; // TODO should we change this to have 3 arrays ? Huge overhead creating arrays
94+ if ( Math . abs ( ddY [ i ] ) > options . broadRatio * maxDdy ) { // TODO should this be a parameter =
95+ broadMask . push ( false ) ;
9196 }
92- }
93- else {
94- if ( ( ddY [ i ] > ddY [ i - 1 ] ) && ( ddY [ i ] > ddY [ i + 1 ] ) ) {
95- minddY . push ( [ X [ i ] , Y [ i ] , i ] ) ; // TODO should we change this to have 3 arrays ? Huge overhead creating arrays
96- if ( Math . abs ( ddY [ i ] ) > options . broadRatio * maxDdy ) { // TODO should this be a parameter =
97- broadMask . push ( false ) ;
98- }
99- else {
100- broadMask . push ( true ) ;
101- }
97+ else {
98+ broadMask . push ( true ) ;
10299 }
103100 }
104-
105101 }
106- realTopDetection ( minddY , X , Y ) ;
102+ if ( options . realTopDetection ) {
103+ realTopDetection ( minddY , X , Y ) ;
104+ }
105+ //
107106 //console.log(intervals);
108- //console.log(minddY);
109107 var signals = [ ] ;
110108
111109 for ( var j = 0 ; j < minddY . length ; j ++ ) {
@@ -128,8 +126,9 @@ function gsd(x, y, options){
128126 if ( Math . abs ( height ) > options . minMaxRatio * maxY ) {
129127 signals . push ( {
130128 x : frequency ,
131- y : height ,
132- width : linewidth //*widthCorrection
129+ y : ( height - yCorrection . b ) / yCorrection . m ,
130+ width : linewidth , //*widthCorrection
131+ soft :broadMask [ j ]
133132 } )
134133 }
135134 }
@@ -139,7 +138,7 @@ function gsd(x, y, options){
139138 // console.log("Nested "+possible);
140139 }
141140 }
142- if ( options . broadRatio > 0 ) {
141+ /* if(options.broadRatio>0){
143142 var broadLines=[[Number.MAX_VALUE,0,0]];
144143 //Optimize the possible broad lines
145144 var max=0, maxI=0,count=0;
@@ -185,7 +184,7 @@ function gsd(x, y, options){
185184 count = 0;
186185 }
187186 }
188- }
187+ }*/
189188
190189 signals . sort ( function ( a , b ) {
191190 return a . x - b . x ;
0 commit comments