forked from uafgeoteach/GEOS694_ICG
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2d_gaussian_embarassing.py
More file actions
49 lines (40 loc) · 1.59 KB
/
Copy path2d_gaussian_embarassing.py
File metadata and controls
49 lines (40 loc) · 1.59 KB
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
import sys
import numpy as np
import matplotlib.pyplot as plt
# Resolution of the grid
STEP = 0.001
def gaussian_2d(x, y, sigma=1.0):
"""Calculate the 2D Gaussian density at point (x, y)."""
coef = 1 / (2 * np.pi * sigma**2)
expr = -1 * (x**2 + y**2) / (2 * sigma**2)
return coef * np.exp(expr)
def main(xmin, xmax, ymin, ymax):
"""Computes and saves a specific chunk of the Gaussian grid."""
# Convert inputs to float
xmin, xmax, ymin, ymax = map(float, [xmin, xmax, ymin, ymax])
x_range = np.arange(xmin, xmax, STEP)
y_range = np.arange(ymin, ymax, STEP)
z_list = []
for x in x_range:
for y in y_range:
z_list.append(gaussian_2d(x, y))
# Reshape based on the actual size of the generated ranges
z_matrix = np.array(z_list).reshape(len(x_range), len(y_range))
# Plotting logic
plt.figure(figsize=(6, 5))
# 'extent' ensures the axis labels match the actual coordinate space
plt.imshow(z_matrix.T, extent=[xmin, xmax, ymin, ymax], origin='lower')
plt.colorbar(label='Density')
plt.xlabel("X")
plt.ylabel("Y")
plt.title(f"Chunk: X[{xmin}, {xmax}] Y[{ymin}, {ymax}]")
# Save the figure
filename = f"gaussian_{xmin}_{xmax}.png"
plt.savefig(filename)
print(f"Successfully saved {filename}")
if __name__ == "__main__":
# Check for correct number of arguments: script.py xmin xmax ymin ymax
if len(sys.argv) == 5:
main(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
else:
print("Usage: python 2d_gaussian_embarassing.py <xmin> <xmax> <ymin> <ymax>")