import "github.com/antha-lang/antha/antha/anthalib/wunit"
Package wunit is a core Antha package for dealing with units in Antha
Core Antha package for dealing with units in Antha
axis.go conversion.go parse.go serialize.go siprefix.go sort.go systemunits.go unit.go unitfromstring.go unitregistry.go wdimension.go wunit.go
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 )
SIPrefixes a list containing all valid SI prefixes
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.
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.
SIPrefixSymbols returns a list of all supported SI prefixes
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
type Angle struct { *ConcreteMeasurement }
angle
generate a new angle unit
type AngularVelocity struct { *ConcreteMeasurement }
func NewAngularVelocity(v float64, unit string) AngularVelocity
type Area struct { *ConcreteMeasurement }
area
make an area unit
Axis represent a particular direction
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
String return the name of the axis
type Concentration struct { *ConcreteMeasurement }
defines a concentration unit
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(v Concentration) Concentration
func DivideConcentration(v Concentration, factor float64) (newconc Concentration)
DivideConcentration divides a concentration by a factor.
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(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(v Concentration, factor float64) (newconc Concentration)
MultiplyConcentration multiplies a concentration by a factor.
func NewConcentration(v float64, unit string) Concentration
NewConcentration makes a new concentration in SI units... either M/l or kg/l
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(concs []Concentration) (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.
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 (c Concentration) Dup() Concentration
Dup deprecated, please use CopyConcentration
func (conc Concentration) GramPerL(molecularWeight float64) Concentration
GramPerL deprecated, please use 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 (m Concentration) MarshalJSON() ([]byte, error)
func (conc Concentration) MolPerL(molecularWeight float64) Concentration
MolPerL deprecated, please use 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 (m *Concentration) UnmarshalJSON(b []byte) error
type ConcreteMeasurement struct { // the raw value Mvalue float64 // the relevant units Munit *Unit }
structure implementing the Measurement interface
func NewMeasurement(v float64, pu string) *ConcreteMeasurement
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 (cm *ConcreteMeasurement) Add(m Measurement)
Add deprecated, please use IncrBy
func (cm *ConcreteMeasurement) ConvertToString(s string) float64
ConvertToString deprecated, please use InStringUnit
func (cm *ConcreteMeasurement) DecrBy(m Measurement) error
DecrBy subtract m from the receiver
func (cm *ConcreteMeasurement) DivideBy(factor float64)
func (cm *ConcreteMeasurement) EqualTo(m Measurement) bool
XXX This should be made more literal and rounded behaviour explicitly called for by user
func (cm *ConcreteMeasurement) EqualToRounded(m Measurement, p int) bool
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 (cm *ConcreteMeasurement) GreaterThan(m Measurement) bool
func (cm *ConcreteMeasurement) GreaterThanRounded(m Measurement, p int) bool
func (cm *ConcreteMeasurement) InStringUnit(symbol string) (Measurement, error)
InStringUnit return a new measurement in the new units
func (cm *ConcreteMeasurement) InUnit(p PrefixedUnit) (Measurement, error)
ConvertTo return a new measurement in the new units
func (cm *ConcreteMeasurement) IncrBy(m Measurement) error
IncrBy add the measurement m to the receiver
func (cm *ConcreteMeasurement) IsNegative() bool
IsNegative true if the measurement is negative by more than a very small delta
func (cm *ConcreteMeasurement) IsNil() bool
func (cm *ConcreteMeasurement) IsPositive() bool
IsPositive true if the measurement is positive by more than a very small delta
func (cm *ConcreteMeasurement) IsZero() bool
func (cm *ConcreteMeasurement) LessThan(m Measurement) bool
func (cm *ConcreteMeasurement) LessThanRounded(m Measurement, p int) bool
func (cm *ConcreteMeasurement) MultiplyBy(factor float64)
multiply
func (cm *ConcreteMeasurement) MustInStringUnit(symbol string) Measurement
MustInStringUnit return a new measurement in the new units
func (cm *ConcreteMeasurement) MustInUnit(p PrefixedUnit) Measurement
MustInUnit convert to the given unit, calls panic() if the units are not compatible
func (cm *ConcreteMeasurement) RawValue() float64
value without conversion
func (cm *ConcreteMeasurement) SIValue() float64
value when converted to SI units
func (cm *ConcreteMeasurement) SetValue(v float64) float64
set the value of this measurement
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 (cm *ConcreteMeasurement) Subtract(m Measurement)
Subtract deprecated, please use DecrBy
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 (cm *ConcreteMeasurement) Unit() PrefixedUnit
get unit with prefix
type Density struct { *ConcreteMeasurement }
a structure which defines a density
make a new density structure in SI units
type Energy struct { *ConcreteMeasurement }
this is really Mass Length/Time^2
make a new energy unit
type FlowRate struct { *ConcreteMeasurement }
type Force struct { *ConcreteMeasurement }
a Force
a new force in Newtons
type Length struct { *ConcreteMeasurement }
length
make a length
type Mass struct { *ConcreteMeasurement }
mass
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.
VolumeToMass multiplies a volume (in L) by a density (in kg/m^3) and returns the mass (in kg).
VolumetoMass deprecated, pelase use VolumeToMass
func (m *Mass) Quantity() Measurement
defines mass to be a SubstanceQuantity
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 struct { *ConcreteMeasurement }
mole
generate a new Amount in moles
generate a new Amount in moles
func (a *Moles) Quantity() Measurement
defines Moles to be a SubstanceQuantity
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 struct { *ConcreteMeasurement }
a Pressure structure
make a new pressure in Pascals
type Rate struct { *ConcreteMeasurement }
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 SpecificHeatCapacity struct { *ConcreteMeasurement }
a structure which defines a specific heat capacity
func NewSpecificHeatCapacity(v float64, unit string) SpecificHeatCapacity
make a new specific heat capacity structure in SI units
type SubstanceQuantity interface { Quantity() Measurement }
mass or mole
type Temperature struct { *ConcreteMeasurement }
temperature
func NewTemperature(v float64, unit string) Temperature
make a temperature
func (m Temperature) MarshalJSON() ([]byte, error)
func (m *Temperature) UnmarshalJSON(b []byte) error
type Time struct { *ConcreteMeasurement }
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).
CopyTime creates a safe duplicate of a time value.
DivideTime divides a Time by a factor.
MultiplyTime multiplies a Time by a factor.
NewTime creates a time unit.
SubtractTimes subtracts a variable number of Time arguments from timeToSubtractFrom.
type Unit struct {
// contains filtered or unexported fields
}
Unit everything we need to know about a unit to support it
BaseSISymbol Base SI or derived unit for this property, equivalent to BaseSISymbol
Copy return a pointer to a new Unit identical to this one
GobDecode deserialise gob
GobEncode encode the unit as gob
MarshalJSON marshal the unit as a JSON string
Name get the full name of the unit
Prefix get the SI prefix of this unit, or " " if none
PrefixedSymbol the symbol including any prefix
RawSymbol symbol without prefex, equivalent to Symbol()
String a string representation of the unit name and symbol
UnmarshalJSON marshal the unit as a JSON string
type UnitRegistry struct {
// contains filtered or unexported fields
}
UnitRegistry store all the valid units in the library
func GetGlobalUnitRegistry() *UnitRegistry
GetGlobalUnitRegistry gets the shared unit registry which contains system types
func NewUnitRegistry() *UnitRegistry
NewUnitRegistry build a new empty unit registry
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 (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 (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 (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 (self *UnitRegistry) GetUnit(symbol string) (*Unit, error)
GetUnit return the unit referred to by symbol
func (self *UnitRegistry) ListValidUnitsForType(measurementType string) []string
ListValidUnitsForType returns a sorted list of all valid unit symbols for a given measurement type
func (self *UnitRegistry) NewMeasurement(value float64, unitSymbol string) (*ConcreteMeasurement, error)
NewMeasurement return a new typed measurement
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 struct { *ConcreteMeasurement }
Velocity3D struct composed of velocities in three axes
func (self *Velocity3D) Dup() *Velocity3D
Dup return a copy of the velocities
func (self *Velocity3D) GetAxis(a Axis) Velocity
GetAxis return the velocity in the axis specified
func (self *Velocity3D) SetAxis(a Axis, v Velocity)
SetAxis return the velocity in the axis specified
type Voltage struct { *ConcreteMeasurement }
type Volume struct { *ConcreteMeasurement }
volume -- strictly speaking of course this is length^3
AddVolumes adds a set of volumes.
DivideVolume divides a volume by a factor.
MassToVolume divides a mass (in kg) by a density (in kg/m^3) and returns the volume (in L).
MasstoVolume deprecated, please use MassToVolume instead
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,
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,
MultiplyVolume multiplies a volume by a factor.
make a volume
ParseVolume parses a volume and valid unit (nl, ul, ml, l) in string format; handles cases where the volume is split with a space.
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,
SubtractVolumes substracts a variable number of volumes from an original volume.
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(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.
Dup deprecated, please use CopyVolume(Volume)
Package wunit imports 12 packages (graph) and is imported by 26 packages. Updated 2019-01-29. Refresh now. Tools for package owners.