brukerconverter
Advanced tools
Comparing version 6.2.3 to 6.2.4-pre.1694336922
136
lib/index.js
@@ -217,2 +217,19 @@ 'use strict'; | ||
function getValueFct(results) { | ||
const getIndex = getIndexFct(results); | ||
return (name) => { | ||
const index = getIndex(name); | ||
if (index > 0 && results[index].status === 'fulfilled') { | ||
return results[index].value; | ||
} | ||
}; | ||
} | ||
function getIndexFct(results) { | ||
return (name) => { | ||
const index = results.findIndex((r) => r.value === name); | ||
return index > -1 ? index + 1 : null; | ||
}; | ||
} | ||
function joinInfoMeta(target, toAppend) { | ||
@@ -283,5 +300,5 @@ for (let key in toAppend.meta) { | ||
async function setFIDSpectrumData(file, spectra) { | ||
function setFIDSpectrumData(file, spectra) { | ||
let td = parseInt(spectra.meta.TD[0], 10); | ||
let ioBuffer = new iobuffer.IOBuffer(await file.arrayBuffer()); | ||
let ioBuffer = new iobuffer.IOBuffer(file); | ||
@@ -359,7 +376,7 @@ if (td * spectra.meta.nbSubSpectra * 4 > ioBuffer.length) { | ||
async function setProcessedSpectrumData(files, spectra) { | ||
function setProcessedSpectrumData(files, spectra) { | ||
const buffers = {}; | ||
for (const key in files) { | ||
if (!files[key]) continue; | ||
buffers[key] = new iobuffer.IOBuffer(await files[key].arrayBuffer()); | ||
buffers[key] = new iobuffer.IOBuffer(files[key]); | ||
} | ||
@@ -428,19 +445,45 @@ | ||
async function convert1D(files, options) { | ||
const result = await parseData(files.procs, options); | ||
const acqus = await parseData(files.acqus, options); | ||
joinInfoMeta(result, acqus); | ||
const promises = []; | ||
promises.push('procs', parseData(files.procs, options)); | ||
promises.push('acqus', parseData(files.acqus, options)); | ||
if (files.quantFactorSample) addEreticFactor(result, files); | ||
if (files.integrals) result.integrals = await parseIntegrals(files); | ||
if (files.quantFactorSample) { | ||
promises.push('ereticFactor', getEreticFactor(files)); | ||
} | ||
if (files.integrals) { | ||
promises.push('integrals', parseIntegrals(files)); | ||
} | ||
if (files['1r'] || files['1i']) { | ||
await setProcessedSpectrumData( | ||
const filesToRead = files['1r'] || files['1i'] ? ['1r', '1i'] : ['fid']; | ||
for (const key of filesToRead) { | ||
if (!files[key]) continue; | ||
promises.push(key, files[key].arrayBuffer()); | ||
} | ||
return Promise.allSettled(promises).then(formatSpectrum$1); | ||
} | ||
function formatSpectrum$1(results) { | ||
const getValue = getValueFct(results); | ||
const result = getValue('procs'); | ||
joinInfoMeta(result, getValue('acqus')); | ||
const getIndex = getIndexFct(results); | ||
if (getIndex('integrals')) { | ||
result.integrals = getValue('integrals'); | ||
} | ||
if (getIndex('ereticFactor')) { | ||
result.info.ereticFactor = getValue('ereticFactor'); | ||
} | ||
if (getIndex('1r') || getIndex('1i')) { | ||
setProcessedSpectrumData( | ||
{ | ||
re: files['1r'], | ||
im: files['1i'], | ||
re: getValue('1r'), | ||
im: getValue('1i'), | ||
}, | ||
result, | ||
); | ||
} else if (files.fid) { | ||
await setFIDSpectrumData(files.fid, result); | ||
} else if (getIndex('fid')) { | ||
setFIDSpectrumData(getValue('fid'), result); | ||
} | ||
@@ -451,9 +494,7 @@ | ||
async function addEreticFactor(result, files) { | ||
async function getEreticFactor(files) { | ||
const quantFactorSample = (await files.quantFactorSample.text()).match( | ||
/<Application[\w\W]+<Eretic_Factor>(?<ereticFactor>[\d.]+)/, | ||
); | ||
if (quantFactorSample) { | ||
result.info.ereticFactor = Number(quantFactorSample.groups.ereticFactor); | ||
} | ||
return Number(quantFactorSample.groups.ereticFactor); | ||
} | ||
@@ -476,20 +517,26 @@ | ||
async function convert2D(files, options) { | ||
const result = mergeMetadata( | ||
await parseData(files.procs, options), | ||
await parseData(files.proc2s, options), | ||
); | ||
const promises = []; | ||
promises.push('procs', parseData(files.procs, options)); | ||
promises.push('proc2s', parseData(files.proc2s, options)); | ||
promises.push('acqus', parseData(files.acqus, options)); | ||
promises.push('acqu2s', parseData(files.acqu2s, options)); | ||
const acqus = mergeMetadata( | ||
await parseData(files.acqus, options), | ||
await parseData(files.acqu2s, options), | ||
); | ||
const filesToRead = ['2rr', '2ri', '2ir', '2ii', 'ser']; | ||
for (const key of filesToRead) { | ||
if (!files[key]) continue; | ||
promises.push(key, files[key].arrayBuffer()); | ||
} | ||
return Promise.allSettled(promises).then(formatSpectrum); | ||
} | ||
function formatSpectrum(results) { | ||
const getIndex = getIndexFct(results); | ||
const getValue = getValueFct(results); | ||
const result = mergeMetadata(getValue('procs'), getValue('proc2s')); | ||
const acqus = mergeMetadata(getValue('acqus'), getValue('acqu2s')); | ||
joinInfoMeta(result, acqus); | ||
result.meta.nbSubSpectra = ['2rr', '2ri', '2ir', '2ii'].some( | ||
(key) => key in files, | ||
) | ||
? parseInt(result.meta.SI[1], 10) | ||
: parseInt(result.meta.TD[1], 10); | ||
if (!result.meta.SW_p) { | ||
@@ -503,4 +550,9 @@ // eslint-disable-next-line camelcase | ||
const isFft = ['2rr', '2ri', '2ir', '2ii'].some((key) => getIndex(key) > 0); | ||
result.meta.nbSubSpectra = isFft | ||
? parseInt(result.meta.SI[1], 10) | ||
: parseInt(result.meta.TD[1], 10); | ||
let firstY, lastY, xOffset, yOffset; | ||
if (files['2rr']) { | ||
if (isFft) { | ||
let sf = Number(result.meta.SF[1]); | ||
@@ -514,12 +566,12 @@ let swP = Number(result.meta.SW_p[1] || result.meta.SW[1]); | ||
result.meta.lastY = lastY; | ||
await setProcessedSpectrumData( | ||
setProcessedSpectrumData( | ||
{ | ||
rr: files['2rr'], | ||
ri: files['2ri'], | ||
ir: files['2ir'], | ||
ii: files['2ii'], | ||
rr: getValue('2rr'), | ||
ri: getValue('2ri'), | ||
ir: getValue('2ir'), | ||
ii: getValue('2ii'), | ||
}, | ||
result, | ||
); | ||
} else if (files.ser) { | ||
} else if (getIndex('ser')) { | ||
firstY = 0; | ||
@@ -537,7 +589,7 @@ lastY = result.meta.nbSubSpectra; | ||
yTransmitterFrequencyOffset / yTransmitterFrequency + yWindowSize / 2; | ||
await setFIDSpectrumData(files.ser, result); | ||
setFIDSpectrumData(getValue('ser'), result); | ||
} | ||
let pageValue = firstY; | ||
let nbSubSpectra = result.meta.nbSubSpectra / (files['2rr'] ? 1 : 2); | ||
let nbSubSpectra = result.meta.nbSubSpectra / (isFft ? 1 : 2); | ||
let deltaY = (lastY - firstY) / (nbSubSpectra - 1); | ||
@@ -544,0 +596,0 @@ for (let i = 0; i < nbSubSpectra; i++) { |
{ | ||
"name": "brukerconverter", | ||
"version": "6.2.3", | ||
"version": "6.2.4-pre.1694336922", | ||
"description": "Parse and convert Bruker raw data", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -0,1 +1,2 @@ | ||
import { getIndexFct, getValueFct } from './getValueFct.js'; | ||
import { joinInfoMeta } from './joinMetaInfo.js'; | ||
@@ -8,19 +9,45 @@ import { parseData } from './parseData'; | ||
export async function convert1D(files, options) { | ||
const result = await parseData(files.procs, options); | ||
const acqus = await parseData(files.acqus, options); | ||
joinInfoMeta(result, acqus); | ||
const promises = []; | ||
promises.push('procs', parseData(files.procs, options)); | ||
promises.push('acqus', parseData(files.acqus, options)); | ||
if (files.quantFactorSample) addEreticFactor(result, files); | ||
if (files.integrals) result.integrals = await parseIntegrals(files); | ||
if (files.quantFactorSample) { | ||
promises.push('ereticFactor', getEreticFactor(files)); | ||
} | ||
if (files.integrals) { | ||
promises.push('integrals', parseIntegrals(files)); | ||
} | ||
if (files['1r'] || files['1i']) { | ||
await setProcessedSpectrumData( | ||
const filesToRead = files['1r'] || files['1i'] ? ['1r', '1i'] : ['fid']; | ||
for (const key of filesToRead) { | ||
if (!files[key]) continue; | ||
promises.push(key, files[key].arrayBuffer()); | ||
} | ||
return Promise.allSettled(promises).then(formatSpectrum); | ||
} | ||
function formatSpectrum(results) { | ||
const getValue = getValueFct(results); | ||
const result = getValue('procs'); | ||
joinInfoMeta(result, getValue('acqus')); | ||
const getIndex = getIndexFct(results); | ||
if (getIndex('integrals')) { | ||
result.integrals = getValue('integrals'); | ||
} | ||
if (getIndex('ereticFactor')) { | ||
result.info.ereticFactor = getValue('ereticFactor'); | ||
} | ||
if (getIndex('1r') || getIndex('1i')) { | ||
setProcessedSpectrumData( | ||
{ | ||
re: files['1r'], | ||
im: files['1i'], | ||
re: getValue('1r'), | ||
im: getValue('1i'), | ||
}, | ||
result, | ||
); | ||
} else if (files.fid) { | ||
await setFIDSpectrumData(files.fid, result); | ||
} else if (getIndex('fid')) { | ||
setFIDSpectrumData(getValue('fid'), result); | ||
} | ||
@@ -31,9 +58,7 @@ | ||
async function addEreticFactor(result, files) { | ||
async function getEreticFactor(files) { | ||
const quantFactorSample = (await files.quantFactorSample.text()).match( | ||
/<Application[\w\W]+<Eretic_Factor>(?<ereticFactor>[\d.]+)/, | ||
); | ||
if (quantFactorSample) { | ||
result.info.ereticFactor = Number(quantFactorSample.groups.ereticFactor); | ||
} | ||
return Number(quantFactorSample.groups.ereticFactor); | ||
} |
@@ -6,22 +6,29 @@ import { joinInfoMeta } from './joinMetaInfo.js'; | ||
import { setProcessedSpectrumData } from './setProcessedSpectrumData'; | ||
import { getIndexFct, getValueFct } from './getValueFct.js'; | ||
export async function convert2D(files, options) { | ||
const result = mergeMetadata( | ||
await parseData(files.procs, options), | ||
await parseData(files.proc2s, options), | ||
); | ||
const promises = []; | ||
promises.push('procs', parseData(files.procs, options)); | ||
promises.push('proc2s', parseData(files.proc2s, options)); | ||
promises.push('acqus', parseData(files.acqus, options)); | ||
promises.push('acqu2s', parseData(files.acqu2s, options)); | ||
const acqus = mergeMetadata( | ||
await parseData(files.acqus, options), | ||
await parseData(files.acqu2s, options), | ||
); | ||
const filesToRead = ['2rr', '2ri', '2ir', '2ii', 'ser']; | ||
for (const key of filesToRead) { | ||
if (!files[key]) continue; | ||
promises.push(key, files[key].arrayBuffer()); | ||
} | ||
return Promise.allSettled(promises).then(formatSpectrum); | ||
} | ||
function formatSpectrum(results) { | ||
const getIndex = getIndexFct(results); | ||
const getValue = getValueFct(results); | ||
const result = mergeMetadata(getValue('procs'), getValue('proc2s')); | ||
const acqus = mergeMetadata(getValue('acqus'), getValue('acqu2s')); | ||
joinInfoMeta(result, acqus); | ||
result.meta.nbSubSpectra = ['2rr', '2ri', '2ir', '2ii'].some( | ||
(key) => key in files, | ||
) | ||
? parseInt(result.meta.SI[1], 10) | ||
: parseInt(result.meta.TD[1], 10); | ||
if (!result.meta.SW_p) { | ||
@@ -35,4 +42,9 @@ // eslint-disable-next-line camelcase | ||
const isFft = ['2rr', '2ri', '2ir', '2ii'].some((key) => getIndex(key) > 0); | ||
result.meta.nbSubSpectra = isFft | ||
? parseInt(result.meta.SI[1], 10) | ||
: parseInt(result.meta.TD[1], 10); | ||
let firstY, lastY, xOffset, yOffset; | ||
if (files['2rr']) { | ||
if (isFft) { | ||
let sf = Number(result.meta.SF[1]); | ||
@@ -46,12 +58,12 @@ let swP = Number(result.meta.SW_p[1] || result.meta.SW[1]); | ||
result.meta.lastY = lastY; | ||
await setProcessedSpectrumData( | ||
setProcessedSpectrumData( | ||
{ | ||
rr: files['2rr'], | ||
ri: files['2ri'], | ||
ir: files['2ir'], | ||
ii: files['2ii'], | ||
rr: getValue('2rr'), | ||
ri: getValue('2ri'), | ||
ir: getValue('2ir'), | ||
ii: getValue('2ii'), | ||
}, | ||
result, | ||
); | ||
} else if (files.ser) { | ||
} else if (getIndex('ser')) { | ||
firstY = 0; | ||
@@ -69,7 +81,7 @@ lastY = result.meta.nbSubSpectra; | ||
yTransmitterFrequencyOffset / yTransmitterFrequency + yWindowSize / 2; | ||
await setFIDSpectrumData(files.ser, result, true); | ||
setFIDSpectrumData(getValue('ser'), result, true); | ||
} | ||
let pageValue = firstY; | ||
let nbSubSpectra = result.meta.nbSubSpectra / (files['2rr'] ? 1 : 2); | ||
let nbSubSpectra = result.meta.nbSubSpectra / (isFft ? 1 : 2); | ||
let deltaY = (lastY - firstY) / (nbSubSpectra - 1); | ||
@@ -76,0 +88,0 @@ for (let i = 0; i < nbSubSpectra; i++) { |
@@ -6,5 +6,5 @@ import { IOBuffer } from 'iobuffer'; | ||
export async function setFIDSpectrumData(file, spectra) { | ||
export function setFIDSpectrumData(file, spectra) { | ||
let td = parseInt(spectra.meta.TD[0], 10); | ||
let ioBuffer = new IOBuffer(await file.arrayBuffer()); | ||
let ioBuffer = new IOBuffer(file); | ||
@@ -11,0 +11,0 @@ if (td * spectra.meta.nbSubSpectra * 4 > ioBuffer.length) { |
@@ -5,7 +5,7 @@ import { IOBuffer } from 'iobuffer'; | ||
export async function setProcessedSpectrumData(files, spectra) { | ||
export function setProcessedSpectrumData(files, spectra) { | ||
const buffers = {}; | ||
for (const key in files) { | ||
if (!files[key]) continue; | ||
buffers[key] = new IOBuffer(await files[key].arrayBuffer()); | ||
buffers[key] = new IOBuffer(files[key]); | ||
} | ||
@@ -12,0 +12,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1731574
50
1966
2