Dew Point jpGraph

I’ve been studying the different jpGraphs that others have developed. I was thinking of trying to develop one either included into the temp/humidity or separate. Kinda figured what the different parts of the code do but when I went to look for the clientrawextra fields for dew point I found there are none.

Anyone think dewpoint would be worthwhile or would it add too much to the clientrawextra if Brian were willing to include it?

–Dave

Dew point can be calculated from Temp and Humidity I think.

Gives a rough idea of Dewpt. Most likely close enough though.

I'm wondering if anyone could please give me the formula for the calculation of dewpoint temperature given relative humidity, current temperature, and station pressure

First calculate the saturation vap. pres. es ¶ at temperature T (oC):

es = 610.78 * exp {A T / (T + B) }

where es in Pa, A = 17.2694 and B = 237.3 for T>0 otherwise 265.5.

Then calculate the actual vapour pressure e ¶ using

e = rH / 100 * es

where rH is the rel.hum in %. Finally invert the equation for es since e = es(Td). The dewpoint temperature Td (oC) is then obtained from

Td = B f / { 1 - f }

where

f = ln ( e / 610.78 ) / A

(Based on Monteith and Unsworth, 1990, Principles of Environmental Physics, sec.ed., Arnold, London, 291pp. ISBN 0-7131-2931-X. Note however that their equation 2.25 for Td is wrong) N.J. Bink

This is what I use

<?php

//where are your clientraw*-files relative to where this file is

$hostloc = "../../";



include ("jp/src/jpgraph.php");//maybe you have to change this path

include ("jp/src/jpgraph_line.php");//maybe you have to change this path



//you dont have to change anything below this

//================================================================================================



// Create the graph and specify the scale for both Y-axis

$graph = new Graph(400,250,"auto",30);    

$graph->SetScale("textlin");

$graph->SetY2Scale("lin",0,100);

$graph->SetShadow();

$graph->SetMarginColor("blue");

$graph->img->SetAntiAliasing();



//$clientraw = get_raw("${hostloc}clientraw.txt");

$clientrawextra = get_raw("${hostloc}clientrawextra.txt");

//$clientrawdaily = get_raw ("${hostloc}clientrawdaily.txt");



//read the clientraw*-files we need

function get_raw( $rawfile ) {

$rawdata = array();

$fd = fopen($rawfile, "r");

if ($fd) {

$rawcontents = '';

while (! feof ($fd) ) {

$rawcontents .= fread($fd, 8192);

}

fclose($fd);

$delimiter = " ";

$rawdata = explode ($delimiter, $rawcontents);

} else {

$rawdata[0]= -9999;

}

return $rawdata;

}



//temp=========================================================================

$y=array($clientrawextra['21'],$clientrawextra['22'],$clientrawextra['23'],$clientrawextra['24'],

$clientrawextra['25'],$clientrawextra['26'],$clientrawextra['27'],$clientrawextra['28'],$clientrawextra['29'],

$clientrawextra['30'],$clientrawextra['31'],$clientrawextra['32'],$clientrawextra['33'],$clientrawextra['34'],

$clientrawextra['35'],$clientrawextra['36'],$clientrawextra['37'],$clientrawextra['38'],$clientrawextra['39'],

$clientrawextra['40'],$clientrawextra['566'],$clientrawextra['567'],$clientrawextra['568'],$clientrawextra['569']);

array_walk($y,'CtoF');

$ydata = $y;



//hum=============================================================================

$y=array($clientrawextra['611'],$clientrawextra['612'],$clientrawextra['613'],$clientrawextra['614'],

$clientrawextra['615'],$clientrawextra['616'],$clientrawextra['617'],$clientrawextra['618'],$clientrawextra['619'],

$clientrawextra['620'],$clientrawextra['621'],$clientrawextra['622'],$clientrawextra['623'],$clientrawextra['624'],

$clientrawextra['625'],$clientrawextra['626'],$clientrawextra['627'],$clientrawextra['628'],$clientrawextra['629'],

$clientrawextra['630'],$clientrawextra['631'],$clientrawextra['632'],$clientrawextra['633'],$clientrawextra['634']);

$y2data = $y;



$Tc[1] = $clientrawextra[21];

$Tc[2] = $clientrawextra[22];

$Tc[3] = $clientrawextra[23];

$Tc[4] = $clientrawextra[24];

$Tc[5] = $clientrawextra[25];

$Tc[6] = $clientrawextra[26];

$Tc[7] = $clientrawextra[27];

$Tc[8] = $clientrawextra[28];

$Tc[9] = $clientrawextra[29];

$Tc[10] = $clientrawextra[30];

$Tc[11] = $clientrawextra[31];

$Tc[12] = $clientrawextra[32];

$Tc[13] = $clientrawextra[33];

$Tc[14] = $clientrawextra[34];

$Tc[15] = $clientrawextra[35];

$Tc[16] = $clientrawextra[36];

$Tc[17] = $clientrawextra[37];

$Tc[18] = $clientrawextra[38];

$Tc[19] = $clientrawextra[39];

$Tc[20] = $clientrawextra[40];

$Tc[21] = $clientrawextra[566];

$Tc[22] = $clientrawextra[567];

$Tc[23] = $clientrawextra[568];

$Tc[24] = $clientrawextra[569];



$RH[1]= $clientrawextra[611];

$RH[2]= $clientrawextra[612];

$RH[3]= $clientrawextra[613];

$RH[4]= $clientrawextra[614];

$RH[5]= $clientrawextra[615];

$RH[6]= $clientrawextra[616];

$RH[7]= $clientrawextra[617];

$RH[8]= $clientrawextra[618];

$RH[9]= $clientrawextra[619];

$RH[10]= $clientrawextra[620];

$RH[11]= $clientrawextra[621];

$RH[12]= $clientrawextra[622];

$RH[13]= $clientrawextra[623];

$RH[14]= $clientrawextra[624];

$RH[15]= $clientrawextra[625];

$RH[16]= $clientrawextra[626];

$RH[17]= $clientrawextra[627];

$RH[18]= $clientrawextra[628];

$RH[19]= $clientrawextra[629];

$RH[20]= $clientrawextra[630];

$RH[21]= $clientrawextra[631];

$RH[22]= $clientrawextra[631];

$RH[23]= $clientrawextra[633];

$RH[24]= $clientrawextra[634];



//dew array in degrees F

$dewF = array();

for ($i = 1;$i < 25;$i++)

{

$dewF = array_merge($dewF,array(DEWF($Tc[$i],$RH[$i])));

}

//dew array in Celcius

$dewC = array();

for ($i = 1;$i < 25;$i++)

{

$dewC = array_merge($dewC,array(DEWC($Tc[$i],$RH[$i])));

}





//

//function

//

// Calculate dewF

function DEWF($Tc,$RH) {

         $Es=6.11*pow(10.0,(7.5*$Tc/(237.7+$Tc)));

         $E=($RH*$Es)/100;

         $Tdc=(-430.22+237.7*log($E))/(-log($E)+19.08);

         $Tdc= sprintf ("%01.1f", $Tdc);

		$Tdf = 1.8*$Tdc+32;

  return $Tdf;

} // end function calculate dewF



// Calculate dewC

function DEWC($Tc,$RH) {

         $Es=6.11*pow(10.0,(7.5*$Tc/(237.7+$Tc)));

         $E=($RH*$Es)/100;

         $Tdc=(-430.22+237.7*log($E))/(-log($E)+19.08);

         $Tdc= sprintf ("%01.1f", $Tdc);



  return $Tdc;

} // end function calculate dewC



// CtoF: converts degrees Celcius to degrees F

function CtoF(&$value) {

  return round($value = ((1.8* $value) + 32),1);

} // end function C_to_F



//create timearray for the x-axis

$n=1;

$limit=24;

$time=date(" H",time());

$datat=array($time);

$x=$datat;

//what you have to add

$add=3600;

$result=strtotime($time);

for ($n=1;$n++;)

{

$result=($result-$add);

$new=date('ga', $result);

$next=array("$new");

$datat= array_merge ($next,$datat);

if ($n>=$limit) break;

  }

$datat=array_merge($datat,$x);



// =====================================================================================

// From here we start creating the graphs

// =====================================================================================

// Box around plotarea

$graph->SetBox();

// No frame around the image

$graph->SetFrame(false);



// Setup the tab title

$graph->tabtitle->Set('Temperature, Dew & Humidity');

$graph->tabtitle->SetFont(FF_FONT1,FS_BOLD,10);

$graph->tabtitle->SetColor('navy','lightyellow','navy');



// Adjust the margin

$graph->img->SetMargin(55,40,25,55);



// Create the 3 linear plot

$lineplot=new LinePlot($ydata);

$lineplot2=new LinePlot($y2data);

$lineplot3=new LinePlot($dewF);



// Add the plot to the graph

$graph->Add($lineplot);

$graph->Add($lineplot3);

$graph->AddY2($lineplot2);

$lineplot2->SetWeight(2);



//x-axis

$graph->xaxis->title->Set(date("M j"));

$graph->xaxis->SetTickLabels($datat); 

$graph->xaxis->SetTextLabelInterval(2);

$graph->xaxis->HideTicks(true,true); 

$graph->xaxis->SetPos("min"); 

$graph->xgrid->Show(true);



//y-axis

$graph->yaxis->title->SetFont(FF_FONT1);

$graph->yaxis->SetColor("red");

$graph->yaxis->SetLabelFormat('%0.0f

Looks like you’ve done the hard work, Pinto. You know I’ll be sealing this, right? :wink:

–Dave

Thanks Pinto, this is something that I wanted,too!