units

class Angle(value: float | int, unit: str)

Bases: AngularPosition

Angle object.

Attributes

unitstr

Symbol of the unit of measurement for angle.

valuefloat or int

Angle numerical value.

Methods

to()

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

sin()

It computes the sine of the angle at a given frequency.

cos()

It computes the cosine of the angle at a given frequency.

tan()

It computes the tangent of the angle at a given frequency.

cos(frequency: float | int | None = 0.15915494309189535) float

It computes the cosine of the angle at a given frequency.

Parameters

frequencyfloat or int, optional

Frequency to multiply by before computing the cosine. Default is \(\frac{1}{2 \pi}\).

Returns

float

Computed cosine of the angle.

sin(frequency: float | int | None = 0.15915494309189535) float

It computes the sine of the angle at a given frequency.

Parameters

frequencyfloat or int, optional

Frequency to multiply by before computing the sine. Default is \(\frac{1}{2 \pi}\).

Returns

float

Computed sine of the angle.

tan(frequency: float | int | None = 0.15915494309189535) float

It computes the tangent of the angle at a given frequency.

Parameters

frequencyfloat or int, optional

Frequency to multiply by before computing the tangent. Default is \(\frac{1}{2 \pi}\).

Returns

float

Computed tangent of the angle.

to(target_unit: str, inplace: bool = False) Angle

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

If inplace is True, it overrides actual value and unit, otherwise it returns a new instance with the converted value and the target_unit as unit.

Parameters

target_unitstr

Target unit to which convert the current value.

inplacebool, optional

Whether to override the current instance value. Default is False, so it does not override the current value.

Returns

Angle

Converted angle.

Raises

TypeError
  • If target_unit is not a str,

  • if inplace is not a bool.

KeyError

If the target_unit is not among available ones.

Examples

Angle instantiation.

>>> from gearpy.units import Angle
>>> a = Angle(180, 'deg')
>>> a
180 deg

Conversion from degree to radian with inplace=False by default, so it does not override the current value.

>>> a.to('rad')
3.141592653589793 rad
>>> a
180 deg

Conversion from degree to minute of arc with inplace=True, in order to override the current value.

>>> a.to('arcmin', inplace=True)
10800.0 arcmin
>>> a
10800.0 arcmin
property unit: str

Symbol of the unit of measurement for angle. It must be a str. Available units are:

  • 'rad' for radian,

  • 'deg' for degree,

  • 'arcmin' for minute of arc,

  • 'arcsec' for second of arc,

  • 'rot' for rotation.

Returns

str

Symbol of the unit of measurement for angle.

Raises

TypeError

If unit is not a str.

KeyError

If the unit is not among available ones.

property value: float | int

Angle numerical value. The relative unit is expressed by the unit property. It must be positive or null.

Returns

float or int

Angle numerical value.

Raises

TypeError

If value is not a float or an int.

ValueError

If value is negative.

class AngularAcceleration(value: float | int, unit: str)

Bases: UnitBase

AngularAcceleration object.

Attributes

unitstr

Symbol of the unit of measurement for angular acceleration.

valuefloat or int

Angular acceleration numerical value.

Methods

to()

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

to(target_unit: str, inplace: bool = False) AngularAcceleration

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

If inplace is True, it overrides actual value and unit, otherwise it returns a new instance with the converted value and the target_unit as unit.

Parameters

target_unitstr

Target unit to which convert the current value.

inplacebool, optional

Whether to override the current instance value. Default is False, so it does not override the current value.

Returns

AngularAcceleration

Converted angular acceleration.

Raises

TypeError
  • If target_unit is not a str,

  • if inplace is not a bool.

KeyError

If the target_unit is not among available ones.

Examples

AngularAcceleration instantiation.

>>> from gearpy.units import AngularAcceleration
>>> a = AngularAcceleration(180, 'deg/s^2')
>>> a
180 deg/s^2

Conversion from degree per second squared to radian per second squared with inplace=False by default, so it does not override the current value.

>>> a.to('rad/s^2')
3.141592653589793 rad/s^2
>>> a
180 deg/s^2

Conversion from degree per second squared to radian per second squared with inplace=True, in order to override the current value.

>>> a.to('rad/s^2', inplace=True)
3.141592653589793 rad/s^2
>>> a
3.141592653589793 rad/s^2
property unit: str

Symbol of the unit of measurement for angular acceleration. It must be a str. Available units are:

  • 'rad/s^2' for radian per second squared,

  • 'deg/s^2' for degree per second squared,

  • 'rot/s^2' for rotation per second squared.

Returns

str

Symbol of the unit of measurement for angular acceleration.

Raises

TypeError

If unit is not a str.

KeyError

If the unit is not among available ones.

property value: float | int

Angular acceleration numerical value. The relative unit is expressed by the unit property.

Returns

float or int

Angular acceleration numerical value.

Raises

TypeError

If value is not a float or an int.

class AngularPosition(value: float | int, unit: str)

Bases: UnitBase

AngularPosition object.

Attributes

unitstr

Symbol of the unit of measurement for angular position.

valuefloat or int

Angular position numerical value.

Methods

to()

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

sin()

It computes the sine of the angular position at a given frequency.

cos()

It computes the cosine of the angular position at a given frequency.

tan()

It computes the tangent of the angular position at a given frequency.

cos(frequency: float | int | None = 0.15915494309189535) float

It computes the cosine of the angular position at a given frequency.

Parameters

frequencyfloat or int, optional

Frequency to multiply by before computing the cosine. Default is \(\frac{1}{2 \pi}\).

Returns

float

Computed cosine of the angular position.

sin(frequency: float | int | None = 0.15915494309189535) float

It computes the sine of the angular position at a given frequency.

Parameters

frequencyfloat or int, optional

Frequency to multiply by before computing the sine. Default is \(\frac{1}{2 \pi}\).

Returns

float

Computed sine of the angular position.

tan(frequency: float | int | None = 0.15915494309189535) float

It computes the tangent of the angular position at a given frequency.

Parameters

frequencyfloat or int, optional

Frequency to multiply by before computing the tangent. Default is \(\frac{1}{2 \pi}\).

Returns

float

Computed tangent of the angular position.

to(target_unit: str, inplace: bool = False) AngularPosition

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

If inplace is True, it overrides actual value and unit, otherwise it returns a new instance with the converted value and the target_unit as unit.

Parameters

target_unitstr

Target unit to which convert the current value.

inplacebool, optional

Whether to override the current instance value. Default is False, so it does not override the current value.

Returns

AngularPosition

Converted angular position.

Raises

TypeError
  • If target_unit is not a str,

  • if inplace is not a bool.

KeyError

If the target_unit is not among available ones.

Examples

AngularPosition instantiation.

>>> from gearpy.units import AngularPosition
>>> p = AngularPosition(180, 'deg')
>>> p
180 deg

Conversion from degree to radian with inplace=False by default, so it does not override the current value.

>>> p.to('rad')
3.141592653589793 rad
>>> p
180 deg

Conversion from degree to minute of arc with inplace=True, in order to override the current value.

>>> p.to('arcmin', inplace=True)
10800.0 arcmin
>>> p
10800.0 arcmin
property unit: str

Symbol of the unit of measurement for angular position. It must be a str. Available units are:

  • 'rad' for radian,

  • 'deg' for degree,

  • 'arcmin' for minute of arc,

  • 'arcsec' for second of arc,

  • 'rot' for rotation.

Returns

str

Symbol of the unit of measurement for angular position.

Raises

TypeError

If unit is not a str.

KeyError

If the unit is not among available ones.

property value: float | int

Angular position numerical value. The relative unit is expressed by the unit property.

Returns

float or int

Angular position numerical value.

Raises

TypeError

If value is not a float or an int.

class AngularSpeed(value: float | int, unit: str)

Bases: UnitBase

AngularSpeed object.

Attributes

unitstr

Symbol of the unit of measurement for angular speed.

valuefloat or int

Angular speed numerical value.

Methods

to()

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

to(target_unit: str, inplace: bool = False) AngularSpeed

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

If inplace is True, it overrides actual value and unit, otherwise it returns a new instance with the converted value and the target_unit as unit.

Parameters

target_unitstr

Target unit to which convert the current value.

inplacebool, optional

Whether to override the current instance value. Default is False, so it does not override the current value.

Returns

AngularSpeed

Converted angular speed.

Raises

TypeError
  • If target_unit is not a str,

  • if inplace is not a bool.

KeyError

If the target_unit is not among available ones.

Examples

AngularSpeed instantiation.

>>> from gearpy.units import AngularSpeed
>>> s = AngularSpeed(1000, 'rpm')
>>> s
1000 rpm

Conversion from revolutions per minute to radian per second with inplace=False by default, so it does not override the current value.

>>> s.to('rad/s')
104.71975511965977 rad/s
>>> s
1000 rpm

Conversion from revolutions per minute to revolutions per second with inplace=True, in order to override the current value.

>>> s.to('rps', inplace=True)
16.666666666666664 rps
>>> s
16.666666666666664 rps
property unit: str

Symbol of the unit of measurement for angular speed. It must be a str. Available units are:

  • 'rad/s' for radian per second,

  • 'rad/min' for radian per minute,

  • 'rad/h' for radian per hour,

  • 'deg/s' for degree per second,

  • 'deg/min' for degree per minute,

  • 'deg/h' for degree per hour,

  • 'rps' for revolutions per second,

  • 'rpm' for revolutions per minute,

  • 'rph' for revolutions per hour.

Returns

str

Symbol of the unit of measurement for angular speed.

Raises

TypeError

If unit is not a str.

KeyError

If the unit is not among available ones.

property value: float | int

Angular speed numerical value. The relative unit is expressed by the unit property.

Returns

float or int

Angular speed numerical value.

Raises

TypeError

If value is not a float or an int.

class Current(value: float | int, unit: str)

Bases: UnitBase

Current object.

Attributes

unitstr

Symbol of the unit of measurement for electrical current.

valuefloat or int

Electrical current numerical value.

Methods

to()

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

to(target_unit: str, inplace: bool = False) Current

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

If inplace is True, it overrides actual value and unit, otherwise it returns a new instance with the converted value and the target_unit as unit.

Parameters

target_unitstr

Target unit to which convert the current value.

inplacebool, optional

Whether to override the current instance value. Default is False, so it does not override the current value.

Returns

Current

Converted electrical current.

Raises

TypeError
  • If target_unit is not a str,

  • if inplace is not a bool.

KeyError

If the target_unit is not among available ones.

Examples

Current instantiation.

>>> from gearpy.units import Current
>>> i = Current(1, 'A')
>>> i
1 A

Conversion from ampere to milli-ampere with inplace=False by default, so it does not override the current value.

>>> i.to('mA')
1000.0 mA
>>> i
1 A

Conversion from ampere to milli-ampere with inplace=True, in order to override the current value.

>>> i.to('mA', inplace=True)
1000.0 mA
>>> i
1000.0 mA
property unit: str

Symbol of the unit of measurement for electrical current. It must be a str. Available units are:

  • 'A' for ampere,

  • 'mA' for milli-ampere,

  • 'uA' for micro-ampere.

Returns

str

Symbol of the unit of measurement for electrical current.

Raises

TypeError

If unit is not a str.

KeyError

If the unit is not among available ones.

property value: float | int

Electrical current numerical value. The relative unit is expressed by the unit property.

Returns

float or int

Electrical current numerical value.

Raises

TypeError

If value is not a float or an int.

class Force(value: float | int, unit: str)

Bases: UnitBase

Force object.

Attributes

unitstr

Symbol of the unit of measurement for force.

valuefloat or int

Force numerical value.

Methods

to()

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

to(target_unit: str, inplace: bool = False) Force

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

If inplace is True, it overrides actual value and unit, otherwise it returns a new instance with the converted value and the target_unit as unit.

Parameters

target_unitstr

Target unit to which convert the current value.

inplacebool, optional

Whether to override the current instance value. Default is False, so it does not override the current value.

Returns

Force

Converted force.

Raises

TypeError
  • If target_unit is not a str,

  • if inplace is not a bool.

KeyError

If the target_unit is not among available ones.

Examples

Force instantiation.

>>> from gearpy.units import Force
>>> f = Force(1, 'N')
>>> f
1 N

Conversion from newton to kilogram force with inplace=False by default, so it does not override the current value.

>>> f.to('kgf')
0.10197162129779283 kgf
>>> f
1 N

Conversion from newton to kilogram force with inplace=True, in order to override the current value.

>>> f.to('kgf', inplace=True)
0.10197162129779283 kgf
>>> f
0.10197162129779283 kgf
property unit: str

Symbol of the unit of measurement for force. It must be a str. Available units are:

  • 'N' for newton,

  • 'mN' for milli-newton,

  • 'kN' for kilo-newton,

  • 'kgf' for kilogram force,

  • 'gf' for gram force.

Returns

str

Symbol of the unit of measurement for force.

Raises

TypeError

If unit is not a str.

KeyError

If the unit is not among available ones.

property value: float | int

Force numerical value. The relative unit is expressed by the unit property.

Returns

float or int

Force numerical value.

Raises

TypeError

If value is not a float or an int.

class InertiaMoment(value: float | int, unit: str)

Bases: UnitBase

InertiaMoment object.

Attributes

unitstr

Symbol of the unit of measurement for moment of inertia.

valuefloat or int

Moment of inertia numerical value.

Methods

to()

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

to(target_unit: str, inplace: bool = False) InertiaMoment

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

If inplace is True, it overrides actual value and unit, otherwise it returns a new instance with the converted value and the target_unit as unit.

Parameters

target_unitstr

Target unit to which convert the current value.

inplacebool, optional

Whether to override the current instance value. Default is False, so it does not override the current value.

Returns

InertiaMoment

Converted moment of inertia.

Raises

TypeError
  • If target_unit is not a str,

  • if inplace is not a bool.

KeyError

If the target_unit is not among available ones.

Examples

InertiaMoment instantiation.

>>> from gearpy.units import InertiaMoment
>>> i = InertiaMoment(1, 'kgm^2')
>>> i
1 kgm^2

Conversion from kilogram-square meter to gram-square meter with inplace=False by default, so it does not override the current value.

>>> i.to('gm^2')
1000.0 gm^2
>>> i
1 kgm^2

Conversion from kilograms-square meter to gram-square meter with inplace=True, in order to override the current value.

>>> i.to('gm^2', inplace=True)
1000.0 gm^2
>>> i
1000.0 gm^2
property unit: str

Symbol of the unit of measurement for moment of inertia. It must be a str. Available units are:

  • 'kgm^2' for kilogram-square meter,

  • 'kgdm^2' for kilogram-square decimeter,

  • 'kgcm^2' for kilogram-square centimeter,

  • 'kgmm^2' for kilogram-square millimeter,

  • 'gm^2' for gram-square meter,

  • 'gdm^2' for gram-square decimeter,

  • 'gcm^2' for gram-square centimeter,

  • 'gmm^2' for gram-square millimeter.

Returns

str

Symbol of the unit of measurement for moment of inertia.

Raises

TypeError

If unit is not a str.

KeyError

If the unit is not among available ones.

property value: float | int

Moment of inertia numerical value. The relative unit is expressed by the unit property. It must be positive.

Returns

float or int

Moment of inertia numerical value.

Raises

TypeError

If value is not a float or an int.

ValueError

If value is negative or null.

class Length(value: float | int, unit: str)

Bases: UnitBase

Length object.

Attributes

unitstr

Symbol of the unit of measurement for length.

valuefloat or int

Length numerical value.

Methods

to()

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

to(target_unit: str, inplace: bool = False) Length

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

If inplace is True, it overrides actual value and unit, otherwise it returns a new instance with the converted value and the target_unit as unit.

Parameters

target_unitstr

Target unit to which convert the current value.

inplacebool, optional

Whether to override the current instance value. Default is False, so it does not override the current value.

Returns

Length

Converted length.

Raises

TypeError
  • If target_unit is not a str,

  • if inplace is not a bool.

KeyError

If the target_unit is not among available ones.

Examples

Length instantiation.

>>> from gearpy.units import Length
>>> l = Length(1, 'm')
>>> l
1 m

Conversion from meter to centimeter with inplace=False by default, so it does not override the current value.

>>> l.to('cm')
100.0 cm
>>> l
1 m

Conversion from meter to centimeter with inplace=True, in order to override the current value.

>>> l.to('cm', inplace=True)
100.0 cm
>>> l
100.0 cm
property unit: str

Symbol of the unit of measurement for length. It must be a str. Available units are:

  • 'm' for meter,

  • 'dm' for decimeter,

  • 'cm' for centimeter,

  • 'mm' for millimeter.

Returns

str

Symbol of the unit of measurement for length.

Raises

TypeError

If unit is not a str.

KeyError

If the unit is not among available ones.

property value: float | int

Length numerical value. The relative unit is expressed by the unit property. It must be positive.

Returns

float or int

Length numerical value.

Raises

TypeError

If value is not a float or an int.

ValueError

If value is negative or null.

class Stress(value: float | int, unit: str)

Bases: UnitBase

Stress object.

Attributes

unitstr

Symbol of the unit of measurement for stress.

valuefloat or int

Stress numerical value.

Methods

to()

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

to(target_unit: str, inplace: bool = False) Stress

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

If inplace is True, it overrides actual value and unit, otherwise it returns a new instance with the converted value and the target_unit as unit.

Parameters

target_unitstr

Target unit to which convert the current value.

inplacebool, optional

Whether to override the current instance value. Default is False, so it does not override the current value.

Returns

Stress

Converted stress.

Raises

TypeError
  • If target_unit is not a str,

  • if inplace is not a bool.

KeyError

If the target_unit is not among available ones.

Examples

Stress instantiation.

>>> from gearpy.units import Stress
>>> s = Stress(1, 'GPa')
>>> s
1 GPa

Conversion from giga-pascal to mega-pascal with inplace=False by default, so it does not override the current value.

>>> s.to('MPa')
1000.0 MPa
>>> s
1 GPa

Conversion from giga-pascal to mega-pascal with inplace=True, in order to override the current value.

>>> s.to('MPa', inplace=True)
1000.0 MPa
>>> s
1000.0 MPa
property unit: str

Symbol of the unit of measurement for stress. It must be a str. Available units are:

  • 'Pa' for pascal,

  • 'kPa' for kilo-pascal,

  • 'MPa' for mega-pascal,

  • 'GPa' for giga-pascal.

Returns

str

Symbol of the unit of measurement for stress.

Raises

TypeError

If unit is not a str.

KeyError

If the unit is not among available ones.

property value: float | int

Stress numerical value. The relative unit is expressed by the unit property.

Returns

float or int

Stress numerical value.

Raises

TypeError

If value is not a float or an int.

class Surface(value: float | int, unit: str)

Bases: UnitBase

Surface object.

Attributes

unitstr

Symbol of the unit of measurement for surface.

valuefloat or int

Surface numerical value.

Methods

to()

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

to(target_unit: str, inplace: bool = False) Surface

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

If inplace is True, it overrides actual value and unit, otherwise it returns a new instance with the converted value and the target_unit as unit.

Parameters

target_unitstr

Target unit to which convert the current value.

inplacebool, optional

Whether to override the current instance value. Default is False, so it does not override the current value.

Returns

Surface

Converted surface.

Raises

TypeError
  • If target_unit is not a str,

  • if inplace is not a bool.

KeyError

If the target_unit is not among available ones.

Examples

Surface instantiation.

>>> from gearpy.units import Surface
>>> s = Surface(1, 'm^2')
>>> s
1 m^2

Conversion from square meter to square millimeter with inplace=False by default, so it does not override the current value.

>>> s.to('mm^2')
1000000.0 mm^2
>>> s
1 m^2

Conversion from square meter to square millimeter with inplace=True, in order to override the current value.

>>> s.to('mm^2', inplace=True)
1000000.0 mm^2
>>> s
1000000.0 mm^2
property unit: str

Symbol of the unit of measurement for surface. It must be a str. Available units are:

  • 'm^2' for square meter,

  • 'dm^2' for square decimeter,

  • 'cm^2' for square centimeter,

  • 'mm^2' for square millimeter.

Returns

str

Symbol of the unit of measurement for surface.

Raises

TypeError

If unit is not a str.

KeyError

If the unit is not among available ones.

property value: float | int

Surface numerical value. The relative unit is expressed by the unit property. It must be positive.

Returns

float or int

Surface numerical value.

Raises

TypeError

If value is not a float or an int.

ValueError

If value is negative or null.

class Time(value: float | int, unit: str)

Bases: UnitBase

Time object.

Attributes

unitstr

Symbol of the unit of measurement for time.

valuefloat or int

Time numerical value.

Methods

to()

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

to(target_unit: str, inplace: bool = False) Time

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

If inplace is True, it overrides actual value and unit, otherwise it returns a new instance with the converted value and the target_unit as unit.

Parameters

target_unitstr

Target unit to which convert the current value.

inplacebool, optional

Whether to override the current instance value. Default is False, so it does not override the current value.

Returns

Time

Converted time.

Raises

TypeError
  • If target_unit is not a str,

  • if inplace is not a bool.

KeyError

If the target_unit is not among available ones.

Examples

Time instantiation.

>>> from gearpy.units import Time
>>> t = Time(1, 'hour')
>>> t
1 hour

Conversion from hour to second with inplace=False by default, so it does not override the current value.

>>> t.to('sec')
3600.0 sec
>>> t
1 hour

Conversion from hour to second with inplace=True, in order to override the current value.

>>> t.to('sec', inplace=True)
3600.0 sec
>>> t
3600.0 sec
property unit: str

Symbol of the unit of measurement for time. It must be a str. Available units are:

  • 'sec' for second,

  • 'min' for minute,

  • 'hour' for hour,

  • 'ms' for millisecond.

Returns

str

Symbol of the unit of measurement for time.

Raises

TypeError

If unit is not a str.

KeyError

If the unit is not among available ones.

property value: float | int

Time numerical value. The relative unit is expressed by the unit property.

Returns

float or int

Time numerical value.

Raises

TypeError

If value is not a float or an int.

class TimeInterval(value: float | int, unit: str)

Bases: Time

TimeInterval object.

Attributes

unitstr

Symbol of the unit of measurement for time interval.

valuefloat or int

Time interval numerical value.

Methods

to()

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

to(target_unit: str, inplace: bool = False) TimeInterval

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

If inplace is True, it overrides actual value and unit, otherwise it returns a new instance with the converted value and the target_unit as unit.

Parameters

target_unitstr

Target unit to which convert the current value.

inplacebool, optional

Whether to override the current instance value. Default is False, so it does not override the current value.

Returns

TimeInterval

Converted time interval.

Raises

TypeError
  • If target_unit is not a str,

  • if inplace is not a bool.

KeyError

If the target_unit is not among available ones.

Examples

TimeInterval instantiation.

>>> from gearpy.units import TimeInterval
>>> dt = TimeInterval(1, 'hour')
>>> dt
1 hour

Conversion from hour to second with inplace=False by default, so it does not override the current value.

>>> dt.to('sec')
3600.0 sec
>>> dt
1 hour

Conversion from hour to second with inplace=True, in order to override the current value.

>>> dt.to('sec', inplace=True)
3600.0 sec
>>> dt
3600.0 sec
property unit: str

Symbol of the unit of measurement for time interval. It must be a str. Available units are:

  • 'sec' for second,

  • 'min' for minute,

  • 'hour' for hour,

  • 'ms' for millisecond.

Returns

str

Symbol of the unit of measurement for time interval.

Raises

TypeError

If unit is not a str.

KeyError

If the unit is not among available ones.

property value: float | int

Time interval numerical value. The relative unit is expressed by the unit property. It must be positive.

Returns

float or int

Time interval numerical value.

Raises

TypeError

If value is not a float or an int.

ValueError

If value is negative or null.

class Torque(value: float | int, unit: str)

Bases: UnitBase

Torque object.

Attributes

unitstr

Symbol of the unit of measurement for torque.

valuefloat or int

Torque numerical value.

Methods

to()

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

to(target_unit: str, inplace: bool = False) Torque

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

If inplace is True, it overrides actual value and unit, otherwise it returns a new instance with the converted value and the target_unit as unit.

Parameters

target_unitstr

Target unit to which convert the current value.

inplacebool, optional

Whether to override the current instance value. Default is False, so it does not override the current value.

Returns

Torque

Converted torque.

Raises

TypeError
  • If target_unit is not a str,

  • if inplace is not a bool.

KeyError

If the target_unit is not among available ones.

Examples

Torque instantiation.

>>> from gearpy.units import Torque
>>> T = Torque(1, 'Nm')
>>> T
1 Nm

Conversion from newton-meter to kilogram force-meter with inplace=False by default, so it does not override the current value.

>>> T.to('kgfm')
0.10197162129779283 kgfm
>>> T
1 Nm

Conversion from newton-meter to kilogram force-meter with inplace=True, in order to override the current value.

>>> T.to('kgfm', inplace=True)
0.10197162129779283 kgfm
>>> T
0.10197162129779283 kgfm
property unit: str

Symbol of the unit of measurement for Torque. It must be a str. Available units are:

  • 'Nm' for newton-meter,

  • 'mNm' for milli-newton-meter,

  • 'mNdm' for milli-newton-decimeter,

  • 'mNcm' for milli-newton-centimeter,

  • 'mNmm' for milli-newton-millimeter,

  • 'kNm' for kilo-newton-meter,

  • 'kNdm' for kilo-newton-decimeter,

  • 'kNcm' for kilo-newton-centimeter,

  • 'kNmm' for kilo-newton-millimeter,

  • 'kgfm' for kilogram force-meter,

  • 'kgfdm' for kilogram force-decimeter,

  • 'kgfcm' for kilogram force-centimeter,

  • 'kgfmm' for kilogram force-millimeter,

  • 'gfm' for gram force-meter,

  • 'gfdm' for gram force-decimeter,

  • 'gfcm' for gram force-centimeter,

  • 'gfmm' for gram force-millimeter.

Returns

str

Symbol of the unit of measurement for torque.

Raises

TypeError

If unit is not a str.

KeyError

If the unit is not among available ones.

property value: float | int

Torque numerical value. The relative unit is expressed by the unit property.

Returns

float or int

Torque numerical value.

Raises

TypeError

If value is not a float or an int.

class UnitBase(value: float | int, unit: str)

Bases: ABC

UnitBase object.

Abstract base class for creating unit objects.

abstractmethod to(target_unit: str, inplace: bool = False) None
abstract property unit: None
abstract property value: None