about summary refs log tree commit diff
path: root/src/old
diff options
context:
space:
mode:
authorhanemile <emile.hansmaennel@gmail.com>2018-01-16 15:56:49 +0100
committerhanemile <emile.hansmaennel@gmail.com>2018-01-16 15:56:49 +0100
commite5d00b1b2e2e7c0684dae7324feb86c36188047b (patch)
tree5d040b37592a4c90d611667432397e3cfb60d2ce /src/old
parent03d51526311de1e7ff1e7803e4bf8ce66bf17933 (diff)
updated the source
Diffstat (limited to 'src/old')
-rwxr-xr-xsrc/old/gen.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/old/gen.py b/src/old/gen.py
new file mode 100755
index 0000000..b4b7933
--- /dev/null
+++ b/src/old/gen.py
@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+
+from numpy import genfromtxt
+import numpy as np
+import math
+import os
+import socket
+import time
+import matplotlib.pyplot as plt
+host = socket.gethostname()
+
+listx = []
+listy = []
+
+def gen_stars(stars):
+    stars = int(stars)
+
+    # lists
+    listrho = []
+
+    # create new file for every calculation
+    path = "data/" + str(host) + "_" + str(os.getpid()) + ".csv"
+    print("path: " + str(path))
+
+    # define the size of the galaxy
+    length = 1.5e6
+
+    # define the borders
+    range_min = -int(length)
+    range_max = int(length)
+
+    # define the rho range
+    rand_min = rho(0)
+    rand_max = rho(math.sqrt(length**2 + length**2))
+
+    # create random stars
+    for r in range(0, stars):
+        x = np.random.uniform(range_min, range_max, size=1)
+        y = np.random.uniform(range_min, range_max, size=1)
+        rand_val = np.random.uniform(rand_min, rand_max, size=1)
+        rho_xy = rho(math.sqrt(x**2 + y**2))
+
+        # if the random value is smaller than the rho value, generate a star
+        if rand_val < rho_xy:
+
+            # open a file to write to
+            with open(path, "a") as data:
+
+                # write the data to the file
+                data.write(str(x).strip("[]") + "," + str(y).strip("[]") + "\n")
+                listx.append(x)
+                listy.append(y)
+                print(str(x) + ", " + str(y))
+
+    print("range_min: " + str(range_min))
+    print("range_max: " + str(range_max))
+
+    print("rand_min: " + str(rand_min))
+    print("rand_max: " + str(rand_max))
+
+# generate n stars
+gen_stars(1e6)
+
+# plot the stars coordinates in 2D space
+plt.scatter(listx, listy)
+plt.show()