CO2 Frank


calculating slope and R2 for soil respiration Goes with the protocol with the same name
//============================================
// Macro for data evaluation on PhotosynQ.org
// created: 19/07/2016
//============================================

//Define the output object here

// Fix for temperature array
for (var i = 0; i < json.temperature.length; i++) {
  json.temperature[i] = parseFloat(json.temperature[i]);
}

// Fix for humidity array
for (var i = 0; i < json.humidity.length; i++) {
  json.humidity[i] = parseFloat(json.humidity[i]);
}

// Fix for pressure array
for (var i = 0; i < json.pressure.length; i++) {
  json.pressure[i] = parseFloat(json.pressure[i]);
}


var output = {};
var temperature = MathMEDIAN(json.temperature);
var humidity = MathMEDIAN(json.humidity);
var pressure = MathMEDIAN(json.pressure);
var Volume = .001701
var Soilweight = 100;
var Pressure_constant = 100;
var Rconstant = 8.31441;
var Cmoleweight = 12.01;
var Kelvin = 273;
var Conversion_factor1 = .000001;
var Conversion_factor2 = 1000;
var Conversion_factor3 = 86.4;
var mgCm3Array = [];
var carbonOutputArray = [];




for (var i = 0; i < json.co2.length; i++) {
  mgCm3Array.push((((json.pressure[i] * Pressure_constant) * Cmoleweight * json.co2[i] * Conversion_factor1) / (Rconstant * (json.temperature[i] + Kelvin))) * Conversion_factor2);
};


for (var i = 0; i < json.co2.length; i++) {
  carbonOutputArray.push(((mgCm3Array[i] * Volume) / Soilweight) * Conversion_factor3);
};

carbonOutputArray = carbonOutputArray.slice(6);

var xArray = [];
for (var i = 0; i < carbonOutputArray.length; i++){
  xArray.push(i * 5);
}
                          
var Carbon_output = MathLINREG(xArray, carbonOutputArray);
output["gC_kgsoil_day"] = Carbon_output.m;
output["carbonOutputB"] = Carbon_output.b;
output["carbonOutputR2"] = Carbon_output.r2;
output["mgCm3Array"] = mgCm3Array;
output["carbonOutputArray"] = carbonOutputArray;
output["temperature_array"] = json.temperature;
output["humidity_array"] = json.humidity;
output["pressure_array"] = json.pressure;
output["co2_array"] = json.co2;
output["temperature"] = temperature;
output["humidity"] = humidity;
output["pressure"] = pressure;


//Check if the key time exists in json
if (json.time !== undefined){

	//Add key time and value to output
	output["time"] = json.time;
}

//Return data
return output;
{
  "time_offset": 240,
  "time": 1468952907884,
  "device_version": "1",
  "device_id": "d4:f5:ff:ff:ff:ff",
  "device_battery": -268,
  "device_firmware": ".5",
  "firmware_version": ".5",
  "device_time": 1468925625,
  "sample": [
    [
      {
        "time": 1468952907902,
        "protocol_id": 1,
        "temperature": [
          "27.290001",
          "27.299999",
          "27.299999",
          "27.299999",
          "27.299999",
          "27.299999",
          "27.299999",
          "27.290001",
          "27.290001",
          "27.290001",
          "27.280001",
          "27.280001",
          "27.280001",
          "27.280001",
          "27.270000",
          "27.270000",
          "27.260000",
          "27.250000",
          "27.250000",
          "27.240000",
          "27.230000",
          "27.230000",
          "27.219999",
          "27.219999"
        ],
        "humidity": [
          "42.562500",
          "42.631836",
          "42.687500",
          "42.765625",
          "42.832031",
          "42.933594",
          "43.000000",
          "43.088867",
          "43.144531",
          "43.222656",
          "43.290039",
          "43.357422",
          "43.412109",
          "43.467773",
          "43.534180",
          "43.589844",
          "43.645508",
          "43.689453",
          "43.745117",
          "43.790039",
          "43.833008",
          "43.876953",
          "43.920898",
          "43.965820"
        ],
        "pressure": [
          "993.450806",
          "993.470093",
          "993.440247",
          "993.467163",
          "993.447815",
          "993.445129",
          "993.480957",
          "993.467346",
          "993.505554",
          "993.505554",
          "993.461304",
          "993.461304",
          "993.483826",
          "993.492126",
          "993.489380",
          "993.443848",
          "993.473450",
          "993.442017",
          "993.435852",
          "993.483643",
          "993.463135",
          "993.428772",
          "993.450012",
          "993.457581"
        ],
        "co2": [
          "643.000000",
          "650.000000",
          "661.000000",
          "666.000000",
          "672.000000",
          "677.000000",
          "682.000000",
          "686.000000",
          "687.000000",
          "686.000000",
          "686.000000",
          "687.000000",
          "686.000000",
          "686.000000",
          "686.000000",
          "685.000000",
          "685.000000",
          "685.000000",
          "684.000000",
          "684.000000",
          "684.000000",
          "683.000000",
          "683.000000",
          "682.000000"
        ],
        "analog_read": [
          "38545.000000",
          "39962.000000",
          "40041.000000",
          "40039.000000",
          "41787.000000",
          "39762.000000",
          "40218.000000",
          "39763.000000",
          "39559.000000",
          "39556.000000",
          "40126.000000",
          "40122.000000",
          "39285.000000",
          "38601.000000",
          "38600.000000",
          "38597.000000",
          "38600.000000",
          "38599.000000",
          "38599.000000",
          "38601.000000",
          "38596.000000",
          "38596.000000",
          "38601.000000",
          "38415.000000"
        ],
        "data_raw": [
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0
        ]
      }
    ]
  ],
  "app_os": "win",
  "app_name": "PhotosynQ",
  "app_version": "0.3.3",
  "app_device": "x86-32",
  "location": [
    "42.7227383",
    "-84.4746533"
  ],
  "notes": "Tested on my desk, no soil present"
}
Dsc 0888
Created by

Frank M


Protocol connections:
2
Latest Update:
Nov 2016