Skip to content

Commit

Permalink
fix: handle different columns in IGA parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin M. Jablonka committed May 5, 2021
1 parent 79b0ab5 commit a642336
Show file tree
Hide file tree
Showing 7 changed files with 964 additions and 15 deletions.
320 changes: 320 additions & 0 deletions dev_notebooks/.ipynb_checkpoints/plot_dvs_data-checkpoint.ipynb

Large diffs are not rendered by default.

320 changes: 320 additions & 0 deletions dev_notebooks/plot_dvs_data.ipynb

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@
"trailingComma": "all"
},
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.13.8",
"@babel/plugin-transform-modules-commonjs": "^7.14.0",
"@rollup/plugin-alias": "^3.1.2",
"@types/jest": "^26.0.23",
"cheminfo-build": "^1.1.10",
"cheminfo-publish": "^1.0.20",
"codecov": "^3.8.1",
"codecov": "^3.8.2",
"eslint": "^7.25.0",
"eslint-config-cheminfo": "^5.2.3",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.3.6",
"eslint-plugin-prettier": "^3.4.0",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"rollup": "^2.45.2"
"rollup": "^2.47.0"
},
"dependencies": {
"common-spectrum": "^0.33.0",
Expand Down
23 changes: 23 additions & 0 deletions src/from/__tests__/fromIGA.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,26 @@ test('fromIGA', () => {
expect(analysis.spectra[2].meta.adsorptionT).toBeCloseTo(59, 0);
expect(analysis.spectra[3].meta.adsorptionT).toBeCloseTo(68, 0);
});

test('fromIGA 2', () => {
const file = readFileSync(
join(__dirname, '../../../testFiles/Isotherm_IGA_67-CO2_20C-2bar.txt'),
'latin1',
);

let analysis = fromIGA(file);
expect(analysis.spectra).toHaveLength(2);
for (let i = 0; i < 2; i++) {
expect(Object.keys(analysis.spectra[i].variables)).toStrictEqual([
'x',
'y',
'r',
't',
]);

expect(analysis.spectra[i].dataType).toBe('Adsorption Isotherm');
}

expect(analysis.spectra[0].meta.adsorptionT).toBeCloseTo(20, 0);
expect(analysis.spectra[1].meta.adsorptionT).toBeCloseTo(20, 0);
});
80 changes: 69 additions & 11 deletions src/from/fromIGA.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,40 @@ function parseIGADataBlock(lines) {
return dataBlock;
}

function parseNonBETData(lines, sampleWeight) {
let dataBlock = {
pressure: [],
gasDensity: [],
totalWeight: [],
sampleT: [],
wtPercent: [],
excessAdsorption: [],
};
for (let line of lines) {
let tmp = line.split(/\s{3,}/);
dataBlock.pressure.push(parseFloat(tmp[0]) * 0.1);
dataBlock.gasDensity.push(parseFloat(tmp[1]));
dataBlock.totalWeight.push(parseFloat(tmp[2]));
dataBlock.sampleT.push(parseFloat(tmp[3]));
let wtPercent = parseFloat(tmp[4]);
dataBlock.wtPercent.push(wtPercent);
dataBlock.excessAdsorption.push(wtPercent * sampleWeight);
}
return dataBlock;
}

function parseOneIGA(lines) {
const measLen = lines.length;
let meta = parseIGAMeasurmentHeader(lines.slice(2, 68));
const dataBlock = parseIGADataBlock(lines.slice(72, measLen - 3));
let dataBlock;
if (lines[68].match('BET')) {
dataBlock = parseIGADataBlock(lines.slice(72, measLen - 3));
} else {
dataBlock = parseNonBETData(
lines.slice(72, measLen - 3),
meta.sampleWeightDry,
);
}
meta.scanEnd = lineSplitTrim(lines[measLen - 2]);
meta.scanReferenceState = lineSplitTrim(lines[measLen - 1]);
return { meta: meta, data: dataBlock };
Expand All @@ -156,7 +186,6 @@ function parseOneIGA(lines) {
*/
export function fromIGA(text) {
const lines = text.split(/[\r\n]+/);

const lineNumbers = getLineNumbersOfMeasurement(lines);
let analysis = new Analysis();
for (let i = 0; i < lineNumbers[0].length; i++) {
Expand All @@ -165,8 +194,9 @@ export function fromIGA(text) {
meas.meta.adsorptionT = mean(meas.data.sampleT);
meas.meta.adsorptionTunits = '°C';

analysis.pushSpectrum(
{
let spectrum;
if ('pp0' in meas.data) {
spectrum = {
x: {
data: meas.data.pressure,
label: 'Pressure',
Expand Down Expand Up @@ -197,14 +227,42 @@ export function fromIGA(text) {
type: 'independent',
units: '°C',
},
},
{
dataType: 'Adsorption Isotherm',
title: meas.meta.experimentTitle,
meta: meas.meta,
},
);
};
} else {
spectrum = {
x: {
data: meas.data.pressure,
label: 'Pressure',
type: 'independent',
units: 'kPa',
},
y: {
data: meas.data.excessAdsorption,
label: 'Excess Adsorption',
type: 'dependent',
units: 'g/g',
},
r: {
data: meas.data.wtPercent,
label: 'Excess Adsorption',
type: 'dependent',
units: '%',
},
t: {
data: meas.data.sampleT,
label: 'Sample Temperature',
type: 'independent',
units: '°C',
},
};
}
analysis.pushSpectrum(spectrum, {
dataType: 'Adsorption Isotherm',
title: meas.meta.experimentTitle,
meta: meas.meta,
});
}

return analysis;
}

Expand Down
6 changes: 5 additions & 1 deletion src/from/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
export function lineSplitTrim(line) {
return lineSplit(line)[1].trim();
try {
return lineSplit(line)[1].trim();
} catch (e) {
return '';
}
}

export function lineSplit(line) {
Expand Down
224 changes: 224 additions & 0 deletions testFiles/Isotherm_IGA_67-CO2_20C-2bar.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
----------------------------------------------------------------------------------------------------
S E R I E S D A T A R E C O R D
----------------------------------------------------------------------------------------------------


System Type IGA Systems
System Owner EPFL
System Reference G200773
System Serial Number HALIGA241
Sample Number 0154
Experiment Type Sequence
Experiment No 014

Title sion-66_b
Comment
Source
Batch
ID

Experiment Title Isotherm_20c_co2_hr
Sample Wet Weight 11.8799 mg
Sample Dry Weight 10.2293 mg
Sample Dry Mass 10.2293 mg
Sample Weight Loss 16.14 %d.b.

Balance Trim (V) 0.0024 cc
Balance Trim (T) Cabinet
Counterweight (M) 0.3065 g
Counterweight (ρ) 7.886 g/cc
Counterweight (T) Air
Tungsten (M) 0.0568 g
Tungsten (ρ) 19.03976 g/cc
Tungsten (T) Sample
Chain Excess (M) 0.0719 g
Chain Excess (ρ) 11.09856 g/cc
Chain Excess (T) Air

Interaction Type Not Specified
Classification Not Specified
Sample Geometry Not Specified
Sample Dimension Not Specified
Presorbed Not Specified
Sample Molar Mass Not Specified
Sample Skeletal Density Not Specified
Absolute Adsorption Basis Not Specified
Adsorbate Density Not Specified
Micropore Volume Not Specified
Dilation Not Specified

Application Code 201510
Mode Vacuum
Source Gas Cylinder
Vessel CF-SW High Pressure
Reactor Conflat SS316L
Pressure Sensor(s) 20 bar
Thermostat Water Bath
Species CO2
EOS Option Lookup Table
SVP Option C.L.Yaws et al

Source Data C:\HIsorp\G200773\Sample_0154\Sequence\Sequence014\Data.txt
Operations Log C:\HIsorp\G200773\Sample_0154\Sequence\Sequence014\Operations Log.txt
Method Log C:\HIsorp\G200773\Sample_0154\Sequence\Sequence014\Method Log.txt

File created 19:19:31 on 26 May 2017 by WR200774
Issue Level Recalculation Not Issued
Series Type Isothermal Series
Data Delimiter Space


Scan 1
Course Sorption
Reference State Device Sample
Scan Title
Scan Commenced 12:38:01 on 21 May 2017 by WR200774


Pressure Gas Total Sample %Wt
Density Weight
(mbar) (g/cc) (mg) (°C) (% d.b.)
----------------------------------------------------
0.7 0.000001 10.2172 30.07 -.12
19.9 0.000036 10.3009 19.91 0.70
39.9 0.000072 10.3669 20.01 1.35
59.8 0.000108 10.4250 20.01 1.91
79.8 0.000144 10.4783 19.99 2.43
99.7 0.000181 10.5276 19.99 2.92
149.7 0.000271 10.6381 19.99 4.00
199.6 0.000361 10.7360 19.99 4.95
249.5 0.000452 10.8251 20.00 5.82
299.4 0.000542 10.9080 19.99 6.64
349.3 0.000632 10.9856 20.00 7.39
399.2 0.000723 11.0590 20.00 8.11
449.0 0.000813 11.1286 20.00 8.79
498.9 0.000903 11.1956 20.00 9.45
598.8 0.001085 11.3216 19.99 10.68
698.5 0.001266 11.4390 19.99 11.83
798.3 0.001447 11.5492 19.99 12.90
897.8 0.001629 11.6535 19.99 13.92
997.6 0.001811 11.7519 19.99 14.88
1097.1 0.001993 11.8451 19.98 15.80
1196.9 0.002175 11.9336 19.99 16.66
1296.6 0.002357 12.0179 19.99 17.49
1396.1 0.002539 12.0985 19.99 18.27
1495.7 0.002722 12.1750 20.00 19.02
1595.3 0.002905 12.2481 19.99 19.74
1694.9 0.003088 12.3185 19.99 20.42
1793.9 0.003270 12.3848 19.99 21.07
1893.3 0.003453 12.4481 20.00 21.69
1993.6 0.003638 12.5089 20.00 22.28
----------------------------------------------------

Scan Ends 22:33:58 on 21 May 2017 by WR200774
Reference State 19.99°C



----------------------------------------------------------------------------------------------------
S E R I E S D A T A R E C O R D
----------------------------------------------------------------------------------------------------


System Type IGA Systems
System Owner EPFL
System Reference G200773
System Serial Number HALIGA241
Sample Number 0154
Experiment Type Sequence
Experiment No 014

Title sion-66_b
Comment
Source
Batch
ID

Experiment Title Isotherm_20c_co2_hr
Sample Wet Weight 11.8799 mg
Sample Dry Weight 10.2293 mg
Sample Dry Mass 10.2293 mg
Sample Weight Loss 16.14 %d.b.

Balance Trim (V) 0.0024 cc
Balance Trim (T) Cabinet
Counterweight (M) 0.3065 g
Counterweight (ρ) 7.886 g/cc
Counterweight (T) Air
Tungsten (M) 0.0568 g
Tungsten (ρ) 19.03976 g/cc
Tungsten (T) Sample
Chain Excess (M) 0.0719 g
Chain Excess (ρ) 11.09856 g/cc
Chain Excess (T) Air

Interaction Type Not Specified
Classification Not Specified
Sample Geometry Not Specified
Sample Dimension Not Specified
Presorbed Not Specified
Sample Molar Mass Not Specified
Sample Skeletal Density Not Specified
Absolute Adsorption Basis Not Specified
Adsorbate Density Not Specified
Micropore Volume Not Specified
Dilation Not Specified

Application Code 201510
Mode Vacuum
Source Gas Cylinder
Vessel CF-SW High Pressure
Reactor Conflat SS316L
Pressure Sensor(s) 20 bar
Thermostat Water Bath
Species CO2
EOS Option Lookup Table
SVP Option C.L.Yaws et al

Source Data C:\HIsorp\G200773\Sample_0154\Sequence\Sequence014\Data.txt
Operations Log C:\HIsorp\G200773\Sample_0154\Sequence\Sequence014\Operations Log.txt
Method Log C:\HIsorp\G200773\Sample_0154\Sequence\Sequence014\Method Log.txt

File created 19:19:32 on 26 May 2017 by WR200774
Issue Level Recalculation Not Issued
Series Type Isothermal Series
Data Delimiter Space


Scan 2
Course Desorption
Reference State Device Sample
Scan Title
Scan Commenced 22:33:59 on 21 May 2017 by WR200774


Pressure Gas Total Sample %Wt
Density Weight
(mbar) (g/cc) (mg) (°C) (% d.b.)
----------------------------------------------------
1993.6 0.003638 12.5089 20.00 22.28
1789.0 0.003261 12.3807 20.01 21.03
1590.9 0.002897 12.2445 20.01 19.70
1393.1 0.002534 12.0949 20.01 18.24
1194.5 0.002170 11.9312 20.02 16.64
995.6 0.001807 11.7495 20.02 14.86
896.2 0.001626 11.6514 20.01 13.90
796.8 0.001445 11.5477 20.00 12.89
697.2 0.001263 11.4382 20.00 11.82
597.7 0.001083 11.3211 20.00 10.67
498.3 0.000902 11.1960 20.02 9.45
399.2 0.000723 11.0607 20.01 8.13
299.5 0.000542 10.9108 19.99 6.66
199.6 0.000361 10.7394 19.99 4.99
99.8 0.000181 10.5313 20.00 2.95
49.9 0.000090 10.4001 20.01 1.67
0.6 0.000001 10.2293 20.35 0.00
----------------------------------------------------

Scan Ends 02:47:11 on 22 May 2017 by WR200774
Reference State 20.03°C





0 comments on commit a642336

Please sign in to comment.