Selected Reading

SciPy - lambda2nu() Method



The SciPy lambda2nu() method is used to convert the wavelength into optical frequency.

A wavelength() represents the distance between two peaks of wave whereas, optical frequency () is measured by number of times the light wave vibrates in a given time period.

In statistics term, we say these are shape(numerical) parameters which determine the relationship of two quantities with respect to speed of light.

The wavelength is measured in meters and the frequency is measured using hertz(Hz). The speed of light in a vacuum is similar to 3 108 m/s. To obtain the following formula −

Speed of light(c) =  wavelength().frequency().

Syntax

Following is the syntax of the SciPy lambda2nu() method −

lambda2nu(lambda_)

Parameters

This method accepts only a single parameter which is −

  • lambda_− This parameter based on either integer or float values.

Return value

This function returns the float value or an array of float values.

Example 1

Following is the basic SciPy lambda2nu() method that illustrates the conversion of wavelength into frequency.

def lambda2nu(lambda_):
   # c is speed of light(m/s)
   c = 3e8  
   # Convert wavelength (in meters) to frequency (in Hz)
   nu = c / lambda_
   return nu

# w is wavelength(m)
w = 500e-9 
f = lambda2nu(w)
print(f"Frequency: {f} Hz")

Output

On execution of above code, we get the following result −

Frequency: 600000000000000.0 Hz

Example 2

Here, the program illustrates how to build an object for the class, and with the help of the lamda2nu() method, it converts wavelengths in different units to frequency.

from scipy.constants import c, nano, micro, milli

class WavelengthConverter:
   UNIT_DICT = {'m': 1, 'nm': nano, 'um': micro, 'mm': milli}
    
   @staticmethod
   def lambda2nu(lambda_, unit='m'):
       if unit not in WavelengthConverter.UNIT_DICT:
           raise ValueError("Unsupported unit")
        
       lambda_in_meters = lambda_ * WavelengthConverter.UNIT_DICT[unit]
        
       if lambda_in_meters <= 0:
           raise ValueError("Wavelength must be positive.")
        
       return c / lambda_in_meters

# show the result
converter = WavelengthConverter()
print("Frequency in Hz for 500 nm wavelength", converter.lambda2nu(500, 'nm'))  
print("Frequency in Hz for 0.5 m wavelength", converter.lambda2nu(0.5, 'um'))  

Output

After executing the above code, we get the following result −

Frequency in Hz for 500 nm wavelength 599584915999999.9
Frequency in Hz for 0.5 m wavelength 599584916000000.0

Example 3

Below the program define an array() which associate to numpy object and accept two parameter float_val and speed_of_light to generate the result.

from scipy.constants import lambda2nu, speed_of_light
import numpy as np
result = lambda2nu(np.array((3.8, speed_of_light)))
print(result)

Output

The above code produces the following result −

[7.88927521e+07 1.00000000e+00]
scipy_reference.htm
Advertisements