Define custom unit

asked 2018-05-13 02:03:59 +0200

johanneh gravatar image

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?

edit retag flag offensive close merge delete