diff --git a/tests/run_pytest.py b/tests/run_pytest.py index a39f5c56dd1c9e0494eca31aedab907ffc1998ef..909b146579ce85b29b566579c88a81a43d656c10 100644 --- a/tests/run_pytest.py +++ b/tests/run_pytest.py @@ -5,4 +5,5 @@ Created on 29/01/2016 ''' import pytest import os -pytest.main(os.path.dirname(__file__) + "./../") +p = os.path.abspath(os.path.join(os.path.dirname(__file__) + "./../")).replace("\\", "/") +pytest.main(p) diff --git a/wetb/dlc/high_level.py b/wetb/dlc/high_level.py index 26b976f7fa6b2fddcf3fb3fd9995d646669e158f..e1be441ed90c99c97afbd55f50757e0c9c9b0a82 100644 --- a/wetb/dlc/high_level.py +++ b/wetb/dlc/high_level.py @@ -149,7 +149,10 @@ class DLCHighLevel(object): start, step, stop = [float(eval(v, globals(), self.__dict__)) for v in values.lower().split(":")] values = np.arange(start, stop + step, step) else: - values = [(eval(v, globals(), self.__dict__)) for v in str(values).lower().replace("/", ",").split(",")] + try: + values = [(eval(v, globals(), self.__dict__)) for v in str(values).lower().replace("/", ",").split(",")] + except SyntaxError: + values = [(eval(v.lstrip('0'), globals(), self.__dict__)) for v in str(values).lower().replace("/", ",").split(",")] dist = self.dlc_df[dist_key][row] if str(dist).lower() == "weibull" or str(dist).lower() == "rayleigh": @@ -287,10 +290,10 @@ class DLCHighLevel(object): if __name__ == "__main__": - dlc_hl = DLCHighLevel(r'X:\NREL5MW\dlc.xlsx') + dlc_hl = DLCHighLevel(r'X:\DTU10MW\Q0010\DLC_post_betas1.xlsx') #print (DLCHighLevelInputFile(r'C:\mmpe\Projects\DLC.xlsx').sensor_info(0, 0, 1)['Name']) #print (dlc_dict()['64']) #print (dlc_hl.fatigue_distribution()['64']) - print (dlc_hl.file_hour_lst(r"X:\NREL5MW/C0008/res/")) + print (dlc_hl.file_hour_lst(r"X:\DTU10MW/Q0010/res/")) diff --git a/wetb/hawc2/htc_contents.py b/wetb/hawc2/htc_contents.py index bc6bba5e0cea3e2419feae926e4651e697cfe2e5..ee1f06d3834f2df2d04d7c843d22180d6bb212f2 100644 --- a/wetb/hawc2/htc_contents.py +++ b/wetb/hawc2/htc_contents.py @@ -155,6 +155,8 @@ class HTCLine(HTCContents): values = None comments = "" def __init__(self, name, values, comments): + if "__" in name: + name = name[:name.index("__")] self.name_ = name self.values = values self.comments = comments diff --git a/wetb/hawc2/htc_file.py b/wetb/hawc2/htc_file.py index 2406ac54da2bfeeaceca48bc7db06cedd4ed2dbd..08193c5e42e524f6e54662a532711152da9c0c71 100644 --- a/wetb/hawc2/htc_file.py +++ b/wetb/hawc2/htc_file.py @@ -13,6 +13,7 @@ from __future__ import absolute_import from io import open from builtins import str from future import standard_library +from wetb.utils.process_exec import pexec standard_library.install_aliases() from collections import OrderedDict @@ -39,6 +40,7 @@ class HTCFile(HTCContents, HTCDefaults): self.lines = self.empty_htc.split("\n") else: self.filename = filename + self.modelpath = os.path.realpath(os.path.join(os.path.dirname(self.filename), modelpath)) self.lines = self.readlines(filename) # with open(filename) as fid: # self.lines = fid.readlines() @@ -55,7 +57,7 @@ class HTCFile(HTCContents, HTCDefaults): self._add_contents(line) if line.name_ == "exit": break - assert 'simulation' in self.contents, "%s could not be loaded. 'simulation' section missing" % filename + #assert 'simulation' in self.contents, "%s could not be loaded. 'simulation' section missing" % filename def readlines(self, filename): self.htc_inputfiles.append(filename) @@ -65,7 +67,7 @@ class HTCFile(HTCContents, HTCDefaults): for l in lines: if l.lower().lstrip().startswith('continue_in_file'): filename = l.lstrip().split(";")[0][len("continue_in_file"):].strip() - filename = os.path.join(os.path.dirname(self.filename), self.modelpath, filename) + filename = os.path.join(self.modelpath, filename) for line in self.readlines(filename): if line.lstrip().lower().startswith('exit'): @@ -95,7 +97,10 @@ class HTCFile(HTCContents, HTCDefaults): def set_name(self, name, folder="htc"): self.filename = os.path.join(self.modelpath, folder, "%s.htc" % name).replace("\\", "/") - self.simulation.logfile = "./log/%s.log" % name + if 'simulation' in self and 'logfile' in self.simulation: + self.simulation.logfile = "./log/%s.log" % name + elif 'test_structure' in self and 'logfile' in self.test_structure: + self.test_structure.logfile = "./log/%s.log" % name self.output.filename = "./res/%s" % name def input_files(self): @@ -172,14 +177,22 @@ class HTCFile(HTCContents, HTCDefaults): return [] dataformat = self.output.get('data_format', 'hawc_ascii') res_filename = self.output.filename[0] - if dataformat == "gtsdf" or dataformat == "gtsdf64": + if dataformat[0] == "gtsdf" or dataformat[0] == "gtsdf64": return [res_filename + ".hdf5"] - elif dataformat == "flex_int": + elif dataformat[0] == "flex_int": return [res_filename + ".int", os.path.join(os.path.dirname(res_filename), 'sensor')] else: return [res_filename + ".sel", res_filename + ".dat"] + def simulate(self, exe): + self.save() + htcfile = os.path.relpath(self.filename, self.modelpath) + hawc2exe = exe + errorcode, stdout, stderr, cmd = pexec([hawc2exe, htcfile], self.modelpath) + + if errorcode or 'Elapsed time' not in stderr: + raise Exception (str(stdout) + str(stderr)) if "__main__" == __name__: f = HTCFile(r"C:\mmpe\HAWC2\Hawc2_model\htc\NREL_5MW_reference_wind_turbine_launcher_test.htc") diff --git a/wetb/hawc2/pc_file.py b/wetb/hawc2/pc_file.py index 4383d78331fbe3f6f69d8094bb7353c39e460e6c..f42cc1076518a42f14b38cb307b65c6847a28a39 100644 --- a/wetb/hawc2/pc_file.py +++ b/wetb/hawc2/pc_file.py @@ -76,12 +76,43 @@ class PCFile(AEFile): return Cx0 + (Cx1 - Cx0) * (thickness - th0) / (th1 - th0) def CL(self, radius, alpha, ae_set_nr=1): + """Lift coefficient + + Parameters + --------- + radius : float + radius [m] + alpha : float + Angle of attack [deg] + ae_set_nr : int optional + Aerdynamic set number, default is 1 + + Returns + ------- + Lift coefficient : float + """ return self._Cxxx(radius, alpha, 1, ae_set_nr) def CD(self, radius, alpha, ae_set_nr=1): + """Drag coefficient + + Parameters + --------- + radius : float + radius [m] + alpha : float + Angle of attack [deg] + ae_set_nr : int optional + Aerdynamic set number, default is 1 + + Returns + ------- + Drag coefficient : float + """ return self._Cxxx(radius, alpha, 2, ae_set_nr) def CM(self, radius, alpha, ae_set_nr=1): + return self._Cxxx(radius, alpha, 3, ae_set_nr) if __name__ == "__main__": diff --git a/wetb/hawc2/simulation.py b/wetb/hawc2/simulation.py index 2f9243016bb18c2ba5adf58c13468a5293a05b89..d1d20e698568c0f91786c47a954c9cdd942955c3 100644 --- a/wetb/hawc2/simulation.py +++ b/wetb/hawc2/simulation.py @@ -297,7 +297,7 @@ class SimulationThread(Thread): htcfile = os.path.relpath(self.sim.htcFile.filename, self.sim.modelpath) hawc2exe = self.sim.hawc2exe stdout = self.sim.stdout_filename - self.process = subprocess.Popen("%s %s 1> %s 2>&1" % (hawc2exe, htcfile, stdout), stdout=None, stderr=None, shell=True, cwd=modelpath, creationflags=CREATE_NO_WINDOW) + self.process = subprocess.Popen('"%s" %s 1> %s 2>&1' % (hawc2exe, htcfile, stdout), stdout=None, stderr=None, shell=True, cwd=modelpath, creationflags=CREATE_NO_WINDOW) Thread.start(self) diff --git a/wetb/utils/cython_compile/cython_compile.py b/wetb/utils/cython_compile/cython_compile.py index af9146883099b7a27cb4e348b47eaf5c669a7a0e..2d09be147d2454350552da9f3ea63a3c055b3ba3 100644 --- a/wetb/utils/cython_compile/cython_compile.py +++ b/wetb/utils/cython_compile/cython_compile.py @@ -381,7 +381,10 @@ def py2pyx(pylines): indent = l[:len(l) - len(l.lstrip())] cdef = l[l.index("#c") + 1:] l = indent + cdef - pyxlines.append(l) + if "__future__" in l: + pyxlines.insert(0, l) # from __future__ import ... must be first + else: + pyxlines.append(l) return pyxlines diff --git a/wetb/utils/geometry.py b/wetb/utils/geometry.py index 01a4daf6e0cbac576dbc95711ab7205957b9a8eb..79086245e3494faf8d1f2ac41836da08436f65f9 100644 --- a/wetb/utils/geometry.py +++ b/wetb/utils/geometry.py @@ -168,11 +168,11 @@ def abvrel2xyz(alpha, beta, vrel): Parameters ---------- alpha : array_like - Pitot tube angle of attack + Pitot tube angle of attack. Zero: Parallel to pitot tube. Positive: Flow from wind side (pressure side) beta : array_like - Pitot tube side slip angle + Pitot tube side slip angle. Zero: Parallel to pitot tube. Positive: Flow from root side vrel : array_like - Pitot tube relative velocity + Pitot tube relative velocity. Positive: flow towards pitot tube Returns ------- @@ -181,13 +181,13 @@ def abvrel2xyz(alpha, beta, vrel): y : array_like Wind component in alpha plane (positive for positive alpha) z : array_like - Wind component in beta plane (positive for positive beta) + Wind component in beta plane (positive for negative beta) """ alpha = np.array(alpha, dtype=np.float) beta = np.array(beta, dtype=np.float) vrel = np.array(vrel, dtype=np.float) - sign_vsx = -((np.abs(beta) > np.pi / 2) * 2 - 1) # +1 for |beta| <= 90, -1 for |beta|>90 + sign_vsx = -((np.abs(beta) > np.pi / 2) * 2 - 1) # +1 for |beta| < 90, -1 for |beta|>90 sign_vsy = np.sign(alpha) #+ for alpha > 0 sign_vsz = -np.sign(beta) #- for beta>0 @@ -196,10 +196,10 @@ def abvrel2xyz(alpha, beta, vrel): m = alpha != 0 y = np.zeros_like(alpha) - y[m] = sign_vsy * np.sqrt(vrel[m] ** 2 / ((1 / np.tan(alpha[m])) ** 2 + 1 + (np.tan(beta[m]) / np.tan(alpha[m])) ** 2)) + y[m] = sign_vsy[m] * np.sqrt(vrel[m] ** 2 / ((1 / np.tan(alpha[m])) ** 2 + 1 + (np.tan(beta[m]) / np.tan(alpha[m])) ** 2)) m = beta != 0 z = np.zeros_like(alpha) - z[m] = sign_vsz * np.sqrt(vrel[m] ** 2 / ((1 / np.tan(beta[m])) ** 2 + 1 + (np.tan(alpha[m]) / np.tan(beta[m])) ** 2)) + z[m] = sign_vsz[m] * np.sqrt(vrel[m] ** 2 / ((1 / np.tan(beta[m])) ** 2 + 1 + (np.tan(alpha[m]) / np.tan(beta[m])) ** 2)) return x, y, z diff --git a/wetb/wind/shear.py b/wetb/wind/shear.py index 77e70135fcd42753b2b0f304e9ef85d1ef86224d..5efe9043fff8b6b47d63a809ff5ae03bee5aed71 100644 --- a/wetb/wind/shear.py +++ b/wetb/wind/shear.py @@ -169,7 +169,7 @@ def fit_log_shear(z_u_lst, include_R=False): Example -------- - >>> fit_log_shear([(85, 8.88131), (21, 4.41832)], 87.13333) + >>> fit_log_shear([(85, 8.88131), (21, 4.41832)]) [ 0.49938238 8.99192568] """ # def shear_error(x, z_u_lst):