From 41322dea056ec583d86587fef0761af2f83dcc5d Mon Sep 17 00:00:00 2001 From: hanemile Date: Mon, 4 Dec 2017 23:24:20 +0100 Subject: rewrote the script to generate stars in a 2D space --- src/gen.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/gen.py b/src/gen.py index 829c30d..ca7616b 100755 --- a/src/gen.py +++ b/src/gen.py @@ -5,6 +5,7 @@ import numpy as np import math import os import socket +import time host = socket.gethostname() # variables @@ -12,28 +13,18 @@ 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) +def rho(r): 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: @@ -62,24 +53,33 @@ def gen_stars(stars): range_max = int(length) # define the rho range - rand_min = rho_new(0, 0, 0) - rand_max = rho_new(length, 0, 0) + 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) - z = 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)) + + print("{:<20}{:<20}{:<20}{:<20}".format(str(x), str(y), str(rho_xy), str(rand_val))) # if the random value is smaller than the rho value, generate a star - if rand_val < rho(x, y, z): + 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("[]") + "," + str(z).strip("[]") + "\n") + data.write(str(x).strip("[]") + "," + str(y).strip("[]") + "\n") + 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(5e7) +gen_stars(1e5) -- cgit 1.4.1 From 19e8be5a5cca95474abf934fd13404dd5b73fe84 Mon Sep 17 00:00:00 2001 From: hanemile Date: Tue, 5 Dec 2017 12:03:44 +0100 Subject: implemented displaying the stars using an x-y-coordinate system --- src/gen.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/gen.py b/src/gen.py index ca7616b..8f8b26f 100755 --- a/src/gen.py +++ b/src/gen.py @@ -6,6 +6,7 @@ import math import os import socket import time +import matplotlib.pyplot as plt host = socket.gethostname() # variables @@ -35,6 +36,9 @@ def phi(x): c = a * b return c +listx = [] +listy = [] + def gen_stars(stars): stars = int(stars) @@ -63,8 +67,6 @@ def gen_stars(stars): rand_val = np.random.uniform(rand_min, rand_max, size=1) rho_xy = rho(math.sqrt(x**2 + y**2)) - print("{:<20}{:<20}{:<20}{:<20}".format(str(x), str(y), str(rho_xy), str(rand_val))) - # if the random value is smaller than the rho value, generate a star if rand_val < rho_xy: @@ -73,6 +75,8 @@ def gen_stars(stars): # 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)) @@ -82,4 +86,9 @@ def gen_stars(stars): print("rand_max: " + str(rand_max)) # generate n stars -gen_stars(1e5) +gen_stars(1e6) + +# plot the stars coordinates in 2D space +plt.scatter(listx, listy) +# plt.plot(listx, listy) +plt.show() -- cgit 1.4.1 From 9014e9febc70f81ad9f3454317a7b16e578dd7a9 Mon Sep 17 00:00:00 2001 From: hanemile Date: Tue, 5 Dec 2017 12:15:18 +0100 Subject: removed the old plot --- src/gen.py | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/gen.py b/src/gen.py index 8f8b26f..242636d 100755 --- a/src/gen.py +++ b/src/gen.py @@ -90,5 +90,4 @@ gen_stars(1e6) # plot the stars coordinates in 2D space plt.scatter(listx, listy) -# plt.plot(listx, listy) plt.show() -- cgit 1.4.1 From 6788e93f0bed952733259b79bbeb0e7b41ce75f7 Mon Sep 17 00:00:00 2001 From: hanemile Date: Tue, 5 Dec 2017 12:19:47 +0100 Subject: deleting repo to clone it using ssh --- src/data/pizzablech_11360.csv | 3 +++ src/data/pizzablech_19005.csv | 3 +++ src/data/pizzablech_21823.csv | 1 + src/data/pizzablech_27529.csv | 1 + src/data/pizzablech_32000.csv | 2 ++ src/data/pizzablech_32315.csv | 2 ++ src/data/pizzablech_7274.csv | 1 + src/data/pizzablech_8705.csv | 1 + src/data/pizzablech_924.csv | 1 + 9 files changed, 15 insertions(+) create mode 100644 src/data/pizzablech_11360.csv create mode 100644 src/data/pizzablech_19005.csv create mode 100644 src/data/pizzablech_21823.csv create mode 100644 src/data/pizzablech_27529.csv create mode 100644 src/data/pizzablech_32000.csv create mode 100644 src/data/pizzablech_32315.csv create mode 100644 src/data/pizzablech_7274.csv create mode 100644 src/data/pizzablech_8705.csv create mode 100644 src/data/pizzablech_924.csv (limited to 'src') 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 -- cgit 1.4.1 From 3945015abbfc48da21f2cc81dee006a9955fcc84 Mon Sep 17 00:00:00 2001 From: hanemile Date: Tue, 5 Dec 2017 16:09:14 +0100 Subject: added comments, command-line arguments and some fancy output --- src/gen.py | 27 --------------------------- 1 file changed, 27 deletions(-) (limited to 'src') diff --git a/src/gen.py b/src/gen.py index 242636d..b4b7933 100755 --- a/src/gen.py +++ b/src/gen.py @@ -9,33 +9,6 @@ import time import matplotlib.pyplot as plt host = socket.gethostname() -# variables -sigma = 200 -f_0 = 0.1 -R_s = 1e4 - -# 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 ) ) - c = a * b - return c - -# 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 - listx = [] listy = [] -- cgit 1.4.1 From 5e17688870d04f4a0ef259431f73287ea21b793d Mon Sep 17 00:00:00 2001 From: hanemile Date: Sat, 9 Dec 2017 14:19:59 +0100 Subject: minor ajustments --- src/README.md | 25 ++++++++++ src/coord.py | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/lookup.py | 86 ++++++++++++++++++++++++++++++++++ src/view.py | 48 +++++++++++++++++++ 4 files changed, 305 insertions(+) create mode 100644 src/README.md create mode 100755 src/coord.py create mode 100755 src/lookup.py create mode 100644 src/view.py (limited to 'src') diff --git a/src/README.md b/src/README.md new file mode 100644 index 0000000..bf572b2 --- /dev/null +++ b/src/README.md @@ -0,0 +1,25 @@ +# README + +### workflow: + +--- + +#### Generate the lookuptable + + + $ ./lookup.py + +- 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 + + +#### Display the stars using Blender + + $ blender --python view.py diff --git a/src/coord.py b/src/coord.py new file mode 100755 index 0000000..f801aee --- /dev/null +++ b/src/coord.py @@ -0,0 +1,146 @@ +#!/usr/bin/env python + +# import libraries +import time +import numpy as np +import sys + +# define the number of stars that should be generated +# (this is not the final value -> the final value is about 1000 times smaller) +nos = int(sys.argv[1]) + +# define some arrays for storing the values +arr_stars = np.zeros((int(nos), 3)) +arr_r = np.zeros((int(nos), 1)) +arr_saved_stars = np.zeros((int(nos), 3)) + +# define various paths +path = "data/rho6.csv" +save_path = "stars/star18.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(): + + time_start_gen_array = time.time() + + # generate n=nos stars + for i in range(0, nos): + + # generate the random values + arr_stars[i][0] = np.random.uniform(range_min, range_max, size=1) + arr_stars[i][1] = np.random.uniform(range_min, range_max, size=1) + arr_stars[i][2] = np.random.uniform(range_min, range_max, size=1) + + # calculate the distance of the star to the center of the galaxy + arr_r[i][0] = np.sqrt(pow(arr_stars[i][0], 2) + pow(arr_stars[i][1], 2) + pow(arr_stars[i][2], 2)) + + # print the randomly generated arrays + print(arr_stars) + print(arr_r) + + time_end_gen_array = time.time() + time_all_gen_array = time_end_gen_array - time_start_gen_array + # define the variables for storing the amount of stars kept or kicked away + stars_kept = 0 + stars_kicked = 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): + # print(i) + + # random value + a = np.random.uniform(rand_min, rand_max, size=1) + + # corresponding rho value + b = float(rho_file[int(round(arr_r[i][0], 0))].split(", ")[1].strip("\n")) + + # 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] = arr_stars[i][0] + arr_saved_stars[stars_kept][1] = arr_stars[i][1] + arr_saved_stars[stars_kept][2] = arr_stars[i][2] + + # increment the star_kept counter + stars_kept += 1 + + else: + # increment the star_kicked counter + stars_kicked += 1 + + if(i % (nos/(nos/10)) == 0): + if(i != 0): + a = str(round(i / nos * 100, 1)) + "%" + time_temp = time.time() + time_past = round(time_temp - start, 2) + print("{:<10}{:<20}".format(a, time_past)) + + print("") + end = time.time() + whole_time = end - start + print(">> Finished generating stars in " + str(whole_time) + " seconds\n") + + start_delete_rows = time.time() + + # delete all unused rows + print(">> Deleting unused rows in the arr_saved_stars array") + # for i in range(nos - stars_kicked, nos): + # np.delete(arr_saved_stars, (i), axis=0) + end_delete_rows = time.time() + time_delete_rows = end_delete_rows - start_delete_rows + print(">> Finished deleting stars in " + str(round(time_delete_rows, 4)) + " seconds \n") + + start_write_file = time.time() + + # write the star coordinates to a file + 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 + print(">> Finished writing star-data to " + save_path + " in " + str(round(time_write_file, 4)) + " seconds\n") + + + stars_percent = stars_kept / nos * 100 + + time_all = whole_time + time_write_file + time_delete_rows + + # print some stats + print("") + print("{:<30}{:<30}".format("Time (complete)", str(round(time_all, 4)) + " seconds")) + print("{:<30}{:<30}".format("Time (gen arrays)", str(round(time_all_gen_array, 4)) + " seconds")) + print("{:<30}{:<30}".format("Time (calculate stars)", str(round(whole_time, 4)) + " seconds")) + print("{:<30}{:<30}".format("Time (delete rows)", str(round(time_delete_rows, 4)) + " seconds")) + print("{:<30}{:<30}".format("Time (write to file)", str(round(time_write_file, 4)) + " seconds")) + print("{:-<40}".format("")) + print("{:<20}{:<20}".format("Number of Stars", str(nos))) + print("{:<20}{:<20}".format("Stars Kept:", str(stars_kept))) + print("{:<20}{:<20}".format("Stars Kicked:", str(stars_kicked))) + print("{:<20}{:<20}".format("Stars Percent", str(round(stars_percent, 4)) + "%")) + +if __name__ == "__main__": + main() 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..5e3808d --- /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 = ["final_star15.csv"] + +# 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) -- cgit 1.4.1 From 95772c59a241cd224310aa209b3ff976080ccdb5 Mon Sep 17 00:00:00 2001 From: hanemile Date: Sat, 9 Dec 2017 15:49:09 +0100 Subject: added feature for exactly generating n files --- src/coord.py | 84 +++++++++++++++++++----------------------------------------- 1 file changed, 27 insertions(+), 57 deletions(-) (limited to 'src') diff --git a/src/coord.py b/src/coord.py index f801aee..b5d9f49 100755 --- a/src/coord.py +++ b/src/coord.py @@ -6,17 +6,15 @@ import numpy as np import sys # define the number of stars that should be generated -# (this is not the final value -> the final value is about 1000 times smaller) nos = int(sys.argv[1]) # define some arrays for storing the values arr_stars = np.zeros((int(nos), 3)) -arr_r = np.zeros((int(nos), 1)) arr_saved_stars = np.zeros((int(nos), 3)) # define various paths path = "data/rho6.csv" -save_path = "stars/star18.csv" +save_path = "stars/star19.csv" # star13 -> 586 stars # define the random-value range [rho_min; rho_max] @@ -30,28 +28,10 @@ range_max = 1e7 # main function def main(): - time_start_gen_array = time.time() - - # generate n=nos stars - for i in range(0, nos): - - # generate the random values - arr_stars[i][0] = np.random.uniform(range_min, range_max, size=1) - arr_stars[i][1] = np.random.uniform(range_min, range_max, size=1) - arr_stars[i][2] = np.random.uniform(range_min, range_max, size=1) - - # calculate the distance of the star to the center of the galaxy - arr_r[i][0] = np.sqrt(pow(arr_stars[i][0], 2) + pow(arr_stars[i][1], 2) + pow(arr_stars[i][2], 2)) - - # print the randomly generated arrays - print(arr_stars) - print(arr_r) - - time_end_gen_array = time.time() - time_all_gen_array = time_end_gen_array - time_start_gen_array # 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() @@ -63,54 +43,50 @@ def main(): rho_file = data.readlines() # for every star... - for i in range(0, nos): - # print(i) + # 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)) - # random value + # generate a random value in the range [rand_min; rand_max] a = np.random.uniform(rand_min, rand_max, size=1) - # corresponding rho value - b = float(rho_file[int(round(arr_r[i][0], 0))].split(", ")[1].strip("\n")) + # read out the corresponding rho value from the lookuptable (rho-file) + b = float(rho_file[int(round(r[0], 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): + if(a < b): # add the coordinate to arr_saved_stars - arr_saved_stars[stars_kept][0] = arr_stars[i][0] - arr_saved_stars[stars_kept][1] = arr_stars[i][1] - arr_saved_stars[stars_kept][2] = arr_stars[i][2] + 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 - if(i % (nos/(nos/10)) == 0): - if(i != 0): - a = str(round(i / nos * 100, 1)) + "%" - time_temp = time.time() - time_past = round(time_temp - start, 2) - print("{:<10}{:<20}".format(a, time_past)) + # increment i + i = i + 1 print("") end = time.time() whole_time = end - start print(">> Finished generating stars in " + str(whole_time) + " seconds\n") - start_delete_rows = time.time() - - # delete all unused rows - print(">> Deleting unused rows in the arr_saved_stars array") - # for i in range(nos - stars_kicked, nos): - # np.delete(arr_saved_stars, (i), axis=0) - end_delete_rows = time.time() - time_delete_rows = end_delete_rows - start_delete_rows - print(">> Finished deleting stars in " + str(round(time_delete_rows, 4)) + " seconds \n") - - start_write_file = time.time() - # 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): @@ -124,23 +100,17 @@ def main(): time_write_file = end_write_file - start_write_file print(">> Finished writing star-data to " + save_path + " in " + str(round(time_write_file, 4)) + " seconds\n") - - stars_percent = stars_kept / nos * 100 - - time_all = whole_time + time_write_file + time_delete_rows + time_all = whole_time + time_write_file # print some stats print("") print("{:<30}{:<30}".format("Time (complete)", str(round(time_all, 4)) + " seconds")) - print("{:<30}{:<30}".format("Time (gen arrays)", str(round(time_all_gen_array, 4)) + " seconds")) print("{:<30}{:<30}".format("Time (calculate stars)", str(round(whole_time, 4)) + " seconds")) - print("{:<30}{:<30}".format("Time (delete rows)", str(round(time_delete_rows, 4)) + " seconds")) print("{:<30}{:<30}".format("Time (write to file)", str(round(time_write_file, 4)) + " seconds")) print("{:-<40}".format("")) print("{:<20}{:<20}".format("Number of Stars", str(nos))) - print("{:<20}{:<20}".format("Stars Kept:", str(stars_kept))) print("{:<20}{:<20}".format("Stars Kicked:", str(stars_kicked))) - print("{:<20}{:<20}".format("Stars Percent", str(round(stars_percent, 4)) + "%")) + print("{:<20}{:<20}".format("Percent: ", str( nos / stars_kicked * 100 ) + "%")) if __name__ == "__main__": main() -- cgit 1.4.1 From 8902a3a319193077009e80f8243ba180876c272c Mon Sep 17 00:00:00 2001 From: hanemile Date: Sat, 9 Dec 2017 15:50:54 +0100 Subject: added command line argument for specifying the file where the coordinates are stored --- src/view.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/view.py b/src/view.py index 5e3808d..a30ec48 100644 --- a/src/view.py +++ b/src/view.py @@ -6,7 +6,7 @@ import sys directory = "stars/" # # print(directory) # -files = ["final_star15.csv"] +files = [sys.argv[3]] # print("### \n\n") # -- cgit 1.4.1 From 23aa8723bc8c6ba0e96bc7cbac88075591116110 Mon Sep 17 00:00:00 2001 From: hanemile Date: Sat, 9 Dec 2017 16:01:33 +0100 Subject: added command line argument for specifying the location where the star coordinates should be saved --- src/coord.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/coord.py b/src/coord.py index b5d9f49..4094b25 100755 --- a/src/coord.py +++ b/src/coord.py @@ -14,7 +14,7 @@ arr_saved_stars = np.zeros((int(nos), 3)) # define various paths path = "data/rho6.csv" -save_path = "stars/star19.csv" +save_path = "stars/" + sys.argv[2] # star13 -> 586 stars # define the random-value range [rho_min; rho_max] -- cgit 1.4.1 From 785ce2de64d9505bf04ed918518b446b8c196d27 Mon Sep 17 00:00:00 2001 From: hanemile Date: Sat, 9 Dec 2017 16:03:23 +0100 Subject: updated the new command line arguments --- src/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/README.md b/src/README.md index bf572b2..a22aa75 100644 --- a/src/README.md +++ b/src/README.md @@ -17,9 +17,9 @@ #### Generate the coordinates - $ ./coord.py + $ ./coord.py #### Display the stars using Blender - $ blender --python view.py + $ blender --python view.py -- cgit 1.4.1 From 073e28e0e052941cf0913182944df6cf6363764d Mon Sep 17 00:00:00 2001 From: hanemile Date: Sat, 9 Dec 2017 17:53:54 +0100 Subject: fixed some bugs --- src/coord.py | 5 +++-- src/gen.py | 66 ------------------------------------------------------------ 2 files changed, 3 insertions(+), 68 deletions(-) delete mode 100755 src/gen.py (limited to 'src') diff --git a/src/coord.py b/src/coord.py index 4094b25..932cf80 100755 --- a/src/coord.py +++ b/src/coord.py @@ -102,11 +102,12 @@ def main(): time_all = whole_time + time_write_file + time_min = round(time_all / 60, 1) + # print some stats print("") print("{:<30}{:<30}".format("Time (complete)", str(round(time_all, 4)) + " seconds")) - print("{:<30}{:<30}".format("Time (calculate stars)", str(round(whole_time, 4)) + " seconds")) - print("{:<30}{:<30}".format("Time (write to file)", str(round(time_write_file, 4)) + " seconds")) + print("{:<30}{:<30}".format("Time (complete)", str(round(time_min, 4)) + " minutes")) print("{:-<40}".format("")) print("{:<20}{:<20}".format("Number of Stars", str(nos))) print("{:<20}{:<20}".format("Stars Kicked:", str(stars_kicked))) diff --git a/src/gen.py b/src/gen.py deleted file mode 100755 index b4b7933..0000000 --- a/src/gen.py +++ /dev/null @@ -1,66 +0,0 @@ -#!/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() -- cgit 1.4.1 From 8d52500a85acaccb19bc0892165c345d2b06a837 Mon Sep 17 00:00:00 2001 From: hanemile Date: Mon, 11 Dec 2017 20:40:58 +0100 Subject: telegram bot now prints where the stars are being saved (path) --- src/coord.py | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/coord.py b/src/coord.py index 932cf80..ecd978c 100755 --- a/src/coord.py +++ b/src/coord.py @@ -4,6 +4,7 @@ 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]) @@ -13,8 +14,8 @@ arr_stars = np.zeros((int(nos), 3)) arr_saved_stars = np.zeros((int(nos), 3)) # define various paths -path = "data/rho6.csv" -save_path = "stars/" + sys.argv[2] +path = "data/2e7.csv" +save_path = "stars/" + sys.argv[2] + ".csv" # star13 -> 586 stars # define the random-value range [rho_min; rho_max] @@ -53,12 +54,13 @@ def main(): # 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[int(round(r[0], 0))].split(", ")[1].strip("\n")) + 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))) @@ -83,7 +85,8 @@ def main(): print("") end = time.time() whole_time = end - start - print(">> Finished generating stars in " + str(whole_time) + " seconds\n") + out = ">> Finished generating stars in " + str(whole_time) + " seconds\n" + print(out) # write the star coordinates to a file start_write_file = time.time() @@ -98,7 +101,8 @@ def main(): end_write_file = time.time() time_write_file = end_write_file - start_write_file - print(">> Finished writing star-data to " + save_path + " in " + str(round(time_write_file, 4)) + " seconds\n") + 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 @@ -106,12 +110,29 @@ def main(): # print some stats print("") - print("{:<30}{:<30}".format("Time (complete)", str(round(time_all, 4)) + " seconds")) - print("{:<30}{:<30}".format("Time (complete)", str(round(time_min, 4)) + " minutes")) + 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() -- cgit 1.4.1