Skip to content

Commit e3148cd

Browse files
committed
feat: fix and improve type script definition
1 parent b17da5d commit e3148cd

File tree

2 files changed

+37
-31
lines changed

2 files changed

+37
-31
lines changed

ml-gsd.d.ts

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
1-
export interface XYNumberArray {
2-
x: Array<number> | Float64Array;
3-
y: Array<number> | Float64Array;
4-
}
1+
import type {DataXY} from 'cheminfo-types';
2+
export {DataXY} from 'cheminfo-types';
53

6-
interface GsdOptions {
4+
export interface GSDOptions {
75
/**
86
* Noise threshold in spectrum y units. Default is three/thresholdFactor times the absolute median of data.y.
97
* @default `median(data.y) * (options.thresholdFactor || 3)`
108
*/
119
noiseLevel?: number;
1210
/**
13-
* Threshold to determine if a given peak should be considered as a noise, bases on its relative height compared to the highest peak.
11+
* Threshold to determine if a given GSDPeak should be considered as a noise, bases on its relative height compared to the highest GSDPeak.
1412
* @default 0.01
1513
*/
1614
minMaxRatio?: number;
1715
/**
18-
* If broadRatio is higher than 0, then all the peaks which second derivative smaller than broadRatio * maxAbsSecondDerivative will be marked with the soft mask equal to true.
16+
* If broadRatio is higher than 0, then all the GSDPeaks which second derivative smaller than broadRatio * maxAbsSecondDerivative will be marked with the soft mask equal to true.
1917
* @default 0.00025
2018
*/
2119
broadRatio?: number;
2220
/**
23-
* Select the peak intensities from a smoothed version of the independent variables.
21+
* Select the GSDPeak intensities from a smoothed version of the independent variables.
2422
* @default true
2523
*/
2624
smoothY?: boolean;
@@ -43,7 +41,7 @@ interface GsdOptions {
4341
* @default -1
4442
*/
4543
/**
46-
* Peaks are local maximum(true) or minimum(false)
44+
* GSDPeaks are local maximum(true) or minimum(false)
4745
* @default true
4846
*/
4947
maxCriteria?: boolean;
@@ -59,25 +57,32 @@ interface GsdOptions {
5957
heightFactor?: number;
6058
}
6159

62-
export interface Peak {
60+
export interface GSDPeak {
61+
index: number;
6362
x: number;
6463
y: number;
6564
width: number;
66-
left?: number;
67-
right?: number;
65+
left?: {
66+
x?:number,
67+
index?:number,
68+
};
69+
right?: {
70+
x?:number,
71+
index?:number,
72+
};
6873
base?: number;
6974
soft?: boolean;
7075
kind?: string;
7176
}
7277

73-
export interface OptimizePeaksOptions {
78+
export interface OptimizeGSDPeaksOptions {
7479
/**
75-
* factor to determine the width at the moment to group the peaks in signals in 'GSD.optimizePeaks' function.
80+
* factor to determine the width at the moment to group the GSDPeaks in signals in 'GSD.optimizeGSDPeaks' function.
7681
* @default 1
7782
*/
7883
factorWidth?: number;
7984
/**
80-
* times of width to use to optimize peaks
85+
* times of width to use to optimize GSDPeaks
8186
* @default 2
8287
*/
8388
factorLimits?: number;
@@ -105,27 +110,27 @@ export interface OptimizationOptions {
105110
timeout?: number;
106111
}
107112

108-
export interface OptimizedPeak {
113+
export interface OptimizedGSDPeak {
109114
x: number;
110115
y: number;
111116
width: number;
112117
mu?: number;
113118
}
114119

115-
export function gsd(data: XYNumberArray, options?: GsdOptions): Peak[];
120+
export function gsd(data: DataXY, options?: GSDOptions): GSDPeak[];
116121

117-
export function optimizePeaks(
118-
data: XYNumberArray,
119-
peakList: Peak[],
120-
options?: OptimizePeaksOptions,
121-
): OptimizedPeak[];
122+
export function optimizeGSDPeaks(
123+
data: DataXY,
124+
PeakList: GSDPeak[],
125+
options?: OptimizeGSDPeaksOptions,
126+
): OptimizedGSDPeak[];
122127

123-
export function joinBroadPeaks(
124-
peakList: Peak[],
125-
options?: JoinBroadPeaksOptions,
126-
): Peak[];
128+
export function joinBroadGSDPeaks(
129+
PeakList: GSDPeak[],
130+
options?: JoinBroadGSDPeaksOptions,
131+
): GSDPeak[];
127132

128-
export interface JoinBroadPeaksOptions {
133+
export interface JoinBroadGSDPeaksOptions {
129134
/**
130135
* @default 0.25
131136
*/
@@ -140,10 +145,10 @@ export interface JoinBroadPeaksOptions {
140145
optimization: OptimizationOptions;
141146
}
142147

143-
export function groupPeaks(peakList: Peak[], factor?: number): Peak[][];
148+
export function groupGSDPeaks(PeakList: GSDPeak[], factor?: number): GSDPeak[][];
144149

145-
export function broadenPeaks(
146-
peakList: Peak[],
150+
export function broadenGSDPeaks(
151+
PeakList: GSDPeak[],
147152
options?: {
148153
/**
149154
* @default 2
@@ -154,4 +159,4 @@ export function broadenPeaks(
154159
*/
155160
overlap: boolean;
156161
},
157-
): Peak[];
162+
): GSDPeak[];

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"xy-parser": "^3.1.1"
7575
},
7676
"dependencies": {
77+
"cheminfo-types": "^0.5.0",
7778
"ml-peak-shape-generator": "^2.0.1",
7879
"ml-savitzky-golay-generalized": "2.0.3",
7980
"ml-spectra-fitting": "^1.0.0",

0 commit comments

Comments
 (0)