faninsar.constants.Wavelength#

class faninsar.constants.Wavelength(data: float, unit: Literal['m', 'cm', 'dm', 'mm'] = 'm')[source]#

Bases: object

Dataclass for wavelength with unit conversion capabilities.

This class represents a wavelength value with its associated unit and provides methods for converting between different wavelength units and to frequency. The class is immutable (frozen) and hashable, allowing instances to be used as dictionary keys or in sets.

data#

The numerical value of the wavelength.

Type:

float

unit#

The unit of the wavelength. Default is “m” (meters).

Type:

Literal[“m”, “cm”, “dm”, “mm”]

Examples

>>> wl = Wavelength(5.5, "cm")
>>> wl.to_mm()
Wavelength(data=55.0, unit='mm')
>>> wl.to_m()
Wavelength(data=0.055, unit='m')
>>> str(wl)
'5.5 cm'
>>> # Can be used as dictionary key
>>> wavelengths = {wl: "C-band"}
>>> # Equality comparison
>>> Wavelength(1, "m") == Wavelength(100, "cm")
True

Notes

All conversions are performed by first converting to the base unit (meters) and then to the target unit. This ensures consistency and avoids accumulation of rounding errors.

The class is immutable (frozen=True), which means attributes cannot be modified after initialization. This ensures thread-safety and allows instances to be used as dictionary keys.

__init__(data: float, unit: Literal['m', 'cm', 'dm', 'mm'] = 'm') None#

Methods

__init__(data[, unit])

to_cm()

Convert wavelength to centimeters.

to_dm()

Convert wavelength to decimeters.

to_frequency([unit])

Convert wavelength to frequency.

to_m()

Convert wavelength to meters.

to_mm()

Convert wavelength to millimeters.

to_unit(unit)

Convert wavelength to the specified unit.

Attributes

unit

m (meters)

data

The numerical value of the wavelength

to_cm() Wavelength[source]#

Convert wavelength to centimeters.

Returns:

A new Wavelength instance in centimeters.

Return type:

Wavelength

to_dm() Wavelength[source]#

Convert wavelength to decimeters.

Returns:

A new Wavelength instance in decimeters.

Return type:

Wavelength

to_frequency(unit: Literal['GHz', 'MHz', 'kHz', 'Hz'] = 'GHz') Frequency[source]#

Convert wavelength to frequency.

Uses the relationship: frequency = speed_of_light / wavelength

Parameters:

unit (Literal["GHz", "MHz", "kHz", "Hz"], optional) – The unit of the resulting frequency. Default is “GHz”.

Returns:

A new Frequency instance with the converted value.

Return type:

Frequency

Examples

>>> wl = Wavelength(0.055, "m")
>>> freq = wl.to_frequency("GHz")
>>> round(freq.data, 3)
5.451
to_m() Wavelength[source]#

Convert wavelength to meters.

Returns:

A new Wavelength instance in meters.

Return type:

Wavelength

to_mm() Wavelength[source]#

Convert wavelength to millimeters.

Returns:

A new Wavelength instance in millimeters.

Return type:

Wavelength

to_unit(unit: Literal['m', 'cm', 'dm', 'mm']) Wavelength[source]#

Convert wavelength to the specified unit.

Parameters:

unit (Literal["m", "cm", "dm", "mm"]) – The target unit for conversion.

Returns:

A new Wavelength instance with the converted value and unit.

Return type:

Wavelength

Raises:

ValueError – If the target unit is not recognized.

Examples

>>> wl = Wavelength(1, "m")
>>> wl.to_unit("cm")
Wavelength(data=100.0, unit='cm')
data: float#

The numerical value of the wavelength

unit: Literal['m', 'cm', 'dm', 'mm'] = 'm'#

m (meters)

Type:

The unit of the wavelength. Default