wunit

package
v0.0.0-...-040724e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2019 License: BSD-3-Clause, GPL-2.0, BSD-3-Clause, + 1 more Imports: 12 Imported by: 26

Documentation

Overview

Package wunit is a core Antha package for dealing with units in Antha

Core Antha package for dealing with units in Antha

Index

Constants

View Source
const Epsilon = 0.00000000001

Epsilon a small delta used when to avoid floating point errors when comparing

Variables

View Source
var (
	Yocto = newPrefix("y", "yocto", 1e-24)
	Zepto = newPrefix("z", "zepto", 1e-21)
	Atto  = newPrefix("a", "atto", 1e-18)
	Femto = newPrefix("f", "femto", 1e-15)
	Pico  = newPrefix("p", "pico", 1e-12)
	Nano  = newPrefix("n", "nano", 1e-9)
	Micro = newPrefix("u", "micro", 1e-6)
	Milli = newPrefix("m", "milli", 1e-3)
	Centi = newPrefix("c", "centi", 1e-2)
	Deci  = newPrefix("d", "deci", 1e-1)
	Deca  = newPrefix("da", "deca", 1e1)
	Hecto = newPrefix("h", "hecto", 1e2)
	Kilo  = newPrefix("k", "kilo", 1e3)
	Mega  = newPrefix("M", "mega", 1e6)
	Giga  = newPrefix("G", "giga", 1e9)
	Tera  = newPrefix("T", "tera", 1e12)
	Peta  = newPrefix("P", "peta", 1e15)
	Exa   = newPrefix("E", "exa", 1e18)
	Zetta = newPrefix("Z", "zetta", 1e21)
	Yotta = newPrefix("Y", "yotta", 1e24)
	None  = SIPrefix{Symbol: "", Name: "", Value: 1.0} // not a valid SIPrefix, hence not in SIPrefixes, but used for non-prefixed units
)
View Source
var SIPrefixes []SIPrefix

SIPrefixes a list containing all valid SI prefixes

Functions

func DivideConcentrations

func DivideConcentrations(num, den Concentration) (float64, error)

DivideConcentrations divides the SI Value of conc1 by conc2 to return a factor. An error is returned if the concentration unit is not dividable or the number generated is infinity.

func DivideVolumes

func DivideVolumes(vol1, vol2 Volume) (float64, error)

DivideVolumes divides the SI Value of vol1 by vol2 to return a factor. An error is returned if the volume is infinity or not a number.

func SIPrefixSymbols

func SIPrefixSymbols() []string

SIPrefixSymbols returns a list of all supported SI prefixes

func SplitValueAndUnit

func SplitValueAndUnit(str string) (float64, string)

SplitValueAndUnit splits a joined value and unit in string format into seperate typed value and unit fields. If the string input is not in the valid format of value followed by unit it will not be parsed correctly. If a value on its own is given the unit will be returned blank, if the unit is given alone the value will be 0.0 valid: 10s, 10 s, 10.5s, 2.16e+04 s, 10, s invalid: s 10 s10

Types

type Angle

type Angle struct {
	*ConcreteMeasurement
}

angle

func NewAngle

func NewAngle(v float64, unit string) Angle

generate a new angle unit

func (Angle) MarshalJSON

func (m Angle) MarshalJSON() ([]byte, error)

func (*Angle) UnmarshalJSON

func (m *Angle) UnmarshalJSON(b []byte) error

type AngularVelocity

type AngularVelocity struct {
	*ConcreteMeasurement
}

func NewAngularVelocity

func NewAngularVelocity(v float64, unit string) AngularVelocity

type Area

type Area struct {
	*ConcreteMeasurement
}

area

func NewArea

func NewArea(v float64, unit string) Area

make an area unit

func ZeroArea

func ZeroArea() Area

func (Area) MarshalJSON

func (m Area) MarshalJSON() ([]byte, error)

func (*Area) UnmarshalJSON

func (m *Area) UnmarshalJSON(b []byte) error

type Axis

type Axis int

Axis represent a particular direction

const (
	XAxis Axis = iota
	YAxis
	ZAxis
)

func AxisFromString

func AxisFromString(a string) (Axis, error)

AxisFromString return the relevant axis from the string which should be "X", "Y", or "Z" (or lowercase), otherwise returns an invalid axis and an error

func (Axis) String

func (a Axis) String() string

String return the name of the axis

type Concentration

type Concentration struct {
	*ConcreteMeasurement
}

defines a concentration unit

func AddConcentrations

func AddConcentrations(concs ...Concentration) (Concentration, error)

AddConcentrations adds a variable number of concentrations from an original concentration. An error is returned if the concentration units are incompatible.

func CopyConcentration

func CopyConcentration(v Concentration) Concentration

func DivideConcentration

func DivideConcentration(v Concentration, factor float64) (newconc Concentration)

DivideConcentration divides a concentration by a factor.

func MaxConcentration

func MaxConcentration(concs []Concentration) (max Concentration, err error)

MaxConcentration returns the highest concentration value from a set of concentration values. An error will be returned if no values are specified or the base units of any of the concentrations are incompatible, e.g. units of X and g/l would not be compatible.

func MinConcentration

func MinConcentration(concs []Concentration) (min Concentration, err error)

MinConcentration returns the lowest concentration value from a set of concentration values. An error will be returned if no values are specified or the base units of any of the concentrations are incompatible, e.g. units of X and g/l would not be compatible.

func MultiplyConcentration

func MultiplyConcentration(v Concentration, factor float64) (newconc Concentration)

MultiplyConcentration multiplies a concentration by a factor.

func NewConcentration

func NewConcentration(v float64, unit string) Concentration

NewConcentration makes a new concentration in SI units... either M/l or kg/l

func ParseConcentration

func ParseConcentration(s string) (bool, Concentration, string)

ParseConcentration utility to extract concentration and component name from a string. Valid inputs include

  • "6M Glucose", "6 M Glucose"
  • "Glucose 6 M", "Glucose 6M"
  • "Glucose (M)", "Glucose M", "Glucose (6 M)"
  • "Glucose"

returns three values - a boolean which is true if the value of the concentration was set, the parsed concentration, and the remaining component name. if removing the concentration would leave the empty string, the component name is set as the input string

func SortConcentrations

func SortConcentrations(concs []Concentration, descending ...SortOption) (sorted []Concentration, err error)

SortConcentrations sorts a set of Concentration values. An error will be returned if no values are specified or the base units of any of the concentrations are incompatible, e.g. units of X and g/l would not be compatible. An optional second argument DescendingOrder can be specified to indicate that the sorting will be in descending order. By default sorting will be in ascending order.

func SubtractConcentrations

func SubtractConcentrations(originalConc Concentration, subtractConcs ...Concentration) (Concentration, error)

SubtractConcentrations substracts a variable number of concentrations from an original concentration. An error is returned if the concentration units are incompatible.

func (Concentration) Dup

func (c Concentration) Dup() Concentration

Dup deprecated, please use CopyConcentration

func (Concentration) GramPerL

func (conc Concentration) GramPerL(molecularWeight float64) Concentration

GramPerL deprecated, please use GramsPerLitre

func (Concentration) GramsPerLitre

func (conc Concentration) GramsPerLitre(molecularweight float64) (Concentration, error)

GramsPerLitre return a new concentration equal to the current one in grams per litre, using molecularweight given in grams per mole to convert if necessary. Returns an error if the units of conc are not compatible with grams per litre or grams per mole (such as "X" or "v/v")

func (Concentration) MarshalJSON

func (m Concentration) MarshalJSON() ([]byte, error)

func (Concentration) MolPerL

func (conc Concentration) MolPerL(molecularWeight float64) Concentration

MolPerL deprecated, please use MolesPerLitre

func (Concentration) MolesPerLitre

func (conc Concentration) MolesPerLitre(molecularweight float64) (Concentration, error)

MolesPerLitre return a new concentration equal to the current one in mols per litre, using molecularweight given in grams per mole to convert if necessary. Returns an error if the units of conc are not compatible with grams per litre or grams per mole (such as "X" or "v/v")

func (*Concentration) UnmarshalJSON

func (m *Concentration) UnmarshalJSON(b []byte) error

type ConcreteMeasurement

type ConcreteMeasurement struct {
	// the raw value
	Mvalue float64
	// the relevant units
	Munit *Unit
}

structure implementing the Measurement interface

func NewMeasurement

func NewMeasurement(v float64, pu string) *ConcreteMeasurement

func NewTypedMeasurement

func NewTypedMeasurement(measurementType string, value float64, unit string) *ConcreteMeasurement

NewTypedMeasurement create a new measurement from the global registry asserting that the supplied units match the given type, and calling panic() if not

func (*ConcreteMeasurement) Add

func (cm *ConcreteMeasurement) Add(m Measurement)

Add deprecated, please use IncrBy

func (*ConcreteMeasurement) ConvertToString

func (cm *ConcreteMeasurement) ConvertToString(s string) float64

ConvertToString deprecated, please use InStringUnit

func (*ConcreteMeasurement) DecrBy

func (cm *ConcreteMeasurement) DecrBy(m Measurement) error

DecrBy subtract m from the receiver

func (*ConcreteMeasurement) DivideBy

func (cm *ConcreteMeasurement) DivideBy(factor float64)

func (*ConcreteMeasurement) EqualTo

func (cm *ConcreteMeasurement) EqualTo(m Measurement) bool

XXX This should be made more literal and rounded behaviour explicitly called for by user

func (*ConcreteMeasurement) EqualToRounded

func (cm *ConcreteMeasurement) EqualToRounded(m Measurement, p int) bool

func (*ConcreteMeasurement) EqualToTolerance

func (cm *ConcreteMeasurement) EqualToTolerance(m Measurement, tol float64) bool

EqualToTolerance return true if the two measurements are within a small tolerace, tol, of each other where tol is expressed in the same units as the receiver

func (*ConcreteMeasurement) GreaterThan

func (cm *ConcreteMeasurement) GreaterThan(m Measurement) bool

func (*ConcreteMeasurement) GreaterThanRounded

func (cm *ConcreteMeasurement) GreaterThanRounded(m Measurement, p int) bool

func (*ConcreteMeasurement) InStringUnit

func (cm *ConcreteMeasurement) InStringUnit(symbol string) (Measurement, error)

InStringUnit return a new measurement in the new units

func (*ConcreteMeasurement) InUnit

ConvertTo return a new measurement in the new units

func (*ConcreteMeasurement) IncrBy

func (cm *ConcreteMeasurement) IncrBy(m Measurement) error

IncrBy add the measurement m to the receiver

func (*ConcreteMeasurement) IsNegative

func (cm *ConcreteMeasurement) IsNegative() bool

IsNegative true if the measurement is negative by more than a very small delta

func (*ConcreteMeasurement) IsNil

func (cm *ConcreteMeasurement) IsNil() bool

func (*ConcreteMeasurement) IsPositive

func (cm *ConcreteMeasurement) IsPositive() bool

IsPositive true if the measurement is positive by more than a very small delta

func (*ConcreteMeasurement) IsZero

func (cm *ConcreteMeasurement) IsZero() bool

func (*ConcreteMeasurement) LessThan

func (cm *ConcreteMeasurement) LessThan(m Measurement) bool

func (*ConcreteMeasurement) LessThanRounded

func (cm *ConcreteMeasurement) LessThanRounded(m Measurement, p int) bool

func (*ConcreteMeasurement) MinusEpsilon

func (cm *ConcreteMeasurement) MinusEpsilon() *ConcreteMeasurement

MinusEpsillon returns a new measurement whose value is a very small amount less than the original useful for comparison ignoring floating point errors, for example:

a.LessThan(b.MinusEpilon())

returns true if a is meaningfully less than b

func (*ConcreteMeasurement) MultiplyBy

func (cm *ConcreteMeasurement) MultiplyBy(factor float64)

multiply

func (*ConcreteMeasurement) MustInStringUnit

func (cm *ConcreteMeasurement) MustInStringUnit(symbol string) Measurement

MustInStringUnit return a new measurement in the new units

func (*ConcreteMeasurement) MustInUnit

func (cm *ConcreteMeasurement) MustInUnit(p PrefixedUnit) Measurement

MustInUnit convert to the given unit, calls panic() if the units are not compatible

func (*ConcreteMeasurement) PlusEpsilon

func (cm *ConcreteMeasurement) PlusEpsilon() *ConcreteMeasurement

PlusEpsillon returns a new measurement whose value is a very small amount larger than the original useful for comparison ignoring floating point errors, for example:

a.GreaterThan(b.PlusEpilon())

returns true if a is meaningfully greater than b

func (*ConcreteMeasurement) RawValue

func (cm *ConcreteMeasurement) RawValue() float64

value without conversion

func (*ConcreteMeasurement) SIValue

func (cm *ConcreteMeasurement) SIValue() float64

value when converted to SI units

func (*ConcreteMeasurement) SetValue

func (cm *ConcreteMeasurement) SetValue(v float64) float64

set the value of this measurement

func (*ConcreteMeasurement) String

func (cm *ConcreteMeasurement) String() string

String will return a summary of the ConcreteMeasurement Value and prefixed unit as a string. The value will be formatted in scientific notation for large exponents and the value unbounded. The Summary() method should be used to return a rounded string.

func (*ConcreteMeasurement) Subtract

func (cm *ConcreteMeasurement) Subtract(m Measurement)

Subtract deprecated, please use DecrBy

func (*ConcreteMeasurement) ToString

func (cm *ConcreteMeasurement) ToString() string

ToString will return a summary of the ConcreteMeasurement Value and prefixed unit as a string. The value will be formatted in scientific notation for large exponents and will be bounded to 3 decimal places. The String() method should be used to use the unbounded value.

func (*ConcreteMeasurement) Unit

func (cm *ConcreteMeasurement) Unit() PrefixedUnit

get unit with prefix

type Density

type Density struct {
	*ConcreteMeasurement
}

a structure which defines a density

func NewDensity

func NewDensity(v float64, unit string) Density

make a new density structure in SI units

func (Density) MarshalJSON

func (m Density) MarshalJSON() ([]byte, error)

func (*Density) UnmarshalJSON

func (m *Density) UnmarshalJSON(b []byte) error

type Energy

type Energy struct {
	*ConcreteMeasurement
}

this is really Mass Length/Time^2

func NewEnergy

func NewEnergy(v float64, unit string) Energy

make a new energy unit

func (Energy) MarshalJSON

func (m Energy) MarshalJSON() ([]byte, error)

func (*Energy) UnmarshalJSON

func (m *Energy) UnmarshalJSON(b []byte) error

type FlowRate

type FlowRate struct {
	*ConcreteMeasurement
}

func NewFlowRate

func NewFlowRate(v float64, unit string) FlowRate

func (FlowRate) MarshalJSON

func (m FlowRate) MarshalJSON() ([]byte, error)

func (*FlowRate) UnmarshalJSON

func (m *FlowRate) UnmarshalJSON(b []byte) error

type Force

type Force struct {
	*ConcreteMeasurement
}

a Force

func NewForce

func NewForce(v float64, unit string) Force

a new force in Newtons

func (Force) MarshalJSON

func (m Force) MarshalJSON() ([]byte, error)

func (*Force) UnmarshalJSON

func (m *Force) UnmarshalJSON(b []byte) error

type Length

type Length struct {
	*ConcreteMeasurement
}

length

func NewLength

func NewLength(v float64, unit string) Length

make a length

func ZeroLength

func ZeroLength() Length

func (Length) MarshalJSON

func (m Length) MarshalJSON() ([]byte, error)

func (*Length) UnmarshalJSON

func (m *Length) UnmarshalJSON(b []byte) error

type Mass

type Mass struct {
	*ConcreteMeasurement
}

mass

func MassForTargetConcentration

func MassForTargetConcentration(targetConc Concentration, totalVol Volume) (Mass, error)

MassForTargetConcentration multiplies a concentration (in g/l) by a volume (in l) to return the mass (in g). if a concentration is not in a form convertable to g/l an error is returned.

func NewMass

func NewMass(v float64, unit string) Mass

func VolumeToMass

func VolumeToMass(v Volume, d Density) (Mass, error)

VolumeToMass multiplies a volume (in L) by a density (in kg/m^3) and returns the mass (in kg).

func VolumetoMass

func VolumetoMass(v Volume, d Density) Mass

VolumetoMass deprecated, pelase use VolumeToMass

func (Mass) MarshalJSON

func (m Mass) MarshalJSON() ([]byte, error)

func (*Mass) Quantity

func (m *Mass) Quantity() Measurement

defines mass to be a SubstanceQuantity

func (*Mass) UnmarshalJSON

func (m *Mass) UnmarshalJSON(b []byte) error

type Measurement

type Measurement interface {
	// the value in base SI units
	SIValue() float64
	// the value in the current units
	RawValue() float64
	// unit plus prefix
	Unit() PrefixedUnit
	// set the value, this must be thread-safe
	// returns old value
	SetValue(v float64) float64
	// InUnit get a new Measurement with the new units, returns error if units are not compatible
	InUnit(p PrefixedUnit) (Measurement, error)
	// InStringUnit wrapper for InUnit which fetches the unit from the global UnitRegistry
	InStringUnit(symbol string) (Measurement, error)
	// MustInUnit get a new Measurement with the new units, equivalent to InUnit except calls panic() if units are not compatible
	MustInUnit(p PrefixedUnit) Measurement
	// MustInStringUnit wrapper for InUnit which fetches the unit from the global UnitRegistry,
	// equivalent to InStringUnit but calls panic() if units are incompatible
	MustInStringUnit(symbol string) Measurement
	// ConvertToString deprecated, please use ConvertTo or InStringUnit
	ConvertToString(s string) float64
	// IncrBy add to this measurement
	IncrBy(m Measurement) error
	// DecrBy subtract from this measurement
	DecrBy(m Measurement) error
	// Add deprecated, please use IncrBy
	Add(m Measurement)
	// Subtract deprecated, please use DecrBy
	Subtract(m Measurement)
	// multiply measurement by a factor
	MultiplyBy(factor float64)
	// divide measurement by a factor
	DivideBy(factor float64)
	// comparison operators
	LessThan(m Measurement) bool
	GreaterThan(m Measurement) bool
	EqualTo(m Measurement) bool

	// A nice string representation
	ToString() string
}

fundamental representation of a value in the system

type Moles

type Moles struct {
	*ConcreteMeasurement
}

mole

func NewAmount

func NewAmount(v float64, unit string) Moles

generate a new Amount in moles

func NewMoles

func NewMoles(v float64, unit string) Moles

generate a new Amount in moles

func (Moles) MarshalJSON

func (m Moles) MarshalJSON() ([]byte, error)

func (*Moles) Quantity

func (a *Moles) Quantity() Measurement

defines Moles to be a SubstanceQuantity

func (*Moles) UnmarshalJSON

func (m *Moles) UnmarshalJSON(b []byte) error

type PrefixedUnit

type PrefixedUnit interface {
	// Name get the full name of the unit
	Name() string
	// String return a string including the long name of the unit, its prefix, and symbol, e.g. "miligrams[mg]"
	String() string
	// Prefix get the SI prefix associated with the unit, or None if none, e.g. Mili
	Prefix() SIPrefix
	// PrefixedSymbol get the symbol including any prefix, e.g. "mg"
	PrefixedSymbol() string
	// RawSymbol the unit symbol excluding any prefix, e.g. "g"
	RawSymbol() string
	// BaseSISymbol returns the symbol of the appropriate unit if we ask for SI values, e.g. "kg"
	BaseSISymbol() string
}

PrefixedUnit a unit with an SI prefix

type Pressure

type Pressure struct {
	*ConcreteMeasurement
}

a Pressure structure

func NewPressure

func NewPressure(v float64, unit string) Pressure

make a new pressure in Pascals

func (Pressure) MarshalJSON

func (m Pressure) MarshalJSON() ([]byte, error)

func (*Pressure) UnmarshalJSON

func (m *Pressure) UnmarshalJSON(b []byte) error

type Rate

type Rate struct {
	*ConcreteMeasurement
}

func NewRate

func NewRate(v float64, unit string) (r Rate, err error)

func (Rate) MarshalJSON

func (m Rate) MarshalJSON() ([]byte, error)

func (*Rate) UnmarshalJSON

func (m *Rate) UnmarshalJSON(b []byte) error

type SIPrefix

type SIPrefix struct {
	Symbol string  // short version of the prefix
	Name   string  // long name of the prefix
	Value  float64 // multiplier that the exponent applies to the value
}

SIPrefix

type SortOption

type SortOption string

SortOption is an option to add to

const DescendingOrder SortOption = "DescendingOrder"

DescendingOrder is an optional argument which can be used in SortConcentrations and SortVolumes in order to sort by descending order.

type SpecificHeatCapacity

type SpecificHeatCapacity struct {
	*ConcreteMeasurement
}

a structure which defines a specific heat capacity

func NewSpecificHeatCapacity

func NewSpecificHeatCapacity(v float64, unit string) SpecificHeatCapacity

make a new specific heat capacity structure in SI units

type SubstanceQuantity

type SubstanceQuantity interface {
	Quantity() Measurement
}

mass or mole

type Temperature

type Temperature struct {
	*ConcreteMeasurement
}

temperature

func NewTemperature

func NewTemperature(v float64, unit string) Temperature

make a temperature

func (Temperature) MarshalJSON

func (m Temperature) MarshalJSON() ([]byte, error)

func (*Temperature) UnmarshalJSON

func (m *Temperature) UnmarshalJSON(b []byte) error

type Time

type Time struct {
	*ConcreteMeasurement
}

time

func AddTimes

func AddTimes(timesToAdd ...Time) (sum Time)

AddTimes sums a variable number of Time arguments. If the dimension of the times are different the product will be returned in the SI value of Time (seconds).

func CopyTime

func CopyTime(time Time) Time

CopyTime creates a safe duplicate of a time value.

func DivideTime

func DivideTime(v Time, factor float64) Time

DivideTime divides a Time by a factor.

func FromDuration

func FromDuration(t time.Duration) Time

func MultiplyTime

func MultiplyTime(v Time, factor float64) Time

MultiplyTime multiplies a Time by a factor.

func NewTime

func NewTime(v float64, unit string) (t Time)

NewTime creates a time unit.

func SubtractTimes

func SubtractTimes(timeToSubtractFrom Time, timesToSubtract ...Time) (newTime Time)

SubtractTimes subtracts a variable number of Time arguments from timeToSubtractFrom.

func (Time) AsDuration

func (t Time) AsDuration() time.Duration

func (Time) MarshalJSON

func (m Time) MarshalJSON() ([]byte, error)

func (Time) Seconds

func (t Time) Seconds() float64

func (*Time) UnmarshalJSON

func (m *Time) UnmarshalJSON(b []byte) error

type Unit

type Unit struct {
	// contains filtered or unexported fields
}

Unit everything we need to know about a unit to support it

func (*Unit) BaseSISymbol

func (self *Unit) BaseSISymbol() string

BaseSISymbol Base SI or derived unit for this property, equivalent to BaseSISymbol

func (*Unit) Copy

func (self *Unit) Copy() *Unit

Copy return a pointer to a new Unit identical to this one

func (*Unit) GobDecode

func (self *Unit) GobDecode(b []byte) error

GobDecode deserialise gob

func (*Unit) GobEncode

func (self *Unit) GobEncode() ([]byte, error)

GobEncode encode the unit as gob

func (*Unit) MarshalJSON

func (self *Unit) MarshalJSON() ([]byte, error)

MarshalJSON marshal the unit as a JSON string

func (*Unit) Name

func (self *Unit) Name() string

Name get the full name of the unit

func (*Unit) Prefix

func (self *Unit) Prefix() SIPrefix

Prefix get the SI prefix of this unit, or " " if none

func (*Unit) PrefixedSymbol

func (self *Unit) PrefixedSymbol() string

PrefixedSymbol the symbol including any prefix

func (*Unit) RawSymbol

func (self *Unit) RawSymbol() string

RawSymbol symbol without prefex, equivalent to Symbol()

func (*Unit) String

func (self *Unit) String() string

String a string representation of the unit name and symbol

func (*Unit) UnmarshalJSON

func (self *Unit) UnmarshalJSON(data []byte) error

UnmarshalJSON marshal the unit as a JSON string

type UnitRegistry

type UnitRegistry struct {
	// contains filtered or unexported fields
}

UnitRegistry store all the valid units in the library

func GetGlobalUnitRegistry

func GetGlobalUnitRegistry() *UnitRegistry

GetGlobalUnitRegistry gets the shared unit registry which contains system types

func NewUnitRegistry

func NewUnitRegistry() *UnitRegistry

NewUnitRegistry build a new empty unit registry

func (*UnitRegistry) AssertValidUnitForType

func (self *UnitRegistry) AssertValidUnitForType(measurementType, symbol string) error

AssertValidForType assert that the symbol refers to a valid unit for the given type the same as ValidUnitForType, except this function returns a useful

func (*UnitRegistry) DeclareAlias

func (self *UnitRegistry) DeclareAlias(measurementType, baseSymbol, baseTarget string, validPrefixes []SIPrefix) error

DeclareAlias declare an alias for a target symbol such that units with the alias are converted to the target. This is expected to be used when there are multiple convensions for writing a unit, for example

reg.DeclareAlias("volume", "L", "l", SIPrefixes)

will lead to all units with "L" (e.g. "uL", "mL") being converted to "l" (e.g. "ul", "ml", etc). If validPrefixes is zero length, only the base symbol will be added Note there is no value scaling, for that see DeclareDerivedUnit

func (*UnitRegistry) DeclareDerivedUnit

func (self *UnitRegistry) DeclareDerivedUnit(measurementType string, name, symbol string, validPrefixes []SIPrefix, exponent int, target string, symbolInTargets float64) error

DeclareDerivedUnit such that references to "symbol" are converted to "target" using the conversion factor symbolInTargets, for each valid prefix. The target should already exist in the Registry. If validPrefixes is nil or zero length, only the base unit will be added e.g. DeclareDerivedUnit("pint", nil, "l", 0.568) will cause the unit "1 pint" to be understood as "0.568 l"

func (*UnitRegistry) DeclareUnit

func (self *UnitRegistry) DeclareUnit(measurementType, name, baseSymbol, SISymbol string, validPrefixes []SIPrefix, exponent int) error

DeclareUnit add a unit to the registry, as well as corresponding entries for valid prefixes If validPrefixes is zero length, only the base symbol will be added

func (*UnitRegistry) GetUnit

func (self *UnitRegistry) GetUnit(symbol string) (*Unit, error)

GetUnit return the unit referred to by symbol

func (*UnitRegistry) ListValidUnitsForType

func (self *UnitRegistry) ListValidUnitsForType(measurementType string) []string

ListValidUnitsForType returns a sorted list of all valid unit symbols for a given measurement type

func (*UnitRegistry) NewMeasurement

func (self *UnitRegistry) NewMeasurement(value float64, unitSymbol string) (*ConcreteMeasurement, error)

NewMeasurement return a new typed measurement

func (*UnitRegistry) ValidUnitForType

func (self *UnitRegistry) ValidUnitForType(measurementType, symbol string) bool

ValidUnitForType return true if the given symbol represents a unit that is valid for the given measurement type e.g. ValidUnitForType("Length", "m") -> true and ValidUnitForType("Area", "l") -> false

type Velocity

type Velocity struct {
	*ConcreteMeasurement
}

func NewVelocity

func NewVelocity(v float64, unit string) Velocity

func (Velocity) MarshalJSON

func (m Velocity) MarshalJSON() ([]byte, error)

func (*Velocity) UnmarshalJSON

func (m *Velocity) UnmarshalJSON(b []byte) error

type Velocity3D

type Velocity3D struct {
	X, Y, Z Velocity
}

Velocity3D struct composed of velocities in three axes

func (*Velocity3D) Dup

func (self *Velocity3D) Dup() *Velocity3D

Dup return a copy of the velocities

func (*Velocity3D) GetAxis

func (self *Velocity3D) GetAxis(a Axis) Velocity

GetAxis return the velocity in the axis specified

func (*Velocity3D) SetAxis

func (self *Velocity3D) SetAxis(a Axis, v Velocity)

SetAxis return the velocity in the axis specified

type Voltage

type Voltage struct {
	*ConcreteMeasurement
}

func NewVoltage

func NewVoltage(value float64, unit string) (Voltage, error)

type Volume

type Volume struct {
	*ConcreteMeasurement
}

volume -- strictly speaking of course this is length^3

func AddVolumes

func AddVolumes(vols ...Volume) (newvolume Volume)

AddVolumes adds a set of volumes.

func CopyVolume

func CopyVolume(v Volume) Volume

func DivideVolume

func DivideVolume(v Volume, factor float64) (newvolume Volume)

DivideVolume divides a volume by a factor.

func MassToVolume

func MassToVolume(m Mass, d Density) (Volume, error)

MassToVolume divides a mass (in kg) by a density (in kg/m^3) and returns the volume (in L).

func MasstoVolume

func MasstoVolume(m Mass, d Density) Volume

MasstoVolume deprecated, please use MassToVolume instead

func MaxVolume

func MaxVolume(volumes []Volume) (max Volume, err error)

MaxVolume returns the highest Volume value from a set of volume values. An error will be returned if no values are specified or the base units of any of the volumes are incompatible,

func MinVolume

func MinVolume(volumes []Volume) (min Volume, err error)

MinVolume returns the lowest Volume value from a set of volume values. An error will be returned if no values are specified or the base units of any of the volumes are incompatible,

func MultiplyVolume

func MultiplyVolume(v Volume, factor float64) (newvolume Volume)

MultiplyVolume multiplies a volume by a factor.

func NewVolume

func NewVolume(v float64, unit string) Volume

make a volume

func ParseVolume

func ParseVolume(volstring string) (volume Volume, err error)

ParseVolume parses a volume and valid unit (nl, ul, ml, l) in string format; handles cases where the volume is split with a space.

func SortVolumes

func SortVolumes(volumes []Volume, descending ...SortOption) (sorted []Volume, err error)

SortVolumes sorts a set of Volume values. An error will be returned if no values are specified or the base units of any of the volumes are incompatible, An optional second argument DescendingOrder can be specified to indicate that the sorting will be in descending order. By default sorting will be in ascending order.

func SubtractVolumes

func SubtractVolumes(OriginalVol Volume, subtractvols ...Volume) (newvolume Volume)

SubtractVolumes substracts a variable number of volumes from an original volume.

func VolumeForTargetConcentration

func VolumeForTargetConcentration(targetConc Concentration, stockConc Concentration, totalVol Volume) (Volume, error)

VolumeForTargetConcentration returns the volume required to convert a starting stock concentration to a target concentration of volume total volume returns an error if the concentration units are incompatible (M/l and g/L) or if the target concentration is higher than the stock concentration unless the total volume is zero

func VolumeForTargetMass

func VolumeForTargetMass(targetMass Mass, stockConc Concentration) (Volume, error)

VolumeForTargetMass returns the volume required to convert a starting stock concentration to a solution containing a target mass. returns an error if the concentration units are not based on g/l. If the stock concentration is zero a volume of 0ul will be returned with an error. if the target mass is zero a volume of 0ul will be returned with no error.

func ZeroVolume

func ZeroVolume() Volume

func (Volume) Dup

func (v Volume) Dup() Volume

Dup deprecated, please use CopyVolume(Volume)

func (Volume) MarshalJSON

func (m Volume) MarshalJSON() ([]byte, error)

func (*Volume) UnmarshalJSON

func (m *Volume) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL