Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions physics/diffraction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import math

def check_min_intensity(slit_width = 1,diff_angle=0, wavelength=100):

Check failure on line 3 in physics/diffraction.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

physics/diffraction.py:1:1: I001 Import block is un-sorted or un-formatted

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: check_min_intensity. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: slit_width

Please provide type hint for the parameter: diff_angle

Please provide type hint for the parameter: wavelength

"""
Checks for the condition of minimum intensity in a diffraction pattern.

Check failure on line 6 in physics/diffraction.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

physics/diffraction.py:6:1: W293 Blank line contains whitespace
Args:
slit_width (float): The width of the slit in millimeters.
diff_angle (float): The diffraction angle in radians.
wavelength (float): The wavelength of light in nanometers.

Check failure on line 11 in physics/diffraction.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

physics/diffraction.py:11:1: W293 Blank line contains whitespace
Returns:
bool: True if minimum intensity is met, otherwise False.

>>> check_min_intensity(4, 0.25, 300)
False
>>> check_min_intensity(1, 0.0001, 100)
True
"""
wavelength *= 10**-6
n_val = round(slit_width*(diff_angle)/wavelength,5)
r_val = (n_val-math.floor(n_val)==0)
return r_val

def check_max_intensity(slit_width=1,diff_angle=0,wavelength=100):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: check_max_intensity. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: slit_width

Please provide type hint for the parameter: diff_angle

Please provide type hint for the parameter: wavelength

"""
Checks for the condition of maximum intensity in a diffraction pattern.

Check failure on line 28 in physics/diffraction.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

physics/diffraction.py:28:1: W293 Blank line contains whitespace
Args:
slit_width (float): The width of the slit in millimeters.
diff_angle (float): The diffraction angle in radians.
wavelength (float): The wavelength of light in nanometers.

Check failure on line 33 in physics/diffraction.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

physics/diffraction.py:33:1: W293 Blank line contains whitespace
Returns:
bool: True if maximum intensity is met, otherwise False.

>>> check_max_intensity(1, 0.001, 100)
False
>>> check_max_intensity(1, 0.00005, 100)
True
"""
wavelength *=10**-6
n_val = round(((2*slit_width*diff_angle)-wavelength)/(2*wavelength),4)
r_val = (n_val-math.floor(n_val)==0)
return r_val

def intensity_single_slit(slit_width=1,diff_angle=0,wavelength=100):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: intensity_single_slit. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: slit_width

Please provide type hint for the parameter: diff_angle

Please provide type hint for the parameter: wavelength

"""
Computes the intensity for a single slit diffraction pattern.

Check failure on line 50 in physics/diffraction.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

physics/diffraction.py:50:1: W293 Blank line contains whitespace
Args:
slit_width (float): The width of the slit in millimeters.
diff_angle (float): The diffraction angle in radians.
wavelength (float): The wavelength of light in nanometers.

Check failure on line 55 in physics/diffraction.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

physics/diffraction.py:55:1: W293 Blank line contains whitespace
Returns:
str: The intensity of the diffraction pattern.

>>> intensity_single_slit(1, 0.0005, 100)
'0.9999999999177533 I0'
"""
beta = math.pi*slit_width*(math.sin(diff_angle)/wavelength)
i_coeff = (math.sin(beta)/beta)**2
return f"{i_coeff} I0"

def intensity_double_slit(path_diff=0,intensity_max="I0"):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: intensity_double_slit. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: path_diff

Please provide type hint for the parameter: intensity_max

"""
Computes the intensity for a double slit diffraction pattern.

Check failure on line 69 in physics/diffraction.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

physics/diffraction.py:69:1: W293 Blank line contains whitespace
Args:
path_diff (float): The path difference in the two waves.
intensity_max (str or int): The maximum intensity.

Returns:
str or float: The intensity of the diffraction pattern.

>>> intensity_double_slit(0, 1)
4.0
>>> intensity_double_slit(0.001, 1)
3.999999000000084
>>> intensity_double_slit(0)
'4.0 I0'
"""
r_val = 4*intensity_max*(math.cos(path_diff/2))**2 if (type(intensity_max) is int) else f"{4*(math.cos(path_diff/2)**2)} I0"

Check failure on line 84 in physics/diffraction.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

physics/diffraction.py:84:89: E501 Line too long (128 > 88)
return r_val

if(__name__=="__main__"):
import doctest
doctest.testmod()
#pass

Check failure on line 90 in physics/diffraction.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W292)

physics/diffraction.py:90:10: W292 No newline at end of file