Ok. So pH is an interesting one. The original definition -log10( H+ ions in
mol/l ). The SI units here are mol and m3. There is a unit mol/l == Molar.
However, we need m3 which is a thousand liter, which is then I guess kilo
Molar. To create that unit:
final static Unit mol_m3 = new Measurement(1, Unit.mol).div( new
Measurement(1, Unit.m3)).getUnit();
Unit is unfortunately not extendable but I have no problem proposing to add
this unit. I think it would also nice if we had a conversion class to common
non-SI units. Maybe we should also enable creating units directly and not
indirectly through Measurement.
So now to convert from pH to measurement:
Measurement pH( double pH ) {
double molPerM3 = Math.pow(10, -pH) * 1000; // Molar * 1000
return new Measurement(molPerM3, mol_m3);
}
And back:
double pH( Measurement molPerM3 ) {
assert molPerM3.getUnit().equals( mol_m3 );
return - Math.log10(molPerM3.getValue()/1000);
}
Interestingly, you can now ask how many mols there are are in 5 liter:
pH(5) * new Measurement(0.005, Unit.m3 ) => mol in 5 liter
However, reading Wikipedia I think pH is nowadays more subtle than H+ ions/l?
Anyway, have not tested the code so make sure you test it :-)
Kind regards,
Peter Kriens
On 9 dec 2010, at 17:11, John E. Conlon wrote:
> Hi Peter,
>
> (Thought you might be the only to reply to this one.)
>
> I'm just trying to understand how to use Measurement when I have sensors that
> are outputting pH values. How do I convert these pH values to Measurement
> and what kind of Unit do I use?
>
> thanks,
>
> John
>
>
> Peter Kriens wrote:
>> Can you elaborate what you're looking for? A function to go from int pH ->
>> Measurement and vice versa?
>>
>> Kind regards,
>>
>> Peter Kriens
>>
>> On 8 dec 2010, at 18:41, John E. Conlon wrote:
>>
>>
>>> Would like to use the org.osgi.util.measurement.Measurement class for pH
>>> measurements. On first thought :
>>> Measurement m = new Measurement(.1,Unit.mol);//1
>>> m = new Measurement(.01,Unit.mol);// pH of 2
>>> m = new Measurement(.001,Unit.mol);//pH of 3
>>> Measurement water = new Measurement(.0000001, Unit.mol);//pH of 7
>>>
>>> Is there a standard equation for conversion to record these?
>>>
>>> thanks for any insight,
>>> John
>>>
>>>
>>>
>>> _______________________________________________
>>> OSGi Developer Mail List
>>> [email protected]
>>> https://mail.osgi.org/mailman/listinfo/osgi-dev
>>>
>>
>>
>>
>
>
_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev