1+ import type { Info2D } from '@zakodium/nmr-types' ;
12import type { Spectrum2D } from '@zakodium/nmrium-core' ;
3+ import type { NmrData2DContent , NmrData2DFt } from 'cheminfo-types' ;
24import { xyzAutoZonesPicking } from 'nmr-processing' ;
35
46export interface DetectionZonesOptions {
@@ -11,70 +13,46 @@ export interface DetectionZonesOptions {
1113 thresholdFactor : number ;
1214 maxPercentCutOff : number ;
1315 tolerances ?: number [ ] ;
14- convolutionByFFT ?: boolean ;
15- enhanceSymmetry ?: boolean ;
1616}
1717
1818/**
1919 *
20- * @param {object } options
21- * @param {object } options.selectedZone
22- * @param {number } options.selectedZone.fromX
23- * @param {number } options.selectedZone.fromY
24- * @param {number } options.selectedZone.toX
25- * @param {number } options.selectedZone.toY
26- * @param {number } options.thresholdFactor
27- * @param {boolean } options.convolutionByFFT
20+ * @param spectrum
21+ * @param options
2822 */
2923export function getDetectionZones (
3024 spectrum : Spectrum2D ,
3125 options : DetectionZonesOptions ,
3226) {
33- let dataMatrix = { } ;
34- const { selectedZone } = options ;
35- if ( selectedZone ) {
36- options . enhanceSymmetry = false ;
37- dataMatrix = getSubMatrix ( spectrum , selectedZone ) ;
38- } else {
39- dataMatrix = spectrum . data ;
40- }
41-
42- return autoZonesDetection ( dataMatrix , {
43- ...options ,
44- info : spectrum . info ,
45- } ) ;
27+ const dataMatrix = getSubMatrix ( spectrum , options . selectedZone ) ;
28+ return autoZonesDetection ( dataMatrix , spectrum . info , options ) ;
4629}
4730
48- function autoZonesDetection ( data : any , options : any ) {
49- const {
50- clean,
51- tolerances,
52- thresholdFactor,
53- maxPercentCutOff,
54- convolutionByFFT,
55- info : { nucleus : nuclei , originFrequency } ,
56- } = options ;
57-
58- const { enhanceSymmetry = nuclei [ 0 ] === nuclei [ 1 ] } = options ;
31+ function autoZonesDetection (
32+ data : NmrData2DContent ,
33+ info : Info2D ,
34+ options : DetectionZonesOptions ,
35+ ) {
36+ const { tolerances, thresholdFactor, maxPercentCutOff } = options ;
37+ const { nucleus : nuclei , originFrequency } = info ;
5938
60- const zones = xyzAutoZonesPicking ( data , {
39+ return xyzAutoZonesPicking ( data , {
6140 nuclei,
6241 tolerances,
6342 observedFrequencies : originFrequency ,
6443 thresholdFactor,
6544 realTopDetection : true ,
66- clean,
6745 maxPercentCutOff,
68- enhanceSymmetry,
69- convolutionByFFT,
46+ enhanceSymmetry : false ,
7047 } ) ;
71-
72- return zones ;
7348}
7449
75- function getSubMatrix ( datum : any , selectedZone : any ) {
50+ function getSubMatrix (
51+ datum : Spectrum2D ,
52+ selectedZone : DetectionZonesOptions [ 'selectedZone' ] ,
53+ ) : NmrData2DContent {
7654 const { fromX, toX, fromY, toY } = selectedZone ;
77- const data = datum . data . rr ;
55+ const data = ( datum . data as NmrData2DFt ) . rr ;
7856 const xStep = ( data . maxX - data . minX ) / ( data . z [ 0 ] . length - 1 ) ;
7957 const yStep = ( data . maxY - data . minY ) / ( data . z . length - 1 ) ;
8058 let xIndexFrom = Math . max ( Math . floor ( ( fromX - data . minX ) / xStep ) , 0 ) ;
@@ -91,20 +69,14 @@ function getSubMatrix(datum: any, selectedZone: any) {
9169 if ( xIndexFrom > xIndexTo ) [ xIndexFrom , xIndexTo ] = [ xIndexTo , xIndexFrom ] ;
9270 if ( yIndexFrom > yIndexTo ) [ yIndexFrom , yIndexTo ] = [ yIndexTo , yIndexFrom ] ;
9371
94- const dataMatrix : any = {
95- z : [ ] ,
96- maxX : data . minX + xIndexTo * xStep ,
97- minX : data . minX + xIndexFrom * xStep ,
98- maxY : data . minY + yIndexTo * yStep ,
99- minY : data . minY + yIndexFrom * yStep ,
100- } ;
101- let maxZ = Number . MIN_SAFE_INTEGER ;
102- let minZ = Number . MAX_SAFE_INTEGER ;
72+ const z : NmrData2DContent [ 'z' ] = [ ] ;
73+ let maxZ = Number . MAX_SAFE_INTEGER ;
74+ let minZ = Number . MIN_SAFE_INTEGER ;
10375
10476 const nbXPoints = xIndexTo - xIndexFrom + 1 ;
10577
10678 for ( let j = yIndexFrom ; j < yIndexTo ; j ++ ) {
107- const row = new Float32Array ( nbXPoints ) ;
79+ const row = new Float64Array ( nbXPoints ) ;
10880 let xIndex = xIndexFrom ;
10981 for ( let i = 0 ; i < nbXPoints ; i ++ ) {
11082 row [ i ] = data . z [ j ] [ xIndex ++ ] ;
@@ -113,9 +85,16 @@ function getSubMatrix(datum: any, selectedZone: any) {
11385 if ( maxZ < rowValue ) maxZ = rowValue ;
11486 if ( minZ > rowValue ) minZ = rowValue ;
11587 }
116- dataMatrix . z . push ( Array . from ( row ) ) ;
88+ z . push ( row ) ;
11789 }
118- dataMatrix . minZ = minZ ;
119- dataMatrix . maxZ = maxZ ;
120- return dataMatrix ;
90+
91+ return {
92+ z,
93+ maxX : data . minX + xIndexTo * xStep ,
94+ minX : data . minX + xIndexFrom * xStep ,
95+ maxY : data . minY + yIndexTo * yStep ,
96+ minY : data . minY + yIndexFrom * yStep ,
97+ maxZ,
98+ minZ,
99+ } ;
121100}
0 commit comments