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
- Variables
- func DivideConcentrations(num, den Concentration) (float64, error)
- func DivideVolumes(vol1, vol2 Volume) (float64, error)
- func SIPrefixSymbols() []string
- func SplitValueAndUnit(str string) (float64, string)
- type Angle
- type AngularVelocity
- type Area
- type Axis
- type Concentration
- func AddConcentrations(concs ...Concentration) (Concentration, error)
- func CopyConcentration(v Concentration) Concentration
- func DivideConcentration(v Concentration, factor float64) (newconc Concentration)
- func MaxConcentration(concs []Concentration) (max Concentration, err error)
- func MinConcentration(concs []Concentration) (min Concentration, err error)
- func MultiplyConcentration(v Concentration, factor float64) (newconc Concentration)
- func NewConcentration(v float64, unit string) Concentration
- func ParseConcentration(s string) (bool, Concentration, string)
- func SortConcentrations(concs []Concentration, descending ...SortOption) (sorted []Concentration, err error)
- func SubtractConcentrations(originalConc Concentration, subtractConcs ...Concentration) (Concentration, error)
- func (c Concentration) Dup() Concentration
- func (conc Concentration) GramPerL(molecularWeight float64) Concentration
- func (conc Concentration) GramsPerLitre(molecularweight float64) (Concentration, error)
- func (m Concentration) MarshalJSON() ([]byte, error)
- func (conc Concentration) MolPerL(molecularWeight float64) Concentration
- func (conc Concentration) MolesPerLitre(molecularweight float64) (Concentration, error)
- func (m *Concentration) UnmarshalJSON(b []byte) error
- type ConcreteMeasurement
- func (cm *ConcreteMeasurement) Add(m Measurement)
- func (cm *ConcreteMeasurement) ConvertToString(s string) float64
- func (cm *ConcreteMeasurement) DecrBy(m Measurement) error
- func (cm *ConcreteMeasurement) DivideBy(factor float64)
- func (cm *ConcreteMeasurement) EqualTo(m Measurement) bool
- func (cm *ConcreteMeasurement) EqualToRounded(m Measurement, p int) bool
- func (cm *ConcreteMeasurement) EqualToTolerance(m Measurement, tol float64) bool
- func (cm *ConcreteMeasurement) GreaterThan(m Measurement) bool
- func (cm *ConcreteMeasurement) GreaterThanRounded(m Measurement, p int) bool
- func (cm *ConcreteMeasurement) InStringUnit(symbol string) (Measurement, error)
- func (cm *ConcreteMeasurement) InUnit(p PrefixedUnit) (Measurement, error)
- func (cm *ConcreteMeasurement) IncrBy(m Measurement) error
- func (cm *ConcreteMeasurement) IsNegative() bool
- func (cm *ConcreteMeasurement) IsNil() bool
- func (cm *ConcreteMeasurement) IsPositive() bool
- func (cm *ConcreteMeasurement) IsZero() bool
- func (cm *ConcreteMeasurement) LessThan(m Measurement) bool
- func (cm *ConcreteMeasurement) LessThanRounded(m Measurement, p int) bool
- func (cm *ConcreteMeasurement) MinusEpsilon() *ConcreteMeasurement
- func (cm *ConcreteMeasurement) MultiplyBy(factor float64)
- func (cm *ConcreteMeasurement) MustInStringUnit(symbol string) Measurement
- func (cm *ConcreteMeasurement) MustInUnit(p PrefixedUnit) Measurement
- func (cm *ConcreteMeasurement) PlusEpsilon() *ConcreteMeasurement
- func (cm *ConcreteMeasurement) RawValue() float64
- func (cm *ConcreteMeasurement) SIValue() float64
- func (cm *ConcreteMeasurement) SetValue(v float64) float64
- func (cm *ConcreteMeasurement) String() string
- func (cm *ConcreteMeasurement) Subtract(m Measurement)
- func (cm *ConcreteMeasurement) ToString() string
- func (cm *ConcreteMeasurement) Unit() PrefixedUnit
- type Density
- type Energy
- type FlowRate
- type Force
- type Length
- type Mass
- type Measurement
- type Moles
- type PrefixedUnit
- type Pressure
- type Rate
- type SIPrefix
- type SortOption
- type SpecificHeatCapacity
- type SubstanceQuantity
- type Temperature
- type Time
- func AddTimes(timesToAdd ...Time) (sum Time)
- func CopyTime(time Time) Time
- func DivideTime(v Time, factor float64) Time
- func FromDuration(t time.Duration) Time
- func MultiplyTime(v Time, factor float64) Time
- func NewTime(v float64, unit string) (t Time)
- func SubtractTimes(timeToSubtractFrom Time, timesToSubtract ...Time) (newTime Time)
- type Unit
- func (self *Unit) BaseSISymbol() string
- func (self *Unit) Copy() *Unit
- func (self *Unit) GobDecode(b []byte) error
- func (self *Unit) GobEncode() ([]byte, error)
- func (self *Unit) MarshalJSON() ([]byte, error)
- func (self *Unit) Name() string
- func (self *Unit) Prefix() SIPrefix
- func (self *Unit) PrefixedSymbol() string
- func (self *Unit) RawSymbol() string
- func (self *Unit) String() string
- func (self *Unit) UnmarshalJSON(data []byte) error
- type UnitRegistry
- func (self *UnitRegistry) AssertValidUnitForType(measurementType, symbol string) error
- func (self *UnitRegistry) DeclareAlias(measurementType, baseSymbol, baseTarget string, validPrefixes []SIPrefix) error
- func (self *UnitRegistry) DeclareDerivedUnit(measurementType string, name, symbol string, validPrefixes []SIPrefix, ...) error
- func (self *UnitRegistry) DeclareUnit(measurementType, name, baseSymbol, SISymbol string, validPrefixes []SIPrefix, ...) error
- func (self *UnitRegistry) GetUnit(symbol string) (*Unit, error)
- func (self *UnitRegistry) ListValidUnitsForType(measurementType string) []string
- func (self *UnitRegistry) NewMeasurement(value float64, unitSymbol string) (*ConcreteMeasurement, error)
- func (self *UnitRegistry) ValidUnitForType(measurementType, symbol string) bool
- type Velocity
- type Velocity3D
- type Voltage
- type Volume
- func AddVolumes(vols ...Volume) (newvolume Volume)
- func CopyVolume(v Volume) Volume
- func DivideVolume(v Volume, factor float64) (newvolume Volume)
- func MassToVolume(m Mass, d Density) (Volume, error)
- func MasstoVolume(m Mass, d Density) Volume
- func MaxVolume(volumes []Volume) (max Volume, err error)
- func MinVolume(volumes []Volume) (min Volume, err error)
- func MultiplyVolume(v Volume, factor float64) (newvolume Volume)
- func NewVolume(v float64, unit string) Volume
- func ParseVolume(volstring string) (volume Volume, err error)
- func SortVolumes(volumes []Volume, descending ...SortOption) (sorted []Volume, err error)
- func SubtractVolumes(OriginalVol Volume, subtractvols ...Volume) (newvolume Volume)
- func VolumeForTargetConcentration(targetConc Concentration, stockConc Concentration, totalVol Volume) (Volume, error)
- func VolumeForTargetMass(targetMass Mass, stockConc Concentration) (Volume, error)
- func ZeroVolume() Volume
Constants ¶
const Epsilon = 0.00000000001
Epsilon a small delta used when to avoid floating point errors when comparing
Variables ¶
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 )
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 ¶
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 ¶
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 (Angle) MarshalJSON ¶
func (*Angle) UnmarshalJSON ¶
type AngularVelocity ¶
type AngularVelocity struct {
*ConcreteMeasurement
}
func NewAngularVelocity ¶
func NewAngularVelocity(v float64, unit string) AngularVelocity
type Area ¶
type Area struct {
*ConcreteMeasurement
}
area
func (Area) MarshalJSON ¶
func (*Area) UnmarshalJSON ¶
type Axis ¶
type Axis int
Axis represent a particular direction
func AxisFromString ¶
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
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 ¶
func (cm *ConcreteMeasurement) InUnit(p PrefixedUnit) (Measurement, error)
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 ¶
make a new density structure in SI units
func (Density) MarshalJSON ¶
func (*Density) UnmarshalJSON ¶
type Energy ¶
type Energy struct {
*ConcreteMeasurement
}
this is really Mass Length/Time^2
func (Energy) MarshalJSON ¶
func (*Energy) UnmarshalJSON ¶
type FlowRate ¶
type FlowRate struct {
*ConcreteMeasurement
}
func NewFlowRate ¶
func (FlowRate) MarshalJSON ¶
func (*FlowRate) UnmarshalJSON ¶
type Force ¶
type Force struct {
*ConcreteMeasurement
}
a Force
func (Force) MarshalJSON ¶
func (*Force) UnmarshalJSON ¶
type Length ¶
type Length struct {
*ConcreteMeasurement
}
length
func ZeroLength ¶
func ZeroLength() Length
func (Length) MarshalJSON ¶
func (*Length) UnmarshalJSON ¶
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 VolumeToMass ¶
VolumeToMass multiplies a volume (in L) by a density (in kg/m^3) and returns the mass (in kg).
func VolumetoMass ¶
VolumetoMass deprecated, pelase use VolumeToMass
func (Mass) MarshalJSON ¶
func (*Mass) Quantity ¶
func (m *Mass) Quantity() Measurement
defines mass to be a SubstanceQuantity
func (*Mass) UnmarshalJSON ¶
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 (Moles) MarshalJSON ¶
func (*Moles) Quantity ¶
func (a *Moles) Quantity() Measurement
defines Moles to be a SubstanceQuantity
func (*Moles) UnmarshalJSON ¶
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 (Pressure) MarshalJSON ¶
func (*Pressure) UnmarshalJSON ¶
type Rate ¶
type Rate struct {
*ConcreteMeasurement
}
func (Rate) MarshalJSON ¶
func (*Rate) UnmarshalJSON ¶
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 Temperature ¶
type Temperature struct {
*ConcreteMeasurement
}
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 ¶
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 DivideTime ¶
DivideTime divides a Time by a factor.
func FromDuration ¶
func MultiplyTime ¶
MultiplyTime multiplies a Time by a factor.
func SubtractTimes ¶
SubtractTimes subtracts a variable number of Time arguments from timeToSubtractFrom.
func (Time) AsDuration ¶
func (Time) MarshalJSON ¶
func (*Time) UnmarshalJSON ¶
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 ¶
BaseSISymbol Base SI or derived unit for this property, equivalent to BaseSISymbol
func (*Unit) MarshalJSON ¶
MarshalJSON marshal the unit as a JSON string
func (*Unit) PrefixedSymbol ¶
PrefixedSymbol the symbol including any prefix
func (*Unit) UnmarshalJSON ¶
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 (Velocity) MarshalJSON ¶
func (*Velocity) UnmarshalJSON ¶
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
}
type Volume ¶
type Volume struct {
*ConcreteMeasurement
}
volume -- strictly speaking of course this is length^3
func AddVolumes ¶
AddVolumes adds a set of volumes.
func CopyVolume ¶
func DivideVolume ¶
DivideVolume divides a volume by a factor.
func MassToVolume ¶
MassToVolume divides a mass (in kg) by a density (in kg/m^3) and returns the volume (in L).
func MasstoVolume ¶
MasstoVolume deprecated, please use MassToVolume instead
func MaxVolume ¶
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 ¶
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 ¶
MultiplyVolume multiplies a volume by a factor.
func ParseVolume ¶
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 ¶
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