[OpendTect_Developers] Using units of measure in OpendTect

Raman Singh raman at opendtect.org
Mon Jan 24 06:28:18 CET 2011


Dear fellow developers,

As we all know, despite tremendous efforts from the our scientific 
community to standardize units of measurement for all physical 
quantities, we keep using different units for the same quantity in 
different times/places/contexts. Here I will discuss what an OpendTect 
developer needs to know/do to handle these variety of units.

In OpendTect, internally we almost always use SI units. For example, in 
a time survey, the Z values internally are always in seconds (SI) and 
not in milliseconds. The only exception is 'Feet' which is still used if 
the survey is in Feet. But as you will notice, in all the user 
interfaces, the Z(time) is mentioned in milliseconds as this is the 
'popular' unit and therefore is more intuitive to the user. Therefore, 
based on the units of measure, we can have three different values of a 
quantity:

1. SI value : value in SI units.
2. Internal value: value in OpendTect internal units (same as SI units 
except for Feet);
3. User value : value in user units.

To make the conversions from one value to another, we use the class 
UnitOfMeasure. You can get a UnitOfMeasure object for your desired unit 
from the global UnitOfMeasureRepository UoMR(). For example, you can get 
a UnitOfMeasure for milliseconds in the following manner:

const UnitOfMeasure* msuom = UoMR().get( "ms" );
(A null pointer is returned if the unit is not available in the repository)

Now, to convert a value from user units (ms in this case) to SI units (sec),

const float valinsi = msuom->getSIValue( valinms );

To convert back from SI units to user units:

const float valinms = msuom->getUserValueFromSI( valinsi );

To convert from user units to internal units:

const float valinternal = msuom->getInternal( valinms );
(The internal unit and SI unit is the same(sec) in this case)

To convert from internal units back to user units:

const float valinms = msuom->userValue( valinternal );

Please note that the user unit is the unit of the UnitOfMeasure object 
(ms in the above example).

As you might have realized, these conversions are mostly useful while 
importing/exporting data. In those cases, the user tells us the units of 
input/output data. For getting this input from the user, we have a UI 
class uiUnitSel. It gives the user a list of units (depending on the 
PropertyRef::StdType parameter) to choose from and you can get the 
corresponding UnitOfMeasure object for the selected unit using getUnit() 
function. For example, if we wish to get a Z(in time) value from the 
user, in the UI constructor we can write something like:

zinputfld_ = new uiGenInput( this, "Z value", FloatInpSpec() );
unitfld_ = new uiUnitSel( this, PropertyRef::Time );
unitfld_->attach( rightTo, zinputfld_ );

and then to extract the value,

const UnitOfMeasure* selunit = unitfld_->getUnit();
const float val = selunit->getInternal( zinputfld_->getfvalue() );

Now this 'val' can be directly used in OpendTect as it is in internal units.

I hope this information is helpful to you. For any 
questions/suggestions, you can write back to me.

Happy coding!

Best regards,
Raman


-- 

- Raman K Singh
- OpendTect Developer
-
- dGB Earth Sciences
- 304, Gateway Plaza, Hiranandani Gardens, Powai, Mumbai 400 076, India
- Phone: +91 22 25704984 , Fax: +91 22 25704977, Mobile: +91 9819082417
-mailto:raman.singh at opendtect.org,http://www.opendtect.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opendtect.org/pipermail/developers/attachments/20110124/ae72f593/attachment.html>


More information about the Developers mailing list