Skip to content

Commit 1c45213

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 6ae4a0f commit 1c45213

1 file changed

Lines changed: 30 additions & 23 deletions

File tree

‎physics/diffraction.py‎

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
21
import math
32

43

5-
6-
def check_min_intensity(slit_width = 1,diff_angle=0, wavelength=100):
4+
def check_min_intensity(slit_width=1, diff_angle=0, wavelength=100):
75
"""
86
Checks for the condition of minimum intensity in a diffraction pattern.
9-
7+
108
Args:
119
slit_width (float): The width of the slit in millimeters.
1210
diff_angle (float): The diffraction angle in radians.
1311
wavelength (float): The wavelength of light in nanometers.
14-
12+
1513
Returns:
1614
bool: True if minimum intensity is met, otherwise False.
1715
@@ -21,19 +19,20 @@ def check_min_intensity(slit_width = 1,diff_angle=0, wavelength=100):
2119
True
2220
"""
2321
wavelength *= 10**-6
24-
n_val = round(slit_width*(diff_angle)/wavelength,5)
25-
r_val = True if (n_val-math.floor(n_val)==0) else False
22+
n_val = round(slit_width * (diff_angle) / wavelength, 5)
23+
r_val = True if (n_val - math.floor(n_val) == 0) else False
2624
return r_val
2725

28-
def check_max_intensity(slit_width=1,diff_angle=0,wavelength=100):
26+
27+
def check_max_intensity(slit_width=1, diff_angle=0, wavelength=100):
2928
"""
3029
Checks for the condition of maximum intensity in a diffraction pattern.
31-
30+
3231
Args:
3332
slit_width (float): The width of the slit in millimeters.
3433
diff_angle (float): The diffraction angle in radians.
3534
wavelength (float): The wavelength of light in nanometers.
36-
35+
3736
Returns:
3837
bool: True if maximum intensity is met, otherwise False.
3938
@@ -42,34 +41,36 @@ def check_max_intensity(slit_width=1,diff_angle=0,wavelength=100):
4241
>>> check_max_intensity(1, 0.00005, 100)
4342
True
4443
"""
45-
wavelength *=10**-6
46-
n_val = round(((2*slit_width*diff_angle)-wavelength)/(2*wavelength),4)
47-
r_val = True if (n_val-math.floor(n_val)==0) else False
44+
wavelength *= 10**-6
45+
n_val = round(((2 * slit_width * diff_angle) - wavelength) / (2 * wavelength), 4)
46+
r_val = True if (n_val - math.floor(n_val) == 0) else False
4847
return r_val
4948

50-
def intensity_single_slit(slit_width=1,diff_angle=0,wavelength=100):
49+
50+
def intensity_single_slit(slit_width=1, diff_angle=0, wavelength=100):
5151
"""
5252
Computes the intensity for a single slit diffraction pattern.
53-
53+
5454
Args:
5555
slit_width (float): The width of the slit in millimeters.
5656
diff_angle (float): The diffraction angle in radians.
5757
wavelength (float): The wavelength of light in nanometers.
58-
58+
5959
Returns:
6060
str: The intensity of the diffraction pattern.
6161
6262
>>> intensity_single_slit(1, 0.0005, 100)
6363
'0.9999999999177533 I0'
6464
"""
65-
beta = math.pi*slit_width*(math.sin(diff_angle)/wavelength)
66-
i_coeff = (math.sin(beta)/beta)**2
65+
beta = math.pi * slit_width * (math.sin(diff_angle) / wavelength)
66+
i_coeff = (math.sin(beta) / beta) ** 2
6767
return "{coeff} I0".format(coeff=i_coeff)
6868

69-
def intensity_double_slit(path_diff=0,intensity_max="I0"):
69+
70+
def intensity_double_slit(path_diff=0, intensity_max="I0"):
7071
"""
7172
Computes the intensity for a double slit diffraction pattern.
72-
73+
7374
Args:
7475
path_diff (float): The path difference in the two waves.
7576
intensity_max (str or int): The maximum intensity.
@@ -84,10 +85,16 @@ def intensity_double_slit(path_diff=0,intensity_max="I0"):
8485
>>> intensity_double_slit(0)
8586
'4.0 I0'
8687
"""
87-
r_val = 4*intensity_max*(math.cos(path_diff/2))**2 if (type(intensity_max)==type(0)) else "{coeff} I0".format(coeff=(4*(math.cos(path_diff/2)**2)))
88+
r_val = (
89+
4 * intensity_max * (math.cos(path_diff / 2)) ** 2
90+
if (type(intensity_max) == type(0))
91+
else "{coeff} I0".format(coeff=(4 * (math.cos(path_diff / 2) ** 2)))
92+
)
8893
return r_val
8994

90-
if(__name__=="__main__"):
95+
96+
if __name__ == "__main__":
9197
import doctest
98+
9299
doctest.testmod()
93-
#pass
100+
# pass

0 commit comments

Comments
 (0)