diff --git a/package.json b/package.json index d3e5592..c922610 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ }, "dependencies": { "common-spectrum": "^1.0.2", + "ensure-string": "^1.2.0", "ml-array-max": "^1.2.4", "ml-array-mean": "^1.1.6", "papaparse": "^5.3.2", diff --git a/src/from/__tests__/__snapshots__/fromBelsorpCSV.test.js.snap b/src/from/__tests__/__snapshots__/fromBelsorpCSV.test.js.snap new file mode 100644 index 0000000..ad16731 --- /dev/null +++ b/src/from/__tests__/__snapshots__/fromBelsorpCSV.test.js.snap @@ -0,0 +1,977 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`fromBelsorpCSV belsorp.csv 1`] = ` +Array [ + Object { + "dataType": "Adsorption Isotherm", + "meta": Object { + "Adsorption temperature": "77.000 [K]", + "Adsorptive": "N2", + "Adsorptive cross section area": "0.1620 [nm^2]", + "Apparatus temperature": "0.0000 [C]", + "COMMENT1": "Standard 1", + "COMMENT2": "dsun", + "COMMENT3": "", + "COMMENT4": ", Vacuum degree before measurement:1.111E-4Pa", + "Date of measurement": "18/02/06", + "Dead volume": "30.402 [cm^3]", + "Equilibrium time": "0 [SEC]", + "File Name": "Act Carbon 2018 A.DAT", + "File name of wall adsorption": "", + "Number of adsorption data point :": "48", + "Number of desorption data point :": "34", + "Sample weight": "8.1300E-02 [g]", + "Saturated vapor pressure": "100.000 [kPa]", + "Serial number": "00463", + "Standard volume": "24.502 [cm^3]", + "Time of measurement": "30:25:37", + "Version": "", + "Wall adsorption correction value1": "", + "Wall adsorption correction value2": "", + }, + "title": "Standard 1", + "variables": Object { + "p": Object { + "data": Array [ + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + ], + "isMonotone": true, + "label": "Relative pressure", + "max": 100, + "min": 100, + "units": "kPa", + "variable": "p0", + }, + "x": Object { + "data": Array [ + 0.00002519, + 0.000053514, + 0.00012073, + 0.00029799, + 0.0012932, + 0.0017461, + 0.0026076, + 0.0054841, + 0.0078345, + 0.010417, + 0.015887, + 0.021483, + 0.04261, + 0.058021, + 0.073734, + 0.089467, + 0.1105, + 0.1382, + 0.1682, + 0.2097, + 0.2616, + 0.3141, + 0.355, + 0.4004, + 0.4518, + 0.502, + 0.552, + 0.6016, + 0.6512, + 0.7004, + 0.7488, + 0.7965, + 0.8417, + 0.8512, + 0.8841, + 0.8946, + 0.8989, + 0.9184, + 0.927, + 0.9322, + 0.9382, + 0.9413, + 0.9436, + 0.945, + 0.9464, + 0.9485, + 0.9495, + 0.9502, + ], + "isMonotone": true, + "label": "p/p0", + "max": 0.9502, + "min": 0.00002519, + "units": "", + "variable": "p/p0", + }, + "y": Object { + "data": Array [ + 0.000022289, + 0.000044887, + 0.00010545, + 0.00025223, + 0.00038821, + 0.00040127, + 0.00041572, + 0.00043709, + 0.00044646, + 0.00045753, + 0.00046899, + 0.00047417, + 0.00048363, + 0.00048831, + 0.00049304, + 0.00049674, + 0.00050272, + 0.00051142, + 0.00052507, + 0.00055171, + 0.00060275, + 0.00066873, + 0.00059409, + 0.00062153, + 0.00064272, + 0.0006607, + 0.00068386, + 0.00071687, + 0.00076635, + 0.00083787, + 0.0009399, + 0.0010829, + 0.0013107, + 0.0013923, + 0.0017455, + 0.0019372, + 0.0020646, + 0.0026912, + 0.0031789, + 0.003597, + 0.0042866, + 0.0048782, + 0.0054185, + 0.005928, + 0.006388, + 0.0072107, + 0.0079749, + 0.0087115, + ], + "isMonotone": false, + "label": "Amount of absorbed gas", + "max": 0.0087115, + "min": 0.000022289, + "units": "mol/g", + "variable": "na", + }, + }, + }, + Object { + "dataType": "Desorption Isotherm", + "meta": Object { + "Adsorption temperature": "77.000 [K]", + "Adsorptive": "N2", + "Adsorptive cross section area": "0.1620 [nm^2]", + "Apparatus temperature": "0.0000 [C]", + "COMMENT1": "Standard 1", + "COMMENT2": "dsun", + "COMMENT3": "", + "COMMENT4": ", Vacuum degree before measurement:1.111E-4Pa", + "Date of measurement": "18/02/06", + "Dead volume": "30.402 [cm^3]", + "Equilibrium time": "0 [SEC]", + "File Name": "Act Carbon 2018 A.DAT", + "File name of wall adsorption": "", + "Number of adsorption data point :": "48", + "Number of desorption data point :": "34", + "Sample weight": "8.1300E-02 [g]", + "Saturated vapor pressure": "100.000 [kPa]", + "Serial number": "00463", + "Standard volume": "24.502 [cm^3]", + "Time of measurement": "30:25:37", + "Version": "", + "Wall adsorption correction value1": "", + "Wall adsorption correction value2": "", + }, + "title": "Standard 1", + "variables": Object { + "p": Object { + "data": Array [ + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + undefined, + ], + "isMonotone": false, + "label": "Relative pressure", + "max": 100, + "min": 100, + "units": "kPa", + "variable": "p0", + }, + "x": Object { + "data": Array [ + 0.9453, + 0.9401, + 0.9355, + 0.9302, + 0.9242, + 0.9171, + 0.91, + 0.9023, + 0.881, + 0.8572, + 0.8491, + 0.8041, + 0.7963, + 0.7502, + 0.6992, + 0.6484, + 0.5981, + 0.5478, + 0.4981, + 0.4483, + 0.3985, + 0.3488, + 0.2991, + 0.2368, + 0.2064, + 0.1515, + 0.1229, + 0.099338, + 0.080461, + 0.066185, + 0.051949, + 0.037806, + 0.02102, + 0.014369, + undefined, + ], + "isMonotone": true, + "label": "p/p0", + "max": 0.9453, + "min": 0.014369, + "units": "", + "variable": "p/p0", + }, + "y": Object { + "data": Array [ + 0.0082783, + 0.0072084, + 0.0062144, + 0.0052137, + 0.0043358, + 0.0036074, + 0.0029867, + 0.002568, + 0.0018215, + 0.0014289, + 0.00134, + 0.0010485, + 0.0010128, + 0.00086486, + 0.0007548, + 0.00068038, + 0.00063005, + 0.00060302, + 0.00058049, + 0.00056955, + 0.00054921, + 0.00051936, + 0.00048032, + 0.00043257, + 0.0004195, + 0.00041188, + 0.00041282, + 0.00041751, + 0.00042107, + 0.000423, + 0.00042577, + 0.00042812, + 0.00042641, + 0.00042234, + undefined, + ], + "isMonotone": false, + "label": "Amount of absorbed gas", + "max": 0.0082783, + "min": 0.00041188, + "units": "mol/g", + "variable": "na", + }, + }, + }, +] +`; + +exports[`fromBelsorpCSV belsorp2.csv 1`] = ` +Array [ + Object { + "dataType": "Adsorption Isotherm", + "meta": Object { + "Adsorption temperature": "77 [K]", + "Adsorptive": "N2", + "Adsorptive cross section area": "0.162 [nm^2]", + "Apparatus temperature": "0 [C]", + "COMMENT1": "Standard 1", + "COMMENT2": "dsun", + "COMMENT3": "", + "COMMENT4": ", Vacuum degree before measurement:1.111E-4Pa", + "Date of measurement": "18.02.06", + "Dead volume": "30.402 [cm^3]", + "Equilibrium time": "0 [SEC]", + "File Name": "Act Carbon 2018 A.DAT", + "File name of wall adsorption": "", + "Number of adsorption data point :": "48", + "Number of desorption data point :": "34", + "Sample weight": "8.13E-02 [g]", + "Saturated vapor pressure": "100 [kPa]", + "Serial number": "463", + "Standard volume": "24.502 [cm^3]", + "Time of measurement": "30:25:37", + "Version": "", + "Wall adsorption correction value1": "", + "Wall adsorption correction value2": "", + }, + "title": "Standard 1", + "variables": Object { + "p": Object { + "data": Array [ + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + ], + "isMonotone": true, + "label": "Relative pressure", + "max": 100, + "min": 100, + "units": "kPa", + "variable": "p0", + }, + "x": Object { + "data": Array [ + 0.0000252, + 0.0000535, + 0.000121, + 0.000298, + 0.00129, + 0.00175, + 0.00261, + 0.00548, + 0.00783, + 0.0104, + 0.0159, + 0.0215, + 0.0426, + 0.058, + 0.0737, + 0.0895, + 0.1105, + 0.1382, + 0.1682, + 0.2097, + 0.2616, + 0.3141, + 0.355, + 0.4004, + 0.4518, + 0.502, + 0.552, + 0.6016, + 0.6512, + 0.7004, + 0.7488, + 0.7965, + 0.8417, + 0.8512, + 0.8841, + 0.8946, + 0.8989, + 0.9184, + 0.927, + 0.9322, + 0.9382, + 0.9413, + 0.9436, + 0.945, + 0.9464, + 0.9485, + 0.9495, + 0.9502, + ], + "isMonotone": true, + "label": "p/p0", + "max": 0.9502, + "min": 0.0000252, + "units": "", + "variable": "p/p0", + }, + "y": Object { + "data": Array [ + 195.26, + 178.75, + 161.62, + 143.18, + 132.87, + 121.45, + 109.34, + 96.079, + 80.623, + 71.252, + 60.32, + 46.276, + 43.42, + 39.124, + 31.207, + 29.378, + 24.273, + 21.067, + 18.78, + 17.177, + 16.068, + 15.328, + 14.809, + 14.406, + 13.931, + 13.316, + 14.989, + 13.51, + 12.366, + 11.769, + 11.463, + 11.268, + 11.134, + 11.051, + 10.945, + 10.84, + 10.628, + 10.512, + 10.255, + 10.007, + 9.797, + 9.318, + 8.994, + 8.7014, + 5.6535, + 2.3636, + 1.0061, + 0.4996, + ], + "isMonotone": false, + "label": "Amount of absorbed gas", + "max": 195.26, + "min": 0.4996, + "units": "cm^3(STP)/g", + "variable": "Va", + }, + }, + }, + Object { + "dataType": "Desorption Isotherm", + "meta": Object { + "Adsorption temperature": "77 [K]", + "Adsorptive": "N2", + "Adsorptive cross section area": "0.162 [nm^2]", + "Apparatus temperature": "0 [C]", + "COMMENT1": "Standard 1", + "COMMENT2": "dsun", + "COMMENT3": "", + "COMMENT4": ", Vacuum degree before measurement:1.111E-4Pa", + "Date of measurement": "18.02.06", + "Dead volume": "30.402 [cm^3]", + "Equilibrium time": "0 [SEC]", + "File Name": "Act Carbon 2018 A.DAT", + "File name of wall adsorption": "", + "Number of adsorption data point :": "48", + "Number of desorption data point :": "34", + "Sample weight": "8.13E-02 [g]", + "Saturated vapor pressure": "100 [kPa]", + "Serial number": "463", + "Standard volume": "24.502 [cm^3]", + "Time of measurement": "30:25:37", + "Version": "", + "Wall adsorption correction value1": "", + "Wall adsorption correction value2": "", + }, + "title": "Standard 1", + "variables": Object { + "p": Object { + "data": Array [ + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + ], + "isMonotone": true, + "label": "Relative pressure", + "max": 100, + "min": 100, + "units": "kPa", + "variable": "p0", + }, + "x": Object { + "data": Array [ + 0.0144, + 0.021, + 0.0378, + 0.0519, + 0.0662, + 0.0805, + 0.0993, + 0.1229, + 0.1515, + 0.2064, + 0.2368, + 0.2991, + 0.3488, + 0.3985, + 0.4483, + 0.4981, + 0.5478, + 0.5981, + 0.6484, + 0.6992, + 0.7502, + 0.7963, + 0.8041, + 0.8491, + 0.8572, + 0.881, + 0.9023, + 0.91, + 0.9171, + 0.9242, + 0.9302, + 0.9355, + 0.9401, + 0.9453, + ], + "isMonotone": true, + "label": "p/p0", + "max": 0.9453, + "min": 0.0144, + "units": "", + "variable": "p/p0", + }, + "y": Object { + "data": Array [ + 195.26, + 178.75, + 161.62, + 143.18, + 132.87, + 121.45, + 109.34, + 96.079, + 80.623, + 71.252, + 60.32, + 46.276, + 43.42, + 39.124, + 31.207, + 29.378, + 24.273, + 21.067, + 18.78, + 17.177, + 16.068, + 15.328, + 14.809, + 14.406, + 13.931, + 13.316, + 14.989, + 13.51, + 12.366, + 11.769, + 11.463, + 11.268, + 11.134, + 11.051, + 10.945, + 10.84, + 10.628, + 10.512, + 10.255, + 10.007, + 9.797, + 9.318, + 8.994, + 8.7014, + 5.6535, + 2.3636, + 1.0061, + 0.4996, + ], + "isMonotone": false, + "label": "Amount of absorbed gas", + "max": 195.26, + "min": 0.4996, + "units": "cm^3(STP)/g", + "variable": "Va", + }, + }, + }, +] +`; + +exports[`fromBelsorpCSV belsorp3.csv 1`] = ` +Array [ + Object { + "dataType": "Adsorption Isotherm", + "meta": Object { + "Adsorption data point number": "18", + "Adsorption temperature": "77.360 [K]", + "Adsorptive": "N2", + "Adsorptive molecular weight": "28.013", + "Analysis date": "06/08/2021", + "Analysis time": "10:02:06", + "Comment1": "test measurement", + "Comment2": "", + "Comment3": "", + "Comment4": ", Vacuum degree before measurement:3.446E-5Pa", + "Data file": "TS-074_A-Port1.DAT", + "Desorption data point number": "9", + "Free space": "41.112 [cm^3]", + "Manifold volume": "34.034 [cm^3]", + "Molecular cross-sectional area": "0.1620 [nm^2]", + "S/N": "182", + "Sample mass": "0.0548 [g]", + "Sample molecular weight": "0.0000", + "Saturation vapor pressure": "96.436 [kPa]", + "Specific surface area": "0.0000 [m^2 g^-1]", + }, + "title": "", + "variables": Object { + "p": Object { + "data": Array [ + 97.737, + 97.098, + 96.731, + 96.594, + 96.507, + 96.512, + 96.489, + 96.441, + 96.492, + 96.42, + 96.429, + 96.378, + 96.407, + 96.375, + 96.353, + 96.352, + 96.283, + 96.27, + ], + "isMonotone": false, + "label": "Relative pressure", + "max": 97.737, + "min": 96.27, + "units": " kPa", + "variable": "p0", + }, + "x": Object { + "data": Array [ + 0.00029762, + 0.0021711, + 0.0058163, + 0.013711, + 0.019327, + 0.025799, + 0.043602, + 0.106, + 0.2734, + 0.3041, + 0.4451, + 0.5195, + 0.7366, + 0.8751, + 0.8813, + 0.9334, + 0.9474, + 0.9521, + ], + "isMonotone": true, + "label": "p/p0", + "max": 0.9521, + "min": 0.00029762, + "units": "", + "variable": "p/p0", + }, + "y": Object { + "data": Array [ + 5.7645, + 10.006, + 12.816, + 15.044, + 16.074, + 16.645, + 18.213, + 21.016, + 26.064, + 26.952, + 30.59, + 32.761, + 42.234, + 60.51, + 62.52, + 93.558, + 112.06, + 122.29, + ], + "isMonotone": true, + "label": "Amount of absorbed gas", + "max": 122.29, + "min": 5.7645, + "units": "cm^3(STP)/g", + "variable": "Va", + }, + }, + }, + Object { + "dataType": "Desorption Isotherm", + "meta": Object { + "Adsorption data point number": "18", + "Adsorption temperature": "77.360 [K]", + "Adsorptive": "N2", + "Adsorptive molecular weight": "28.013", + "Analysis date": "06/08/2021", + "Analysis time": "10:02:06", + "Comment1": "test measurement", + "Comment2": "", + "Comment3": "", + "Comment4": ", Vacuum degree before measurement:3.446E-5Pa", + "Data file": "TS-074_A-Port1.DAT", + "Desorption data point number": "9", + "Free space": "41.112 [cm^3]", + "Manifold volume": "34.034 [cm^3]", + "Molecular cross-sectional area": "0.1620 [nm^2]", + "S/N": "182", + "Sample mass": "0.0548 [g]", + "Sample molecular weight": "0.0000", + "Saturation vapor pressure": "96.436 [kPa]", + "Specific surface area": "0.0000 [m^2 g^-1]", + }, + "title": "", + "variables": Object { + "p": Object { + "data": Array [ + 96.245, + 96.234, + 96.228, + 96.214, + 96.209, + 96.196, + 96.192, + 96.193, + 96.187, + undefined, + ], + "isMonotone": false, + "label": "Relative pressure", + "max": 96.245, + "min": 96.187, + "units": " kPa", + "variable": "p0", + }, + "x": Object { + "data": Array [ + 0.9478, + 0.9185, + 0.8795, + 0.8032, + 0.6577, + 0.5122, + 0.3675, + 0.2637, + 0.1388, + undefined, + ], + "isMonotone": true, + "label": "p/p0", + "max": 0.9478, + "min": 0.1388, + "units": "", + "variable": "p/p0", + }, + "y": Object { + "data": Array [ + 5.7645, + 10.006, + 12.816, + 15.044, + 16.074, + 16.645, + 18.213, + 21.016, + 26.064, + 26.952, + 30.59, + 32.761, + 42.234, + 60.51, + 62.52, + 93.558, + 112.06, + 122.29, + ], + "isMonotone": true, + "label": "Amount of absorbed gas", + "max": 122.29, + "min": 5.7645, + "units": "cm^3(STP)/g", + "variable": "Va", + }, + }, + }, +] +`; diff --git a/src/from/__tests__/__snapshots__/parseBelsorpCSV.test.js.snap b/src/from/__tests__/__snapshots__/parseBelsorpCSV.test.js.snap new file mode 100644 index 0000000..f507c42 --- /dev/null +++ b/src/from/__tests__/__snapshots__/parseBelsorpCSV.test.js.snap @@ -0,0 +1,714 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`parseBelsorpCSV 1`] = ` +Object { + "adsorption": Object { + "No": Object { + "data": Array [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27, + 28, + 29, + 30, + 31, + 32, + 33, + 34, + 35, + 36, + 37, + 38, + 39, + 40, + 41, + 42, + 43, + 44, + 45, + 46, + 47, + 48, + ], + "label": "Peak number", + "units": "", + "variable": "No", + }, + "na": Object { + "data": Array [ + 0.000022289, + 0.000044887, + 0.00010545, + 0.00025223, + 0.00038821, + 0.00040127, + 0.00041572, + 0.00043709, + 0.00044646, + 0.00045753, + 0.00046899, + 0.00047417, + 0.00048363, + 0.00048831, + 0.00049304, + 0.00049674, + 0.00050272, + 0.00051142, + 0.00052507, + 0.00055171, + 0.00060275, + 0.00066873, + 0.00059409, + 0.00062153, + 0.00064272, + 0.0006607, + 0.00068386, + 0.00071687, + 0.00076635, + 0.00083787, + 0.0009399, + 0.0010829, + 0.0013107, + 0.0013923, + 0.0017455, + 0.0019372, + 0.0020646, + 0.0026912, + 0.0031789, + 0.003597, + 0.0042866, + 0.0048782, + 0.0054185, + 0.005928, + 0.006388, + 0.0072107, + 0.0079749, + 0.0087115, + ], + "label": "Amount of absorbed gas", + "units": "mol/g", + "variable": "na", + }, + "p/p0": Object { + "data": Array [ + 0.00002519, + 0.000053514, + 0.00012073, + 0.00029799, + 0.0012932, + 0.0017461, + 0.0026076, + 0.0054841, + 0.0078345, + 0.010417, + 0.015887, + 0.021483, + 0.04261, + 0.058021, + 0.073734, + 0.089467, + 0.1105, + 0.1382, + 0.1682, + 0.2097, + 0.2616, + 0.3141, + 0.355, + 0.4004, + 0.4518, + 0.502, + 0.552, + 0.6016, + 0.6512, + 0.7004, + 0.7488, + 0.7965, + 0.8417, + 0.8512, + 0.8841, + 0.8946, + 0.8989, + 0.9184, + 0.927, + 0.9322, + 0.9382, + 0.9413, + 0.9436, + 0.945, + 0.9464, + 0.9485, + 0.9495, + 0.9502, + ], + "label": "p/p0", + "units": "", + "variable": "p/p0", + }, + "p0": Object { + "data": Array [ + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + ], + "label": "Relative pressure", + "units": "kPa", + "variable": "p0", + }, + "pe": Object { + "data": Array [ + 0.002519, + 0.0053514, + 0.012073, + 0.029799, + 0.1293, + 0.1746, + 0.2608, + 0.5484, + 0.7834, + 1.0417, + 1.5887, + 2.1483, + 4.261, + 5.8021, + 7.3734, + 8.9467, + 11.048, + 13.816, + 16.818, + 20.972, + 26.156, + 31.412, + 35.5, + 40.04, + 45.182, + 50.202, + 55.204, + 60.158, + 65.121, + 70.04, + 74.882, + 79.653, + 84.165, + 85.118, + 88.414, + 89.455, + 89.89, + 91.837, + 92.696, + 93.221, + 93.815, + 94.131, + 94.36, + 94.503, + 94.641, + 94.853, + 94.954, + 95.017, + ], + "label": "Absolute pressure", + "units": "kPa", + "variable": "pe", + }, + "pe2": Object { + "data": Array [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + ], + "label": "pe2", + "units": "kPa", + "variable": "pe2", + }, + "pi": Object { + "data": Array [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + ], + "label": "Initial pressure", + "units": "kPa", + "variable": "pi", + }, + }, + "desorption": Object { + "No": Object { + "data": Array [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27, + 28, + 29, + 30, + 31, + 32, + 33, + 34, + 0, + ], + "label": "Peak number", + "units": "", + "variable": "No", + }, + "na": Object { + "data": Array [ + 0.0082783, + 0.0072084, + 0.0062144, + 0.0052137, + 0.0043358, + 0.0036074, + 0.0029867, + 0.002568, + 0.0018215, + 0.0014289, + 0.00134, + 0.0010485, + 0.0010128, + 0.00086486, + 0.0007548, + 0.00068038, + 0.00063005, + 0.00060302, + 0.00058049, + 0.00056955, + 0.00054921, + 0.00051936, + 0.00048032, + 0.00043257, + 0.0004195, + 0.00041188, + 0.00041282, + 0.00041751, + 0.00042107, + 0.000423, + 0.00042577, + 0.00042812, + 0.00042641, + 0.00042234, + undefined, + ], + "label": "Amount of absorbed gas", + "units": "mol/g", + "variable": "na", + }, + "p/p0": Object { + "data": Array [ + 0.9453, + 0.9401, + 0.9355, + 0.9302, + 0.9242, + 0.9171, + 0.91, + 0.9023, + 0.881, + 0.8572, + 0.8491, + 0.8041, + 0.7963, + 0.7502, + 0.6992, + 0.6484, + 0.5981, + 0.5478, + 0.4981, + 0.4483, + 0.3985, + 0.3488, + 0.2991, + 0.2368, + 0.2064, + 0.1515, + 0.1229, + 0.099338, + 0.080461, + 0.066185, + 0.051949, + 0.037806, + 0.02102, + 0.014369, + undefined, + ], + "label": "p/p0", + "units": "", + "variable": "p/p0", + }, + "p0": Object { + "data": Array [ + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + undefined, + ], + "label": "Relative pressure", + "units": "kPa", + "variable": "p0", + }, + "pe": Object { + "data": Array [ + 94.527, + 94.01, + 93.549, + 93.019, + 92.425, + 91.709, + 91.004, + 90.233, + 88.101, + 85.715, + 84.913, + 80.405, + 79.629, + 75.024, + 69.916, + 64.839, + 59.81, + 54.78, + 49.808, + 44.826, + 39.845, + 34.884, + 29.909, + 23.679, + 20.636, + 15.151, + 12.288, + 9.9338, + 8.0461, + 6.6185, + 5.1949, + 3.7806, + 2.102, + 1.4369, + undefined, + ], + "label": "Absolute pressure", + "units": "kPa", + "variable": "pe", + }, + "pe2": Object { + "data": Array [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + undefined, + ], + "label": "pe2", + "units": "kPa", + "variable": "pe2", + }, + "pi": Object { + "data": Array [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + undefined, + ], + "label": "Initial pressure", + "units": "kPa", + "variable": "pi", + }, + }, + "meta": Object { + "Adsorption temperature": "77.000 [K]", + "Adsorptive": "N2", + "Adsorptive cross section area": "0.1620 [nm^2]", + "Apparatus temperature": "0.0000 [C]", + "COMMENT1": "Standard 1", + "COMMENT2": "dsun", + "COMMENT3": "", + "COMMENT4": ", Vacuum degree before measurement:1.111E-4Pa", + "Date of measurement": "18/02/06", + "Dead volume": "30.402 [cm^3]", + "Equilibrium time": "0 [SEC]", + "File Name": "Act Carbon 2018 A.DAT", + "File name of wall adsorption": "", + "Number of adsorption data point :": "48", + "Number of desorption data point :": "34", + "Sample weight": "8.1300E-02 [g]", + "Saturated vapor pressure": "100.000 [kPa]", + "Serial number": "00463", + "Standard volume": "24.502 [cm^3]", + "Time of measurement": "30:25:37", + "Version": "", + "Wall adsorption correction value1": "", + "Wall adsorption correction value2": "", + }, +} +`; diff --git a/src/from/__tests__/data/belsorp.csv b/src/from/__tests__/data/belsorp.csv new file mode 100644 index 0000000..17138bf --- /dev/null +++ b/src/from/__tests__/data/belsorp.csv @@ -0,0 +1,109 @@ +File Name,Act Carbon 2018 A.DAT +Date of measurement,18/02/06 +Time of measurement,30:25:37 +COMMENT1,Standard 1 +COMMENT2,dsun +COMMENT3, +COMMENT4,, Vacuum degree before measurement:1.111E-4Pa +Serial number,00463 +Version, +Sample weight,8.1300E-02,[g] +Standard volume,24.502,[cm^3] +Dead volume,30.402,[cm^3] +Equilibrium time,0,[SEC] +Adsorptive,N2 +Apparatus temperature,0.0000,[C] +Adsorption temperature,77.000,[K] +Saturated vapor pressure,100.000,[kPa] +Adsorptive cross section area,0.1620,[nm^2] +File name of wall adsorption, +Wall adsorption correction value1, +Wall adsorption correction value2, +Number of adsorption data point :,48 +Number of desorption data point :,34 + +No,pi/kPa,pe/kPa,pe2/kPa,p0/kPa,p/p0,na/mol g^-1 +ADS +1,0.0000,2.5190E-03,0.0000,100.000,2.5190E-05,2.2289E-05 +2,0.0000,5.3514E-03,0.0000,100.000,5.3514E-05,4.4887E-05 +3,0.0000,1.2073E-02,0.0000,100.000,1.2073E-04,1.0545E-04 +4,0.0000,2.9799E-02,0.0000,100.000,2.9799E-04,2.5223E-04 +5,0.0000,0.1293,0.0000,100.000,1.2932E-03,3.8821E-04 +6,0.0000,0.1746,0.0000,100.000,1.7461E-03,4.0127E-04 +7,0.0000,0.2608,0.0000,100.000,2.6076E-03,4.1572E-04 +8,0.0000,0.5484,0.0000,100.000,5.4841E-03,4.3709E-04 +9,0.0000,0.7834,0.0000,100.000,7.8345E-03,4.4646E-04 +10,0.0000,1.0417,0.0000,100.000,1.0417E-02,4.5753E-04 +11,0.0000,1.5887,0.0000,100.000,1.5887E-02,4.6899E-04 +12,0.0000,2.1483,0.0000,100.000,2.1483E-02,4.7417E-04 +13,0.0000,4.2610,0.0000,100.000,4.2610E-02,4.8363E-04 +14,0.0000,5.8021,0.0000,100.000,5.8021E-02,4.8831E-04 +15,0.0000,7.3734,0.0000,100.000,7.3734E-02,4.9304E-04 +16,0.0000,8.9467,0.0000,100.000,8.9467E-02,4.9674E-04 +17,0.0000,11.048,0.0000,100.000,0.1105,5.0272E-04 +18,0.0000,13.816,0.0000,100.000,0.1382,5.1142E-04 +19,0.0000,16.818,0.0000,100.000,0.1682,5.2507E-04 +20,0.0000,20.972,0.0000,100.000,0.2097,5.5171E-04 +21,0.0000,26.156,0.0000,100.000,0.2616,6.0275E-04 +22,0.0000,31.412,0.0000,100.000,0.3141,6.6873E-04 +23,0.0000,35.500,0.0000,100.000,0.3550,5.9409E-04 +24,0.0000,40.040,0.0000,100.000,0.4004,6.2153E-04 +25,0.0000,45.182,0.0000,100.000,0.4518,6.4272E-04 +26,0.0000,50.202,0.0000,100.000,0.5020,6.6070E-04 +27,0.0000,55.204,0.0000,100.000,0.5520,6.8386E-04 +28,0.0000,60.158,0.0000,100.000,0.6016,7.1687E-04 +29,0.0000,65.121,0.0000,100.000,0.6512,7.6635E-04 +30,0.0000,70.040,0.0000,100.000,0.7004,8.3787E-04 +31,0.0000,74.882,0.0000,100.000,0.7488,9.3990E-04 +32,0.0000,79.653,0.0000,100.000,0.7965,1.0829E-03 +33,0.0000,84.165,0.0000,100.000,0.8417,1.3107E-03 +34,0.0000,85.118,0.0000,100.000,0.8512,1.3923E-03 +35,0.0000,88.414,0.0000,100.000,0.8841,1.7455E-03 +36,0.0000,89.455,0.0000,100.000,0.8946,1.9372E-03 +37,0.0000,89.890,0.0000,100.000,0.8989,2.0646E-03 +38,0.0000,91.837,0.0000,100.000,0.9184,2.6912E-03 +39,0.0000,92.696,0.0000,100.000,0.9270,3.1789E-03 +40,0.0000,93.221,0.0000,100.000,0.9322,3.5970E-03 +41,0.0000,93.815,0.0000,100.000,0.9382,4.2866E-03 +42,0.0000,94.131,0.0000,100.000,0.9413,4.8782E-03 +43,0.0000,94.360,0.0000,100.000,0.9436,5.4185E-03 +44,0.0000,94.503,0.0000,100.000,0.9450,5.9280E-03 +45,0.0000,94.641,0.0000,100.000,0.9464,6.3880E-03 +46,0.0000,94.853,0.0000,100.000,0.9485,7.2107E-03 +47,0.0000,94.954,0.0000,100.000,0.9495,7.9749E-03 +48,0.0000,95.017,0.0000,100.000,0.9502,8.7115E-03 +DES +1,0.0000,94.527,0.0000,100.000,0.9453,8.2783E-03 +2,0.0000,94.010,0.0000,100.000,0.9401,7.2084E-03 +3,0.0000,93.549,0.0000,100.000,0.9355,6.2144E-03 +4,0.0000,93.019,0.0000,100.000,0.9302,5.2137E-03 +5,0.0000,92.425,0.0000,100.000,0.9242,4.3358E-03 +6,0.0000,91.709,0.0000,100.000,0.9171,3.6074E-03 +7,0.0000,91.004,0.0000,100.000,0.9100,2.9867E-03 +8,0.0000,90.233,0.0000,100.000,0.9023,2.5680E-03 +9,0.0000,88.101,0.0000,100.000,0.8810,1.8215E-03 +10,0.0000,85.715,0.0000,100.000,0.8572,1.4289E-03 +11,0.0000,84.913,0.0000,100.000,0.8491,1.3400E-03 +12,0.0000,80.405,0.0000,100.000,0.8041,1.0485E-03 +13,0.0000,79.629,0.0000,100.000,0.7963,1.0128E-03 +14,0.0000,75.024,0.0000,100.000,0.7502,8.6486E-04 +15,0.0000,69.916,0.0000,100.000,0.6992,7.5480E-04 +16,0.0000,64.839,0.0000,100.000,0.6484,6.8038E-04 +17,0.0000,59.810,0.0000,100.000,0.5981,6.3005E-04 +18,0.0000,54.780,0.0000,100.000,0.5478,6.0302E-04 +19,0.0000,49.808,0.0000,100.000,0.4981,5.8049E-04 +20,0.0000,44.826,0.0000,100.000,0.4483,5.6955E-04 +21,0.0000,39.845,0.0000,100.000,0.3985,5.4921E-04 +22,0.0000,34.884,0.0000,100.000,0.3488,5.1936E-04 +23,0.0000,29.909,0.0000,100.000,0.2991,4.8032E-04 +24,0.0000,23.679,0.0000,100.000,0.2368,4.3257E-04 +25,0.0000,20.636,0.0000,100.000,0.2064,4.1950E-04 +26,0.0000,15.151,0.0000,100.000,0.1515,4.1188E-04 +27,0.0000,12.288,0.0000,100.000,0.1229,4.1282E-04 +28,0.0000,9.9338,0.0000,100.000,9.9338E-02,4.1751E-04 +29,0.0000,8.0461,0.0000,100.000,8.0461E-02,4.2107E-04 +30,0.0000,6.6185,0.0000,100.000,6.6185E-02,4.2300E-04 +31,0.0000,5.1949,0.0000,100.000,5.1949E-02,4.2577E-04 +32,0.0000,3.7806,0.0000,100.000,3.7806E-02,4.2812E-04 +33,0.0000,2.1020,0.0000,100.000,2.1020E-02,4.2641E-04 +34,0.0000,1.4369,0.0000,100.000,1.4369E-02,4.2234E-04 diff --git a/src/from/__tests__/data/belsorp2.csv b/src/from/__tests__/data/belsorp2.csv new file mode 100644 index 0000000..164d971 --- /dev/null +++ b/src/from/__tests__/data/belsorp2.csv @@ -0,0 +1,109 @@ +File Name,Act Carbon 2018 A.DAT,,,,, +Date of measurement,18.02.06,,,,, +Time of measurement,30:25:37,,,,, +COMMENT1,Standard 1,,,,, +COMMENT2,dsun,,,,, +COMMENT3,,,,,, +COMMENT4,, Vacuum degree before measurement:1.111E-4Pa,,,, +Serial number,463,,,,, +Version,,,,,, +Sample weight,8.13E-02,[g],,,, +Standard volume,24.502,[cm^3],,,, +Dead volume,30.402,[cm^3],,,, +Equilibrium time,0,[SEC],,,, +Adsorptive,N2,,,,, +Apparatus temperature,0,[C],,,, +Adsorption temperature,77,[K],,,, +Saturated vapor pressure,100,[kPa],,,, +Adsorptive cross section area,0.162,[nm^2],,,, +File name of wall adsorption,,,,,, +Wall adsorption correction value1,,,,,, +Wall adsorption correction value2,,,,,, +Number of adsorption data point :,48,,,,, +Number of desorption data point :,34,,,,, +,,,,,, +No,pi/kPa,pe/kPa,pe2/kPa,p0/kPa,p/p0,Va/cm^3(STP) g^-1 +ADS,,,,,, +1,0,2.52E-03,0,100,2.52E-05,0.4996 +2,0,5.35E-03,0,100,5.35E-05,1.0061 +3,0,1.21E-02,0,100,1.21E-04,2.3636 +4,0,2.98E-02,0,100,2.98E-04,5.6535 +5,0,0.1293,0,100,1.29E-03,8.7014 +6,0,0.1746,0,100,1.75E-03,8.994 +7,0,0.2608,0,100,2.61E-03,9.318 +8,0,0.5484,0,100,5.48E-03,9.797 +9,0,0.7834,0,100,7.83E-03,10.007 +10,0,1.0417,0,100,1.04E-02,10.255 +11,0,1.5887,0,100,1.59E-02,10.512 +12,0,2.1483,0,100,2.15E-02,10.628 +13,0,4.261,0,100,4.26E-02,10.84 +14,0,5.8021,0,100,5.80E-02,10.945 +15,0,7.3734,0,100,7.37E-02,11.051 +16,0,8.9467,0,100,8.95E-02,11.134 +17,0,11.048,0,100,0.1105,11.268 +18,0,13.816,0,100,0.1382,11.463 +19,0,16.818,0,100,0.1682,11.769 +20,0,20.972,0,100,0.2097,12.366 +21,0,26.156,0,100,0.2616,13.51 +22,0,31.412,0,100,0.3141,14.989 +23,0,35.5,0,100,0.355,13.316 +24,0,40.04,0,100,0.4004,13.931 +25,0,45.182,0,100,0.4518,14.406 +26,0,50.202,0,100,0.502,14.809 +27,0,55.204,0,100,0.552,15.328 +28,0,60.158,0,100,0.6016,16.068 +29,0,65.121,0,100,0.6512,17.177 +30,0,70.04,0,100,0.7004,18.78 +31,0,74.882,0,100,0.7488,21.067 +32,0,79.653,0,100,0.7965,24.273 +33,0,84.165,0,100,0.8417,29.378 +34,0,85.118,0,100,0.8512,31.207 +35,0,88.414,0,100,0.8841,39.124 +36,0,89.455,0,100,0.8946,43.42 +37,0,89.89,0,100,0.8989,46.276 +38,0,91.837,0,100,0.9184,60.32 +39,0,92.696,0,100,0.927,71.252 +40,0,93.221,0,100,0.9322,80.623 +41,0,93.815,0,100,0.9382,96.079 +42,0,94.131,0,100,0.9413,109.34 +43,0,94.36,0,100,0.9436,121.45 +44,0,94.503,0,100,0.945,132.87 +45,0,94.641,0,100,0.9464,143.18 +46,0,94.853,0,100,0.9485,161.62 +47,0,94.954,0,100,0.9495,178.75 +48,0,95.017,0,100,0.9502,195.26 +DES,,,,,, +1,0,94.527,0,100,0.9453,185.55 +2,0,94.01,0,100,0.9401,161.57 +3,0,93.549,0,100,0.9355,139.29 +4,0,93.019,0,100,0.9302,116.86 +5,0,92.425,0,100,0.9242,97.182 +6,0,91.709,0,100,0.9171,80.856 +7,0,91.004,0,100,0.91,66.945 +8,0,90.233,0,100,0.9023,57.559 +9,0,88.101,0,100,0.881,40.827 +10,0,85.715,0,100,0.8572,32.027 +11,0,84.913,0,100,0.8491,30.035 +12,0,80.405,0,100,0.8041,23.501 +13,0,79.629,0,100,0.7963,22.702 +14,0,75.024,0,100,0.7502,19.385 +15,0,69.916,0,100,0.6992,16.918 +16,0,64.839,0,100,0.6484,15.25 +17,0,59.81,0,100,0.5981,14.122 +18,0,54.78,0,100,0.5478,13.516 +19,0,49.808,0,100,0.4981,13.011 +20,0,44.826,0,100,0.4483,12.766 +21,0,39.845,0,100,0.3985,12.31 +22,0,34.884,0,100,0.3488,11.641 +23,0,29.909,0,100,0.2991,10.766 +24,0,23.679,0,100,0.2368,9.6956 +25,0,20.636,0,100,0.2064,9.4026 +26,0,15.151,0,100,0.1515,9.2319 +27,0,12.288,0,100,0.1229,9.2529 +28,0,9.9338,0,100,9.93E-02,9.358 +29,0,8.0461,0,100,8.05E-02,9.4378 +30,0,6.6185,0,100,6.62E-02,9.4812 +31,0,5.1949,0,100,5.19E-02,9.5433 +32,0,3.7806,0,100,3.78E-02,9.5958 +33,0,2.102,0,100,2.10E-02,9.5575 +34,0,1.4369,0,100,1.44E-02,9.4663 \ No newline at end of file diff --git a/src/from/__tests__/data/belsorp3.csv b/src/from/__tests__/data/belsorp3.csv new file mode 100644 index 0000000..a8b34d3 --- /dev/null +++ b/src/from/__tests__/data/belsorp3.csv @@ -0,0 +1,51 @@ +Data file,TS-074_A-Port1.DAT +Analysis date,06/08/2021 +Analysis time,10:02:06 +Comment1,test measurement +Comment2, +Comment3, +Comment4,, Vacuum degree before measurement:3.446E-5Pa +S/N,182 +Sample mass,0.0548,[g] +Manifold volume,34.034,[cm^3] +Free space,41.112,[cm^3] +Adsorptive,N2 +Adsorption temperature,77.360,[K] +Saturation vapor pressure,96.436,[kPa] +Molecular cross-sectional area,0.1620,[nm^2] +Adsorption data point number,18 +Desorption data point number,9 +Adsorptive molecular weight,28.013 +Sample molecular weight,0.0000 +Specific surface area,0.0000,[m^2 g^-1] + +No,pe/ kPa,p0/ kPa,p/p0,Va/cm^3(STP) g^-1 +ADS +1,2.9088E-02,97.737,2.9762E-04,5.7645 +2,0.2108,97.098,2.1711E-03,10.006 +3,0.5626,96.731,5.8163E-03,12.816 +4,1.3244,96.594,1.3711E-02,15.044 +5,1.8652,96.507,1.9327E-02,16.074 +6,2.4899,96.512,2.5799E-02,16.645 +7,4.2071,96.489,4.3602E-02,18.213 +8,10.222,96.441,0.1060,21.016 +9,26.377,96.492,0.2734,26.064 +10,29.325,96.420,0.3041,26.952 +11,42.917,96.429,0.4451,30.590 +12,50.070,96.378,0.5195,32.761 +13,71.009,96.407,0.7366,42.234 +14,84.342,96.375,0.8751,60.510 +15,84.914,96.353,0.8813,62.520 +16,89.936,96.352,0.9334,93.558 +17,91.214,96.283,0.9474,112.06 +18,91.656,96.270,0.9521,122.29 +DES +1,91.224,96.245,0.9478,119.94 +2,88.389,96.234,0.9185,91.856 +3,84.637,96.228,0.8795,69.919 +4,77.281,96.214,0.8032,53.231 +5,63.275,96.209,0.6577,42.253 +6,49.271,96.196,0.5122,37.170 +7,35.346,96.192,0.3675,33.185 +8,25.362,96.193,0.2637,30.852 +9,13.355,96.187,0.1388,27.310 diff --git a/src/from/__tests__/fromBelsorpCSV.test.js b/src/from/__tests__/fromBelsorpCSV.test.js new file mode 100644 index 0000000..c6c20b6 --- /dev/null +++ b/src/from/__tests__/fromBelsorpCSV.test.js @@ -0,0 +1,22 @@ +import { readFileSync } from 'fs'; +import { join } from 'path'; + +import { fromBelsorpCSV } from '../fromBelsorpCSV'; + +describe('fromBelsorpCSV', () => { + it('belsorp.csv', () => { + const binary = readFileSync(join(__dirname, 'data/belsorp.csv')); + const analysis = fromBelsorpCSV(binary); + expect(analysis.spectra).toMatchSnapshot(); + }); + it('belsorp2.csv', () => { + const binary = readFileSync(join(__dirname, 'data/belsorp2.csv')); + const analysis = fromBelsorpCSV(binary); + expect(analysis.spectra).toMatchSnapshot(); + }); + it('belsorp3.csv', () => { + const binary = readFileSync(join(__dirname, 'data/belsorp3.csv')); + const analysis = fromBelsorpCSV(binary); + expect(analysis.spectra).toMatchSnapshot(); + }); +}); diff --git a/src/from/__tests__/parseBelsorpCSV.test.js b/src/from/__tests__/parseBelsorpCSV.test.js new file mode 100644 index 0000000..82fdac4 --- /dev/null +++ b/src/from/__tests__/parseBelsorpCSV.test.js @@ -0,0 +1,17 @@ +import { readFileSync } from 'fs'; +import { join } from 'path'; + +import { parseBelsorpCSV } from '../parseBelsorpCSV'; + +test('parseBelsorpCSV', () => { + const binary = readFileSync(join(__dirname, 'data/belsorp.csv')); + + const parsed = parseBelsorpCSV(binary); + + expect(Object.keys(parsed)).toStrictEqual([ + 'meta', + 'adsorption', + 'desorption', + ]); + expect(parsed).toMatchSnapshot(); +}); diff --git a/src/from/fromBelsorpCSV.js b/src/from/fromBelsorpCSV.js new file mode 100644 index 0000000..96a3ad1 --- /dev/null +++ b/src/from/fromBelsorpCSV.js @@ -0,0 +1,36 @@ +import { Analysis } from 'common-spectrum'; + +import { parseBelsorpCSV } from './parseBelsorpCSV'; + +export function fromBelsorpCSV(binary) { + const result = parseBelsorpCSV(binary); + const analysis = new Analysis(); + + analysis.pushSpectrum( + { + x: result.adsorption['p/p0'], + y: result.adsorption.na || result.adsorption.Va, + p: result.adsorption.p0, + }, + { + dataType: 'Adsorption Isotherm', + title: result.meta.COMMENT1, + meta: result.meta, + }, + ); + + analysis.pushSpectrum( + { + x: result.desorption['p/p0'], + y: result.desorption.na || result.adsorption.Va, + p: result.desorption.p0, + }, + { + dataType: 'Desorption Isotherm', + title: result.meta.COMMENT1, + meta: result.meta, + }, + ); + + return analysis; +} diff --git a/src/from/parseBelsorpCSV.js b/src/from/parseBelsorpCSV.js new file mode 100644 index 0000000..ac513bd --- /dev/null +++ b/src/from/parseBelsorpCSV.js @@ -0,0 +1,94 @@ +import { ensureString } from 'ensure-string'; + +const variableLabels = { + No: 'Peak number', + pi: 'Initial pressure', // kPa + pe: 'Absolute pressure', // kPa + p0: 'Relative pressure', // kPa + 'p/p0': 'p/p0', + na: 'Amount of absorbed gas', // mol g^-1 + Va: 'Amount of absorbed gas', // ml g^-1 +}; + +// p0 = saturation pressure +// p/p0 = relative pressure +// na = amount of adsorbed gas (N2 or CO2 for example) + +/* +For adsorption we want: +- x: p/p0 +- y: na or va +- p: + +Adsorptive,N2 +Adsorption temperature,77.000,[K] + +For desorption we want +- x: +- y: +- p: + + +*/ + +export function parseBelsorpCSV(binary) { + const text = ensureString(binary); + const result = {}; + result.meta = {}; + + const [header, data] = text.split(/\r?\n,*\r?\n/); + appendMeta(header, result); + appendData(data, result); + + return result; +} + +function appendMeta(header, result) { + for (let line of header.split(/\r?\n/)) { + let comma = line.indexOf(','); + if (comma > 0) { + result.meta[line.substring(0, comma)] = line + .substring(comma + 1) + .replace(',[', ' [') + .replace(/,+$/, ''); + } + } +} + +function appendData(data, result) { + const lines = data.split(/\r?\n/); + const variables = {}; + const variableNames = []; + for (let field of lines[0].split(',')) { + const parts = field === 'p/p0' ? [field] : field.split('/'); + const variable = { + label: variableLabels[parts[0]] || parts[0], + variable: parts[0], + units: parts[1] ? parts[1].replace(' g^-1', '/g') : '', + data: [], + }; + variableNames.push(parts[0]); + variables[parts[0]] = variable; + } + + let target; + for (let line of lines) { + if (line.startsWith('ADS')) { + target = JSON.parse(JSON.stringify(variables)); + result.adsorption = target; + } else if (line.startsWith('DES')) { + target = JSON.parse(JSON.stringify(variables)); + result.desorption = target; + } + if (target) { + if (line.match(/^[0-9E,.-]*$/)) { + const fields = line.split(',').map((field) => Number(field)); + for (let i = 0; i < variableNames.length; i++) { + if (variableNames[i]) { + target[variableNames[i]].data.push(fields[i]); + } + } + } + } + } +} diff --git a/src/index.js b/src/index.js index 9eefe8b..c06ddb4 100755 --- a/src/index.js +++ b/src/index.js @@ -12,5 +12,6 @@ export { fromIGA } from './from/fromIGA'; export { fromMicrometricsTXT } from './from/fromMicrometricsTXT'; export { fromMicrometricsCSV } from './from/fromMicrometricsCSV'; export { fromBelsorp } from './from/fromBelsorp'; +export { fromBelsorpCSV } from './from/fromBelsorpCSV'; export { parseRubotherm } from './from/parser/parseRubotherm/parseRubotherm'; export { parseMicromeriticsExcel } from './from/parser/parseMicrometricsExcel/parseMicrometricsExcel';