Comparing version
@@ -24,3 +24,7 @@ import type { DataXY } from 'cheminfo-types'; | ||
/** | ||
* Threshold to determine if a given peak should be considered as a noise | ||
* Peak under the noiseLevel (or over in case of maxCriteria=false) are ignored. | ||
*/ | ||
noiseLevel?: number; | ||
/** | ||
* Minimal height of small peaks based on the ratio between min and max | ||
* @default 0.00025 | ||
@@ -27,0 +31,0 @@ */ |
import { sgg } from 'ml-savitzky-golay-generalized'; | ||
import { xIsEquallySpaced, xIsMonotoneIncreasing, xMinValue, xMaxValue, } from 'ml-spectra-processing'; | ||
import { xIsEquallySpaced, xIsMonotoneIncreasing, xMinValue, xMaxValue, xNoiseStandardDeviation, } from 'ml-spectra-processing'; | ||
import { optimizeTop } from './utils/optimizeTop'; | ||
@@ -15,3 +15,3 @@ /** | ||
polynomial: 3, | ||
}, smoothY = false, maxCriteria = true, minMaxRatio = 0.00025, realTopDetection = false, } = options; | ||
}, noiseLevel, smoothY = false, maxCriteria = true, minMaxRatio = 0.00025, realTopDetection = false, } = options; | ||
let { x, y } = data; | ||
@@ -25,2 +25,21 @@ if (!xIsMonotoneIncreasing(x)) { | ||
let equallySpaced = xIsEquallySpaced(x); | ||
if (noiseLevel === undefined) { | ||
if (equallySpaced) { | ||
const noiseInfo = xNoiseStandardDeviation(y); | ||
if (maxCriteria) { | ||
noiseLevel = noiseInfo.median + 1.5 * noiseInfo.sd; | ||
} | ||
else { | ||
noiseLevel = -noiseInfo.median + 1.5 * noiseInfo.sd; | ||
} | ||
} | ||
else { | ||
noiseLevel = 0; | ||
} | ||
} | ||
else { | ||
if (maxCriteria === false) { | ||
noiseLevel *= -1; | ||
} | ||
} | ||
if (maxCriteria === false) { | ||
@@ -31,2 +50,9 @@ for (let i = 0; i < y.length; i++) { | ||
} | ||
if (noiseLevel) { | ||
for (let i = 0; i < y.length; i++) { | ||
if (y[i] < noiseLevel) { | ||
y[i] = noiseLevel; | ||
} | ||
} | ||
} | ||
let yData = y; | ||
@@ -33,0 +59,0 @@ let dY, ddY; |
export * from './gsd'; | ||
export * from './post/optimizePeaks'; | ||
export * from './post/broadenPeaks'; | ||
export * from './GSDBroadenPeak'; | ||
export * from './GSDPeak'; | ||
export * from './GSDPeakOptimized'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -6,2 +6,5 @@ export * from './gsd'; | ||
export * from './post/broadenPeaks'; | ||
export * from './GSDBroadenPeak'; | ||
export * from './GSDPeak'; | ||
export * from './GSDPeakOptimized'; | ||
//# sourceMappingURL=index.js.map |
@@ -24,3 +24,7 @@ import type { DataXY } from 'cheminfo-types'; | ||
/** | ||
* Threshold to determine if a given peak should be considered as a noise | ||
* Peak under the noiseLevel (or over in case of maxCriteria=false) are ignored. | ||
*/ | ||
noiseLevel?: number; | ||
/** | ||
* Minimal height of small peaks based on the ratio between min and max | ||
* @default 0.00025 | ||
@@ -27,0 +31,0 @@ */ |
@@ -18,3 +18,3 @@ "use strict"; | ||
polynomial: 3, | ||
}, smoothY = false, maxCriteria = true, minMaxRatio = 0.00025, realTopDetection = false, } = options; | ||
}, noiseLevel, smoothY = false, maxCriteria = true, minMaxRatio = 0.00025, realTopDetection = false, } = options; | ||
let { x, y } = data; | ||
@@ -28,2 +28,21 @@ if (!(0, ml_spectra_processing_1.xIsMonotoneIncreasing)(x)) { | ||
let equallySpaced = (0, ml_spectra_processing_1.xIsEquallySpaced)(x); | ||
if (noiseLevel === undefined) { | ||
if (equallySpaced) { | ||
const noiseInfo = (0, ml_spectra_processing_1.xNoiseStandardDeviation)(y); | ||
if (maxCriteria) { | ||
noiseLevel = noiseInfo.median + 1.5 * noiseInfo.sd; | ||
} | ||
else { | ||
noiseLevel = -noiseInfo.median + 1.5 * noiseInfo.sd; | ||
} | ||
} | ||
else { | ||
noiseLevel = 0; | ||
} | ||
} | ||
else { | ||
if (maxCriteria === false) { | ||
noiseLevel *= -1; | ||
} | ||
} | ||
if (maxCriteria === false) { | ||
@@ -34,2 +53,9 @@ for (let i = 0; i < y.length; i++) { | ||
} | ||
if (noiseLevel) { | ||
for (let i = 0; i < y.length; i++) { | ||
if (y[i] < noiseLevel) { | ||
y[i] = noiseLevel; | ||
} | ||
} | ||
} | ||
let yData = y; | ||
@@ -36,0 +62,0 @@ let dY, ddY; |
export * from './gsd'; | ||
export * from './post/optimizePeaks'; | ||
export * from './post/broadenPeaks'; | ||
export * from './GSDBroadenPeak'; | ||
export * from './GSDPeak'; | ||
export * from './GSDPeakOptimized'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -18,2 +18,5 @@ "use strict"; | ||
__exportStar(require("./post/broadenPeaks"), exports); | ||
__exportStar(require("./GSDBroadenPeak"), exports); | ||
__exportStar(require("./GSDPeak"), exports); | ||
__exportStar(require("./GSDPeakOptimized"), exports); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "ml-gsd", | ||
"version": "10.0.0", | ||
"version": "10.1.0", | ||
"description": "Global Spectra Deconvolution", | ||
@@ -66,7 +66,7 @@ "main": "./lib/index.js", | ||
"eslint-config-cheminfo-typescript": "^10.3.0", | ||
"eslint-plugin-jest": "^26.1.0", | ||
"eslint-plugin-jest": "^26.1.1", | ||
"esm": "^3.2.25", | ||
"jest": "^27.5.1", | ||
"jest-matcher-deep-close-to": "^3.0.2", | ||
"mf-global": "^1.4.20", | ||
"mf-global": "^1.4.22", | ||
"ml-stat": "^1.3.3", | ||
@@ -76,3 +76,3 @@ "nodemon": "^2.0.15", | ||
"rimraf": "^3.0.2", | ||
"spectrum-generator": "^6.0.4", | ||
"spectrum-generator": "^7.0.0", | ||
"ts-jest": "^27.1.3", | ||
@@ -87,4 +87,4 @@ "typescript": "^4.5.5", | ||
"ml-spectra-fitting": "^3.0.4", | ||
"ml-spectra-processing": "^10.0.0" | ||
"ml-spectra-processing": "^10.1.2" | ||
} | ||
} |
@@ -15,2 +15,3 @@ # global-spectral-deconvolution and peak optimizer | ||
- `maxCriteria`: search either for maxima or minima. We will invert the data and the results if searching for a minima | ||
- `noiseLevel`: specifies the noise level. All the peaks bellow this value (or above in case of maxCriteria=false) are ignored. By default the noiseLevel will be set to the median + 3 x sd. This is a good value when not too many peaks are present in the spectrum. | ||
- `sgOptions`: Savitzky-Golay filter that is used to smooth the data for the calculation of the derivatives | ||
@@ -17,0 +18,0 @@ - `smoothY`: If this value is true the SG filter is not only applied during the calculation of the derivatives but also on the original data |
@@ -9,3 +9,3 @@ import { gsd } from '../gsd'; | ||
gsd({ x, y }); | ||
}).toThrow('Window size is higher than the data length 9>0'); | ||
}).toThrow('input must not be empty'); | ||
}); | ||
@@ -12,0 +12,0 @@ |
@@ -8,2 +8,3 @@ import type { DataXY } from 'cheminfo-types'; | ||
xMaxValue, | ||
xNoiseStandardDeviation, | ||
} from 'ml-spectra-processing'; | ||
@@ -34,7 +35,10 @@ | ||
/** | ||
* Threshold to determine if a given peak should be considered as a noise | ||
* Peak under the noiseLevel (or over in case of maxCriteria=false) are ignored. | ||
*/ | ||
noiseLevel?: number; | ||
/** | ||
* Minimal height of small peaks based on the ratio between min and max | ||
* @default 0.00025 | ||
*/ | ||
minMaxRatio?: number; | ||
/** | ||
@@ -61,2 +65,3 @@ * Use a quadratic optimizations with the peak and its 3 closest neighbors | ||
}, | ||
noiseLevel, | ||
smoothY = false, | ||
@@ -78,2 +83,19 @@ maxCriteria = true, | ||
if (noiseLevel === undefined) { | ||
if (equallySpaced) { | ||
const noiseInfo = xNoiseStandardDeviation(y); | ||
if (maxCriteria) { | ||
noiseLevel = noiseInfo.median + 1.5 * noiseInfo.sd; | ||
} else { | ||
noiseLevel = -noiseInfo.median + 1.5 * noiseInfo.sd; | ||
} | ||
} else { | ||
noiseLevel = 0; | ||
} | ||
} else { | ||
if (maxCriteria === false) { | ||
noiseLevel *= -1; | ||
} | ||
} | ||
if (maxCriteria === false) { | ||
@@ -84,2 +106,9 @@ for (let i = 0; i < y.length; i++) { | ||
} | ||
if (noiseLevel) { | ||
for (let i = 0; i < y.length; i++) { | ||
if (y[i] < noiseLevel) { | ||
y[i] = noiseLevel; | ||
} | ||
} | ||
} | ||
@@ -86,0 +115,0 @@ let yData = y; |
@@ -6,1 +6,5 @@ export * from './gsd'; | ||
export * from './post/broadenPeaks'; | ||
export * from './GSDBroadenPeak'; | ||
export * from './GSDPeak'; | ||
export * from './GSDPeakOptimized'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
2607374
0.33%135
1.5%9757
2.53%126
0.8%0
-100%