faninsar.constants.Frequency#

class faninsar.constants.Frequency(data: float, unit: Literal['GHz', 'MHz', 'kHz', 'Hz'] = 'GHz')[source]#

Bases: object

Dataclass for frequency with unit conversion capabilities.

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

data#

The numerical value of the frequency.

Type:

float

unit#

The unit of the frequency. Default is “GHz” (gigahertz).

Type:

Literal[“GHz”, “MHz”, “kHz”, “Hz”]

Examples

>>> freq = Frequency(5.405, "GHz")
>>> freq.to_MHz()
Frequency(data=5405.0, unit='MHz')
>>> freq.to_Hz()
Frequency(data=5405000000.0, unit='Hz')
>>> str(freq)
'5.405 GHz'
>>> # Can be used as dictionary key
>>> frequencies = {freq: "Sentinel-1"}
>>> # Equality comparison
>>> Frequency(1, "GHz") == Frequency(1000, "MHz")
True

Notes

All conversions are performed by first converting to the base unit (Hz) 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['GHz', 'MHz', 'kHz', 'Hz'] = 'GHz') None#

Methods

__init__(data[, unit])

to_GHz()

Convert frequency to GHz.

to_Hz()

Convert frequency to Hz.

to_MHz()

Convert frequency to MHz.

to_kHz()

Convert frequency to kHz.

to_unit(unit)

Convert frequency to the specified unit.

to_wavelength([unit])

Convert frequency to wavelength.

Attributes

unit

GHz (gigahertz)

data

The numerical value of the frequency

to_GHz() Frequency[source]#

Convert frequency to GHz.

Returns:

A new Frequency instance in GHz.

Return type:

Frequency

to_Hz() Frequency[source]#

Convert frequency to Hz.

Returns:

A new Frequency instance in Hz.

Return type:

Frequency

to_MHz() Frequency[source]#

Convert frequency to MHz.

Returns:

A new Frequency instance in MHz.

Return type:

Frequency

to_kHz() Frequency[source]#

Convert frequency to kHz.

Returns:

A new Frequency instance in kHz.

Return type:

Frequency

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

Convert frequency to the specified unit.

Parameters:

unit (Literal["GHz", "MHz", "kHz", "Hz"]) – The target unit for conversion.

Returns:

A new Frequency instance with the converted value and unit.

Return type:

Frequency

Raises:

ValueError – If the target unit is not recognized.

Examples

>>> freq = Frequency(1, "GHz")
>>> freq.to_unit("MHz")
Frequency(data=1000.0, unit='MHz')
to_wavelength(unit: Literal['m', 'cm', 'dm', 'mm'] = 'm') Wavelength[source]#

Convert frequency to wavelength.

Uses the relationship: wavelength = speed_of_light / frequency

Parameters:

unit (Literal["m", "cm", "dm", "mm"], optional) – The unit of the resulting wavelength. Default is “m”.

Returns:

A new Wavelength instance with the converted value.

Return type:

Wavelength

Examples

>>> freq = Frequency(5.405, "GHz")
>>> wl = freq.to_wavelength("mm")
>>> round(wl.data, 2)
55.46
data: float#

The numerical value of the frequency

unit: Literal['GHz', 'MHz', 'kHz', 'Hz'] = 'GHz'#

GHz (gigahertz)

Type:

The unit of the frequency. Default