Skip to content

Commit f38ae66

Browse files
authored
Merge pull request #237 from LukePrior/testing
ozonesonde ozone partial pressure calc
2 parents 049762b + 4bc225f commit f38ae66

File tree

1 file changed

+47
-38
lines changed

1 file changed

+47
-38
lines changed

js/xdata.js

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,43 @@
33
* Authors: Mark Jessop & Luke Prior
44
*/
55

6-
function parseOzonesonde(xdata) {
6+
// Pump Efficiency Correction Parameters for ECC-6A Ozone Sensor, with 3.0cm^3 volume.
7+
// We are using these as a nominal correction value for pump efficiency vs pressure
8+
//
9+
OIF411_Cef_Pressure = [ 0, 2, 3, 5, 10, 20, 30, 50, 100, 200, 300, 500, 1000, 1100];
10+
OIF411_Cef = [ 1.171, 1.171, 1.131, 1.092, 1.055, 1.032, 1.022, 1.015, 1.011, 1.008, 1.006, 1.004, 1, 1];
11+
12+
function lerp(x, y, a){
13+
// Helper function for linear interpolation between two points
14+
return x * (1 - a) + y * a
15+
}
16+
17+
function get_oif411_Cef(pressure){
18+
// Get the Pump efficiency correction value for a given pressure.
19+
20+
// Off-scale use bottom-end value
21+
if (pressure <= OIF411_Cef_Pressure[0]){
22+
return OIF411_Cef[0];
23+
}
24+
25+
// Off-scale top, use top-end value
26+
if (pressure >= OIF411_Cef_Pressure[OIF411_Cef_Pressure.length-1]){
27+
return OIF411_Cef[OIF411_Cef.length-1];
28+
}
29+
30+
31+
// Within the correction range, perform linear interpolation.
32+
for(i= 1; i<OIF411_Cef_Pressure.length; i++){
33+
if (pressure < OIF411_Cef_Pressure[i]) {
34+
return lerp(OIF411_Cef[i-1], OIF411_Cef[i], ( (pressure-OIF411_Cef_Pressure[i-1]) / (OIF411_Cef_Pressure[i]-OIF411_Cef_Pressure[i-1])) );
35+
}
36+
}
37+
38+
// Otherwise, bomb out and return 1.0
39+
return 1.0;
40+
}
41+
42+
function parseOzonesonde(xdata, pressure) {
743
// Attempt to parse an XDATA string from an ECC Ozonesonde
844
// Returns an object with parameters to be added to the sondes telemetry.
945
//
@@ -29,7 +65,7 @@ function parseOzonesonde(xdata) {
2965
_output['ozonesonde_instrument_number'] = parseInt(xdata.substr(2,2),16);
3066

3167
// Cell Current
32-
_cell_current = parseInt(xdata.substr(4,4),16)*0.001; // micro-Amps
68+
_cell_current = parseInt(xdata.substr(4,4),16)*0.001; // uA
3369
_output['ozonesonde_cell_current'] = Math.round(_cell_current * 1000) / 1000; // 3 DP
3470

3571
// Pump Temperature
@@ -48,44 +84,17 @@ function parseOzonesonde(xdata) {
4884
_battery_voltage = parseInt(xdata.substr(14,2),16)*0.1; // Volts
4985
_output['ozondesonde_battery_voltage'] = Math.round(_battery_voltage * 10) / 10; // 1 DP
5086

51-
return _output
52-
}
53-
54-
// Pump Efficiency Correction Parameters for ECC-6A Ozone Sensor, with 3.0cm^3 volume.
55-
// We are using these as a nominal correction value for pump efficiency vs pressure
56-
//
57-
OIF411_Cef_Pressure = [ 0, 2, 3, 5, 10, 20, 30, 50, 100, 200, 300, 500, 1000, 1100];
58-
OIF411_Cef = [ 1.171, 1.171, 1.131, 1.092, 1.055, 1.032, 1.022, 1.015, 1.011, 1.008, 1.006, 1.004, 1, 1];
59-
60-
function lerp(x, y, a){
61-
// Helper function for linear interpolation between two points
62-
return x * (1 - a) + y * a
63-
}
64-
87+
// Now attempt to calculate the O3 partial pressure (copy OIF411 calculations)
6588

66-
function get_oif411_Cef(pressure){
67-
// Get the Pump efficiency correction value for a given pressure.
68-
69-
// Off-scale use bottom-end value
70-
if (pressure <= OIF411_Cef_Pressure[0]){
71-
return OIF411_Cef[0];
72-
}
73-
74-
// Off-scale top, use top-end value
75-
if (pressure >= OIF411_Cef_Pressure[OIF411_Cef_Pressure.length-1]){
76-
return OIF411_Cef[OIF411_Cef.length-1];
77-
}
78-
89+
// Calibration values
90+
Ibg = 0.0; // The BOM appear to use a Ozone background current value of 0 uA
91+
Cef = get_oif411_Cef(pressure); // Calculate the pump efficiency correction.
92+
FlowRate = 28.5; // Use a 'nominal' value for Flow Rate (seconds per 100mL).
7993

80-
// Within the correction range, perform linear interpolation.
81-
for(i= 1; i<OIF411_Cef_Pressure.length; i++){
82-
if (pressure < OIF411_Cef_Pressure[i]) {
83-
return lerp(OIF411_Cef[i-1], OIF411_Cef[i], ( (pressure-OIF411_Cef_Pressure[i-1]) / (OIF411_Cef_Pressure[i]-OIF411_Cef_Pressure[i-1])) );
84-
}
85-
}
94+
_O3_partial_pressure = (4.30851e-4)*(_output['ozonesonde_cell_current'] - Ibg)*(_output['ozonesonde_pump_temperature']+273.15)*FlowRate*Cef; // mPa
95+
_output['ozondesonde_O3_partial_pressure'] = Math.round(_O3_partial_pressure * 1000) / 1000; // 3 DP
8696

87-
// Otherwise, bomb out and return 1.0
88-
return 1.0;
97+
return _output
8998
}
9099

91100
function parseOIF411(xdata, pressure){
@@ -615,7 +624,7 @@ function parseXDATA(data, pressure, temperature){
615624
if (_instrument === '01') {
616625
if (_current_xdata.length = 16) {
617626
// Ozonesonde
618-
_xdata_temp = parseOzonesonde(_current_xdata);
627+
_xdata_temp = parseOzonesonde(_current_xdata, pressure);
619628
_output = Object.assign(_output,_xdata_temp);
620629
if (!_instruments.includes("Ozonesonde")) _instruments.push('Ozonesonde');
621630
}

0 commit comments

Comments
 (0)