-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(contours): use xSanplot instead of absMedian (#1790)
* fix(contours): use xSanplot instead of absMedian * chore: move calculateSanPlot to data folder
- Loading branch information
Showing
3 changed files
with
52 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { xNoiseSanPlot } from 'ml-spectra-processing'; | ||
|
||
import { Data1D } from '../types/data1d'; | ||
import { Data2D } from '../types/data2d'; | ||
|
||
export function calculateSanPlot<T extends '1D' | '2D'>( | ||
dimension: T, | ||
data: T extends '1D' ? Data1D : Data2D, | ||
) { | ||
const input = | ||
dimension === '1D' | ||
? prepare1DData(data as Data1D) | ||
: prepare2DData(data as Data2D); | ||
|
||
return xNoiseSanPlot(input); | ||
} | ||
|
||
function prepare1DData(data: Data1D) { | ||
const length = data.re.length; | ||
const jump = Math.floor(length / 307200) || 1; | ||
const array = new Float64Array((length / jump) >> 0); | ||
let index = 0; | ||
for (let i = 0; i < array.length; i += jump) { | ||
array[index++] = data.re[i]; | ||
} | ||
return array; | ||
} | ||
|
||
function prepare2DData(data: Data2D) { | ||
let cols = data.z[0].length; | ||
let rows = data.z.length; | ||
let jump = Math.floor((cols * rows) / 204800) || 1; | ||
const array = new Float64Array(((cols * rows) / jump) >> 0); | ||
let index = 0; | ||
// console.log('jump', jump, cols * rows); | ||
for (let r = 0; r < rows; r += 1) { | ||
for (let c = 0; c < cols; c += jump) { | ||
array[index++] = data.z[r][c]; | ||
} | ||
} | ||
|
||
return array; | ||
} |