Revision history [back]

Define custom unit

Is it possible to declare custom units that can be converted to SI base units? For example: if I want to measure time in ticks and I know that one tick is exactly one nanosecond, can I create a unit 'tick' that can later be converted to seconds?

I know that a custom unit can be declared with

sage: sage.symbolic.units.str_to_unit('tick')
tick


I also know that predefined units can be converted, for example by

sage: units.time.minute.convert(units.time.second)
60*second


However, I want to be able to declare a unit that has both its own name and that can be converted to other units.

sage: tick = sage.symbolic.units.str_to_unit('tick')
sage: tick
tick
sage: #(define relation to SI units here)
sage: tick.convert(units.time.second)
(ValueError: Incompatible units)


Is it possible to define a unit ‘tick’ that can be converted to seconds in this manner?