From 542cd1b95066520c99c4ca4a18beab0e5d24e86f Mon Sep 17 00:00:00 2001 From: Franz Masatoshi Yuri Date: Tue, 13 Sep 2022 19:54:21 -0300 Subject: [PATCH 01/15] implemented dictionary creation --- data/dispersion csv files/juninho.csv | 23 ++++++++++ rocketpy/utilities.py | 62 +++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 data/dispersion csv files/juninho.csv diff --git a/data/dispersion csv files/juninho.csv b/data/dispersion csv files/juninho.csv new file mode 100644 index 000000000..5f40bbfc6 --- /dev/null +++ b/data/dispersion csv files/juninho.csv @@ -0,0 +1,23 @@ +;;value;standard deviation;;;;;value;standard deviation;;;;;value;standard deviation;;;;;value;standard deviation +Rocket Parameters:;;;;;;Motor Parameters:;;;;;;Launch and Environment;;;;;;Recuperation and eletronics;;; +;rocketMass;12.96;0.648;;;;impulse;3053.198;305.3198;;;;inclination;86;1.18;;;;CdSDrogue;0.37;0.037 +;inertiaI;7.73;0.3867;;;;burnOut;4.488;0.8976;;;;heading;0;1.18;;;;CdSMain;1.06;0.106 +;inertiaZ;0.0279;0.001395;;;;nozzleRadius;0.02222;0.002222;;;;railLength;4.2;0.042;;;;lag_rec;1;0.5 +;radius;0.0529;0.000529;;;;throatRadius;0.00875;0.000875;;;;radiusRailPosition;0;2.5;;;;lag_se;0;0 +;distanceRocketNozzle;-0.91591;-0.0457955;;;;grainSeparation;0.006;0.0006;;;;ensambleMember;[0,1,2,3,4,5];;;;;;; +;distanceRocketProppelant;-0.571773;-0.02858865;;;;grainDensity;1641.5;164.15;;;;windU;[3,4,5,6];;;;;;; +;powerOffDrag;1;0.2;;;;grainOuterRadius;0.03596;0.003596;;;;windV;[3,4,5,6];;;;;;; +;powerOnDrag;1;0.2;;;;grainInitialInnerRadius;0.01596;0.001596;;;;time;[6,12,18];;;;;;; +nose;noseLength;0.41533;0.0041533;;;;grainInitialHeight;0.124;0.0124;;;;day;[23,24,25,26,27,28,29,30,31];;;;;;; +;noseDistanceToCM;1.19467;0.0597335;;;;;;;;;;thetaRailPosition;[0,1,2,3,4,5,6,7,8,9,10];;;;;;; +fins;finSpan;0.13;0.00065;;;;;;;;;;;;;;;;;; +;finRootChord;0.12;0.0006;;;;;;;;;;;;;;;;;; +;finDistanceToCM;-0.72911;0.00364555;;;;;;;;;;;;;;;;;; +tail;tailDistanceToCM;-0.869;0.04345;;;;;;;;;;;;;;;;;; +;tailTopRadius;0.0529;0.000529;;;;;;;;;;;;;;;;;; +;tailbottomRadius;0.043296;0.00043296;;;;;;;;;;;;;;;;;; +;tailLength;0.057;0.00057;;;;;;;;;;;;;;;;;; +canard;canardSpan;0.062;0.00031;;;;;;;;;;;;;;;;;; +;canardRootChord;0.062;0.00031;;;;;;;;;;;;;;;;;; +;canardTipChord;0.062;0.00031;;;;;;;;;;;;;;;;;; +;canardDistanceToCM;0.431771;0.02158855;;;;;;;;;;;;;;;;;; diff --git a/rocketpy/utilities.py b/rocketpy/utilities.py index dc847ea3c..e063c75bc 100644 --- a/rocketpy/utilities.py +++ b/rocketpy/utilities.py @@ -4,6 +4,7 @@ __license__ = "MIT" import numpy as np +import pandas as pd from scipy.integrate import solve_ivp from .Environment import Environment @@ -197,3 +198,64 @@ def du(z, u): velocityFunction() return altitudeFunction, velocityFunction, final_sol + +def create_dispersion_dictionary(dic): + dataframe = pd.read_csv(dic,sep = ';', skiprows=[0,1], header = None) + + + rocketKeys = list(dataframe[1].dropna()) + rocketValues = list(dataframe[2].dropna()) + rocketSD = list(dataframe[3]) + + motorKeys = list(dataframe[7].dropna()) + motorValues = list(dataframe[8].dropna()) + motorSD = list(dataframe[9]) + + launchKeys = list(dataframe[13].dropna()) + launchValues = list(dataframe[14].dropna()) + launchSD = list(dataframe[15]) + + parachuteKeys = list(dataframe[19].dropna()) + parachuteValues = list(dataframe[20].dropna()) + parachuteSD = list(dataframe[21]) + + + allValues = [] + # crating the dictionary + + for i in range(0,len(rocketKeys)): + + if pd.isnull(rocketSD[i]): + allValues.append(rocketValues[i]) + else: + allValues.append(((rocketValues[i]), (rocketSD[i]))) + + for j in range(0,len(motorKeys)): + + if pd.isnull(motorSD[j]): + allValues.append(motorValues[j]) + else: + allValues.append(((motorValues[j]), (motorSD[j]))) + + for k in range(0,len(parachuteKeys)): + + if pd.isnull(parachuteSD[k]): + allValues.append(parachuteValues[k]) + else: + allValues.append(((parachuteValues[k]), (parachuteSD[k]))) + + for l in range(0,len(launchKeys)): + + if pd.isnull(launchSD[l]): + allValues.append(launchValues[l]) + else: + allValues.append(((launchValues[l]), (launchSD[l]))) + + + allKeys = rocketKeys + motorKeys + parachuteKeys + launchKeys + + analysis_parameters = dict(zip(allKeys,allValues)) + return analysis_parameters + + + From bc1fb7641fc2350eff450b7a6c64b96ddcacf443 Mon Sep 17 00:00:00 2001 From: Franz Masatoshi Yuri Date: Tue, 13 Sep 2022 20:03:32 -0300 Subject: [PATCH 02/15] implemented dictionary creation --- data/dispersion csv files/juninho.csv | 23 ++++++++++ rocketpy/utilities.py | 62 +++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 data/dispersion csv files/juninho.csv diff --git a/data/dispersion csv files/juninho.csv b/data/dispersion csv files/juninho.csv new file mode 100644 index 000000000..5f40bbfc6 --- /dev/null +++ b/data/dispersion csv files/juninho.csv @@ -0,0 +1,23 @@ +;;value;standard deviation;;;;;value;standard deviation;;;;;value;standard deviation;;;;;value;standard deviation +Rocket Parameters:;;;;;;Motor Parameters:;;;;;;Launch and Environment;;;;;;Recuperation and eletronics;;; +;rocketMass;12.96;0.648;;;;impulse;3053.198;305.3198;;;;inclination;86;1.18;;;;CdSDrogue;0.37;0.037 +;inertiaI;7.73;0.3867;;;;burnOut;4.488;0.8976;;;;heading;0;1.18;;;;CdSMain;1.06;0.106 +;inertiaZ;0.0279;0.001395;;;;nozzleRadius;0.02222;0.002222;;;;railLength;4.2;0.042;;;;lag_rec;1;0.5 +;radius;0.0529;0.000529;;;;throatRadius;0.00875;0.000875;;;;radiusRailPosition;0;2.5;;;;lag_se;0;0 +;distanceRocketNozzle;-0.91591;-0.0457955;;;;grainSeparation;0.006;0.0006;;;;ensambleMember;[0,1,2,3,4,5];;;;;;; +;distanceRocketProppelant;-0.571773;-0.02858865;;;;grainDensity;1641.5;164.15;;;;windU;[3,4,5,6];;;;;;; +;powerOffDrag;1;0.2;;;;grainOuterRadius;0.03596;0.003596;;;;windV;[3,4,5,6];;;;;;; +;powerOnDrag;1;0.2;;;;grainInitialInnerRadius;0.01596;0.001596;;;;time;[6,12,18];;;;;;; +nose;noseLength;0.41533;0.0041533;;;;grainInitialHeight;0.124;0.0124;;;;day;[23,24,25,26,27,28,29,30,31];;;;;;; +;noseDistanceToCM;1.19467;0.0597335;;;;;;;;;;thetaRailPosition;[0,1,2,3,4,5,6,7,8,9,10];;;;;;; +fins;finSpan;0.13;0.00065;;;;;;;;;;;;;;;;;; +;finRootChord;0.12;0.0006;;;;;;;;;;;;;;;;;; +;finDistanceToCM;-0.72911;0.00364555;;;;;;;;;;;;;;;;;; +tail;tailDistanceToCM;-0.869;0.04345;;;;;;;;;;;;;;;;;; +;tailTopRadius;0.0529;0.000529;;;;;;;;;;;;;;;;;; +;tailbottomRadius;0.043296;0.00043296;;;;;;;;;;;;;;;;;; +;tailLength;0.057;0.00057;;;;;;;;;;;;;;;;;; +canard;canardSpan;0.062;0.00031;;;;;;;;;;;;;;;;;; +;canardRootChord;0.062;0.00031;;;;;;;;;;;;;;;;;; +;canardTipChord;0.062;0.00031;;;;;;;;;;;;;;;;;; +;canardDistanceToCM;0.431771;0.02158855;;;;;;;;;;;;;;;;;; diff --git a/rocketpy/utilities.py b/rocketpy/utilities.py index dc847ea3c..e063c75bc 100644 --- a/rocketpy/utilities.py +++ b/rocketpy/utilities.py @@ -4,6 +4,7 @@ __license__ = "MIT" import numpy as np +import pandas as pd from scipy.integrate import solve_ivp from .Environment import Environment @@ -197,3 +198,64 @@ def du(z, u): velocityFunction() return altitudeFunction, velocityFunction, final_sol + +def create_dispersion_dictionary(dic): + dataframe = pd.read_csv(dic,sep = ';', skiprows=[0,1], header = None) + + + rocketKeys = list(dataframe[1].dropna()) + rocketValues = list(dataframe[2].dropna()) + rocketSD = list(dataframe[3]) + + motorKeys = list(dataframe[7].dropna()) + motorValues = list(dataframe[8].dropna()) + motorSD = list(dataframe[9]) + + launchKeys = list(dataframe[13].dropna()) + launchValues = list(dataframe[14].dropna()) + launchSD = list(dataframe[15]) + + parachuteKeys = list(dataframe[19].dropna()) + parachuteValues = list(dataframe[20].dropna()) + parachuteSD = list(dataframe[21]) + + + allValues = [] + # crating the dictionary + + for i in range(0,len(rocketKeys)): + + if pd.isnull(rocketSD[i]): + allValues.append(rocketValues[i]) + else: + allValues.append(((rocketValues[i]), (rocketSD[i]))) + + for j in range(0,len(motorKeys)): + + if pd.isnull(motorSD[j]): + allValues.append(motorValues[j]) + else: + allValues.append(((motorValues[j]), (motorSD[j]))) + + for k in range(0,len(parachuteKeys)): + + if pd.isnull(parachuteSD[k]): + allValues.append(parachuteValues[k]) + else: + allValues.append(((parachuteValues[k]), (parachuteSD[k]))) + + for l in range(0,len(launchKeys)): + + if pd.isnull(launchSD[l]): + allValues.append(launchValues[l]) + else: + allValues.append(((launchValues[l]), (launchSD[l]))) + + + allKeys = rocketKeys + motorKeys + parachuteKeys + launchKeys + + analysis_parameters = dict(zip(allKeys,allValues)) + return analysis_parameters + + + From 6093de391b9d824ca79fe0b8eec97050033a958c Mon Sep 17 00:00:00 2001 From: Franz Masatoshi Yuri Date: Tue, 13 Sep 2022 20:22:47 -0300 Subject: [PATCH 03/15] formating --- rocketpy/utilities.py | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/rocketpy/utilities.py b/rocketpy/utilities.py index e063c75bc..56ff60501 100644 --- a/rocketpy/utilities.py +++ b/rocketpy/utilities.py @@ -38,7 +38,7 @@ def compute_CdS_from_drop_test( """ - return 2 * rocket_mass * g / ((terminal_velocity**2) * air_density) + return 2 * rocket_mass * g / ((terminal_velocity ** 2) * air_density) # TODO: Needs tests @@ -199,9 +199,21 @@ def du(z, u): return altitudeFunction, velocityFunction, final_sol + def create_dispersion_dictionary(dic): - dataframe = pd.read_csv(dic,sep = ';', skiprows=[0,1], header = None) + """creates a dictinary with the rocket data in a excel .csv file. + Parameters + ---------- + dic : string + String with the path to the .csv file. + + Returns + ------- + dictionary + Dictionary with all rocket data used in dispersion analysis. + """ + dataframe = pd.read_csv(dic, sep=";", skiprows=[0, 1], header=None) rocketKeys = list(dataframe[1].dropna()) rocketValues = list(dataframe[2].dropna()) @@ -214,48 +226,43 @@ def create_dispersion_dictionary(dic): launchKeys = list(dataframe[13].dropna()) launchValues = list(dataframe[14].dropna()) launchSD = list(dataframe[15]) - + parachuteKeys = list(dataframe[19].dropna()) parachuteValues = list(dataframe[20].dropna()) parachuteSD = list(dataframe[21]) - allValues = [] # crating the dictionary - for i in range(0,len(rocketKeys)): + for i in range(0, len(rocketKeys)): if pd.isnull(rocketSD[i]): allValues.append(rocketValues[i]) else: - allValues.append(((rocketValues[i]), (rocketSD[i]))) + allValues.append(((rocketValues[i]), (rocketSD[i]))) - for j in range(0,len(motorKeys)): + for j in range(0, len(motorKeys)): if pd.isnull(motorSD[j]): allValues.append(motorValues[j]) else: - allValues.append(((motorValues[j]), (motorSD[j]))) + allValues.append(((motorValues[j]), (motorSD[j]))) - for k in range(0,len(parachuteKeys)): + for k in range(0, len(parachuteKeys)): if pd.isnull(parachuteSD[k]): allValues.append(parachuteValues[k]) else: - allValues.append(((parachuteValues[k]), (parachuteSD[k]))) + allValues.append(((parachuteValues[k]), (parachuteSD[k]))) - for l in range(0,len(launchKeys)): + for l in range(0, len(launchKeys)): if pd.isnull(launchSD[l]): allValues.append(launchValues[l]) else: - allValues.append(((launchValues[l]), (launchSD[l]))) - + allValues.append(((launchValues[l]), (launchSD[l]))) allKeys = rocketKeys + motorKeys + parachuteKeys + launchKeys - analysis_parameters = dict(zip(allKeys,allValues)) + analysis_parameters = dict(zip(allKeys, allValues)) return analysis_parameters - - - From 3c89ecf206cd11c92de4f82ee4f02d3b3f4b599f Mon Sep 17 00:00:00 2001 From: Lint Action Date: Tue, 13 Sep 2022 23:27:24 +0000 Subject: [PATCH 04/15] Fix code style issues with Black --- rocketpy/utilities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rocketpy/utilities.py b/rocketpy/utilities.py index 56ff60501..365863a66 100644 --- a/rocketpy/utilities.py +++ b/rocketpy/utilities.py @@ -38,7 +38,7 @@ def compute_CdS_from_drop_test( """ - return 2 * rocket_mass * g / ((terminal_velocity ** 2) * air_density) + return 2 * rocket_mass * g / ((terminal_velocity**2) * air_density) # TODO: Needs tests From 05ff0662ddda29e74b6019797ab710725d91831b Mon Sep 17 00:00:00 2001 From: FranzYuri <86535872+FranzYuri@users.noreply.github.com> Date: Thu, 15 Sep 2022 13:30:49 -0300 Subject: [PATCH 05/15] Update utilities.py --- rocketpy/utilities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rocketpy/utilities.py b/rocketpy/utilities.py index 365863a66..273b35a3c 100644 --- a/rocketpy/utilities.py +++ b/rocketpy/utilities.py @@ -213,7 +213,7 @@ def create_dispersion_dictionary(dic): dictionary Dictionary with all rocket data used in dispersion analysis. """ - dataframe = pd.read_csv(dic, sep=";", skiprows=[0, 1], header=None) + dataframe = pd.read_csv(dic, skiprows=[0, 1], header=None) rocketKeys = list(dataframe[1].dropna()) rocketValues = list(dataframe[2].dropna()) From b4f5560361650296f4d30d1a9b8051871c97f3a7 Mon Sep 17 00:00:00 2001 From: Franz Masatoshi Yuri Date: Fri, 16 Sep 2022 14:19:00 -0300 Subject: [PATCH 06/15] included xlsx --- rocketpy/utilities.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rocketpy/utilities.py b/rocketpy/utilities.py index 56ff60501..a411c9593 100644 --- a/rocketpy/utilities.py +++ b/rocketpy/utilities.py @@ -3,6 +3,7 @@ __copyright__ = "Copyright 20XX, RocketPy Team" __license__ = "MIT" +import os import numpy as np import pandas as pd from scipy.integrate import solve_ivp @@ -213,7 +214,13 @@ def create_dispersion_dictionary(dic): dictionary Dictionary with all rocket data used in dispersion analysis. """ - dataframe = pd.read_csv(dic, sep=";", skiprows=[0, 1], header=None) + + file = os.path.splitext(dic) + if file[-1] == ".csv": + dataframe = pd.read_csv(dic, skiprows=[0, 1], header=None) + elif file[-1] == ".xlsx": + dataframe = pd.read_excel(dic, skiprows=[0, 1], header=None) + rocketKeys = list(dataframe[1].dropna()) rocketValues = list(dataframe[2].dropna()) From cb2c2c9d1c4aabbdf1fd2da2c5cd98a403858740 Mon Sep 17 00:00:00 2001 From: Franz Masatoshi Yuri Date: Tue, 20 Sep 2022 15:50:40 -0300 Subject: [PATCH 07/15] removed libraries --- rocketpy/utilities.py | 74 +++++++------------------------------------ 1 file changed, 12 insertions(+), 62 deletions(-) diff --git a/rocketpy/utilities.py b/rocketpy/utilities.py index a411c9593..761bd9ef5 100644 --- a/rocketpy/utilities.py +++ b/rocketpy/utilities.py @@ -3,9 +3,7 @@ __copyright__ = "Copyright 20XX, RocketPy Team" __license__ = "MIT" -import os import numpy as np -import pandas as pd from scipy.integrate import solve_ivp from .Environment import Environment @@ -41,7 +39,6 @@ def compute_CdS_from_drop_test( return 2 * rocket_mass * g / ((terminal_velocity ** 2) * air_density) - # TODO: Needs tests @@ -214,62 +211,15 @@ def create_dispersion_dictionary(dic): dictionary Dictionary with all rocket data used in dispersion analysis. """ - - file = os.path.splitext(dic) - if file[-1] == ".csv": - dataframe = pd.read_csv(dic, skiprows=[0, 1], header=None) - elif file[-1] == ".xlsx": - dataframe = pd.read_excel(dic, skiprows=[0, 1], header=None) - - - rocketKeys = list(dataframe[1].dropna()) - rocketValues = list(dataframe[2].dropna()) - rocketSD = list(dataframe[3]) - - motorKeys = list(dataframe[7].dropna()) - motorValues = list(dataframe[8].dropna()) - motorSD = list(dataframe[9]) - - launchKeys = list(dataframe[13].dropna()) - launchValues = list(dataframe[14].dropna()) - launchSD = list(dataframe[15]) - - parachuteKeys = list(dataframe[19].dropna()) - parachuteValues = list(dataframe[20].dropna()) - parachuteSD = list(dataframe[21]) - - allValues = [] - # crating the dictionary - - for i in range(0, len(rocketKeys)): - - if pd.isnull(rocketSD[i]): - allValues.append(rocketValues[i]) - else: - allValues.append(((rocketValues[i]), (rocketSD[i]))) - - for j in range(0, len(motorKeys)): - - if pd.isnull(motorSD[j]): - allValues.append(motorValues[j]) - else: - allValues.append(((motorValues[j]), (motorSD[j]))) - - for k in range(0, len(parachuteKeys)): - - if pd.isnull(parachuteSD[k]): - allValues.append(parachuteValues[k]) - else: - allValues.append(((parachuteValues[k]), (parachuteSD[k]))) - - for l in range(0, len(launchKeys)): - - if pd.isnull(launchSD[l]): - allValues.append(launchValues[l]) - else: - allValues.append(((launchValues[l]), (launchSD[l]))) - - allKeys = rocketKeys + motorKeys + parachuteKeys + launchKeys - - analysis_parameters = dict(zip(allKeys, allValues)) - return analysis_parameters + try: + file = np.genfromtxt(dic,usecols = (1,2,3),delimiter = ',',dtype = str) + except: + file = np.genfromtxt(dic,usecols = (1,2,3),delimiter = ';',dtype = str) + analysis_parameters = dict() + for list in file: + if list[0] !="": + if list[2] =="": + analysis_parameters[list[0]] = float(list[1]) + else: + analysis_parameters[list[0]] = (float(list[1]),float(list[2])) + return analysis_parameters \ No newline at end of file From 68ba507648d5faadc44ec9bb5113631cded6f6c9 Mon Sep 17 00:00:00 2001 From: Franz Masatoshi Yuri Date: Fri, 23 Sep 2022 17:23:06 -0300 Subject: [PATCH 08/15] removing libraries --- rocketpy/utilities.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/rocketpy/utilities.py b/rocketpy/utilities.py index 761bd9ef5..282563713 100644 --- a/rocketpy/utilities.py +++ b/rocketpy/utilities.py @@ -39,6 +39,7 @@ def compute_CdS_from_drop_test( return 2 * rocket_mass * g / ((terminal_velocity ** 2) * air_density) + # TODO: Needs tests @@ -212,14 +213,14 @@ def create_dispersion_dictionary(dic): Dictionary with all rocket data used in dispersion analysis. """ try: - file = np.genfromtxt(dic,usecols = (1,2,3),delimiter = ',',dtype = str) + file = np.genfromtxt(dic, usecols=(1, 2, 3), delimiter=",", dtype=str) except: - file = np.genfromtxt(dic,usecols = (1,2,3),delimiter = ';',dtype = str) + file = np.genfromtxt(dic, usecols=(1, 2, 3), delimiter=";", dtype=str) analysis_parameters = dict() for list in file: - if list[0] !="": - if list[2] =="": + if list[0] != "": + if list[2] == "": analysis_parameters[list[0]] = float(list[1]) else: - analysis_parameters[list[0]] = (float(list[1]),float(list[2])) + analysis_parameters[list[0]] = (float(list[1]), float(list[2])) return analysis_parameters \ No newline at end of file From dae505669facb7227985b31c33ac0cc4ce2eb0eb Mon Sep 17 00:00:00 2001 From: Franz Masatoshi Yuri Date: Fri, 23 Sep 2022 20:13:00 -0300 Subject: [PATCH 09/15] fixing errors and adding Valetudo.csv --- data/dispersion csv files/Valetudo.csv | 32 ++++++++++++++ rocketpy/utilities.py | 60 ++------------------------ 2 files changed, 36 insertions(+), 56 deletions(-) create mode 100644 data/dispersion csv files/Valetudo.csv diff --git a/data/dispersion csv files/Valetudo.csv b/data/dispersion csv files/Valetudo.csv new file mode 100644 index 000000000..0e52dd5f5 --- /dev/null +++ b/data/dispersion csv files/Valetudo.csv @@ -0,0 +1,32 @@ +;;value;standard deviation;; +Rocket Parameters:;;;;; +;rocketMass;8.257;0.001;; +;inertiaI;3.675;0.03675;; +;inertiaZ;0.007;0.00007;; +;radius;0.04045;0.001;; +;distanceRocketNozzle;-1.024;0.001;; +;distanceRocketPropellant;-0.571;0.001;; +;powerOffDrag;0.864857143;0.033;; +;powerOnDrag;0.864857143;0.033;; +nosecone;noseLength;0.274;0.001;; +;noseDistanceToCM;1.134;0.001;; +fins;finSpan;0.077;0.0005;; +;finRootChord;0.058;0.0005;; +;finTipChord;0.018;0.0005;; +;finDistanceToCM;-0.906;0.001;; +parachute;CdSDrogue;0.4537;0.07;; +;lag_rec;1;0.5;; +;lag_se;0.73;0.16;; +environment;inclination;84.7;1;; +;heading;53;2;; +;railLength;5.7;0.0005;; +;ensembleMember;[0,1,2,3,4,5,6,7,8,9];;; +motor;impulse;1415.15;35.3;; +;burnOut;5.274;1;; +;nozzleRadius;0.021642;0.0005;; +;throatRadius;0.008;0.0005;; +;grainSeparation;0.006;0.001;; +;grainDensity;1707;50;; +;grainOuterRadius;0.0214;0.2;; +;grainInitialInnerRadius;.0097;0.000375;; +;grainInitialHeight;0.12;0.001;; diff --git a/rocketpy/utilities.py b/rocketpy/utilities.py index 1bced064d..a3d6cb552 100644 --- a/rocketpy/utilities.py +++ b/rocketpy/utilities.py @@ -212,7 +212,6 @@ def create_dispersion_dictionary(dic): dictionary Dictionary with all rocket data used in dispersion analysis. """ -<<<<<<< HEAD try: file = np.genfromtxt(dic, usecols=(1, 2, 3), delimiter=",", dtype=str) except: @@ -221,62 +220,11 @@ def create_dispersion_dictionary(dic): for list in file: if list[0] != "": if list[2] == "": - analysis_parameters[list[0]] = float(list[1]) + try: + analysis_parameters[list[0]] = float(list[1]) + except: + analysis_parameters[list[0]] = eval(list[1]) else: analysis_parameters[list[0]] = (float(list[1]), float(list[2])) return analysis_parameters -======= - dataframe = pd.read_csv(dic, skiprows=[0, 1], header=None) - rocketKeys = list(dataframe[1].dropna()) - rocketValues = list(dataframe[2].dropna()) - rocketSD = list(dataframe[3]) - - motorKeys = list(dataframe[7].dropna()) - motorValues = list(dataframe[8].dropna()) - motorSD = list(dataframe[9]) - - launchKeys = list(dataframe[13].dropna()) - launchValues = list(dataframe[14].dropna()) - launchSD = list(dataframe[15]) - - parachuteKeys = list(dataframe[19].dropna()) - parachuteValues = list(dataframe[20].dropna()) - parachuteSD = list(dataframe[21]) - - allValues = [] - # crating the dictionary - - for i in range(0, len(rocketKeys)): - - if pd.isnull(rocketSD[i]): - allValues.append(rocketValues[i]) - else: - allValues.append(((rocketValues[i]), (rocketSD[i]))) - - for j in range(0, len(motorKeys)): - - if pd.isnull(motorSD[j]): - allValues.append(motorValues[j]) - else: - allValues.append(((motorValues[j]), (motorSD[j]))) - - for k in range(0, len(parachuteKeys)): - - if pd.isnull(parachuteSD[k]): - allValues.append(parachuteValues[k]) - else: - allValues.append(((parachuteValues[k]), (parachuteSD[k]))) - - for l in range(0, len(launchKeys)): - - if pd.isnull(launchSD[l]): - allValues.append(launchValues[l]) - else: - allValues.append(((launchValues[l]), (launchSD[l]))) - - allKeys = rocketKeys + motorKeys + parachuteKeys + launchKeys - - analysis_parameters = dict(zip(allKeys, allValues)) - return analysis_parameters ->>>>>>> 05ff0662ddda29e74b6019797ab710725d91831b From 2c065fa3cb347d9dc90703c14e0166c2d53fd871 Mon Sep 17 00:00:00 2001 From: Lint Action Date: Fri, 23 Sep 2022 23:13:44 +0000 Subject: [PATCH 10/15] Fix code style issues with Black --- rocketpy/utilities.py | 1 - 1 file changed, 1 deletion(-) diff --git a/rocketpy/utilities.py b/rocketpy/utilities.py index a3d6cb552..cbb40d411 100644 --- a/rocketpy/utilities.py +++ b/rocketpy/utilities.py @@ -227,4 +227,3 @@ def create_dispersion_dictionary(dic): else: analysis_parameters[list[0]] = (float(list[1]), float(list[2])) return analysis_parameters - From 567192714197e2a7488c55af364ae37ff5deb13b Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Sat, 24 Sep 2022 13:20:10 +0200 Subject: [PATCH 11/15] ENH: Dealing with expect errors cases --- rocketpy/utilities.py | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/rocketpy/utilities.py b/rocketpy/utilities.py index cbb40d411..1b0fe4bc7 100644 --- a/rocketpy/utilities.py +++ b/rocketpy/utilities.py @@ -41,8 +41,6 @@ def compute_CdS_from_drop_test( # TODO: Needs tests - - def calculateEquilibriumAltitude( rocket_mass, CdS, @@ -110,7 +108,7 @@ def check_constant(f, eps): Parameters ---------- - f : array, list + f : array, row _description_ eps : float _description_ @@ -199,31 +197,45 @@ def du(z, u): return altitudeFunction, velocityFunction, final_sol -def create_dispersion_dictionary(dic): - """creates a dictinary with the rocket data in a excel .csv file. +# TODO: Needs tests +def create_dispersion_dictionary(filename): + """Creates a dictionary with the rocket data provided by a .csv file. + File should be organized in four columns: attribute_class, parameter_name, + mean_value, standard_deviation. The first row should be the header. + It is advised to use ";" as separator, but "," should work on most of cases. Parameters ---------- - dic : string + filename : string String with the path to the .csv file. Returns ------- dictionary - Dictionary with all rocket data used in dispersion analysis. + Dictionary with all rocket data to be used in dispersion analysis. """ try: - file = np.genfromtxt(dic, usecols=(1, 2, 3), delimiter=",", dtype=str) + file = np.genfromtxt( + filename, usecols=(1, 2, 3), skip_header=1, delimiter=";", dtype=str + ) except: - file = np.genfromtxt(dic, usecols=(1, 2, 3), delimiter=";", dtype=str) + print( + "Error: The delimiter should be ';'. Using ',' instead, be aware that some resources might not work as expected. Please consider changing the delimiter to ';'." + ) + file = np.genfromtxt( + filename, usecols=(1, 2, 3), skip_header=1, delimiter=",", dtype=str + ) analysis_parameters = dict() - for list in file: - if list[0] != "": - if list[2] == "": + for row in file: + if row[0] != "": + if row[2] == "": try: - analysis_parameters[list[0]] = float(list[1]) + analysis_parameters[row[0]] = float(row[1]) except: - analysis_parameters[list[0]] = eval(list[1]) + analysis_parameters[row[0]] = eval(row[1]) else: - analysis_parameters[list[0]] = (float(list[1]), float(list[2])) + try: + analysis_parameters[row[0]] = (float(row[1]), float(row[2])) + except: + analysis_parameters[row[0]] = "" return analysis_parameters From 88d3a47c4f4e2fb3f920d5fa10cd07a4aea9e724 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Sat, 24 Sep 2022 13:20:28 +0200 Subject: [PATCH 12/15] FIX: Refactor .csv files --- data/dispersion csv files/Valetudo.csv | 63 +++++++++++++------------- data/dispersion csv files/juninho.csv | 23 ---------- 2 files changed, 31 insertions(+), 55 deletions(-) delete mode 100644 data/dispersion csv files/juninho.csv diff --git a/data/dispersion csv files/Valetudo.csv b/data/dispersion csv files/Valetudo.csv index 0e52dd5f5..ac371d0fb 100644 --- a/data/dispersion csv files/Valetudo.csv +++ b/data/dispersion csv files/Valetudo.csv @@ -1,32 +1,31 @@ -;;value;standard deviation;; -Rocket Parameters:;;;;; -;rocketMass;8.257;0.001;; -;inertiaI;3.675;0.03675;; -;inertiaZ;0.007;0.00007;; -;radius;0.04045;0.001;; -;distanceRocketNozzle;-1.024;0.001;; -;distanceRocketPropellant;-0.571;0.001;; -;powerOffDrag;0.864857143;0.033;; -;powerOnDrag;0.864857143;0.033;; -nosecone;noseLength;0.274;0.001;; -;noseDistanceToCM;1.134;0.001;; -fins;finSpan;0.077;0.0005;; -;finRootChord;0.058;0.0005;; -;finTipChord;0.018;0.0005;; -;finDistanceToCM;-0.906;0.001;; -parachute;CdSDrogue;0.4537;0.07;; -;lag_rec;1;0.5;; -;lag_se;0.73;0.16;; -environment;inclination;84.7;1;; -;heading;53;2;; -;railLength;5.7;0.0005;; -;ensembleMember;[0,1,2,3,4,5,6,7,8,9];;; -motor;impulse;1415.15;35.3;; -;burnOut;5.274;1;; -;nozzleRadius;0.021642;0.0005;; -;throatRadius;0.008;0.0005;; -;grainSeparation;0.006;0.001;; -;grainDensity;1707;50;; -;grainOuterRadius;0.0214;0.2;; -;grainInitialInnerRadius;.0097;0.000375;; -;grainInitialHeight;0.12;0.001;; +attribute_class; parameter_name; mean_value; standard_deviation; +environment; ensembleMember; [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];; +motor; impulse; 1415.15; 35.3; +motor; burnOut; 5.274; 1; +motor; nozzleRadius; 0.021642; 0.0005; +motor; throatRadius; 0.008; 0.0005; +motor; grainSeparation; 0.006; 0.001; +motor; grainDensity; 1707; 50; +motor; grainOuterRadius; 0.0214; 0.2; +motor; grainInitialInnerRadius; .0097;0.000375; +motor; grainInitialHeight; 0.12; 0.001 +rocket; rocketMass; 8.257; 0.001; +rocket; inertiaI; 3.675; 0.03675; +rocket; inertiaZ; 0.007; 0.00007; +rocket; radius; 0.04045; 0.001; +rocket; distanceRocketNozzle; -1.024; .001; +rocket; distanceRocketPropellant; -0.51; 0.001; +rocket; powerOffDrag; 0.864857143; 0.03; +rocket; powerOnDrag; 0.864857143; 0.03; +rocket; noseLength; 0.274; 0.001; +rocket; noseDistanceToCM; 1.134; 0.001 +fins; finSpan; 0.077; 0.0005; +fins; finRootChord; 0.058; 0.0005; +fins; finTipChord; 0.018; 0.0005; +fins; finDistanceToCM; -0.906; 0.001; +parachute; CdSDrogue; 0.4537; 0.07; +parachute; lag_rec; 1; 0.5; +parachute; lag_se; 0.73; 0.16; +flight; inclination; 84.7; 1; +flight; heading; 53; 2; +flight; railLength; 5.7; 0.0005; diff --git a/data/dispersion csv files/juninho.csv b/data/dispersion csv files/juninho.csv deleted file mode 100644 index 5f40bbfc6..000000000 --- a/data/dispersion csv files/juninho.csv +++ /dev/null @@ -1,23 +0,0 @@ -;;value;standard deviation;;;;;value;standard deviation;;;;;value;standard deviation;;;;;value;standard deviation -Rocket Parameters:;;;;;;Motor Parameters:;;;;;;Launch and Environment;;;;;;Recuperation and eletronics;;; -;rocketMass;12.96;0.648;;;;impulse;3053.198;305.3198;;;;inclination;86;1.18;;;;CdSDrogue;0.37;0.037 -;inertiaI;7.73;0.3867;;;;burnOut;4.488;0.8976;;;;heading;0;1.18;;;;CdSMain;1.06;0.106 -;inertiaZ;0.0279;0.001395;;;;nozzleRadius;0.02222;0.002222;;;;railLength;4.2;0.042;;;;lag_rec;1;0.5 -;radius;0.0529;0.000529;;;;throatRadius;0.00875;0.000875;;;;radiusRailPosition;0;2.5;;;;lag_se;0;0 -;distanceRocketNozzle;-0.91591;-0.0457955;;;;grainSeparation;0.006;0.0006;;;;ensambleMember;[0,1,2,3,4,5];;;;;;; -;distanceRocketProppelant;-0.571773;-0.02858865;;;;grainDensity;1641.5;164.15;;;;windU;[3,4,5,6];;;;;;; -;powerOffDrag;1;0.2;;;;grainOuterRadius;0.03596;0.003596;;;;windV;[3,4,5,6];;;;;;; -;powerOnDrag;1;0.2;;;;grainInitialInnerRadius;0.01596;0.001596;;;;time;[6,12,18];;;;;;; -nose;noseLength;0.41533;0.0041533;;;;grainInitialHeight;0.124;0.0124;;;;day;[23,24,25,26,27,28,29,30,31];;;;;;; -;noseDistanceToCM;1.19467;0.0597335;;;;;;;;;;thetaRailPosition;[0,1,2,3,4,5,6,7,8,9,10];;;;;;; -fins;finSpan;0.13;0.00065;;;;;;;;;;;;;;;;;; -;finRootChord;0.12;0.0006;;;;;;;;;;;;;;;;;; -;finDistanceToCM;-0.72911;0.00364555;;;;;;;;;;;;;;;;;; -tail;tailDistanceToCM;-0.869;0.04345;;;;;;;;;;;;;;;;;; -;tailTopRadius;0.0529;0.000529;;;;;;;;;;;;;;;;;; -;tailbottomRadius;0.043296;0.00043296;;;;;;;;;;;;;;;;;; -;tailLength;0.057;0.00057;;;;;;;;;;;;;;;;;; -canard;canardSpan;0.062;0.00031;;;;;;;;;;;;;;;;;; -;canardRootChord;0.062;0.00031;;;;;;;;;;;;;;;;;; -;canardTipChord;0.062;0.00031;;;;;;;;;;;;;;;;;; -;canardDistanceToCM;0.431771;0.02158855;;;;;;;;;;;;;;;;;; From e9f1e53f9493d5f71e0d4fd55f7c4b5963b1bf5e Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Sat, 24 Sep 2022 13:29:12 +0200 Subject: [PATCH 13/15] ENH: adding tests --- rocketpy/utilities.py | 1 - tests/fixtures/dispersion/Valetudo_inputs.csv | 31 +++++++++++++++++++ tests/test_utilities.py | 23 ++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/dispersion/Valetudo_inputs.csv diff --git a/rocketpy/utilities.py b/rocketpy/utilities.py index 1b0fe4bc7..3ddb08a9c 100644 --- a/rocketpy/utilities.py +++ b/rocketpy/utilities.py @@ -197,7 +197,6 @@ def du(z, u): return altitudeFunction, velocityFunction, final_sol -# TODO: Needs tests def create_dispersion_dictionary(filename): """Creates a dictionary with the rocket data provided by a .csv file. File should be organized in four columns: attribute_class, parameter_name, diff --git a/tests/fixtures/dispersion/Valetudo_inputs.csv b/tests/fixtures/dispersion/Valetudo_inputs.csv new file mode 100644 index 000000000..ac371d0fb --- /dev/null +++ b/tests/fixtures/dispersion/Valetudo_inputs.csv @@ -0,0 +1,31 @@ +attribute_class; parameter_name; mean_value; standard_deviation; +environment; ensembleMember; [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];; +motor; impulse; 1415.15; 35.3; +motor; burnOut; 5.274; 1; +motor; nozzleRadius; 0.021642; 0.0005; +motor; throatRadius; 0.008; 0.0005; +motor; grainSeparation; 0.006; 0.001; +motor; grainDensity; 1707; 50; +motor; grainOuterRadius; 0.0214; 0.2; +motor; grainInitialInnerRadius; .0097;0.000375; +motor; grainInitialHeight; 0.12; 0.001 +rocket; rocketMass; 8.257; 0.001; +rocket; inertiaI; 3.675; 0.03675; +rocket; inertiaZ; 0.007; 0.00007; +rocket; radius; 0.04045; 0.001; +rocket; distanceRocketNozzle; -1.024; .001; +rocket; distanceRocketPropellant; -0.51; 0.001; +rocket; powerOffDrag; 0.864857143; 0.03; +rocket; powerOnDrag; 0.864857143; 0.03; +rocket; noseLength; 0.274; 0.001; +rocket; noseDistanceToCM; 1.134; 0.001 +fins; finSpan; 0.077; 0.0005; +fins; finRootChord; 0.058; 0.0005; +fins; finTipChord; 0.018; 0.0005; +fins; finDistanceToCM; -0.906; 0.001; +parachute; CdSDrogue; 0.4537; 0.07; +parachute; lag_rec; 1; 0.5; +parachute; lag_se; 0.73; 0.16; +flight; inclination; 84.7; 1; +flight; heading; 53; 2; +flight; railLength; 5.7; 0.0005; diff --git a/tests/test_utilities.py b/tests/test_utilities.py index 3ea384c7c..eafe960df 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -1,7 +1,30 @@ from rocketpy import utilities +import numpy as np def test_compute_CdS_from_drop_test(): assert ( utilities.compute_CdS_from_drop_test(31.064, 18, 1.0476) == 0.3492311157844522 ) + + +def test_create__dispersion_dictionary(): + """Test if the function returns a dictionary with the correct keys. + It reads the keys from the dictionary generated by the utilities function + and compares them to the expected. + Be careful if you change the "fixtures/dispersion/Valetudo_inputs.csv" file. + """ + + returned_dict = utilities.create_dispersion_dictionary( + "fixtures/dispersion/Valetudo_inputs.csv" + ) + + test_dict = np.genfromtxt( + "fixtures/dispersion/Valetudo_inputs.csv", + usecols=(1, 2, 3), + skip_header=1, + delimiter=";", + dtype=str, + ) + + assert returned_dict == test_dict From 26078c5ea918451cd368ab39403cf5ecfdf7edd9 Mon Sep 17 00:00:00 2001 From: Guilherme Fernandes Alves Date: Sat, 24 Sep 2022 13:30:59 +0200 Subject: [PATCH 14/15] FIX: Revert wrong name replace --- rocketpy/utilities.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rocketpy/utilities.py b/rocketpy/utilities.py index 3ddb08a9c..f748eac14 100644 --- a/rocketpy/utilities.py +++ b/rocketpy/utilities.py @@ -108,7 +108,8 @@ def check_constant(f, eps): Parameters ---------- - f : array, row + f : array, list + _description_ eps : float _description_ From adf9414d5ebe1f67ac4a4fcda4442e32a99f388d Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Sat, 24 Sep 2022 13:43:52 +0200 Subject: [PATCH 15/15] ENH: improve utilities' tests --- rocketpy/utilities.py | 8 ++++---- tests/test_utilities.py | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/rocketpy/utilities.py b/rocketpy/utilities.py index f748eac14..02ee2ca51 100644 --- a/rocketpy/utilities.py +++ b/rocketpy/utilities.py @@ -230,12 +230,12 @@ def create_dispersion_dictionary(filename): if row[0] != "": if row[2] == "": try: - analysis_parameters[row[0]] = float(row[1]) + analysis_parameters[row[0].strip()] = float(row[1]) except: - analysis_parameters[row[0]] = eval(row[1]) + analysis_parameters[row[0].strip()] = eval(row[1]) else: try: - analysis_parameters[row[0]] = (float(row[1]), float(row[2])) + analysis_parameters[row[0].strip()] = (float(row[1]), float(row[2])) except: - analysis_parameters[row[0]] = "" + analysis_parameters[row[0].strip()] = "" return analysis_parameters diff --git a/tests/test_utilities.py b/tests/test_utilities.py index eafe960df..8ca4837b3 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -16,15 +16,27 @@ def test_create__dispersion_dictionary(): """ returned_dict = utilities.create_dispersion_dictionary( - "fixtures/dispersion/Valetudo_inputs.csv" + "tests/fixtures/dispersion/Valetudo_inputs.csv" ) - test_dict = np.genfromtxt( - "fixtures/dispersion/Valetudo_inputs.csv", + test_array = np.genfromtxt( + "tests/fixtures/dispersion/Valetudo_inputs.csv", usecols=(1, 2, 3), skip_header=1, delimiter=";", dtype=str, ) - + test_dict = dict() + for row in test_array: + if row[0] != "": + if row[2] == "": + try: + test_dict[row[0].strip()] = float(row[1]) + except: + test_dict[row[0].strip()] = eval(row[1]) + else: + try: + test_dict[row[0].strip()] = (float(row[1]), float(row[2])) + except: + test_dict[row[0].strip()] = "" assert returned_dict == test_dict