forked from leylaunsal/timedelaycolormaps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmult_lens_random
136 lines (103 loc) · 6.3 KB
/
mult_lens_random
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import numpy as np
import matplotlib.pyplot as plt
import random
b = 0.5
##GENERATING RANDOM MASSES for point lenses
def generate_random_mass(mass_start_range, mass_end_range, mass_num_variables):
mass_random_variables = [round(random.uniform(mass_start_range, mass_end_range), 2) for _ in range(mass_num_variables)]
return mass_random_variables
# Define the range and the number of variables
mass_start_range = 0.0
mass_end_range = 5
mass_num_variables = 10
# Call the function to get the generated random numbers
random_mass = generate_random_mass(mass_start_range, mass_end_range, mass_num_variables)
# Now, assign the generated random numbers to the predefined variables m1, m2, ..., m10
m1, m2, m3, m4, m5, m6, m7, m8, m9, m10 = random_mass
#GENERATING RANDOM LOCATIONS for each point lens
def generate_random_location(loc_start_range, loc_end_range, loc_num_variables):
random_variables = [round(random.uniform(loc_start_range, loc_end_range),2) for _ in range(loc_num_variables)]
return random_variables
# Define the range and the number of variables
loc_start_range = -4.8
loc_end_range = 4.8
loc_num_variables = 18
# Call the function to get the generated random numbers
random_loc = generate_random_location(loc_start_range, loc_end_range, loc_num_variables)
# Now, assign the generated random numbers to the predefined variables m1, m2, ..., m10
p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18 = random_loc
#log values for ease of writing the equation
# Define the equation we're plotting
def equation(x, y):
log_1 = m1*np.log(np.sqrt(x**2 + y**2))
log_2 = m2*np.log(np.sqrt((x - p1)**2 + (y - p2)**2))
log_3 = m3*np.log(np.sqrt((x - p3)**2 + (y - p4)**2))
log_4 = m4*np.log(np.sqrt((x - p5)**2 + (y - p6)**2))
log_5 = m5*np.log(np.sqrt((x - p7)**2 + (y - p8)**2))
log_6 = m6*np.log(np.sqrt((x - p9)**2 + (y - p10)**2))
log_7 = m7*np.log(np.sqrt((x - p11)**2 + (y - p12)**2))
log_8 = m8*np.log(np.sqrt((x - p13)**2 + (y - p14)**2))
log_9 = m9*np.log(np.sqrt((x - p15)**2 + (y - p16)**2))
log_10 = m10*np.log(np.sqrt((x - p17)**2 + (y - p18)**2))
return 0.5*((x - b)**2 + y**2) - log_1 - log_2 - log_3 - log_4 - log_5 - log_6 - log_7 - log_8 - log_9 - log_10
# Generate sample data
x = np.linspace(-5, 5, num=100)
y = np.linspace(-5, 5, num=100)
X, Y = np.meshgrid(x, y)
Z = equation(X, Y)
# Plot color map
plt.figure(figsize=(8, 6))
plt.rcParams.update({'font.size': 15})
plt.pcolormesh(X, Y, Z, cmap='rainbow')
plt.colorbar(label='Color Intensity')
plt.clim(vmin=-45, vmax = 0)
plt.title('Figure 4: Color Map of Time Delay From Multiple Point Lenses of Fixed Distance')
plt.xlabel('x1')
plt.ylabel('x2')
#markers for the point masses
plt.plot(0, 0, marker="o", markersize=8, markerfacecolor="red")
plt.plot(p1, p2, marker="o", markersize=8, markerfacecolor="red")
plt.plot(p3, p4, marker="o", markersize=8, markerfacecolor="red")
plt.plot(p5, p6, marker="o", markersize=8, markerfacecolor="red")
plt.plot(p7, p8, marker="o", markersize=8, markerfacecolor="red")
plt.plot(p9, p10, marker="o", markersize=8, markerfacecolor="red")
plt.plot(p11, p12, marker="o", markersize=8, markerfacecolor="red")
plt.plot(p13, p14, marker="o", markersize=8, markerfacecolor="red")
plt.plot(p15, p16, marker="o", markersize=8, markerfacecolor="red")
plt.plot(p17, p18, marker="o", markersize=8, markerfacecolor="red")
#LABELS OF EACH POINT MASS
label1 = "1: mass = " + str(m1) + ", position = " + "(0, 0)"
label2 = "2: mass = " + str(m2) + ", position = (" + str(p1) + "," + str(p2) + ")"
label3 = "3: mass = " + str(m3) + ", position = (" + str(p3) + "," + str(p4) + ")"
label4 = "4: mass = " + str(m4) + ", position = (" + str(p5) + "," + str(p6) + ")"
label5 = "5: mass = " + str(m5) + ", position = (" + str(p7) + "," + str(p8) + ")"
label6 = "6: mass = " + str(m6) + ", position = (" + str(p9) + "," + str(p10) + ")"
label7 = "7: mass = " + str(m7) + ", position = (" + str(p11) + "," + str(p12) + ")"
label8 = "8: mass = " + str(m8) + ", position = (" + str(p13) + "," + str(p14) + ")"
label9 = "9: mass = " + str(m9) + ", position = (" + str(p15) + "," + str(p16) + ")"
label10 = "10: mass = " + str(m10) + ", position = (" + str(p17) + "," + str(p18) + ")"
#ANNOTATING EACH POINT MASS
plt.annotate("1", xy = (0,0), xytext = (0, 0.3), ha = 'center', fontsize = 12)
plt.annotate("2", xy = (p1,p2), xytext = (p1, p2+0.3), ha = 'center', fontsize = 12)
plt.annotate("3", xy = (p3,p4), xytext = (p3, p4+0.3), ha = 'center', fontsize = 12)
plt.annotate("4", xy = (p5,p6), xytext = (p5, p6+0.3), ha = 'center', fontsize = 12)
plt.annotate("5", xy = (p7,p8), xytext = (p7, p8+0.3), ha = 'center', fontsize = 12)
plt.annotate("6", xy = (p9,p10), xytext = (p9, p10+0.3), ha = 'center', fontsize = 12)
plt.annotate("7", xy = (p11,p12), xytext = (p11, p12+0.3), ha = 'center', fontsize = 12)
plt.annotate("8", xy = (p13,p14), xytext = (p13, p14+0.3), ha = 'center', fontsize = 12)
plt.annotate("9", xy = (p15,p16), xytext = (p15, p16+0.3), ha = 'center', fontsize = 12)
plt.annotate("10", xy = (p17,p18), xytext = (p17, p18+0.3), ha = 'center', fontsize = 12)
#DESCRIPTION OFF TO THE SIDE FOR THE MASS + POSITION DESCRIPTIONS
plt.text(-0.6, 0.4, label1, ha='center', va='center', transform=plt.gca().transAxes)
plt.text(-0.6, 0.35, label2, ha='center', va='center', transform=plt.gca().transAxes)
plt.text(-0.6, 0.3, label3, ha='center', va='center', transform=plt.gca().transAxes)
plt.text(-0.6, 0.25, label5, ha='center', va='center', transform=plt.gca().transAxes)
plt.text(-0.6, 0.2, label6, ha='center', va='center', transform=plt.gca().transAxes)
plt.text(-0.6, 0.15, label7, ha='center', va='center', transform=plt.gca().transAxes)
plt.text(-0.6, 0.1, label8, ha='center', va='center', transform=plt.gca().transAxes)
plt.text(-0.6, 0.05, label9, ha='center', va='center', transform=plt.gca().transAxes)
plt.text(-0.6, 0, label10, ha='center', va='center', transform=plt.gca().transAxes)
plt.show()
#could either fix the points of multiple lenses, or randomly generate the coordinates for 10 point lenses, and put the masses in a certain range, but it's more probable for it to be smaller within the range
#mass distribution is non trivial--> ex out of 10 lenses, 2 massive ones, 8 smaller ones
#could also add a few (3) contour lines: show contour of a constant time delay: would help differentiate from single to double