# Unitful: convert frequency to wavenumber

I am trying to convert frequency in THz to wavenumber in cm^-1 by doing `uconvert(1THz / c0, 1.0u"cm^-1")`. But I get the following error:

``````ERROR: MethodError: no method matching uconvert(::Quantity{Float64,𝐋⁻¹,Unitful.FreeUnits{(THz, m⁻¹, s),𝐋⁻¹,nothing}}, ::Quantity{Float64,𝐋⁻¹,Unitful.FreeUnits{(cm⁻¹,),𝐋⁻¹,nothing}})
``````

How can I fix this error?

Ideally, I would like to be able to do `1THz |> cm^-1` to obtain the wavenumber from a frequency. Is this possible?

``````julia> using Unitful

julia> wn(f) = uconvert(u"cm^-1", float(f/Unitful.c))
wn (generic function with 1 method)

julia> 1u"THz" |> wn
33.3564095198152 cm⁻¹
``````

I think you had the arguments in the wrong order.

2 Likes

I made a little package for this, NaturallyUnitful.jl

``````julia> using NaturallyUnitful

julia> natural(1u"THz")
0.0006582119459370421 eV

julia> unnatural(u"cm^-1", 1u"THz")
33.3564095198152 cm^-1
``````
1 Like

This package is nice. But it would be more useful if it were possible to redefine u"cm^-1"() so that `1THz |> cm^-1` automatically uses `unnatural(u"cm^-1", 1u"THz")`.

At the moment, I find it more convenient to define `cm1 = uconvert(u"cm^-1", float(f/Unitful.c))` and do `1THz |> cm1` than use `unnatural(u"cm^-1", 1u"THz")`.