TotalDepth.common.units

This provides Unit conversion information from lookup sources.

The primary source is Schlumberger’s Oilfield Services Data Dictionary (OSDD): https://www.apps.slb.com/cmd/units.aspx

The fallback, secondary source, is from our static snapshot of that page which lives in src/TotalDepth/common/data/osdd_units.json

When running tests with --runslow the tests.integration.common.test_units.test_slb_units_write_to_json test will re-populate that static data file.

This included currencies that all have zero offset and unit scale. Currencies: https://en.wikipedia.org/wiki/ISO_4217 ISO 4217 official currency codes in XML: https://www.currency-iso.org/dam/downloads/lists/list_one.xml

exception TotalDepth.common.units.ExceptionUnits

Base class exception for this module.

exception TotalDepth.common.units.ExceptionUnitsLookup

Raised if the unit lookup fails.

exception TotalDepth.common.units.ExceptionUnitsDimension

Raised if two units are of different dimensions.

class TotalDepth.common.units.Unit

Represents one row in the table at https://www.apps.slb.com/cmd/units.aspx

Examples:

Code    Name                Standard Form   Dimension   Scale               Offset
DEGC    'degree celsius'    degC            Temperature 1                   -273.15
DEGF    'degree fahrenheit' degF            Temperature 0.555555555555556   -459.67
DEGK    'kelvin'            K               Temperature 1                   0
DEGR    'degree rankine'    degR            Temperature 0.555555555555556   0

There will also be an entry for RP66V1 files:

degF    'degree fahrenheit' "5/9 degC +32"  Temperature 0.555555555555556   -459.67

So conversion from, say DEGC to DEGF is:

((value - DEGC.offset) * DEGC.scale) / DEGF.scale + DEGF.offset

((0.0 - -273.15) * 1.0) / 0.555555555555556 + -459.67 == 32.0
code

Alias for field number 0

name

Alias for field number 1

standard_form

Alias for field number 2

dimension

Alias for field number 3

scale

Alias for field number 4

offset

Alias for field number 5

is_primary

True if this is looks like a primary unit.

has_offset() → bool

True if this has an offset, for example DEGC. False otherwise, for example metres.

__getnewargs__()

Return self as a plain tuple. Used by copy and pickle.

static __new__(_cls, code: str, name: str, standard_form: str, dimension: str, scale: float, offset: float)

Create new instance of Unit(code, name, standard_form, dimension, scale, offset)

__repr__()

Return a nicely formatted representation string

TotalDepth.common.units.osdd_data_file_path() → str

Path to our static snapshot of the OSDD units page.

TotalDepth.common.units.read_osdd_static_data() → Dict[str, TotalDepth.common.units.Unit]

Read our static snapshot of the OSDD units page.

TotalDepth.common.units.slb_load_units()

Eagerly load the units into the cache.

TotalDepth.common.units.has_slb_units(unit_code: str) → bool

Returns True if the Schlumberger Unit exists.

TotalDepth.common.units.slb_units(unit: str) → TotalDepth.common.units.Unit

Returns the Schlumberger Unit corresponding to the unit code.

TotalDepth.common.units.has_slb_standard_form(standard_form: str) → bool

Returns True if an entry for the standard form exists.

TotalDepth.common.units.slb_standard_form_to_unit_code(standard_form: str) → List[TotalDepth.common.units.Unit]

Returns the unit(s) corresponding to the standard form. Example given ‘degC’ this returns the Units corresponding to [‘DEGC’, ‘deg C’, ‘oC’].

TotalDepth.common.units.same_dimension(a: TotalDepth.common.units.Unit, b: TotalDepth.common.units.Unit) → bool

Returns True if both units have the same dimension.

TotalDepth.common.units.convert(value: float, unit_from: TotalDepth.common.units.Unit, unit_to: TotalDepth.common.units.Unit) → float

Converts a value from one unit to another.

Examples:

Code    Name                Standard Form   Dimension   Scale               Offset
DEGC    'degree celsius'    degC            Temperature 1                   -273.15
DEGF    'degree fahrenheit' degF            Temperature 0.555555555555556   -459.67

So conversion from, say DEGC to DEGF is:

((value - DEGC.offset) * DEGC.scale) / DEGF.scale + DEGF.offset

((0.0 - -273.15) * 1.0) / 0.555555555555556 + -459.67 == 32.0
TotalDepth.common.units.convert_function(unit_from: TotalDepth.common.units.Unit, unit_to: TotalDepth.common.units.Unit) → Callable

Return a partial function to convert from one units to another.

TotalDepth.common.units.convert_array(array: numpy.ndarray, unit_from: TotalDepth.common.units.Unit, unit_to: TotalDepth.common.units.Unit) → numpy.ndarray

Convert an array of values.

TotalDepth.common.units.convert_array_inplace(array: numpy.ndarray, unit_from: TotalDepth.common.units.Unit, unit_to: TotalDepth.common.units.Unit) → None

Convert an array of values in-place.