about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/README.md25
-rwxr-xr-xsrc/coord.py138
-rw-r--r--src/data/pizzablech_11360.csv3
-rw-r--r--src/data/pizzablech_19005.csv3
-rw-r--r--src/data/pizzablech_21823.csv1
-rw-r--r--src/data/pizzablech_27529.csv1
-rw-r--r--src/data/pizzablech_32000.csv2
-rw-r--r--src/data/pizzablech_32315.csv2
-rw-r--r--src/data/pizzablech_7274.csv1
-rw-r--r--src/data/pizzablech_8705.csv1
-rw-r--r--src/data/pizzablech_924.csv1
-rwxr-xr-xsrc/gen.py85
-rwxr-xr-xsrc/lookup.py86
-rw-r--r--src/view.py48
14 files changed, 312 insertions, 85 deletions
diff --git a/src/README.md b/src/README.md
new file mode 100644
index 0000000..a22aa75
--- /dev/null
+++ b/src/README.md
@@ -0,0 +1,25 @@
+# README
+
+### workflow:
+
+---
+
+#### Generate the lookuptable
+
+
+    $ ./lookup.py <number of values> <filename>
+
+- the __number of values__ can be given using the scientific notaion e.g. 1e7.
+- the __filename__ should not overlap with any existing filename
+
+---
+
+#### Generate the coordinates
+
+
+    $ ./coord.py <number of stars> <save_to_file_location>
+
+
+#### Display the stars using Blender
+
+    $ blender --python view.py <star_coordinates_file>
diff --git a/src/coord.py b/src/coord.py
new file mode 100755
index 0000000..ecd978c
--- /dev/null
+++ b/src/coord.py
@@ -0,0 +1,138 @@
+#!/usr/bin/env python
+
+# import libraries
+import time
+import numpy as np
+import sys
+from subprocess import call
+
+# define the number of stars that should be generated
+nos = int(sys.argv[1])
+
+# define some arrays for storing the values
+arr_stars = np.zeros((int(nos), 3))
+arr_saved_stars = np.zeros((int(nos), 3))
+
+# define various paths
+path = "data/2e7.csv"
+save_path = "stars/" + sys.argv[2] + ".csv"
+# star13 -> 586 stars
+
+# define the random-value range [rho_min; rho_max]
+rand_min = 0
+rand_max = 1477.1586582000994
+
+# define the range (size) of the galaxy
+range_min = -1e7
+range_max = 1e7
+
+# main function
+def main():
+
+    # define the variables for storing the amount of stars kept or kicked away
+    stars_kept = 0
+    stars_kicked = 0
+    i = 0
+
+    # start the timer
+    start = time.time()
+
+    # open the rho file
+    with open(path) as data:
+
+        # read out the lines from the rho file
+        rho_file = data.readlines()
+
+        # for every star...
+        # for i in range(0, nos):
+        while(stars_kept < nos):
+
+            # generate the random star-coordinates
+            x = np.random.uniform(range_min, range_max, size=1)
+            y = np.random.uniform(range_min, range_max, size=1)
+            z = np.random.uniform(range_min, range_max, size=1)
+
+            # calculate the distance of the star to the center of the galaxy
+            r = np.sqrt(pow(x, 2) + pow(y, 2) + pow(z, 2))
+            # print(round(int(r), 0))
+
+            # generate a random value in the range [rand_min; rand_max]
+            a = np.random.uniform(rand_min, rand_max, size=1)
+
+            # read out the corresponding rho value from the lookuptable (rho-file)
+            b = float(rho_file[round(int(r), 0)].split(", ")[1].strip("\n"))
+
+            # print("{:<5}{:<20}{:<20}{:<20}{:<20}{:<20}{:<20}".format(str(stars_kept), str(x), str(y), str(z), str(a), str(b), str(r)))
+
+            # if the random value is smaller than the corresponding rho value
+            if(a < b):
+                # add the coordinate to arr_saved_stars
+                arr_saved_stars[stars_kept][0] = x
+                arr_saved_stars[stars_kept][1] = y
+                arr_saved_stars[stars_kept][2] = z
+
+                # increment the star_kept counter
+                stars_kept += 1
+                print(stars_kept)
+
+            else:
+                # increment the star_kicked counter
+                stars_kicked += 1
+
+            # increment i
+            i = i + 1
+
+    print("")
+    end = time.time()
+    whole_time = end - start
+    out = ">> Finished generating stars in " + str(whole_time) + " seconds\n"
+    print(out)
+
+    # write the star coordinates to a file
+    start_write_file = time.time()
+    print(">> Writing the star-data to " + save_path)
+    with open(save_path, "a") as stars_data:
+        for i in range(0, nos):
+            x = arr_saved_stars[i][0]
+            y = arr_saved_stars[i][1]
+            z = arr_saved_stars[i][2]
+
+            stars_data.write(str(x) + ", " + str(y) + ", " + str(z) + "\n")
+
+    end_write_file = time.time()
+    time_write_file = end_write_file - start_write_file
+    out = ">> Finished writing star-data to " + save_path + " in " + str(round(time_write_file, 4)) + " seconds\n"
+    print(out)
+
+    time_all = whole_time + time_write_file
+
+    time_min = round(time_all / 60, 1)
+
+    # print some stats
+    print("")
+    print("{:<20}{:<20}".format("Time (complete)", str(round(time_all, 4)) + " seconds"))
+    print("{:-<40}".format(""))
+    print("{:<20}{:<20}".format("Number of Stars", str(nos)))
+    print("{:<20}{:<20}".format("Stars Kicked:", str(stars_kicked)))
+    print("{:<20}{:<20}".format("Percent: ", str( nos / stars_kicked * 100 ) + "%"))
+
+    hour = int( time_all // 3600 )
+    time_all = time_all % 3600
+    minutes = int( time_all // 60 )
+    time_all = time_all % 60
+    seconds = int( time_all )
+
+    a = path
+
+    time_a = str(hour) + ":" + str(minutes) + ":" + str(seconds)
+    b = "{:<20}{:<20}".format("Time (h:m:s)", time_a )
+    c = "{:<20}{:<20}".format("Number of Stars", str(nos))
+    d = "{:<20}{:<20}".format("Stars Kicked:", str(stars_kicked))
+    e = "{:<20}{:<20}".format("Percent: ", str( nos / stars_kicked * 100 ) + "%")
+
+    f = a + "\n" + b "\n" + c + "\n" + d + "\n" + e
+
+    call(["telegram-send", "--pre", str(f) ])
+
+if __name__ == "__main__":
+    main()
diff --git a/src/data/pizzablech_11360.csv b/src/data/pizzablech_11360.csv
new file mode 100644
index 0000000..227282f
--- /dev/null
+++ b/src/data/pizzablech_11360.csv
@@ -0,0 +1,3 @@
+ 1774.72102827, 1178.10406515
+-734.67958771,-1207.38476906
+-913.24944432,-5918.62094729
diff --git a/src/data/pizzablech_19005.csv b/src/data/pizzablech_19005.csv
new file mode 100644
index 0000000..0d1e896
--- /dev/null
+++ b/src/data/pizzablech_19005.csv
@@ -0,0 +1,3 @@
+ 17265.79511097,-3162.68726106
+-2369.0947882, 320.72212317
+ 49080.10883372, 62913.02531819
diff --git a/src/data/pizzablech_21823.csv b/src/data/pizzablech_21823.csv
new file mode 100644
index 0000000..20baaa5
--- /dev/null
+++ b/src/data/pizzablech_21823.csv
@@ -0,0 +1 @@
+ 20678.62453795,-120221.31056653
diff --git a/src/data/pizzablech_27529.csv b/src/data/pizzablech_27529.csv
new file mode 100644
index 0000000..8a84290
--- /dev/null
+++ b/src/data/pizzablech_27529.csv
@@ -0,0 +1 @@
+-84.27519625, 2799.48771798
diff --git a/src/data/pizzablech_32000.csv b/src/data/pizzablech_32000.csv
new file mode 100644
index 0000000..8afae9d
--- /dev/null
+++ b/src/data/pizzablech_32000.csv
@@ -0,0 +1,2 @@
+ 14077.72819654, 15732.23314295
+ 4779.21771898,-32486.50451903
diff --git a/src/data/pizzablech_32315.csv b/src/data/pizzablech_32315.csv
new file mode 100644
index 0000000..0aa0951
--- /dev/null
+++ b/src/data/pizzablech_32315.csv
@@ -0,0 +1,2 @@
+ 3914.51482843,-47.19622038
+ 104001.67675349, 87348.92176592
diff --git a/src/data/pizzablech_7274.csv b/src/data/pizzablech_7274.csv
new file mode 100644
index 0000000..2101fa4
--- /dev/null
+++ b/src/data/pizzablech_7274.csv
@@ -0,0 +1 @@
+ 1384.895152, 883.74479782
diff --git a/src/data/pizzablech_8705.csv b/src/data/pizzablech_8705.csv
new file mode 100644
index 0000000..2869ef9
--- /dev/null
+++ b/src/data/pizzablech_8705.csv
@@ -0,0 +1 @@
+-1332.03040452,-1942.03814714
diff --git a/src/data/pizzablech_924.csv b/src/data/pizzablech_924.csv
new file mode 100644
index 0000000..8dbeac9
--- /dev/null
+++ b/src/data/pizzablech_924.csv
@@ -0,0 +1 @@
+-787.29212918, 3181.78632621
diff --git a/src/gen.py b/src/gen.py
deleted file mode 100755
index 829c30d..0000000
--- a/src/gen.py
+++ /dev/null
@@ -1,85 +0,0 @@
-#!/usr/bin/env python
-
-from numpy import genfromtxt
-import numpy as np
-import math
-import os
-import socket
-host = socket.gethostname()
-
-# variables
-sigma = 200
-f_0 = 0.1
-R_s = 1e4
-
-# M..
-Mxx = 0
-Mxy = 8e-6
-Myy = 0
-
-# constants
-pi = math.pi
-e = math.e
-G = 4.302e-3
-
-# rho function
-def rho(x, y, z):
-    r = math.sqrt(x**2 + y**2 + z**2)
-    a = (1) / (math.sqrt( 2 * pi ) * sigma )
-    b = math.exp( - (phi(r) / sigma ** 2 ) )
-    c = a * b
-    return c
-
-def rho_new(x, y, z):
-    a = (1 - ((1) / (2 * (sigma ** 2))) * ( Mxx * x**2 + 2 * Mxy * x * y + Myy * y**2 ) )
-    return rho(x, y, z) * a
-
-# phi function
-def phi(x):
-    if x == 0:
-        return -4 * pi * f_0 * G * R_s**2
-
-    a = - ( 4 * pi * G * f_0 * R_s ** 3 ) / x
-    b = np.log(1. + (x / R_s) )
-    c = a * b
-    return c
-
-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_new(0, 0, 0)
-    rand_max = rho_new(length, 0, 0)
-
-    # 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)
-        z = np.random.uniform(range_min, range_max, size=1)
-        rand_val = np.random.uniform(rand_min, rand_max, size=1)
-
-        # if the random value is smaller than the rho value, generate a star
-        if rand_val < rho(x, y, z):
-
-            # 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("[]") + "," + str(z).strip("[]") + "\n")
-
-# generate n stars
-gen_stars(5e7)
diff --git a/src/lookup.py b/src/lookup.py
new file mode 100755
index 0000000..52e1966
--- /dev/null
+++ b/src/lookup.py
@@ -0,0 +1,86 @@
+#!/usr/bin/env python
+
+# Import some libraries
+import math
+import numpy as np
+import matplotlib.pyplot as plt
+import time
+import os
+import sys
+
+# Defining some variables
+sigma = 200
+f_0 = 0.1
+R_s = 1e4
+
+# Defining some constants
+pi = math.pi
+e = math.e
+G = 4.302e-3
+
+# rho function
+def rho(r):
+    a = (1) / (math.sqrt( 2 * pi ) * sigma )
+    b = math.exp( - (phi(r) / sigma ** 2 ) )
+    return a * b
+
+# phi function
+def phi(x):
+    if x == 0:
+        return -4 * pi * f_0 * G * R_s**2
+    else:
+        a = - ( 4 * pi * G * f_0 * R_s ** 3 ) / x
+        b = np.log(1. + (x / R_s) )
+        return a * b
+
+# Defining a list to store the rho-values for plotting
+list_rho = []
+
+# Define the path to where the data should be stored
+path = 'data/' + str(sys.argv[2]) + '.csv'
+
+# get the start time
+start = time.time()
+
+# define the number of stars using system arguments
+stars = int(float(sys.argv[1]))
+
+# open the file where the information should be written to
+with open(path, "a") as data:
+
+    # for every star
+    for i in range(0, stars):
+
+        # calculate the rho value
+        rho_i = rho(i/10)
+
+        # append the rho value to list_rho for plotting
+        # list_rho.append(rho_i)
+
+        # print the distance to the center of the universe and the rho value to
+        # the user
+        print(str(i) + ", " + str(rho_i))
+
+        # write the data into the file
+        data.write(str(i) + ", " + str(rho_i) + "\n")
+
+# get the end time
+end = time.time()
+
+# calculate the runtime
+runtime = end - start
+
+# print some information to the user
+print("\n Runtime: ", end="")
+print(str(runtime) + " seconds")
+
+print(" Stars: " + str(stars))
+
+print(" Rho-values per second: ", end="")
+print(str(stars / runtime))
+
+# plt.plot(list_rho)
+# plt.xscale('log')
+# plt.yscale('log')
+# plt.grid()
+# plt.show()
diff --git a/src/view.py b/src/view.py
new file mode 100644
index 0000000..a30ec48
--- /dev/null
+++ b/src/view.py
@@ -0,0 +1,48 @@
+import bpy
+from numpy import genfromtxt
+import os
+import sys
+
+directory = "stars/"
+# # print(directory)
+#
+files = [sys.argv[3]]
+
+# print("### \n\n")
+#
+# for data_file in os.listdir(directory):
+#     files.append(data_file)
+#     print(data_file)
+#
+# print("### \n\n")
+
+for data in files:
+    path = str(directory) + str(data)
+    print(path)
+
+    verts = genfromtxt(path, delimiter=', ', skip_header=0)
+
+    print(verts)
+
+# verts = [(-1.0, 1.0, 0.0), (-1.0, -1.0, 0.0), (1.0, -1.0, 0.0), (1.0, 1.0, 0.0)]
+
+    # create mesh and object
+    mesh = bpy.data.meshes.new(data)
+    object = bpy.data.objects.new(data,mesh)
+
+    # set mesh location
+    object.location = bpy.context.scene.cursor_location
+    bpy.context.scene.objects.link(object)
+
+    # create mesh from python data
+    mesh.from_pydata(verts,[],[])
+    mesh.update(calc_edges=True)
+
+    bpy.ops.object.select_all(action='SELECT')
+
+for area in bpy.context.screen.areas:
+    if area.type == 'VIEW_3D':
+        for region in area.regions:
+            if region.type == 'WINDOW':
+                override = {'area': area, 'region': region, 'edit_object': bpy.context.edit_object}
+bpy.ops.view3d.view_all(override)