You can simplify this block of code to:

```
try:
    w = w.to(u.m, equivalencies=u.spectral())
except u.UnitsError:
    raise InputParameterError("First parameter must be in wavelength or frequency units")
```

since the equivalency will take care of intepreting frequency or length in the right way.