diff --git a/wetb/control/control.py b/wetb/control/control.py index f6935f784690e1deef3cca69e94f105fc6fa5f17..e65a7950e481edebb39216eadb94c92fdc6fe774 100644 --- a/wetb/control/control.py +++ b/wetb/control/control.py @@ -17,6 +17,7 @@ class Control(object): def torque_controller_tuning(self, r0, lambda_opt, ksi_pole_part, omega_pole_part, j_dt): + from site import print_trace_now; print_trace_now() """THIS IS A WIP """ @@ -56,6 +57,7 @@ class Control(object): def pitch_controller_tuning(self, pitch, I, dQdt, P, Omr, om, csi): + from site import print_trace_now; print_trace_now() """ Function to compute the gains of the pitch controller of the Basic DTU @@ -119,6 +121,7 @@ class Control(object): return kp, ki, K1, K2 def K_omega2(V, P, R, TSR): + from site import print_trace_now; print_trace_now() Va = np.array(V) Pa = np.array(P) @@ -129,6 +132,7 @@ class Control(object): return K def select_regions(self, pitch, omega, power): + from site import print_trace_now; print_trace_now() """Find indices at wich point the controller should switch between the different operating mode regions. diff --git a/wetb/fast/fast_io.py b/wetb/fast/fast_io.py index cbb1c3f9d380fbf887d13b0b57c544a6c67a52ae..d9368a5634e72a5c3ea34aa316b3aa124e030528 100644 --- a/wetb/fast/fast_io.py +++ b/wetb/fast/fast_io.py @@ -18,6 +18,7 @@ import numpy as np import struct def load_output(filename): + from site import print_trace_now; print_trace_now() """Load a FAST binary or ascii output file Parameters @@ -46,6 +47,7 @@ def load_output(filename): return load_ascii_output(filename) def load_ascii_output(filename): + from site import print_trace_now; print_trace_now() with open(filename) as f: info = {} info['name'] = os.path.splitext(os.path.basename(filename))[0] @@ -63,6 +65,7 @@ def load_ascii_output(filename): def load_binary_output(filename): + from site import print_trace_now; print_trace_now() """Ported from ReadFASTbinary.m by Mads M Pedersen, DTU Wind Info about ReadFASTbinary.m: % Author: Bonnie Jonkman, National Renewable Energy Laboratory @@ -71,6 +74,7 @@ def load_binary_output(filename): % Edited for FAST v7.02.00b-bjj 22-Oct-2012 """ def fread(fid, n, type): + from site import print_trace_now; print_trace_now() fmt, nbytes = {'uint8': ('B', 1), 'int16':('h', 2), 'int32':('i', 4), 'float32':('f', 4), 'float64':('d', 8)}[type] return struct.unpack(fmt * n, fid.read(nbytes * n)) diff --git a/wetb/fatigue_tools/fatigue.py b/wetb/fatigue_tools/fatigue.py index 4be58383bd9b6018c5fb65f478f72eb9d93f1b8e..1f7948bbe719df02d66847458b8466b4a7b53f54 100644 --- a/wetb/fatigue_tools/fatigue.py +++ b/wetb/fatigue_tools/fatigue.py @@ -29,6 +29,7 @@ rainflow_astm = rainflowcount.rainflow_astm def eq_load(signals, no_bins=46, m=[3, 4, 6, 8, 10, 12], neq=1, rainflow_func=rainflow_windap): + from site import print_trace_now; print_trace_now() """Equivalent load calculation Calculate the equivalent loads for a list of Wohler exponent and number of equivalent loads @@ -72,6 +73,7 @@ def eq_load(signals, no_bins=46, m=[3, 4, 6, 8, 10, 12], neq=1, rainflow_func=ra def eq_load_and_cycles(signals, no_bins=46, m=[3, 4, 6, 8, 10, 12], neq=[10 ** 6, 10 ** 7, 10 ** 8], rainflow_func=rainflow_windap): + from site import print_trace_now; print_trace_now() """Calculate combined fatigue equivalent load Parameters @@ -112,6 +114,7 @@ def eq_load_and_cycles(signals, no_bins=46, m=[3, 4, 6, 8, 10, 12], neq=[10 ** 6 def cycle_matrix(signals, ampl_bins=10, mean_bins=10, rainflow_func=rainflow_windap): + from site import print_trace_now; print_trace_now() """Markow load cycle matrix Calculate the Markow load cycle matrix @@ -170,6 +173,7 @@ def cycle_matrix(signals, ampl_bins=10, mean_bins=10, rainflow_func=rainflow_win def cycle_matrix2(signal, nrb_amp, nrb_mean, rainflow_func=rainflow_windap): + from site import print_trace_now; print_trace_now() """ Same as wetb.fatigue_tools.fatigue.cycle_matrix but bin from min_amp to max_amp instead of 0 to max_amp. diff --git a/wetb/fatigue_tools/rainflowcounting/pair_range.py b/wetb/fatigue_tools/rainflowcounting/pair_range.py index c3048fad65ba94fcb3724258e120bc8b73609c96..3c33296cf3effa1f778881ad11f0813948f0e1dc 100644 --- a/wetb/fatigue_tools/rainflowcounting/pair_range.py +++ b/wetb/fatigue_tools/rainflowcounting/pair_range.py @@ -12,6 +12,7 @@ import numpy as np @cython.locals(p=cython.int, q=cython.int, f=cython.int, flow=list, k=cython.int, n=cython.int, ptr=cython.int) def pair_range_amplitude(x): # cpdef pair_range(np.ndarray[long,ndim=1] x): + from site import print_trace_now; print_trace_now() """ Returns a list of half-cycle-amplitudes x: Peak-Trough sequence (integer list of local minima and maxima) @@ -80,6 +81,7 @@ def pair_range_amplitude(x): # cpdef pair_range(np.ndarray[long,ndim=1] x): @cython.locals(p=cython.int, q=cython.int, f=cython.int, flow=list, k=cython.int, n=cython.int, ptr=cython.int) def pair_range_from_to(x): # cpdef pair_range(np.ndarray[long,ndim=1] x): + from site import print_trace_now; print_trace_now() """ Returns a list of half-cycle-amplitudes x: Peak-Trough sequence (integer list of local minima and maxima) diff --git a/wetb/fatigue_tools/rainflowcounting/rainflowcount.py b/wetb/fatigue_tools/rainflowcounting/rainflowcount.py index 146cf9c07356b72fdc179ce6b0fb01997c247aa6..23f748a8672573cc5047e58496ac575fbc009af0 100644 --- a/wetb/fatigue_tools/rainflowcounting/rainflowcount.py +++ b/wetb/fatigue_tools/rainflowcounting/rainflowcount.py @@ -11,6 +11,7 @@ from wetb.fatigue_tools.rainflowcounting import pair_range def check_signal(signal): + from site import print_trace_now; print_trace_now() # check input data validity if not type(signal).__name__ == 'ndarray': raise TypeError('signal must be ndarray, not: ' + type(signal).__name__) @@ -26,6 +27,7 @@ def check_signal(signal): def rainflow_windap(signal, levels=255., thresshold=(255 / 50)): + from site import print_trace_now; print_trace_now() """Windap equivalent rainflow counting @@ -92,6 +94,7 @@ def rainflow_windap(signal, levels=255., thresshold=(255 / 50)): def rainflow_astm(signal): + from site import print_trace_now; print_trace_now() """Matlab equivalent rainflow counting Calculate the amplitude and mean values of half cycles in signal diff --git a/wetb/fatigue_tools/rainflowcounting/rainflowcount_astm.py b/wetb/fatigue_tools/rainflowcounting/rainflowcount_astm.py index 2cb2b2d4a9391bf39c17c5d6380cafa90b7706ff..932ebfb1407793182ad391781f19eb3bc7e0cfc6 100644 --- a/wetb/fatigue_tools/rainflowcounting/rainflowcount_astm.py +++ b/wetb/fatigue_tools/rainflowcounting/rainflowcount_astm.py @@ -25,6 +25,7 @@ import numpy as np def find_extremes(signal): #cpdef find_extremes(np.ndarray[double,ndim=1] signal): + from site import print_trace_now; print_trace_now() """return indexes of local minima and maxima plus first and last element of signal""" #cdef int pi, i @@ -56,6 +57,7 @@ def find_extremes(signal): #cpdef find_extremes(np.ndarray[double,ndim=1] signa def rainflowcount(sig): #cpdef rainflowcount(np.ndarray[double,ndim=1] sig): + from site import print_trace_now; print_trace_now() """Cython compilable rain ampl_mean count without time analysis diff --git a/wetb/gtsdf/__init__.py b/wetb/gtsdf/__init__.py index 1c26d6b949b0f7248ca38e5f1c40d03d17807d99..3e00dba83466066f2c6d217185da877b8c230b05 100644 --- a/wetb/gtsdf/__init__.py +++ b/wetb/gtsdf/__init__.py @@ -44,9 +44,11 @@ from .gtsdf import compress2statistics class Dataset(object): def __init__(self, filename): + from site import print_trace_now; print_trace_now() self.filename = filename self.time, self.data, self.info = load(filename) def __call__(self, id): + from site import print_trace_now; print_trace_now() if isinstance(id, str): if id=="Time": return self.time @@ -58,9 +60,11 @@ class Dataset(object): return self.data[:, id - 2] def attribute_names_str(self): + from site import print_trace_now; print_trace_now() return "\n".join(["1: Time"]+["%d: %s"%(i,n) for i, n in enumerate(self.info['attribute_names'],2)]) def __getattribute__(self, name): + from site import print_trace_now; print_trace_now() try: return object.__getattribute__(self, name) @@ -73,6 +77,7 @@ class Dataset(object): raise e def __contains__(self, name): + from site import print_trace_now; print_trace_now() return name in self.info['attribute_names'] diff --git a/wetb/prepost/GenerateDLCs.py b/wetb/prepost/GenerateDLCs.py index 8303c3eac02636388a43097bb0d5e53647671f0d..d3001143ba6fcbfb7f3d8a6bd8a6cca7613fd026 100644 --- a/wetb/prepost/GenerateDLCs.py +++ b/wetb/prepost/GenerateDLCs.py @@ -20,6 +20,7 @@ import os def multi_for(iterables): + from site import print_trace_now; print_trace_now() """ Routine to create list with combination of elements. """ @@ -48,10 +49,12 @@ class GeneralDLC(object): """ def __init__(self): + from site import print_trace_now; print_trace_now() pass def remove_from_dict(self, non_defaults, defaults): + from site import print_trace_now; print_trace_now() for key in non_defaults.keys(): try: @@ -61,6 +64,7 @@ class GeneralDLC(object): return defaults def add_variables_tag(self, dlc, variables, variables_order): + from site import print_trace_now; print_trace_now() cases_len = [] for tag in variables_order: @@ -114,11 +118,13 @@ class GeneralDLC(object): dlc[variables_order[icol]].append(value) def add_constants_tag(self, dlc, constants): + from site import print_trace_now; print_trace_now() for key in constants.keys(): dlc[key] = [constants[key]]*len(dlc['[wsp]']) def sort_formulas(self, formulas): + from site import print_trace_now; print_trace_now() # sort formulas based on their dependency keys_list = sorted(formulas) @@ -134,6 +140,7 @@ class GeneralDLC(object): return keys_list def eval_formulas(self, dlc): + from site import print_trace_now; print_trace_now() for key in dlc.keys(): if isinstance(dlc[key][0], str): @@ -148,6 +155,7 @@ class GeneralDLC(object): dlc[key][iformula] = eval(formula) def add_formulas(self, dlc, formulas): + from site import print_trace_now; print_trace_now() keys_list = self.sort_formulas(formulas) @@ -217,6 +225,7 @@ class GenerateDLCCases(GeneralDLC): """ def execute(self, filename='DLCs.xlsx', folder='', isheets=None): + from site import print_trace_now; print_trace_now() book = xlrd.open_workbook(filename) diff --git a/wetb/prepost/Simulations.py b/wetb/prepost/Simulations.py index c3fe5ae90e5bc4242e09c92ce441a84470327887..a4b5850a40a5652fc28885ad7afc24c39ed15ce7 100755 --- a/wetb/prepost/Simulations.py +++ b/wetb/prepost/Simulations.py @@ -59,22 +59,26 @@ from wetb.utils.envelope import compute_envelope from os.path import join as os_path_join def join_path(*args): + from site import print_trace_now; print_trace_now() return os_path_join(*args).replace("\\","/") os.path.join = join_path def load_pickled_file(source): + from site import print_trace_now; print_trace_now() FILE = open(source, 'rb') result = pickle.load(FILE) FILE.close() return result def save_pickle(source, variable): + from site import print_trace_now; print_trace_now() FILE = open(source, 'wb') pickle.dump(variable, FILE, protocol=2) FILE.close() def write_file(file_path, file_contents, mode): + from site import print_trace_now; print_trace_now() """ INPUT: file_path: path/to/file/name.csv @@ -87,6 +91,7 @@ def write_file(file_path, file_contents, mode): FILE.close() def create_multiloop_list(iter_dict, debug=False): + from site import print_trace_now; print_trace_now() """ Create a list based on multiple nested loops ============================================ @@ -206,6 +211,7 @@ def create_multiloop_list(iter_dict, debug=False): return iter_list def local_shell_script(htc_dict, sim_id): + from site import print_trace_now; print_trace_now() """ """ shellscript = '' @@ -235,6 +241,7 @@ def local_shell_script(htc_dict, sim_id): print(scriptpath) def local_windows_script(cases, sim_id, nr_cpus=2): + from site import print_trace_now; print_trace_now() """ """ @@ -335,6 +342,7 @@ def local_windows_script(cases, sim_id, nr_cpus=2): print(scriptpath) def run_local_ram(cases, check_log=True): + from site import print_trace_now; print_trace_now() ram_root = '/tmp/HAWC2/' @@ -406,6 +414,7 @@ def run_local_ram(cases, check_log=True): def run_local(cases, silent=False, check_log=True): + from site import print_trace_now; print_trace_now() """ Run all HAWC2 simulations locally from cases =============================================== @@ -569,6 +578,7 @@ def prepare_launch(iter_dict, opt_tags, master, variable_tag_func, m=[3,4,6,8,9,10,12], postpro_node_zipchunks=True, postpro_node=False, exesingle=None, exechunks=None, wine_arch='win32', wine_prefix='~/.wine32'): + from site import print_trace_now; print_trace_now() """ Create the htc files, pbs scripts and replace the tags in master file ===================================================================== @@ -817,6 +827,7 @@ def prepare_launch(iter_dict, opt_tags, master, variable_tag_func, def prepare_relaunch(cases, runmethod='gorm', verbose=False, write_htc=True, copyback_turb=True, silent=False, check_log=True): + from site import print_trace_now; print_trace_now() """ Instead of redoing everything, we know recreate the HTC file for those in the given cases dict. Nothing else changes. The data and zip files @@ -886,6 +897,7 @@ def prepare_relaunch(cases, runmethod='gorm', verbose=False, write_htc=True, def prepare_launch_cases(cases, runmethod='gorm', verbose=False,write_htc=True, copyback_turb=True, silent=False, check_log=True, variable_tag_func=None, sim_id_new=None): + from site import print_trace_now; print_trace_now() """ Same as prepare_launch, but now the input is just a cases object (cao). If relaunching some earlier defined simulations, make sure to at least @@ -1015,6 +1027,7 @@ def launch(cases, runmethod='none', verbose=False, copyback_turb=True, maxcpu=1, pyenv='wetb_py3', wine_64bit=False, m=[3,4,6,8,9,10,12], postpro_node_zipchunks=True, postpro_node=False, exesingle=None, exechunks=None, wine_arch='win32', wine_prefix='~/.wine32'): + from site import print_trace_now; print_trace_now() """ The actual launching of all cases in the Cases dictionary. Note that here only the PBS files are written and not the actuall htc files. @@ -1078,6 +1091,7 @@ def launch(cases, runmethod='none', verbose=False, copyback_turb=True, def post_launch(cases, save_iter=False, silent=False, suffix=None, path_errorlog=None): + from site import print_trace_now; print_trace_now() """ Do some basics checks: do all launched cases have a result and LOG file and are there any errors in the LOG files? @@ -1214,6 +1228,7 @@ def post_launch(cases, save_iter=False, silent=False, suffix=None, def copy_pbs_in_failedcases(cases_fail, path='pbs_in_fail', silent=True): + from site import print_trace_now; print_trace_now() """ Copy all the pbs_in files from failed cases to a new directory so it is easy to re-launch them @@ -1238,6 +1253,7 @@ def copy_pbs_in_failedcases(cases_fail, path='pbs_in_fail', silent=True): def logcheck_case(errorlogs, cases, case, silent=False): + from site import print_trace_now; print_trace_now() """ Check logfile of a single case ============================== @@ -1301,12 +1317,14 @@ class Log(object): .save(target), print(current log to screen with .printLog() """ def __init__(self): + from site import print_trace_now; print_trace_now() self.log = [] # option, should the lines added to the log be printed as well? self.print_logging = False self.file_mode = 'a' def add(self, lines): + from site import print_trace_now; print_trace_now() # the input is a list, where each entry is considered as a new line for k in lines: self.log.append(k) @@ -1314,6 +1332,7 @@ class Log(object): print(k) def save(self, target): + from site import print_trace_now; print_trace_now() # tread every item in the log list as a new line FILE = open(target, self.file_mode) for k in self.log: @@ -1323,6 +1342,7 @@ class Log(object): self.log = [] def printscreen(self): + from site import print_trace_now; print_trace_now() for k in self.log: print(k) @@ -1331,6 +1351,7 @@ class HtcMaster(object): """ def __init__(self, verbose=False, silent=False): + from site import print_trace_now; print_trace_now() """ """ @@ -1413,6 +1434,7 @@ class HtcMaster(object): '[meand_dir]', '[eigenfreq_dir]'] def create_run_dir(self): + from site import print_trace_now; print_trace_now() """ If non existent, create run_dir and all required model sub directories """ @@ -1431,6 +1453,7 @@ class HtcMaster(object): # TODO: copy_model_data and create_model_zip should be the same. def copy_model_data(self): + from site import print_trace_now; print_trace_now() """ Copy the model data to the execution folder @@ -1510,6 +1533,7 @@ class HtcMaster(object): # TODO: copy_model_data and create_model_zip should be the same. def create_model_zip(self): + from site import print_trace_now; print_trace_now() """ Create the model zip file based on the master tags file settings. @@ -1636,6 +1660,7 @@ class HtcMaster(object): #shutil.copy2(src, dst) def _sweep_tags(self): + from site import print_trace_now; print_trace_now() """ The original way with all tags in the htc file for each blade node """ @@ -1659,6 +1684,7 @@ class HtcMaster(object): self.tags[item]=format(self.tags[it_nosweep], ff) def _staircase_windramp(self, nr_steps, wind_step, ramptime, septime): + from site import print_trace_now; print_trace_now() """Create a stair case wind ramp @@ -1667,6 +1693,7 @@ class HtcMaster(object): pass def _all_in_one_blade_tag(self, radius_new=None): + from site import print_trace_now; print_trace_now() """ Create htc input based on a HAWTOPT blade result file @@ -1780,6 +1807,7 @@ class HtcMaster(object): #write_file(file_path, tmp2, 'w') def loadmaster(self): + from site import print_trace_now; print_trace_now() """ Load the master file, path to master file is defined in __init__(): target, master. Additionally, find all the tags in the @@ -1823,6 +1851,7 @@ class HtcMaster(object): def createcase_check(self, htc_dict_repo, \ tmp_dir='/tmp/HawcPyTmp/', write_htc=True): + from site import print_trace_now; print_trace_now() """ Check if a certain case name already exists in a specified htc_dict. If true, return a message and do not create the case. It can be that @@ -1846,6 +1875,7 @@ class HtcMaster(object): return htc def createcase(self, tmp_dir='/tmp/HawcPyTmp/', write_htc=True): + from site import print_trace_now; print_trace_now() """ replace all the tags from the master file and save the new htc file """ @@ -1909,6 +1939,7 @@ class HtcMaster(object): return {cname : copy.copy(self.tags)} def write_htc(self, cname, htc, htc_target): + from site import print_trace_now; print_trace_now() # create subfolder if necesarry if not os.path.exists(htc_target): os.makedirs(htc_target) @@ -1916,6 +1947,7 @@ class HtcMaster(object): # write_file(tmp_dir + case, htc, 'w') def lower_case_output(self): + from site import print_trace_now; print_trace_now() """ force lower case tags on output files since HAWC2 will force them to lower case anyway @@ -1926,6 +1958,7 @@ class HtcMaster(object): self.tags[key] = self.tags[key].lower() def write_tags(self, fname=False): + from site import print_trace_now; print_trace_now() """Write all tags to a DLC alike spreadsheet """ @@ -1951,6 +1984,7 @@ class PBS(object): wine_64bit=False, m=[3,4,6,8,9,10,12], exesingle=None, postpro_node_zipchunks=True, postpro_node=False, exechunks=None, wine_arch='win32', wine_prefix='~/.wine32'): + from site import print_trace_now; print_trace_now() """ Define the settings here. This should be done outside, but how? In a text file, paramters list or first create the object and than set @@ -2077,6 +2111,7 @@ class PBS(object): self.copyto_fname = [] def create(self): + from site import print_trace_now; print_trace_now() """ Main loop for creating the pbs scripts, based on cases, which contains the case name as key and tag dictionairy as value @@ -2445,6 +2480,7 @@ class PBS(object): # + ' partially loaded...' def starting(self, tag_dict, jobid): + from site import print_trace_now; print_trace_now() """ First part of the pbs script """ @@ -2532,6 +2568,7 @@ class PBS(object): self.pbs += '# ' + '='*78 + '\n' def ending(self, pbs_path): + from site import print_trace_now; print_trace_now() """ Last part of the pbs script, including command to write script to disc COPY BACK: from node to @@ -2613,6 +2650,7 @@ class PBS(object): self.pbs = '' def copyback_all_files(self, mode, cpu_nr): + from site import print_trace_now; print_trace_now() """Copy back all the files from either scratch to run_dir (PBS mode), or from CPU sub-directory back to main directory in find+xargs mode. """ @@ -2758,6 +2796,7 @@ class PBS(object): self.pbs += '# ' + '-'*78 + '\n' def checklogs(self): + from site import print_trace_now; print_trace_now() """ """ self.pbs += 'python -c "from wetb.prepost import statsdel; ' @@ -2765,6 +2804,7 @@ class PBS(object): self.pbs += 'statsdel.logcheck(\'%s\')"\n' % rpl def postprocessing(self): + from site import print_trace_now; print_trace_now() """Run post-processing just after HAWC2 has ran """ self.pbs += 'python -c "from wetb.prepost import statsdel; ' @@ -2775,6 +2815,7 @@ class PBS(object): 'neq=%s, i0=0, i1=None, ftype=\'%s\')"\n' % rpl) def check_results(self, cases): + from site import print_trace_now; print_trace_now() """ Cross-check if all simulations on the list have returned a simulation. Combine with ErrorLogs to identify which errors occur where. @@ -2852,6 +2893,7 @@ class ErrorLogs(windIO.LogFile): # TODO: move to the HAWC2 plugin for cases def __init__(self, silent=False, cases=None, resultfile='ErrorLog.csv'): + from site import print_trace_now; print_trace_now() # call init from base class super(ErrorLogs, self).__init__() @@ -2864,6 +2906,7 @@ class ErrorLogs(windIO.LogFile): # TODO: save this not a csv text string but a df_dict, and save as excel # and DataFrame! def check(self, appendlog=False, save_iter=False): + from site import print_trace_now; print_trace_now() """Check all log files that are to be found in the directory ErrorLogs.PathToLogs, or check the specific log file if ErrorLogs.PathToLogs points to a specific log file. @@ -2919,6 +2962,7 @@ class ErrorLogs(windIO.LogFile): self.save(appendlog=appendlog) def save(self, appendlog=False, suffix=None): + from site import print_trace_now; print_trace_now() contents = self._header() contents = self._msglistlog2csv(contents) @@ -2970,6 +3014,7 @@ class ModelData(object): y_e = 18 def __init__(self, verbose=False, silent=False): + from site import print_trace_now; print_trace_now() self.verbose = verbose self.silent = silent # define the column width for printing @@ -3010,6 +3055,7 @@ class ModelData(object): self.column_header_line += '\n' + (19 * self.col_width * '=') + '\n' def fromline(self, line, separator=' '): + from site import print_trace_now; print_trace_now() # TODO: move this to the global function space (dav-general-module) """ split a line, but ignore any blank spaces and return a list with only @@ -3029,6 +3075,7 @@ class ModelData(object): return values def load_st(self, file_path, file_name): + from site import print_trace_now; print_trace_now() """ Now a better format: st_dict has following key/value pairs 'nset' : total number of sets in the file (int). @@ -3151,6 +3198,7 @@ class ModelData(object): self.st_comments = st_comments def _format_nr(self, number): + from site import print_trace_now; print_trace_now() """ Automatic format the number @@ -3188,6 +3236,7 @@ class ModelData(object): return numfor def write_st(self, file_path, file_name, print_header=False): + from site import print_trace_now; print_trace_now() """ prec_loss : float, default=0.01 acceptible precision loss expressed in % @@ -3232,6 +3281,7 @@ class ModelData(object): print('st file written:', file_path + file_name) def write_latex(self, fpath, selection=[]): + from site import print_trace_now; print_trace_now() """ Write a table in Latex format based on the data in the st file. @@ -3364,6 +3414,7 @@ class ModelData(object): class WeibullParameters(object): def __init__(self): + from site import print_trace_now; print_trace_now() self.Vin = 4. self.Vr = 12. self.Vout = 26. @@ -3428,6 +3479,7 @@ class Cases(object): #def __init__(self, post_dir, sim_id, resdir=False): def __init__(self, *args, **kwargs): + from site import print_trace_now; print_trace_now() """ Either load the cases dictionary if post_dir and sim_id is given, otherwise the input is a cases dictionary @@ -3499,6 +3551,7 @@ class Cases(object): #return self.cases def select(self, search_keyval=False, search_key=False): + from site import print_trace_now; print_trace_now() """ Select only a sub set of the cases @@ -3533,6 +3586,7 @@ class Cases(object): def launch(self, runmethod='local', verbose=False, copyback_turb=True, silent=False, check_log=True): + from site import print_trace_now; print_trace_now() """ Launch all cases """ @@ -3542,6 +3596,7 @@ class Cases(object): def post_launch(self, save_iter=False, pbs_failed_path=False, suffix=None, path_errorlog=None, silent=False): + from site import print_trace_now; print_trace_now() """ Post Launching Maintenance @@ -3581,6 +3636,7 @@ class Cases(object): self.remove_failed() def load_case(self, case): + from site import print_trace_now; print_trace_now() try: iterations = self.load_iterations(case) except IOError: @@ -3589,6 +3645,7 @@ class Cases(object): return res, iterations def load_iterations(self, case): + from site import print_trace_now; print_trace_now() fp = os.path.join(case['[run_dir]'], case['[iter_dir]'], case['[case_id]']) @@ -3597,6 +3654,7 @@ class Cases(object): # TODO: HAWC2 result file reading should be moved to Simulations # and we should also switch to faster HAWC2 reading! def load_result_file(self, case, _slice=False): + from site import print_trace_now; print_trace_now() """ Set the correct HAWC2 channels @@ -3628,6 +3686,7 @@ class Cases(object): return self.res def load_struct_results(self, case, max_modes=500, nrmodes=1000): + from site import print_trace_now; print_trace_now() """ Load the structural analysis result files """ @@ -3668,6 +3727,7 @@ class Cases(object): return beam, body, eigen_body, eigen_struct, struct_inertia def load_errorlogs(self): + from site import print_trace_now; print_trace_now() """Load error log analysis """ @@ -3680,6 +3740,7 @@ class Cases(object): return df_err def change_results_dir(self, forcedir, post_dir=False): + from site import print_trace_now; print_trace_now() """ if the post processing concerns simulations done by thyra/gorm, and is downloaded locally, change path to results accordingly @@ -3693,6 +3754,7 @@ class Cases(object): #return cases def _get_cases_dict(self, post_dir, sim_id): + from site import print_trace_now; print_trace_now() """ Load the pickled dictionary containing all the cases and their respective tags. @@ -3720,6 +3782,7 @@ class Cases(object): return def cases2df(self): + from site import print_trace_now; print_trace_now() """Convert the cases dict to a DataFrame and check data types""" tag_set = [] @@ -3748,6 +3811,7 @@ class Cases(object): return pd.DataFrame(df_dict2) def merge_sim_ids(self, sim_id_list, silent=False): + from site import print_trace_now; print_trace_now() """ Load and merge for a list of sim_id's cases, fail, dynprop and stats ==================================================================== @@ -3792,6 +3856,7 @@ class Cases(object): self.cases_fail = cases_fail_merged def printall(self, scenario, figpath=''): + from site import print_trace_now; print_trace_now() """ For all the cases, get the average value of a certain channel """ @@ -3804,6 +3869,7 @@ class Cases(object): self.blade_deflection(self.cases[k], self.figpath) def diff(self, refcase_dict, cases): + from site import print_trace_now; print_trace_now() """ See wich tags change over the given cases of the simulation object """ @@ -3840,6 +3906,7 @@ class Cases(object): return diffdict, adddict, remdict def blade_deflection(self, case, **kwargs): + from site import print_trace_now; print_trace_now() """ """ @@ -3867,6 +3934,7 @@ class Cases(object): def find_failed(self, df_cases=None, df_err=None, save=True, rem_failed=None): + from site import print_trace_now; print_trace_now() """Given the log file analysis and the Cases tag list, generate a list of failed cases. This is usefull when either some cases have been re-run or when the post-processing is done at the same time as the @@ -3926,6 +3994,7 @@ class Cases(object): self.cases_fail) def remove_failed(self): + from site import print_trace_now; print_trace_now() # don't do anything if there is nothing defined if self.cases_fail == None: @@ -3944,6 +4013,7 @@ class Cases(object): print(' ', k) def load_failed(self, sim_id): + from site import print_trace_now; print_trace_now() fname = os.path.join(self.post_dir, sim_id + '_fail.pkl') FILE = open(fname, 'rb') @@ -3951,6 +4021,7 @@ class Cases(object): FILE.close() def load_stats(self, **kwargs): + from site import print_trace_now; print_trace_now() """ Load an existing statistcs file @@ -4014,6 +4085,7 @@ class Cases(object): chs_resultant=[], i0=0, i1=None, saveinterval=1000, csv=True, suffix=None, A=None, add_sigs={}, ch_wind=None, save_new_sigs=False, xlsx=False): + from site import print_trace_now; print_trace_now() """ Calculate statistics and save them in a pandas dataframe. Save also every 500 cases the statistics file. @@ -4080,6 +4152,7 @@ class Cases(object): """ def add_df_row(df_dict, **kwargs): + from site import print_trace_now; print_trace_now() """ add a new channel to the df_dict format of ch_df """ @@ -4509,6 +4582,7 @@ class Cases(object): return dfs def _add2newsigs(self, ch_dict, name, i_new_chans, new_sigs, addendum): + from site import print_trace_now; print_trace_now() ch_dict[name] = {} ch_dict[name]['chi'] = i_new_chans @@ -4518,6 +4592,7 @@ class Cases(object): # TODO: use the version in misc instead. def _df_dict_save(self, df_dict2, post_dir, sim_id, save=True, update=False, csv=True, suffix=None): + from site import print_trace_now; print_trace_now() """ Convert the df_dict to df and save/update. @@ -4573,6 +4648,7 @@ class Cases(object): # TODO: use the version in misc instead. def _df_dict_check_datatypes(self, df_dict): + from site import print_trace_now; print_trace_now() """ there might be a mix of strings and numbers now, see if we can have the same data type throughout a column @@ -4622,6 +4698,7 @@ class Cases(object): dlc_folder="dlc%s_iec61400-1ed3/", extra_cols=[], save=False, update=False, csv=False, new_sim_id=False, xlsx=False, years=20.0, silent=False): + from site import print_trace_now; print_trace_now() """ Cacluate the fatigue over a selection of cases and indicate how many hours each case contributes to its life time. @@ -4830,6 +4907,7 @@ class Cases(object): def AEP(self, dfs, fh_lst=None, ch_powe='DLL-2-inpvec-2', extra_cols=[], res_dir='res/', dlc_folder="dlc%s_iec61400-1ed3/", csv=False, new_sim_id=False, save=False, years=20.0, update=False, xlsx=False): + from site import print_trace_now; print_trace_now() """ Calculate the Annual Energy Production (AEP) for DLC1.2 cases. @@ -4913,6 +4991,7 @@ class Cases(object): # the case_id to indentify the corresponding entry from the statistics # DataFrame (exluciding the .sel extension) def basename(k): + from site import print_trace_now; print_trace_now() return os.path.basename(k[0].replace('.sel', '')) fh_lst_basename = [(basename(k), k[1]) for k in fh_lst] # only take dlc12 for power production @@ -4972,6 +5051,7 @@ class Cases(object): return df_AEP def stats2dataframe(self, ch_sel=None, tags=['[seed]','[windspeed]']): + from site import print_trace_now; print_trace_now() """ Convert the archaic statistics dictionary of a group of cases to a more convienent pandas dataframe format. @@ -5054,6 +5134,7 @@ class Cases(object): return dfs def load_azimuth(self, azi, load, sectors=360): + from site import print_trace_now; print_trace_now() """ Establish load dependency on rotor azimuth angle """ @@ -5067,6 +5148,7 @@ class Cases(object): load_sel = np.interp(azi_sel, azi, load) def find_windchan_hub(self): + from site import print_trace_now; print_trace_now() """ """ # if we sort we'll get the largest absolute coordinate last @@ -5076,12 +5158,15 @@ class Cases(object): return chan_found def ct(self, thrust, wind, A, rho=1.225): + from site import print_trace_now; print_trace_now() return thrust / (0.5 * rho * A * wind * wind) def cp(self, power, wind, A, rho=1.225): + from site import print_trace_now; print_trace_now() return power / (0.5 * rho * A * wind * wind * wind) def shaft_power(self): + from site import print_trace_now; print_trace_now() """ Return the mechanical shaft power based on the shaft torsional loading """ @@ -5106,6 +5191,7 @@ class Cases(object): return -1.0*torque*rads def calc_torque_const(self, save=False, name='ojf'): + from site import print_trace_now; print_trace_now() """ If we have constant RPM over the simulation, calculate the torque constant. The current loaded HAWC2 case is considered. Consequently, @@ -5173,6 +5259,7 @@ class Cases(object): return result def compute_envelopes(self, ch_list, int_env=False, Nx=300): + from site import print_trace_now; print_trace_now() """ The function computes load envelopes for given signals and a single load case. Starting from Mx and My moments, the other cross-sectional @@ -5215,6 +5302,7 @@ class Cases(object): return envelope def envelopes(self, silent=False, ch_list=[], append=''): + from site import print_trace_now; print_trace_now() """ Calculate envelopes and save them in a table. @@ -5291,6 +5379,7 @@ class Cases(object): h5f.close() def force_lower_case_id(self): + from site import print_trace_now; print_trace_now() """Keep for backwards compatibility with the dlctemplate.py """ msg = "force_lower_case_id is depricated and is integrated in " @@ -5333,11 +5422,13 @@ class Results(object): # OK, for now use this to do operations on HAWC2 results files def __init___(self): + from site import print_trace_now; print_trace_now() """ """ pass def m_equiv(self, st_arr, load, pos): + from site import print_trace_now; print_trace_now() r"""Centrifugal corrected equivalent moment Convert beam loading into a single equivalent bending moment. Note that @@ -5416,6 +5507,7 @@ class MannTurb64(prepost.PBSScript): """ def __init__(self, silent=False): + from site import print_trace_now; print_trace_now() super(MannTurb64, self).__init__() self.exe = 'time WINEARCH=win64 WINEPREFIX=~/.wine wine mann_turb_x64.exe' self.winefix = 'winefix\n' @@ -5429,6 +5521,7 @@ class MannTurb64(prepost.PBSScript): self.pbs_in_dir = 'pbs_in_turb/' def gen_pbs(self, cases): + from site import print_trace_now; print_trace_now() """ Parameters ---------- @@ -5496,6 +5589,7 @@ class MannTurb64(prepost.PBSScript): def eigenbody(cases, debug=False): + from site import print_trace_now; print_trace_now() """ Read HAWC2 body eigenalysis result file ======================================= @@ -5542,6 +5636,7 @@ def eigenbody(cases, debug=False): return cases def eigenstructure(cases, debug=False): + from site import print_trace_now; print_trace_now() """ Read HAWC2 structure eigenalysis result file ============================================ diff --git a/wetb/prepost/dlcdefs.py b/wetb/prepost/dlcdefs.py index 69ef0a15b21f6312e24ae8e719d6dad1b934729e..654354851049b01ba205c1894f879cc182e5b74f 100644 --- a/wetb/prepost/dlcdefs.py +++ b/wetb/prepost/dlcdefs.py @@ -25,12 +25,14 @@ from wetb.prepost import hawcstab2 def casedict2xlsx(): + from site import print_trace_now; print_trace_now() """ Convert a full Cases.cases dict to Excel spreadsheets """ def configure_dirs(verbose=False, pattern_master='*_master_*'): + from site import print_trace_now; print_trace_now() """ Automatically configure required directories to launch simulations """ @@ -65,6 +67,7 @@ def configure_dirs(verbose=False, pattern_master='*_master_*'): def find_master_file(proot, htc_dir='htc', master_dir='_master', pattern='*_master_*'): + from site import print_trace_now; print_trace_now() """ Find the master file name. It is assumed that the master file is in the folder _master, under htc, and contains _master_ in the file name. If @@ -92,6 +95,7 @@ def find_master_file(proot, htc_dir='htc', master_dir='_master', def variable_tag_func(master, case_id_short=False): + from site import print_trace_now; print_trace_now() """ When using the Excel definitions, and the whole default setup, the variable_tag_func is not required to do anything extra. @@ -133,6 +137,7 @@ def variable_tag_func(master, case_id_short=False): def vartag_dlcs(master): + from site import print_trace_now; print_trace_now() mt = master.tags @@ -161,6 +166,7 @@ def vartag_dlcs(master): def vartag_excel_stabcon(master): + from site import print_trace_now; print_trace_now() """Variable tag function type that generates a hydro input file for the wave kinematics dll if [hydro input name] is defined properly. """ @@ -216,6 +222,7 @@ def vartag_excel_stabcon(master): def tags_dlcs(master): + from site import print_trace_now; print_trace_now() """ Initiate tags that are defined in the DLC spreadsheets """ @@ -272,6 +279,7 @@ def tags_dlcs(master): def tags_defaults(master): + from site import print_trace_now; print_trace_now() # other required tags and their defaults master.tags['[dt_sim]'] = 0.02 @@ -335,6 +343,7 @@ def tags_defaults(master): def excel_stabcon(proot, fext='xlsx', pignore=None, pinclude=None, sheet=0, silent=False, p_source=False): + from site import print_trace_now; print_trace_now() """ Read all MS Excel files that hold load case definitions according to the team STABCON definitions. Save each case in a list according to the @@ -508,6 +517,7 @@ def excel_stabcon(proot, fext='xlsx', pignore=None, pinclude=None, sheet=0, def read_tags_spreadsheet(fname): + from site import print_trace_now; print_trace_now() """Read a spreadsheet with HAWC2 tags, make sure no 0/1/nan ends up replacing the ";" or "" (empty). Do not add any other tags. @@ -545,9 +555,11 @@ class Tests(unittest.TestCase): """ def setUp(self): + from site import print_trace_now; print_trace_now() self.fpath = os.path.join(os.path.dirname(__file__), 'data/DLCs') def test_read_tag_exchange_file(self): + from site import print_trace_now; print_trace_now() df_list = misc.read_excel_files(self.fpath, fext='xlsx', pignore=None, sheet=0, pinclude=None) @@ -557,6 +569,7 @@ class Tests(unittest.TestCase): # df.replace(';', False, inplace=True) def test_excel_stabcon(self): + from site import print_trace_now; print_trace_now() opt_tags = excel_stabcon(self.fpath) diff --git a/wetb/prepost/dlcplots.py b/wetb/prepost/dlcplots.py index de17561a12a8f1dac837399daa98c358609fd74c..3e72a413a52dd3e005c738050792b0e685fc0092 100644 --- a/wetb/prepost/dlcplots.py +++ b/wetb/prepost/dlcplots.py @@ -53,6 +53,7 @@ plt.rc('legend', borderaxespad=0) def merge_sim_ids(sim_ids, post_dirs, post_dir_save=False): + from site import print_trace_now; print_trace_now() """ """ @@ -168,6 +169,7 @@ def merge_sim_ids(sim_ids, post_dirs, post_dir_save=False): def plot_stats2(sim_ids, post_dirs, plot_chans, fig_dir_base=None, labels=None, post_dir_save=False, dlc_ignore=['00'], figsize=(8,6), eps=False, ylabels=None, title=True, chans_ms_1hz={}): + from site import print_trace_now; print_trace_now() """ Map which channels have to be compared """ @@ -188,6 +190,7 @@ def plot_dlc_stats(df_stats, plot_chans, fig_dir_base, labels=None, figsize=(8,6), dlc_ignore=['00'], run_dirs=None, sim_ids=[], eps=False, ylabels=None, title=True, chans_ms_1hz={}): + from site import print_trace_now; print_trace_now() """Create for each DLC an overview plot of the statistics. df_stats required columns: @@ -239,6 +242,7 @@ def plot_dlc_stats(df_stats, plot_chans, fig_dir_base, labels=None, """ def fig_epilogue(fig, ax, fname_base): + from site import print_trace_now; print_trace_now() ax.grid() ax.set_xlim(xlims) leg = ax.legend(bbox_to_anchor=(1, 1), loc='lower right', ncol=3) @@ -477,9 +481,11 @@ def plot_dlc_stats(df_stats, plot_chans, fig_dir_base, labels=None, class PlotStats(object): def __init__(self): + from site import print_trace_now; print_trace_now() pass def load_stats(self, sim_ids, post_dirs, post_dir_save=False): + from site import print_trace_now; print_trace_now() self.sim_ids = sim_ids self.post_dirs = post_dirs @@ -536,11 +542,13 @@ class PlotStats(object): return df_stats def select_extremes_blade_radial(self, df): + from site import print_trace_now; print_trace_now() """ For each radial position of the blade, find the extremes """ def selector(x): + from site import print_trace_now; print_trace_now() """ select following channels: 'local-blade%1i-node-%03i-momentvec-x' @@ -560,6 +568,7 @@ class PlotStats(object): df_ext = {'dlc':[], 'case':[], 'node':[], 'max':[], 'min':[], 'comp':[]} def fillvalues(x, ii, maxmin): + from site import print_trace_now; print_trace_now() x['node'].append(m_group[3].ix[ii]) x['dlc'].append(m_group['[DLC]'].ix[ii]) x['case'].append(m_group['[case_id]'].ix[ii]) @@ -597,6 +606,7 @@ class PlotStats(object): return df_ext def plot_extremes_blade_radial(self, df_ext, fpath): + from site import print_trace_now; print_trace_now() nrows = 2 ncols = 2 figsize = (11,7.15) @@ -647,8 +657,10 @@ class PlotStats(object): df_ext.ix[my_min.index].to_excel(fpath.replace('.png', '_my_min.xls')) def extract_leq_blade_radial(self, df_leq, fpath): + from site import print_trace_now; print_trace_now() def selector(x): + from site import print_trace_now; print_trace_now() """ select following channels: 'local-blade%1i-node-%03i-momentvec-x' @@ -694,6 +706,7 @@ class PlotStats(object): class PlotPerf(object): def __init__(self, nrows=4, ncols=1, figsize=(14,11)): + from site import print_trace_now; print_trace_now() self.fig, self.axes = mplutils.make_fig(nrows=nrows, ncols=ncols, figsize=figsize) @@ -703,6 +716,7 @@ class PlotPerf(object): self.i = 0 def plot(self, res, label_id): + from site import print_trace_now; print_trace_now() """ """ i = self.i @@ -776,6 +790,7 @@ class PlotPerf(object): self.i += 1 def final(self, fig_path, fig_name): + from site import print_trace_now; print_trace_now() axs = self.axes.ravel() @@ -803,6 +818,7 @@ class PlotPerf(object): def plot_dlc01_powercurve(sim_ids, post_dirs, run_dirs, fig_dir_base): + from site import print_trace_now; print_trace_now() """ Create power curve based on steady DLC01 results Use the same format as for HS2 for easy comparison! @@ -813,6 +829,7 @@ def plot_dlc01_powercurve(sim_ids, post_dirs, run_dirs, fig_dir_base): def plot_dlc00(sim_ids, post_dirs, run_dirs, fig_dir_base=None, labels=None, cnames=['dlc00_stair_wsp04_25_noturb.htc', 'dlc00_ramp_wsp04_25_04_noturb.htc'], figsize=(14,11)): + from site import print_trace_now; print_trace_now() """ This version is an update over plot_staircase. """ @@ -862,6 +879,7 @@ def plot_dlc00(sim_ids, post_dirs, run_dirs, fig_dir_base=None, labels=None, def plot_staircase(sim_ids, post_dirs, run_dirs, fig_dir_base=None, cname='dlc00_stair_wsp04_25_noturb.htc'): + from site import print_trace_now; print_trace_now() """ Default stair and ramp names: diff --git a/wetb/prepost/dlctemplate.py b/wetb/prepost/dlctemplate.py index 8f7685635cecf817dbea21332cac6fad97a32e6b..8f08c1e385b42943d5ad2b2dd320028e6de40db7 100644 --- a/wetb/prepost/dlctemplate.py +++ b/wetb/prepost/dlctemplate.py @@ -54,6 +54,7 @@ plt.rc('legend', borderaxespad=0) # ============================================================================= def master_tags(sim_id, runmethod='local', silent=False, verbose=False): + from site import print_trace_now; print_trace_now() """ Create HtcMaster() object ========================= @@ -141,6 +142,7 @@ def master_tags(sim_id, runmethod='local', silent=False, verbose=False): def variable_tag_func(master, case_id_short=False): + from site import print_trace_now; print_trace_now() """ Function which updates HtcMaster.tags and returns an HtcMaster object @@ -190,6 +192,7 @@ def variable_tag_func(master, case_id_short=False): def variable_tag_func_mod1(master, case_id_short=False): + from site import print_trace_now; print_trace_now() """ CAUTION: this is version will add an additional layer in the folder structure in order to seperate input and output file types: @@ -269,6 +272,7 @@ def launch_dlcs_excel(sim_id, silent=False, verbose=False, pbs_turb=False, dlcs_dir='htc/DLCs', wine_64bit=False, m=[3,4,6,8,9,10,12], postpro_node_zipchunks=True, wine_arch='win32', wine_prefix='~/.wine32'): + from site import print_trace_now; print_trace_now() """ Launch load cases defined in Excel files """ @@ -372,6 +376,7 @@ def post_launch(sim_id, statistics=True, rem_failed=True, check_logs=True, years=20.0, fatigue=True, A=None, AEP=False, save_new_sigs=False, envelopeturbine=False, envelopeblade=False, save_iter=False, pbs_failed_path=False): + from site import print_trace_now; print_trace_now() # ========================================================================= # check logfiles, results files, pbs output files @@ -477,6 +482,7 @@ def post_launch(sim_id, statistics=True, rem_failed=True, check_logs=True, def postpro_node_merge(tqdm=False, zipchunks=False, m=[3,4,6,8,9,10,12]): + from site import print_trace_now; print_trace_now() """With postpro_node each individual case has a .csv file for the log file analysis and a .csv file for the statistics tables. Merge all these single files into one table/DataFrame. diff --git a/wetb/prepost/filters.py b/wetb/prepost/filters.py index 22f6fd6cd33c92da67b8e1c3395ad3c5a4c5f6fb..9b559eca493437df6fd6078fb3ccff84045ec0fe 100644 --- a/wetb/prepost/filters.py +++ b/wetb/prepost/filters.py @@ -26,10 +26,12 @@ from wetb.prepost import mplutils class Filters(object): def __init__(self): + from site import print_trace_now; print_trace_now() pass def smooth(self, x, window_len=11, window='hanning'): + from site import print_trace_now; print_trace_now() """ Smooth the data using a window with requested size ================================================== @@ -94,6 +96,7 @@ class Filters(object): return y def butter(self, time, data, **kwargs): + from site import print_trace_now; print_trace_now() """ Source: https://azitech.wordpress.com/2011/03/15/ @@ -122,6 +125,7 @@ class Filters(object): return data_filt def fir(self, time, data, **kwargs): + from site import print_trace_now; print_trace_now() """ Based on the xxample from the SciPy cook boock, see http://www.scipy.org/Cookbook/FIRFilter @@ -228,6 +232,7 @@ class Filters(object): def plot_fir(self, figpath, figfile, time, data, filtered_x, N, delay, sample_rate, taps, nyq_rate): + from site import print_trace_now; print_trace_now() """ """ @@ -330,6 +335,7 @@ class Filters(object): def scipy_example(self, time, data, figpath, sample_rate=None): + from site import print_trace_now; print_trace_now() """ Example from the SciPy Cookboock, see http://www.scipy.org/Cookbook/FIRFilter @@ -464,4 +470,4 @@ class Filters(object): ax3.set_xlabel('t') ax3.grid(True) - plot.save_fig() \ No newline at end of file + plot.save_fig() diff --git a/wetb/prepost/h2_vs_hs2.py b/wetb/prepost/h2_vs_hs2.py index c5ce25a5d37e9486a42a3a63277522033d325a33..446cf4226d5cbb2da86eb1c6c5a309152f4fd4a3 100644 --- a/wetb/prepost/h2_vs_hs2.py +++ b/wetb/prepost/h2_vs_hs2.py @@ -33,9 +33,11 @@ from wetb.prepost import mplutils class ConfigBase(object): def __init__(self): + from site import print_trace_now; print_trace_now() pass def set_master_defaults(self): + from site import print_trace_now; print_trace_now() """Create a set of default master tags that are required for proper compatibility with Simulations.py """ @@ -96,6 +98,7 @@ class ConfigBase(object): return mt def opt_tags_h2_eigenanalysis(self, basename): + from site import print_trace_now; print_trace_now() """Return opt_tags suitable for a standstill HAWC2 eigen analysis. """ opt_tags = [self.opt_h2.copy()] @@ -116,6 +119,7 @@ class ConfigBase(object): return opt_tags def opt_tags_hs_structure_body_eigen(self, basename): + from site import print_trace_now; print_trace_now() """Return opt_tags suitable for a standstill HAWCStab2 body eigen analysis, at 0 RPM. """ @@ -134,12 +138,14 @@ class ConfigBase(object): return opt_tags def opt_tags_hs2(self, basename): + from site import print_trace_now; print_trace_now() opt_tags = [self.opt_hs2.copy()] opt_tags[0]['[Case id.]'] = '%s_hawcstab2' % basename return opt_tags def set_hs2opdata(self, master, basename): + from site import print_trace_now; print_trace_now() """Load the HS2 operational data file and create opt_tags for HAWC2 cases. @@ -158,6 +164,7 @@ class ConfigBase(object): return self.set_opdata(winds, pitchs, omegas, basename=basename) def set_opdata(self, winds, pitchs, omegas, basename=None): + from site import print_trace_now; print_trace_now() """Return opt_tags for HAWC2 based on an HAWCStab2 operational data file. @@ -208,6 +215,7 @@ class Sims(object): def __init__(self, sim_id, P_MASTERFILE, MASTERFILE, P_SOURCE, P_RUN, PROJECT, POST_DIR, master_tags_default): + from site import print_trace_now; print_trace_now() """ Create HtcMaster() object ========================= @@ -267,6 +275,7 @@ class Sims(object): self.master.tags.update(master_tags_default) def _var_tag_func(self, master, case_id_short=False): + from site import print_trace_now; print_trace_now() """ Function which updates HtcMaster.tags and returns an HtcMaster object @@ -342,6 +351,7 @@ class Sims(object): return master def _set_path_auto_config(self, verbose=True): + from site import print_trace_now; print_trace_now() """ auto configure directories: assume you are running in the root of the relevant HAWC2 model @@ -353,6 +363,7 @@ class Sims(object): self.P_MASTERFILE, self.MASTERFILE, self.POST_DIR) = tmp def _set_path_config(self, p_root_run='auto'): + from site import print_trace_now; print_trace_now() """ Set the path configuration into the tags """ @@ -382,6 +393,7 @@ class Sims(object): self.master.tags['[model_zip]'] = '%s_%s.zip' % rpl def get_dlc_casedefs(self): + from site import print_trace_now; print_trace_now() """ Create iter_dict and opt_tags based on spreadsheets """ @@ -419,6 +431,7 @@ class Sims(object): return iter_dict, opt_tags def create_inputs(self, iter_dict, opt_tags, runmethod='pbs'): + from site import print_trace_now; print_trace_now() self.runmethod = runmethod sim.prepare_launch(iter_dict, opt_tags, self.master, self._var_tag_func, @@ -428,6 +441,7 @@ class Sims(object): pbs_fname_appendix=False, short_job_names=False) def get_control_tuning(self, fpath): + from site import print_trace_now; print_trace_now() """ Read a HAWCStab2 controller tuning file and return as tags """ @@ -437,6 +451,7 @@ class Sims(object): def post_processing(self, statistics=True, resdir=None, complib='blosc', calc_mech_power=False): + from site import print_trace_now; print_trace_now() """ Parameters ---------- @@ -474,6 +489,7 @@ class Sims(object): class MappingsH2HS2(object): def __init__(self, config): + from site import print_trace_now; print_trace_now() """ Parameters @@ -511,11 +527,13 @@ class MappingsH2HS2(object): 'chord': '[m]'} def powercurve(self, h2_df_stats, fname_hs): + from site import print_trace_now; print_trace_now() self._powercurve_h2(h2_df_stats) self._powercurve_hs2(fname_hs) def _powercurve_h2(self, df_stats): + from site import print_trace_now; print_trace_now() df_stats.sort_values('[windspeed]', inplace=True) df_mean = pd.DataFrame() @@ -539,6 +557,7 @@ class MappingsH2HS2(object): self.h2_df_stats = df_stats def _powercurve_hs2(self, fname): + from site import print_trace_now; print_trace_now() mappings = {'P [kW]' :'P_aero', 'T [kN]' :'T_aero', @@ -552,6 +571,7 @@ class MappingsH2HS2(object): def blade_distribution(self, fname_h2, fname_hs2, h2_df_stats=None, fname_h2_tors=None): + from site import print_trace_now; print_trace_now() self.hs2_res.df_ind = self.hs2_res.load_ind(fname_hs2) self.h2_res = sim.windIO.ReadOutputAtTime(fname_h2) @@ -563,6 +583,7 @@ class MappingsH2HS2(object): self.distribution_stats_h2(fname_h2_tors, 'Tors_e', 'torsion') def _distribution_hs2(self): + from site import print_trace_now; print_trace_now() """Read a HAWCStab2 *.ind file (blade distribution loading) rot_angle and rot_vec_123 in HS2 should be in rotor polar coordinates @@ -623,6 +644,7 @@ class MappingsH2HS2(object): self.hs_aero['twist'] *= (180.0/np.pi) def _distribution_h2(self): + from site import print_trace_now; print_trace_now() mapping_h2 = { 'Radius_s' :'curved_s', 'Cl' :'Cl', 'Cd' :'Cd', @@ -662,6 +684,7 @@ class MappingsH2HS2(object): self.h2_aero = h2_aero def distribution_stats_h2(self, fname_h2, sensortype, newname): + from site import print_trace_now; print_trace_now() """Determine blade distribution sensor from the HAWC2 statistics. This requires that for each aerodynamic calculation point there should be an output sensor defined manually in the output section. @@ -714,10 +737,12 @@ class MappingsH2HS2(object): self.h2_aero['%s_radius_s' % newname] = df_tors_e['radius'].values.copy() def body_structure_modes(self, fname_h2, fname_hs): + from site import print_trace_now; print_trace_now() self._body_structure_modes_h2(fname_h2) self._body_structure_modes_hs(fname_hs) def _body_structure_modes_h2(self, fname): + from site import print_trace_now; print_trace_now() self.body_freq_h2 = sim.windIO.ReadEigenBody(fname) blade_h2 = self.body_freq_h2[self.body_freq_h2['body']=='blade1'].copy() @@ -730,9 +755,11 @@ class MappingsH2HS2(object): self.blade_body_freq_h2 = blade_h2.query(query) def _body_structure_modes_hs(self, fname): + from site import print_trace_now; print_trace_now() self.body_freq_hs = hs2.results().load_cmb_df(fname) def save(self, fpath, fname_prefix): + from site import print_trace_now; print_trace_now() """Save all the HAWC2 mappings created to fixed width text files similar to HAWCStab2. """ @@ -763,6 +790,7 @@ class Plots(object): """ def __init__(self, config): + from site import print_trace_now; print_trace_now() """ Parameters ---------- @@ -793,6 +821,7 @@ class Plots(object): 'F_x', 'F_y', 'M', 'torsion'] def load_h2(self, fname_h2, h2_df_stats=None, fname_h2_tors=None): + from site import print_trace_now; print_trace_now() res = MappingsH2HS2(self.config) res.h2_res = sim.windIO.ReadOutputAtTime(fname_h2) @@ -806,6 +835,7 @@ class Plots(object): return res def load_hs(self, fname_hs): + from site import print_trace_now; print_trace_now() res = MappingsH2HS2(self.config) res.df_ind = res.hs2_res.load_ind(fname_hs) @@ -815,6 +845,7 @@ class Plots(object): return res def new_fig(self, title=None, nrows=2, ncols=1, dpi=150, size=(12.0, 5.0)): + from site import print_trace_now; print_trace_now() if self.interactive: subplots = plt.subplots @@ -831,6 +862,7 @@ class Plots(object): return fig, axes def set_axes_label_grid(self, axes, setlegend=False): + from site import print_trace_now; print_trace_now() if isinstance(axes, np.ndarray): axes = axes.ravel() @@ -844,6 +876,7 @@ class Plots(object): return axes def save_fig(self, fig, axes, fname): + from site import print_trace_now; print_trace_now() fig.tight_layout() fig.subplots_adjust(top=0.89) fig.savefig(fname, dpi=150) @@ -853,6 +886,7 @@ class Plots(object): def distribution(self, results, labels, title, channels, x_ax='pos_z', xlabel='Z-coordinate [m]', nrows=2, ncols=4, size=(16, 5), i0=1, iplot_legend=0, legloc='best'): + from site import print_trace_now; print_trace_now() """ Compare blade distribution results """ @@ -929,6 +963,7 @@ class Plots(object): def all_h2_channels(self, results, labels, fpath, channels=None, size=(10,5)): + from site import print_trace_now; print_trace_now() """Results is a list of res (=HAWC2 results object)""" for chan, details in results[0].ch_dict.items(): @@ -956,6 +991,7 @@ class Plots(object): def h2_blade_distribution(self, fname_1, fname_2, title, labels, n0=0, df_stats1=None, df_stats2=None, iplot_legend=0, legloc='best'): + from site import print_trace_now; print_trace_now() """ Compare blade distribution aerodynamics of two HAWC2 cases. """ @@ -977,6 +1013,7 @@ class Plots(object): def hs_blade_distribution(self, fname_1, fname_2, title, labels, n0=0, iplot_legend=0, legloc='best'): + from site import print_trace_now; print_trace_now() res1 = self.load_hs(fname_1) res2 = self.load_hs(fname_2) @@ -997,6 +1034,7 @@ class Plots(object): def blade_distribution(self, fname_h2, fname_hs2, title, n0=0, h2_df_stats=None, fname_h2_tors=None, iplot_legend=0, legloc='best'): + from site import print_trace_now; print_trace_now() """Compare aerodynamics, blade deflections between HAWC2 and HAWCStab2. This is based on HAWCSTab2 *.ind files, and an HAWC2 output_at_time output file. @@ -1035,6 +1073,7 @@ class Plots(object): def blade_distribution2(self, fname_h2, fname_hs2, title, n0=0, iplot_legend=0, legloc='best'): + from site import print_trace_now; print_trace_now() """Compare aerodynamics, blade deflections between HAWC2 and HAWCStab2. This is based on HAWCSTab2 *.ind files, and an HAWC2 output_at_time output file. @@ -1057,6 +1096,7 @@ class Plots(object): return fig, axes def powercurve(self, h2_df_stats, fname_hs, title, size=(8.6, 4)): + from site import print_trace_now; print_trace_now() results = MappingsH2HS2(self.config) results.powercurve(h2_df_stats, fname_hs) @@ -1143,6 +1183,7 @@ class Plots(object): def h2_powercurve(self, h2_df_stats1, h2_df_stats2, title, labels, size=(8.6,4)): + from site import print_trace_now; print_trace_now() res1 = MappingsH2HS2(self.config) res1._powercurve_h2(h2_df_stats1) wind1 = res1.pwr_h2_mean['windspeed'].values @@ -1210,6 +1251,7 @@ class Plots(object): return fig, axes def hs_powercurve(self, fname1, fname2, title, labels, size=(8.6, 4)): + from site import print_trace_now; print_trace_now() res1 = MappingsH2HS2(self.config) res1._powercurve_hs2(fname1) diff --git a/wetb/prepost/hawcstab2.py b/wetb/prepost/hawcstab2.py index 62f812f4b2002e50b1e6e6aa65af506da77611de..6642c3fae08a3ed6d28f10e79864adb8bd6d89b5 100644 --- a/wetb/prepost/hawcstab2.py +++ b/wetb/prepost/hawcstab2.py @@ -26,18 +26,21 @@ from wetb.prepost import (mplutils, misc) class dummy(object): def __init__(self, name='dummy'): + from site import print_trace_now; print_trace_now() self.__name__ = name regex_units = re.compile('(\\[.*?\\])') def ReadFileHAWCStab2Header(fname): + from site import print_trace_now; print_trace_now() """ Read a file with a weird HAWCStab2 header that starts with a #, and includes the column number and units between square brackets. """ def get_lines(fname): + from site import print_trace_now; print_trace_now() # get the line that contains the header/column names and the first # line that holds the data with open(fname) as f: @@ -51,6 +54,7 @@ def ReadFileHAWCStab2Header(fname): return line_header, line_data def get_col_widths(line): + from site import print_trace_now; print_trace_now() # it is very annoying that various files can have various column widths # also, the first column is one character wider than the rest i0 = re.search(r'\S',line).start() @@ -61,6 +65,7 @@ def ReadFileHAWCStab2Header(fname): return colwidths def get_col_names(line, colwidths): + from site import print_trace_now; print_trace_now() # because sometimes there are no spaces between the header of each column # sanitize the headers ci = np.array([0] + colwidths).cumsum() @@ -99,11 +104,13 @@ class InductionResults(object): output. Use get_col_width() for automatic detection. """ def __init__(self, colwidth=None): + from site import print_trace_now; print_trace_now() """with gradients currently ind has columns width of 28 instead of 14! """ self.cw = colwidth def get_col_width(self, fname): + from site import print_trace_now; print_trace_now() # figure out column width with open(fname) as fid: # line1 contains the header @@ -131,6 +138,7 @@ class InductionResults(object): self.columns.append(colname) def read(self, fname): + from site import print_trace_now; print_trace_now() if self.cw is None: self.get_col_width(fname) self.wsp = int(fname.split('_u')[-1][:-4]) / 1000.0 @@ -147,9 +155,11 @@ class results(object): """ def __init__(self): + from site import print_trace_now; print_trace_now() pass def load_pwr(self, fname): + from site import print_trace_now; print_trace_now() pwr = np.loadtxt(fname) res = dummy() @@ -165,9 +175,11 @@ class results(object): return res def load_pwr_df(self, fname): + from site import print_trace_now; print_trace_now() return ReadFileHAWCStab2Header(fname) def load_cmb(self, fname): + from site import print_trace_now; print_trace_now() # aero-(servo)-elastic results for HS2>=2.14 have real_eig as 3th set with open(fname) as f: header = f.readline().replace('\n', '') @@ -189,6 +201,7 @@ class results(object): return wind, freq, damp, real_eig def load_cmb_df(self, fname): + from site import print_trace_now; print_trace_now() # index name can be rotor speed or wind speed with open(fname) as f: header = f.readline() @@ -214,6 +227,7 @@ class results(object): return df def load_frf(self, fname, nr_inputs=3): + from site import print_trace_now; print_trace_now() frf = np.loadtxt(fname) self.nr_outputs = ((frf.shape[1] - 1) / 2) / nr_inputs @@ -222,6 +236,7 @@ class results(object): return frf def load_ind(self, fname, colwidth=None): + from site import print_trace_now; print_trace_now() """for results withouth gradients, colwidth=14, otherwise 28. Set to None to derive automatically. """ @@ -230,6 +245,7 @@ class results(object): return ind.df_data def load_amp(self, fname): + from site import print_trace_now; print_trace_now() with open(fname) as f: line = f.readline() @@ -256,6 +272,7 @@ class results(object): return df, units def load_operation(self, fname): + from site import print_trace_now; print_trace_now() operation = np.loadtxt(fname, skiprows=1) # when the array is empty, set operation to an empty DataFrame @@ -277,6 +294,7 @@ class results(object): def load_matrices(self, fpath, basename, operating_point=1, control_mat=False, local_wind_mat=False): + from site import print_trace_now; print_trace_now() """Load HAWCStab2 State Space system matrices The general file name format is: @@ -336,6 +354,7 @@ class results(object): return matrices def write_ae_sections_h2(self): + from site import print_trace_now; print_trace_now() """ Get the aerosection positions from the HS2 ind result file and write them as outputs for HAWC2 @@ -343,6 +362,7 @@ class results(object): self.ind def plot_pwr(self, figname, fnames, labels=[], figsize=(11,7.15), dpi=120): + from site import print_trace_now; print_trace_now() results = [] if isinstance(fnames, list): @@ -408,11 +428,13 @@ class results(object): class ReadControlTuning(object): def __init__(self): + from site import print_trace_now; print_trace_now() """ """ self._aerogains = False def parse_line(self, line, controller): + from site import print_trace_now; print_trace_now() """Parses the output lines with the controller tuning parameters. Does not parse the aerodynamic gain lines. """ @@ -436,6 +458,7 @@ class ReadControlTuning(object): pass def read_parameters(self, fpath): + from site import print_trace_now; print_trace_now() """ Read the controller tuning file =============================== @@ -488,6 +511,7 @@ class ReadControlTuning(object): setattr(self.aero_damp, 'Ko2', 0.0) def parameters2tags(self): + from site import print_trace_now; print_trace_now() """Convert the tuning parameters into a dictionary whos keys are compatible with tag names in a HAWC2 master file. """ diff --git a/wetb/prepost/misc.py b/wetb/prepost/misc.py index b6129907304a3cb7c58fef4cf63f0368315312eb..dfeca62909157e475fb9959d67c5a28c24cbab60 100644 --- a/wetb/prepost/misc.py +++ b/wetb/prepost/misc.py @@ -48,6 +48,7 @@ class Logger(object): """ def __init__(self, logFile, echo): + from site import print_trace_now; print_trace_now() """Arguments: logFile a file object that is available for writing echo Boolean. If True, output is sent to standard output in @@ -59,6 +60,7 @@ class Logger(object): self.echo = echo def write(self, s): + from site import print_trace_now; print_trace_now() """Required method that replaces stdout. You don't have to call this directly--all print statements will be redirected here.""" self.logFile.write(s) @@ -68,6 +70,7 @@ class Logger(object): def path_split_dirs(path): + from site import print_trace_now; print_trace_now() """ Return a list with dirnames. Ignore any leading "./" """ @@ -78,6 +81,7 @@ def path_split_dirs(path): def print_both(f, text, end='\n'): + from site import print_trace_now; print_trace_now() """ Print both to a file and the console """ @@ -86,6 +90,7 @@ def print_both(f, text, end='\n'): f.write(text + end) def unique(s): + from site import print_trace_now; print_trace_now() """ SOURCE: http://code.activestate.com/recipes/52560/ AUTHOR: Tim Peters @@ -158,6 +163,7 @@ def unique(s): return u def CoeffDeter(obs, model): + from site import print_trace_now; print_trace_now() """ Coefficient of determination ============================ @@ -193,6 +199,7 @@ def CoeffDeter(obs, model): def calc_sample_rate(time, rel_error=1e-4): + from site import print_trace_now; print_trace_now() """ the sample rate should be constant throughout the measurement serie define the maximum allowable relative error on the local sample rate @@ -209,6 +216,7 @@ def calc_sample_rate(time, rel_error=1e-4): return 1/deltas.mean() def findIntersection(fun1, fun2, x0): + from site import print_trace_now; print_trace_now() """ Find Intersection points of two functions ========================================= @@ -239,6 +247,7 @@ def findIntersection(fun1, fun2, x0): # TODO: replace this with some of the pyrain functions def find0(array, xi=0, yi=1, verbose=False, zerovalue=0.0): + from site import print_trace_now; print_trace_now() """ Find single zero crossing ========================= @@ -350,6 +359,7 @@ def find0(array, xi=0, yi=1, verbose=False, zerovalue=0.0): return y0, y0i def remove_items(list, value): + from site import print_trace_now; print_trace_now() """Remove items from list The given list wil be returned withouth the items equal to value. Empty ('') is allowed. So this is een extension on list.remove() @@ -382,6 +392,7 @@ class DictDB(object): """ def __init__(self, dict_db): + from site import print_trace_now; print_trace_now() """ """ # TODO: data checks to see if the dict can qualify as a database @@ -390,6 +401,7 @@ class DictDB(object): self.dict_db = dict_db def search(self, dict_search): + from site import print_trace_now; print_trace_now() """ Search a dictionary based database ================================== @@ -440,6 +452,7 @@ class DictDB(object): # TODO: merge with search into a more general search/select method? # shouldn't I be moving to a proper database with queries? def search_key(self, dict_search): + from site import print_trace_now; print_trace_now() """ Search for a string in dictionary keys ====================================== @@ -491,16 +504,20 @@ class DictDiff(object): fast-comparison-between-two-python-dictionary """ def __init__(self, current_dict, past_dict): + from site import print_trace_now; print_trace_now() self.current_d = current_dict self.past_d = past_dict self.set_current = set(current_dict.keys()) self.set_past = set(past_dict.keys()) self.intersect = self.set_current.intersection(self.set_past) def added(self): + from site import print_trace_now; print_trace_now() return self.set_current - self.intersect def removed(self): + from site import print_trace_now; print_trace_now() return self.set_past - self.intersect def changed(self): + from site import print_trace_now; print_trace_now() #set(o for o in self.intersect if self.past_d[o] != self.current_d[o]) # which is the similar (exept for the extension) as below olist = [] @@ -514,15 +531,18 @@ class DictDiff(object): return set(olist) def unchanged(self): + from site import print_trace_now; print_trace_now() t=set(o for o in self.intersect if self.past_d[o] == self.current_d[o]) return t def fit_exp(time, data, checkplot=True, method='linear', func=None, C0=0.0): + from site import print_trace_now; print_trace_now() """ Note that all values in data have to be possitive for this method to work! """ def fit_exp_linear(t, y, C=0): + from site import print_trace_now; print_trace_now() y = y - C y = np.log(y) K, A_log = np.polyfit(t, y, 1) @@ -530,6 +550,7 @@ def fit_exp(time, data, checkplot=True, method='linear', func=None, C0=0.0): return A, K def fit_exp_nonlinear(t, y): + from site import print_trace_now; print_trace_now() # The model function, f(x, ...). It must take the independent variable # as the first argument and the parameters to fit as separate remaining # arguments. @@ -538,6 +559,7 @@ def fit_exp(time, data, checkplot=True, method='linear', func=None, C0=0.0): return A, K, C def model_func(t, A, K, C): + from site import print_trace_now; print_trace_now() return A * np.exp(K * t) + C # Linear fit @@ -564,6 +586,7 @@ def fit_exp(time, data, checkplot=True, method='linear', func=None, C0=0.0): return fit, A, K, C def curve_fit_exp(time, data, checkplot=True, weights=None): + from site import print_trace_now; print_trace_now() """ This code is based on a StackOverflow question/answer: http://stackoverflow.com/questions/3938042/ @@ -573,6 +596,7 @@ def curve_fit_exp(time, data, checkplot=True, weights=None): """ def fit_exp_linear(t, y, C=0): + from site import print_trace_now; print_trace_now() y = y - C y = np.log(y) K, A_log = np.polyfit(t, y, 1) @@ -580,6 +604,7 @@ def curve_fit_exp(time, data, checkplot=True, weights=None): return A, K def fit_exp_nonlinear(t, y): + from site import print_trace_now; print_trace_now() # The model function, f(x, ...). It must take the independent variable # as the first argument and the parameters to fit as separate remaining # arguments. @@ -588,6 +613,7 @@ def curve_fit_exp(time, data, checkplot=True, weights=None): return A, K, C def model_func(t, A, K, C): + from site import print_trace_now; print_trace_now() return A * np.exp(K * t) + C C0 = 0 @@ -622,6 +648,7 @@ def curve_fit_exp(time, data, checkplot=True, weights=None): return def convert_to_utf8(filename): + from site import print_trace_now; print_trace_now() # gather the encodings you think that the file may be # encoded inside a tuple encodings = ('windows-1253', 'iso-8859-7', 'macgreek') @@ -671,6 +698,7 @@ def convert_to_utf8(filename): f.close() def to_lower_case(proot): + from site import print_trace_now; print_trace_now() """ Rename all the files in the subfolders of proot to lower case, and also the subfolder name when it the folder name starts with DLC @@ -688,6 +716,7 @@ def to_lower_case(proot): def read_excel_files(proot, fext='xlsx', pignore=None, sheet=0, pinclude=None, silent=False): + from site import print_trace_now; print_trace_now() """ Read recursively all MS Excel files with extension "fext". Only the default name for the first sheet (Sheet1) of the Excel file is considered. @@ -752,6 +781,7 @@ def read_excel_files(proot, fext='xlsx', pignore=None, sheet=0, return df_list def convert_xlsx2csv(fpath, sheet='Sheet1', fext='xlsx'): + from site import print_trace_now; print_trace_now() """ Convert xlsx load case definitions to csv so we can track them with git """ @@ -768,6 +798,7 @@ def convert_xlsx2csv(fpath, sheet='Sheet1', fext='xlsx'): df.to_csv(fcsv, sep=';') def check_df_dict(df_dict): + from site import print_trace_now; print_trace_now() """ Verify if the dictionary that needs to be transferred to a Pandas DataFrame makes sense @@ -787,6 +818,7 @@ def check_df_dict(df_dict): def find_tags(fname): + from site import print_trace_now; print_trace_now() """ Find all unqiue tags in a text file. """ @@ -811,6 +843,7 @@ def find_tags(fname): def read_mathematica_3darray(fname, shape=None, data=None, dtype=None): + from site import print_trace_now; print_trace_now() """ I am not sure with which Mathematica command you generate this data, but this is the format in which I got it. @@ -852,6 +885,7 @@ def read_mathematica_3darray(fname, shape=None, data=None, dtype=None): def CDF(series, sort=True): + from site import print_trace_now; print_trace_now() """ Cumulative distribution function ================================ @@ -908,6 +942,7 @@ def CDF(series, sort=True): def rebin(hist, bins, nrbins): + from site import print_trace_now; print_trace_now() """ Assume within a bin, the values are equally distributed. Only works for equally spaced bins. @@ -958,6 +993,7 @@ def rebin(hist, bins, nrbins): def histfit(hist, bin_edges, xnew): + from site import print_trace_now; print_trace_now() """ This should be similar to the Matlab function histfit: http://se.mathworks.com/help/stats/histfit.html @@ -1008,6 +1044,7 @@ def histfit(hist, bin_edges, xnew): def histfit_arbritrary(edges, pdf, edges_new, resolution=100): + from site import print_trace_now; print_trace_now() """Re-bin based on the CDF of a PDF. Assume normal distribution within a bin to transform the CDF to higher resolution. @@ -1089,6 +1126,7 @@ def histfit_arbritrary(edges, pdf, edges_new, resolution=100): def hist_centers2edges(centers): + from site import print_trace_now; print_trace_now() """Given the centers of bins, return its edges and bin widths. """ @@ -1103,6 +1141,7 @@ def hist_centers2edges(centers): def df_dict_check_datatypes(df_dict): + from site import print_trace_now; print_trace_now() """ there might be a mix of strings and numbers now, see if we can have the same data type throughout a column @@ -1150,6 +1189,7 @@ def df_dict_check_datatypes(df_dict): def dict2df(df_dict, fname, save=True, update=False, csv=False, colsort=None, check_datatypes=False, rowsort=None, csv_index=False, xlsx=False, complib='blosc'): + from site import print_trace_now; print_trace_now() """ Convert the df_dict to df and save/update if required. If converting to df fails, pickle the object. Optionally save as csv too. @@ -1236,9 +1276,11 @@ def dict2df(df_dict, fname, save=True, update=False, csv=False, colsort=None, class Tests(unittest.TestCase): def setUp(self): + from site import print_trace_now; print_trace_now() pass def test_rebin1(self): + from site import print_trace_now; print_trace_now() hist = np.array([2,5,5,9,2,6]) bins = np.arange(7) nrbins = 3 @@ -1249,6 +1291,7 @@ class Tests(unittest.TestCase): self.assertTrue(np.allclose(binanswer, bins_)) def test_rebin2(self): + from site import print_trace_now; print_trace_now() hist = np.array([2,5,5,9,2,6]) bins = np.arange(7) nrbins = 1 @@ -1259,6 +1302,7 @@ class Tests(unittest.TestCase): self.assertTrue(np.allclose(binanswer, bins_)) def test_rebin3(self): + from site import print_trace_now; print_trace_now() hist = np.array([1,1,1]) bins = np.arange(4) nrbins = 2 @@ -1269,6 +1313,7 @@ class Tests(unittest.TestCase): self.assertTrue(np.allclose(binanswer, bins_)) def test_rebin4(self): + from site import print_trace_now; print_trace_now() hist = np.array([1,1,1]) bins = np.arange(2, 14, 3) nrbins = 2 @@ -1279,6 +1324,7 @@ class Tests(unittest.TestCase): self.assertTrue(np.allclose(binanswer, bins_)) def test_rebin5(self): + from site import print_trace_now; print_trace_now() hist = np.array([1,4,2,5,6,11,9,10,8,0.5]) bins = np.linspace(-2, 10, 11) nrbins = 8 diff --git a/wetb/prepost/mplutils.py b/wetb/prepost/mplutils.py index 94bda4e42d4f800b553c9160358307eebe97dcf3..9356a189fb9c0dc71a19db1b3012bbf77751f339 100644 --- a/wetb/prepost/mplutils.py +++ b/wetb/prepost/mplutils.py @@ -32,6 +32,7 @@ except ImportError: def make_fig(nrows=1, ncols=1, figsize=(12,8), dpi=120): + from site import print_trace_now; print_trace_now() """ Equivalent function of pyplot.subplots(). The difference is that this one @@ -51,6 +52,7 @@ def make_fig(nrows=1, ncols=1, figsize=(12,8), dpi=120): def subplots(nrows=1, ncols=1, figsize=(12,8), dpi=120, num=0, subplot_kw={}): + from site import print_trace_now; print_trace_now() """ Equivalent function of pyplot.subplots(). The difference is that this one @@ -82,6 +84,7 @@ def subplots(nrows=1, ncols=1, figsize=(12,8), dpi=120, num=0, subplot_kw={}): def match_axis_ticks(ax1, ax2, ax1_format=None, ax2_format=None): + from site import print_trace_now; print_trace_now() """ Match ticks of ax2 to ax1 ========================= @@ -118,6 +121,7 @@ def match_axis_ticks(ax1, ax2, ax1_format=None, ax2_format=None): def one_legend(*args, **kwargs): + from site import print_trace_now; print_trace_now() """First list all the axes as arguments. Any keyword arguments will be passed on to ax.legend(). Legend will be placed on the last axes that was passed as an argument. @@ -144,6 +148,7 @@ def one_legend(*args, **kwargs): def p4psd(ax, rpm_mean, p_max=17, y_pos_rel=0.25, color='g', ls='--', col_text='w'): + from site import print_trace_now; print_trace_now() """ Add the P's on a PSD @@ -195,6 +200,7 @@ def p4psd(ax, rpm_mean, p_max=17, y_pos_rel=0.25, color='g', ls='--', def peaks(ax, freqs, Pxx, fn_max, min_h, nr_peaks=15, col_line='k', ypos_mean=0.14, col_text='w', ypos_delta=0.06, bbox_alpha=0.5, verbose=False): + from site import print_trace_now; print_trace_now() """ indicate the peaks """ @@ -257,6 +263,7 @@ def peaks(ax, freqs, Pxx, fn_max, min_h, nr_peaks=15, col_line='k', def match_yticks(ax1, ax2, nr_ticks_forced=None, extend=False): + from site import print_trace_now; print_trace_now() """ """ @@ -284,6 +291,7 @@ def match_yticks(ax1, ax2, nr_ticks_forced=None, extend=False): def psd(ax, time, sig, nfft=None, res_param=250, f0=0, f1=None, nr_peaks=10, min_h=15, mark_peaks=False, col='r-', label=None, alpha=1.0, ypos_peaks=0.9, ypos_peaks_delta=0.12): + from site import print_trace_now; print_trace_now() """Only plot the psd on a given axis and optionally mark the peaks. """ @@ -317,6 +325,7 @@ def time_psd(results, labels, axes, alphas=[1.0, 0.7], colors=['k-', 'r-'], NFFT=None, res_param=250, f0=0, f1=None, nr_peaks=10, min_h=15, mark_peaks=False, xlabels=['frequency [Hz]', 'time [s]'], ypos_peaks=[0.3, 0.9], ypos_peaks_delta=[0.12, 0.12]): + from site import print_trace_now; print_trace_now() """ Plot time series and the corresponding PSD of the channel. diff --git a/wetb/prepost/prepost.py b/wetb/prepost/prepost.py index 2bc93cb56e8df1ed99ddd9bae9fda66051c3c542..f13658230e4fc9752faef8e3e16cfe51e2054e25 100644 --- a/wetb/prepost/prepost.py +++ b/wetb/prepost/prepost.py @@ -73,6 +73,7 @@ exit """ def __init__(self): + from site import print_trace_now; print_trace_now() # PBS configuration self.jobname = 'no_name_job' @@ -100,6 +101,7 @@ exit self.scratchdir = '/scratch/$USER/$PBS_JOBID/' def check_dirs(self): + from site import print_trace_now; print_trace_now() """Create the directories of std out, std error and pbs file if they do not exist""" dnames = set([os.path.dirname(self.path_pbs_o), @@ -110,6 +112,7 @@ exit os.makedirs(os.path.join(self.pbsworkdir, dname)) def create(self, **kwargs): + from site import print_trace_now; print_trace_now() """ path_pbs_e, path_pbs_o, and path_pbs are relative with respect to the working dir diff --git a/wetb/prepost/simchunks.py b/wetb/prepost/simchunks.py index abb00f702267cc51d535d652bc1d42a013275be4..84bd86c4af469ce68f02c87edcc02fc15b8db178 100644 --- a/wetb/prepost/simchunks.py +++ b/wetb/prepost/simchunks.py @@ -44,6 +44,7 @@ def create_chunks_htc_pbs(cases, sort_by_values=['[Windspeed]'], ppn=20, i0=0, """ def chunker(seq, size): + from site import print_trace_now; print_trace_now() # for DataFrames you can also use groupby, as taken from: # http://stackoverflow.com/a/25703030/3156685 # for k,g in df.groupby(np.arange(len(df))//10) @@ -53,6 +54,7 @@ def create_chunks_htc_pbs(cases, sort_by_values=['[Windspeed]'], ppn=20, i0=0, return (seq[pos:pos + size] for pos in range(0, len(seq), size)) def make_zip_chunks(df, ii, sim_id, run_dir, model_zip): + from site import print_trace_now; print_trace_now() """Create zip cunks and also create an index """ @@ -480,6 +482,7 @@ def create_chunks_htc_pbs(cases, sort_by_values=['[Windspeed]'], ppn=20, i0=0, f.write(pbs) def make_pbs_postpro_chunks(): + from site import print_trace_now; print_trace_now() """When only the post-processing has to be re-done for a chunk. """ pass @@ -528,6 +531,7 @@ def create_chunks_htc_pbs(cases, sort_by_values=['[Windspeed]'], ppn=20, i0=0, def regroup_tarfiles(cc): + from site import print_trace_now; print_trace_now() """Re-group all chunks again per [Case folder] compressed file. First all chunks are copied to the node scratch disc, then start working on them. This only works on a node with PBS stuff. @@ -577,6 +581,7 @@ def regroup_tarfiles(cc): def merge_from_tarfiles(df_fname, path, pattern, tarmode='r:xz', tqdm=False, header='infer', names=None, sep=',', min_itemsize={}, verbose=False, dtypes={}): + from site import print_trace_now; print_trace_now() """Merge all csv files from various tar archives into a big pd.DataFrame store. @@ -627,6 +632,7 @@ def merge_from_tarfiles(df_fname, path, pattern, tarmode='r:xz', tqdm=False, from tqdm import tqdm else: def tqdm(itereable): + from site import print_trace_now; print_trace_now() return itereable for tar_fname in tqdm(glob.glob(os.path.join(path, pattern))): @@ -666,14 +672,17 @@ class AppendDataFrames(object): """ def __init__(self, tqdm=False): + from site import print_trace_now; print_trace_now() if tqdm: from tqdm import tqdm else: def tqdm(itereable): + from site import print_trace_now; print_trace_now() return itereable self.tqdm = tqdm def _open(self, fname, tarmode='r:xz'): + from site import print_trace_now; print_trace_now() """Open text file directly or from a tar archive. Return iterable since a tar archive might contain several csv text files """ @@ -693,6 +702,7 @@ class AppendDataFrames(object): def df2store(self, store, path, tarmode='r:xz', min_itemsize={}, colnames=None, header='infer', columns=None, sep=';', index2col=None, ignore_index=True, fname_col=False): + from site import print_trace_now; print_trace_now() """This is very slow, use txt2txt instead. """ @@ -739,6 +749,7 @@ class AppendDataFrames(object): # skipping over one case def txt2txt(self, fjoined, path, tarmode='r:xz', header=None, sep=';', fname_col=False, header_fjoined=None, recursive=False): + from site import print_trace_now; print_trace_now() """Read as strings, write to another file as strings. Parameters diff --git a/wetb/prepost/windIO.py b/wetb/prepost/windIO.py index 27364329e6968c5a408894a251d3a91262d72f01..b1986c6581751aa8173d082c0fa149deb2f135df 100755 --- a/wetb/prepost/windIO.py +++ b/wetb/prepost/windIO.py @@ -48,6 +48,7 @@ class LogFile(object): """ def __init__(self): + from site import print_trace_now; print_trace_now() # the total message list log: self.MsgListLog = [] @@ -141,6 +142,7 @@ class LogFile(object): self.header = None def readlog(self, fname, case=None, save_iter=False): + from site import print_trace_now; print_trace_now() """ """ # open the current log file @@ -374,6 +376,7 @@ class LogFile(object): self.MsgListLog2[fname] = [found_error, exit_correct] def _msglistlog2csv(self, contents): + from site import print_trace_now; print_trace_now() """Write LogFile.MsgListLog to a csv file. Use LogFile._header to create a header. """ @@ -385,6 +388,7 @@ class LogFile(object): return contents def csv2df(self, fname, header=0): + from site import print_trace_now; print_trace_now() """Read a csv log file analysis and convert to a pandas.DataFrame """ colnames, min_itemsize, dtypes = self.headers4df() @@ -397,6 +401,7 @@ class LogFile(object): return df def _header(self): + from site import print_trace_now; print_trace_now() """Header for log analysis csv file """ @@ -414,6 +419,7 @@ class LogFile(object): return contents def headers4df(self): + from site import print_trace_now; print_trace_now() """Create header and a minimum itemsize for string columns when converting a Log check analysis to a pandas.DataFrame @@ -590,6 +596,7 @@ class LoadResults(ReadHawc2): # TODO: THIS IS STILL A WIP def _make_channel_names(self): + from site import print_trace_now; print_trace_now() """Give every channel a unique channel name which is (nearly) identical to the channel names as defined in the htc output section. Instead of spaces, use colon (;) to seperate the different commands. @@ -724,6 +731,7 @@ class LoadResults(ReadHawc2): return names, index def _unified_channel_names(self): + from site import print_trace_now; print_trace_now() """ Make certain channels independent from their index. @@ -1321,6 +1329,7 @@ class LoadResults(ReadHawc2): def _ch_dict2df(self): + from site import print_trace_now; print_trace_now() """ Create a DataFrame version of the ch_dict, and the chi columns is set as the index @@ -1345,6 +1354,7 @@ class LoadResults(ReadHawc2): self.ch_df.set_index('chi', inplace=True) def _data_window(self, nr_rev=None, time=None): + from site import print_trace_now; print_trace_now() """ Based on a time interval, create a proper slice object ====================================================== @@ -1407,6 +1417,7 @@ class LoadResults(ReadHawc2): return slice_, window, zoomtype, time_range def sig2df(self): + from site import print_trace_now; print_trace_now() """Convert sig to dataframe with unique channel names as column names. """ # channels that are not part of the naming scheme are not included @@ -1417,6 +1428,7 @@ class LoadResults(ReadHawc2): # TODO: general signal method, this is not HAWC2 specific, move out def calc_stats(self, sig, i0=0, i1=None): + from site import print_trace_now; print_trace_now() stats = {} # calculate the statistics values: @@ -1509,6 +1521,7 @@ class LoadResults(ReadHawc2): # TODO: general signal method, this is not HAWC2 specific, move out def calc_fatigue(self, signal, no_bins=46, m=[3, 4, 6, 8, 10, 12], neq=1): + from site import print_trace_now; print_trace_now() """ Parameters ---------- @@ -1531,6 +1544,7 @@ class LoadResults(ReadHawc2): return eq_load(signal, no_bins=no_bins, m=m, neq=neq)[0] def cycle_matrix(self, signal, no_bins=46): + from site import print_trace_now; print_trace_now() """Cycle/Markov matrix. Convenience function for wetb.fatigue_tools.fatigue.cycle_matrix2 @@ -1562,6 +1576,7 @@ class LoadResults(ReadHawc2): return cycle_matrix2(signal, no_bins) def blade_deflection(self): + from site import print_trace_now; print_trace_now() """ """ @@ -1585,6 +1600,7 @@ class LoadResults(ReadHawc2): return np.array(zvals), np.array(yvals) def save_chan_names(self, fname): + from site import print_trace_now; print_trace_now() """Save unique channel names to text file. """ channels = self.ch_df.ch_name.values @@ -1592,6 +1608,7 @@ class LoadResults(ReadHawc2): np.savetxt(fname, channels, fmt='%-100s') def save_channel_info(self, fname): + from site import print_trace_now; print_trace_now() """Save all channel info: unique naming + HAWC2 description from *.sel. """ p1 = self.ch_df.copy() @@ -1611,10 +1628,12 @@ class LoadResults(ReadHawc2): return tmp def load_chan_names(self, fname): + from site import print_trace_now; print_trace_now() dtype = np.dtype('U100') return np.genfromtxt(fname, dtype=dtype, delimiter=';').tolist() def save_csv(self, fname, fmt='%.18e', delimiter=','): + from site import print_trace_now; print_trace_now() """ Save to csv and use the unified channel names as columns """ @@ -1639,6 +1658,7 @@ class LoadResults(ReadHawc2): print(fname) def save_df(self, fname): + from site import print_trace_now; print_trace_now() """ Save the HAWC2 data and sel file in a DataFrame that contains all the data, and all the channel information (the one from the sel file @@ -1651,6 +1671,7 @@ class LoadResults(ReadHawc2): def ReadOutputAtTime(fname): + from site import print_trace_now; print_trace_now() """Distributed blade loading as generated by the HAWC2 output_at_time command. From HAWC2 12.3-beta and onwards, there are 7 header columns, earlier version only have 3. @@ -1683,6 +1704,7 @@ def ReadOutputAtTime(fname): def ReadEigenBody(fname, debug=False): + from site import print_trace_now; print_trace_now() """ Read HAWC2 body eigenalysis result file ======================================= @@ -1754,6 +1776,7 @@ def ReadEigenBody(fname, debug=False): def ReadEigenStructure(file_path, file_name, debug=False, max_modes=500): + from site import print_trace_now; print_trace_now() """ Read HAWC2 structure eigenalysis result file ============================================ @@ -1839,6 +1862,7 @@ class UserWind(object): """ def __init__(self): + from site import print_trace_now; print_trace_now() pass def __call__(self, z_h, r_blade_tip, a_phi=None, shear_exp=None, nr_hor=3, @@ -1919,6 +1943,7 @@ class UserWind(object): return uu, vv, ww, x, z def create_coords(self, z_h, r_blade_tip, nr_vert=3, nr_hor=20): + from site import print_trace_now; print_trace_now() """ Utility to create the coordinates of the wind field based on hub heigth and blade length. Add 15% to r_blade_tip to make sure horizontal edges @@ -1932,6 +1957,7 @@ class UserWind(object): return x, z def deltaphi2aphi(self, d_phi, z_h, r_blade_tip, h_ME=500.0): + from site import print_trace_now; print_trace_now() """For a given `\\Delta \\varphi` over the rotor diameter, estimate the corresponding `a_{\\varphi}`. @@ -1965,6 +1991,7 @@ class UserWind(object): return a_phi def deltaphi2aphi_opt(self, deltaphi, z, z_h, r_blade_tip, h_ME): + from site import print_trace_now; print_trace_now() """ convert delta_phi over a given interval z to a_phi using scipy.optimize.fsolve on veer_ekman_mod. @@ -1980,6 +2007,7 @@ class UserWind(object): """ def func(a_phi, z, z_h, h_ME, deltaphi_target): + from site import print_trace_now; print_trace_now() phis = WindProfiles.veer_ekman_mod(z, z_h, h_ME=h_ME, a_phi=a_phi) return np.abs(deltaphi_target - (phis[1] - phis[0])) @@ -1987,6 +2015,7 @@ class UserWind(object): return sp.optimize.fsolve(func, [0], args=args)[0] def decompose_veer(self, phi_rad, nr_hor): + from site import print_trace_now; print_trace_now() """ Convert a veer angle into u, v, and w components, ready for the HAWC2 user defined veer input file. nr_vert refers to the number of @@ -2040,6 +2069,7 @@ class UserWind(object): return u_full, v_full, w_full def read(self, fname): + from site import print_trace_now; print_trace_now() """ Read a user defined shear input file as used for HAWC2. @@ -2118,15 +2148,18 @@ class UserWind(object): class WindProfiles(object): def logarithmic(z, z_ref, r_0): + from site import print_trace_now; print_trace_now() return np.log10(z/r_0)/np.log10(z_ref/r_0) def powerlaw(z, z_ref, a): + from site import print_trace_now; print_trace_now() profile = np.power(z/z_ref, a) # when a negative, make sure we return zero and not inf profile[np.isinf(profile)] = 0.0 return profile def veer_ekman_mod(z, z_h, h_ME=500.0, a_phi=0.5): + from site import print_trace_now; print_trace_now() """ Modified Ekman veer profile, as defined by Mark C. Kelly in email on 10 October 2014 15:10 (RE: veer profile) @@ -2182,10 +2215,12 @@ class WindProfiles(object): class Turbulence(object): def __init__(self): + from site import print_trace_now; print_trace_now() pass def read_hawc2(self, fpath, shape): + from site import print_trace_now; print_trace_now() """ Read the HAWC2 turbulence format """ @@ -2197,6 +2232,7 @@ class Turbulence(object): return turb def read_bladed(self, fpath, basename): + from site import print_trace_now; print_trace_now() fid = open(fpath + basename + '.wnd', 'rb') R1 = struct.unpack('h', fid.read(2))[0] @@ -2232,6 +2268,7 @@ class Turbulence(object): return points def convert2bladed(self, fpath, basename, shape=(4096,32,32)): + from site import print_trace_now; print_trace_now() """ Convert turbulence box to BLADED format """ @@ -2284,6 +2321,7 @@ class Turbulence(object): return iu.astype(np.int16), iv.astype(np.int16), iw.astype(np.int16) def write_bladed(self, fpath, basename, shape): + from site import print_trace_now; print_trace_now() """ Write turbulence BLADED file """ @@ -2360,6 +2398,7 @@ class Turbulence(object): class Bladed(object): def __init__(self): + from site import print_trace_now; print_trace_now() """ Some BLADED results I have seen are just weird text files. Convert them to a more convienent format. @@ -2378,6 +2417,7 @@ class Bladed(object): pass def infer_format(self, lines): + from site import print_trace_now; print_trace_now() """ Figure out how many channels and time steps are included """ @@ -2391,6 +2431,7 @@ class Bladed(object): return int(chans), int(iters) def read(self, fname, chans=None, iters=None, enc='cp1252'): + from site import print_trace_now; print_trace_now() """ Parameters ---------- diff --git a/wetb/utils/caching.py b/wetb/utils/caching.py index b4fd84849198447b9db606a41836d86b48fc9c9d..0e6ab99f63480e086ae97739139988e7dec77d97 100644 --- a/wetb/utils/caching.py +++ b/wetb/utils/caching.py @@ -15,6 +15,7 @@ standard_library.install_aliases() import inspect import numpy as np def set_cache_property(obj, name, get_func, set_func=None): + from site import print_trace_now; print_trace_now() """Create a cached property Parameters @@ -43,6 +44,7 @@ def set_cache_property(obj, name, get_func, set_func=None): _name = "_" + name setattr(obj, _name, None) def get(self): + from site import print_trace_now; print_trace_now() if getattr(obj, _name) is None: setattr(obj, _name, get_func()) return getattr(obj, _name) @@ -51,6 +53,7 @@ def set_cache_property(obj, name, get_func, set_func=None): return setattr(obj.__class__, name, p) def cache_function(f): + from site import print_trace_now; print_trace_now() """Cache function decorator Example: @@ -65,6 +68,7 @@ def cache_function(f): >>> e.slow_function() # Return stored result of e.slow_function """ def wrap(*args, **kwargs): + from site import print_trace_now; print_trace_now() self = args[0] name = "_" + f.__name__ if not hasattr(self, name) or getattr(self, name) is None or kwargs.get("reload", False): @@ -78,6 +82,7 @@ def cache_function(f): if not hasattr(self, "cache_attr_lst"): self.cache_attr_lst = set() def clear_cache(): + from site import print_trace_now; print_trace_now() for attr in self.cache_attr_lst: delattr(self, attr) self.cache_attr_lst = set() @@ -95,11 +100,14 @@ def cache_function(f): class cache_method(): def __init__(self, N): + from site import print_trace_now; print_trace_now() self.N = N def __call__(self, f): + from site import print_trace_now; print_trace_now() def wrapped(caller_obj, *args): + from site import print_trace_now; print_trace_now() name = "_" + f.__name__ arg_id = ";".join([str(a) for a in args]) if not hasattr(caller_obj,'%s_cache_dict'%name): @@ -113,9 +121,12 @@ class cache_method(): return wrapped def cache_npsave(f): + from site import print_trace_now; print_trace_now() def wrap(filename,*args,**kwargs): + from site import print_trace_now; print_trace_now() np_filename = os.path.splitext(filename)[0] + ".npy" def loadsave(): + from site import print_trace_now; print_trace_now() res = f(filename,*args,**kwargs) np.save(np_filename,res) return res @@ -129,9 +140,12 @@ def cache_npsave(f): return wrap def _get_npsavez_wrap(f, compress): + from site import print_trace_now; print_trace_now() def wrap(filename,*args,**kwargs): + from site import print_trace_now; print_trace_now() np_filename = os.path.splitext(filename)[0] + ".npy%s.npz"%("",".c")[compress] def loadsave(): + from site import print_trace_now; print_trace_now() res = f(filename,*args,**kwargs) if compress: np.savez_compressed(np_filename,*res) @@ -149,8 +163,10 @@ def _get_npsavez_wrap(f, compress): return wrap def cache_npsavez(f): + from site import print_trace_now; print_trace_now() return _get_npsavez_wrap(f,False) def cache_npsavez_compressed(f): - return _get_npsavez_wrap(f, True) \ No newline at end of file + from site import print_trace_now; print_trace_now() + return _get_npsavez_wrap(f, True) diff --git a/wetb/utils/cluster_tools/cluster_resource.py b/wetb/utils/cluster_tools/cluster_resource.py index d196a372778a830ab0bb2cfafd282b672d4c8586..fa5b9605f829a0b0c010c523ebb815150e6bedef 100644 --- a/wetb/utils/cluster_tools/cluster_resource.py +++ b/wetb/utils/cluster_tools/cluster_resource.py @@ -13,6 +13,7 @@ from wetb.utils.cluster_tools import pbswrap def unix_path(path, cwd=None, fail_on_missing=False): + from site import print_trace_now; print_trace_now() """Convert case insensitive filename into unix case sensitive filename If no matching file or folder is found an error is raised @@ -42,6 +43,7 @@ def unix_path(path, cwd=None, fail_on_missing=False): return path.replace("\\","/") def unix_path_old(filename): + from site import print_trace_now; print_trace_now() filename = os.path.realpath(filename.replace("\\", "/")).replace("\\", "/") ufn, rest = os.path.splitdrive(filename) ufn += "/" @@ -61,6 +63,7 @@ def unix_path_old(filename): class Resource(object): def __init__(self, min_cpu, min_free): + from site import print_trace_now; print_trace_now() self.min_cpu = min_cpu self.min_free = min_free self.cpu_free=0 @@ -70,6 +73,7 @@ class Resource(object): self.resource_lock = threading.Lock() def ok2submit(self): + from site import print_trace_now; print_trace_now() """Always ok to have min_cpu cpus and ok to have more if there are min_free free cpus""" try: #print ("ok2submit") @@ -88,15 +92,18 @@ class Resource(object): # return False def acquire(self): + from site import print_trace_now; print_trace_now() with self.resource_lock: self.acquired += 1 def release(self): + from site import print_trace_now; print_trace_now() with self.resource_lock: self.acquired -= 1 def update_resource_status(self): + from site import print_trace_now; print_trace_now() try: self.no_cpu, self.cpu_free, self.used_by_user = self.check_resources() except Exception: @@ -109,28 +116,34 @@ class SSHPBSClusterResource(Resource): is_executing = [] def __init__(self, sshclient, min_cpu, min_free): + from site import print_trace_now; print_trace_now() Resource.__init__(self, min_cpu, min_free) self.ssh = sshclient self.resource_lock = threading.Lock() def glob(self, filepattern, cwd="", recursive=False): + from site import print_trace_now; print_trace_now() return self.ssh.glob(filepattern, cwd, recursive) @property def host(self): + from site import print_trace_now; print_trace_now() return self.ssh.host @property def username(self): + from site import print_trace_now; print_trace_now() return self.ssh.username def new_ssh_connection(self): + from site import print_trace_now; print_trace_now() from wetb.utils.cluster_tools.ssh_client import SSHClient return SSHClient(self.host, self.ssh.username, self.ssh.password, self.ssh.port) #return self.ssh def check_resources(self): + from site import print_trace_now; print_trace_now() with self.resource_lock: try: with self.ssh: @@ -155,15 +168,18 @@ class SSHPBSClusterResource(Resource): def jobids(self, jobname_prefix): + from site import print_trace_now; print_trace_now() _, output, _ = self.ssh.execute('qstat -u %s' % self.username) return [l.split()[0].split(".")[0] for l in output.split("\n")[5:] if l.strip() != "" and l.split()[3].startswith("h2l")] def stop_pbsjobs(self, jobids): + from site import print_trace_now; print_trace_now() if not hasattr(jobids, "len"): jobids = list(jobids) self.ssh.execute("qdel %s" % (" ".join(jobids))) def setup_wine(self): + from site import print_trace_now; print_trace_now() self.ssh.execute("""rm -f ./config-wine-hawc2.sh && wget https://gitlab.windenergy.dtu.dk/toolbox/pbsutils/raw/master/config-wine-hawc2.sh && chmod 777 config-wine-hawc2.sh && @@ -173,6 +189,7 @@ chmod 777 config-wine-hawc2.sh && class LocalResource(Resource): def __init__(self, cpu_limit): + from site import print_trace_now; print_trace_now() Resource.__init__(self, cpu_limit, multiprocessing.cpu_count()) #self.process_name = process_name @@ -181,6 +198,7 @@ class LocalResource(Resource): def check_resources(self): + from site import print_trace_now; print_trace_now() import psutil no_cpu = multiprocessing.cpu_count() cpu_free = (1 - psutil.cpu_percent(.1) / 100) * no_cpu diff --git a/wetb/utils/cluster_tools/pbsjob.py b/wetb/utils/cluster_tools/pbsjob.py index 0343b2de5a9a2d2bbf268f9bb86cf587f2f78ba2..09937f9486c27faeed54d131eb0e8d64ecba953a 100644 --- a/wetb/utils/cluster_tools/pbsjob.py +++ b/wetb/utils/cluster_tools/pbsjob.py @@ -18,10 +18,12 @@ class SSHPBSJob(object): def __init__(self, sshClient): + from site import print_trace_now; print_trace_now() self.ssh = sshClient def submit(self, job, cwd, pbs_out_file): + from site import print_trace_now; print_trace_now() self.cwd = cwd self.pbs_out_file = os.path.relpath(cwd + pbs_out_file).replace("\\", "/") self.nodeid = None @@ -37,6 +39,7 @@ class SSHPBSJob(object): @property def status(self): + from site import print_trace_now; print_trace_now() if self._status in [NOT_SUBMITTED, DONE]: return self._status with self.ssh: @@ -48,6 +51,7 @@ class SSHPBSJob(object): return self._status def get_nodeid(self): + from site import print_trace_now; print_trace_now() try: _, out, _ = self.ssh.execute("qstat -f %s | grep exec_host" % self.jobid) return out.strip().replace("exec_host = ", "").split(".")[0] @@ -57,6 +61,7 @@ class SSHPBSJob(object): #raise e def stop(self): + from site import print_trace_now; print_trace_now() if self.jobid: try: self.ssh.execute("qdel %s" % self.jobid) @@ -67,6 +72,7 @@ class SSHPBSJob(object): def is_executing(self): + from site import print_trace_now; print_trace_now() try: self.ssh.execute("qstat %s" % self.jobid) return True diff --git a/wetb/utils/cluster_tools/pbswrap.py b/wetb/utils/cluster_tools/pbswrap.py index e4bff2dafb40e5836cb412283e234f1e8d884597..71b413efba67f6bd8b78267b943a74e35f84964b 100644 --- a/wetb/utils/cluster_tools/pbswrap.py +++ b/wetb/utils/cluster_tools/pbswrap.py @@ -13,6 +13,7 @@ import os import socket def print_dashboard(users, host, pbsnodes): + from site import print_trace_now; print_trace_now() # print nicely # the header @@ -74,6 +75,7 @@ def print_dashboard(users, host, pbsnodes): def print_node_loading(users, host, nodes, nodesload): + from site import print_trace_now; print_trace_now() """ Give an overview of how each node is loaded """ @@ -127,6 +129,7 @@ def print_node_loading(users, host, nodes, nodesload): def parse_pbsnode_lall(output): + from site import print_trace_now; print_trace_now() """Parse output of pbsnodes -l all """ # read the qstat output @@ -177,6 +180,7 @@ def parse_pbsnode_lall(output): def parse_qstat_n1(output, hostname=None): + from site import print_trace_now; print_trace_now() """ Parse the output of qstat -n1 """ @@ -268,6 +272,7 @@ def parse_qstat_n1(output, hostname=None): # FIXME: counts diffferent compared to launch.py.... def count_cpus(users, host, pbsnodes): + from site import print_trace_now; print_trace_now() """ See how many cpu's are actually free """ @@ -324,6 +329,7 @@ exit # TODO: this is very similar compared to what happens in qsub-wrap def create_input(walltime='00:59:59', queue='xpresq', pbs_in='pbs_in/', ppn=1, pbs_out='pbs_out/', jobname=None, commands=None, lnodes=1): + from site import print_trace_now; print_trace_now() """ Create a PBS script for a command. Optionally, define a python environment. """ diff --git a/wetb/utils/cluster_tools/ssh_client.py b/wetb/utils/cluster_tools/ssh_client.py index 12277503eaff393b645c413e2e7a72ef5592285c..7018380cad09af580edff2571d42e84bd987cf63 100644 --- a/wetb/utils/cluster_tools/ssh_client.py +++ b/wetb/utils/cluster_tools/ssh_client.py @@ -47,10 +47,12 @@ class SSHInteractiveAuthTunnelForwarder(SSHTunnelForwarder): allow_agent=True, * args, ** kwargs): + from site import print_trace_now; print_trace_now() self.interactive_auth_handler = interactive_auth_handler SSHTunnelForwarder.__init__(self, ssh_address_or_host=ssh_address_or_host, ssh_config_file=ssh_config_file, ssh_host_key=ssh_host_key, ssh_password=ssh_password, ssh_pkey=ssh_pkey, ssh_private_key_password=ssh_private_key_password, ssh_proxy=ssh_proxy, ssh_proxy_enabled=ssh_proxy_enabled, ssh_username=ssh_username, local_bind_address=local_bind_address, local_bind_addresses=local_bind_addresses, logger=logger, mute_exceptions=mute_exceptions, remote_bind_address=remote_bind_address, remote_bind_addresses=remote_bind_addresses, set_keepalive=set_keepalive, threaded=threaded, compression=compression, allow_agent=allow_agent, *args, **kwargs) def _connect_to_gateway(self): + from site import print_trace_now; print_trace_now() """ Open connection to SSH gateway - First try with all keys loaded from an SSH agent (if allowed) @@ -70,6 +72,7 @@ class SSHInteractiveAuthTunnelForwarder(SSHTunnelForwarder): self.logger.error('Could not open connection to gateway') def _connect_to_gateway_old(self): + from site import print_trace_now; print_trace_now() """ Open connection to SSH gateway - First try with all keys loaded from an SSH agent (if allowed) @@ -103,6 +106,7 @@ class SSHClient(object): TIMEOUT = 4 def __init__(self, host, username, password=None, port=22, key=None, passphrase=None, interactive_auth_handler=None, gateway=None, ui=UI()): + from site import print_trace_now; print_trace_now() self.host = host self.username = username self.password = password @@ -122,9 +126,11 @@ class SSHClient(object): self.key = paramiko.RSAKey.from_private_key(StringIO(key), password=passphrase) def info(self): + from site import print_trace_now; print_trace_now() return self.host, self.username, self.password, self.port def __enter__(self): + from site import print_trace_now; print_trace_now() with self.ssh_lock: self.disconnect += 1 if self.client is None or self.client._transport is None or self.client._transport.is_active() is False: @@ -139,6 +145,7 @@ class SSHClient(object): return self.client def connect(self): + from site import print_trace_now; print_trace_now() if self.gateway: if self.gateway.interactive_auth_handler: self.tunnel = SSHInteractiveAuthTunnelForwarder(self.gateway.interactive_auth_handler, @@ -185,10 +192,12 @@ class SSHClient(object): def __del__(self): + from site import print_trace_now; print_trace_now() self.close() @property def sftp(self): + from site import print_trace_now; print_trace_now() return paramiko.SFTPClient.from_transport(self.client._transport) # @sftp.setter @@ -196,12 +205,14 @@ class SSHClient(object): # pass def __exit__(self, *args): + from site import print_trace_now; print_trace_now() self.disconnect -= 1 if self.disconnect == 0: self.close() def download(self, remotefilepath, localfile, verbose=False, retry=1, callback=None): + from site import print_trace_now; print_trace_now() if verbose: ret = None print ("Download %s > %s" % (remotefilepath, str(localfile))) @@ -229,6 +240,7 @@ class SSHClient(object): print (ret) def upload(self, localfile, filepath, verbose=False, callback=None): + from site import print_trace_now; print_trace_now() if verbose: print ("Upload %s > %s" % (localfile, filepath)) if callback is None: @@ -251,6 +263,7 @@ class SSHClient(object): def upload_files(self, localpath, remotepath, file_lst=["."], compression_level=1, callback=None): + from site import print_trace_now; print_trace_now() assert os.path.isdir(localpath) if not isinstance(file_lst, (tuple, list)): file_lst = [file_lst] @@ -282,6 +295,7 @@ class SSHClient(object): def download_files(self, remote_path, localpath, file_lst=["."], compression_level=1, callback=None): + from site import print_trace_now; print_trace_now() if not isinstance(file_lst, (tuple, list)): file_lst = [file_lst] file_lst = [f.replace("\\","/") for f in file_lst] @@ -303,6 +317,7 @@ class SSHClient(object): def close(self): + from site import print_trace_now; print_trace_now() for x in ["client", 'tunnel' ]: try: getattr(self, x).close() @@ -312,10 +327,12 @@ class SSHClient(object): self.disconnect = False def file_exists(self, filename): + from site import print_trace_now; print_trace_now() _, out, _ = (self.execute('[ -f %s ] && echo "File exists" || echo "File does not exists"' % filename.replace("\\", "/"))) return out.strip() == "File exists" def execute(self, command, sudo=False, verbose=False): + from site import print_trace_now; print_trace_now() feed_password = False if sudo and self.username != "root": command = "sudo -S -p '' %s" % command @@ -348,6 +365,7 @@ class SSHClient(object): return v, out, err def append_wine_path(self, path): + from site import print_trace_now; print_trace_now() ret = self.execute('wine regedit /E tmp.reg "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment"') self.download('tmp.reg', 'tmp.reg') with open('tmp.reg') as fid: @@ -366,6 +384,7 @@ class SSHClient(object): ret = self.execute('wine regedit tmp.reg') def glob(self, filepattern, cwd="", recursive=False): + from site import print_trace_now; print_trace_now() if isinstance(filepattern, list): with self: return [f for fp in filepattern for f in self.glob(fp, cwd, recursive)] @@ -382,6 +401,7 @@ class SSHClient(object): class SharedSSHClient(SSHClient): def __init__(self, host, username, password=None, port=22, key=None, passphrase=None, interactive_auth_handler=None, gateway=None): + from site import print_trace_now; print_trace_now() SSHClient.__init__(self, host, username, password=password, port=port, key=key, passphrase=passphrase, interactive_auth_handler=interactive_auth_handler, gateway=gateway) self.shared_ssh_queue = deque() @@ -392,6 +412,7 @@ class SharedSSHClient(SSHClient): def execute(self, command, sudo=False, verbose=False): + from site import print_trace_now; print_trace_now() res = SSHClient.execute(self, command, sudo=sudo, verbose=verbose) return res @@ -399,6 +420,7 @@ class SharedSSHClient(SSHClient): def __enter__(self): + from site import print_trace_now; print_trace_now() with self.ssh_lock: SSHClient.__enter__(self) #print ("request SSH", threading.currentThread()) @@ -420,6 +442,7 @@ class SharedSSHClient(SSHClient): return self.client def __exit__(self, *args): + from site import print_trace_now; print_trace_now() with self.ssh_lock: if len(self.shared_ssh_queue)>0 and self.shared_ssh_queue[0] == threading.get_ident(): self.shared_ssh_queue.popleft() diff --git a/wetb/utils/envelope.py b/wetb/utils/envelope.py index 4a3c1b3860fa775fa03c48858794221e46a897c5..7c2c99d86d765b37d77c68af11ac3d4acf37f5b1 100644 --- a/wetb/utils/envelope.py +++ b/wetb/utils/envelope.py @@ -25,6 +25,7 @@ import scipy def compute_env_of_env(envelope, dlc_list, Nx=300, Nsectors=12, Ntheta=181): + from site import print_trace_now; print_trace_now() """ The function computes load envelopes for given channels and a groups of load cases starting from the envelopes computed for single simulations. @@ -100,6 +101,7 @@ def compute_env_of_env(envelope, dlc_list, Nx=300, Nsectors=12, Ntheta=181): def int_envelope(ch1, ch2, Nx): + from site import print_trace_now; print_trace_now() """ Function to interpolate envelopes and output arrays of same length @@ -138,6 +140,7 @@ def int_envelope(ch1, ch2, Nx): def proj_envelope(env_x, env_up, env_low, env, Nx, Nsectors, Ntheta): + from site import print_trace_now; print_trace_now() """ Function to project envelope on given angles @@ -209,6 +212,7 @@ def proj_envelope(env_x, env_up, env_low, env, Nx, Nsectors, Ntheta): def closed_contour(cloud): + from site import print_trace_now; print_trace_now() """Return indices of the vertices of the closed convex contour that contain all points of the (x,y) cloud of pairs. @@ -250,6 +254,7 @@ def closed_contour(cloud): def compute_envelope(cloud, int_env=False, Nx=300): + from site import print_trace_now; print_trace_now() """ The function computes load envelopes for given signals and a single load case. Starting from Mx and My moments, the other cross-sectional diff --git a/wetb/utils/euler.py b/wetb/utils/euler.py index 6c2f9247f71c4b2fa694241820002e01023ddd7e..d2db4ee8fce4599a1658ecc0fe49c48465d240d4 100644 --- a/wetb/utils/euler.py +++ b/wetb/utils/euler.py @@ -9,6 +9,7 @@ from wetb.utils.geometry import deg def Ax(angle): + from site import print_trace_now; print_trace_now() cos = np.cos(angle) sin = np.sin(angle) return np.array([[1, 0, 0], @@ -16,6 +17,7 @@ def Ax(angle): [0, sin, cos]]) def Ay(angle): + from site import print_trace_now; print_trace_now() cos = np.cos(angle) sin = np.sin(angle) return np.array([[cos, 0, sin], @@ -23,6 +25,7 @@ def Ay(angle): [-sin, 0, cos ]]) def Az(angle): + from site import print_trace_now; print_trace_now() cos = np.cos(angle) sin = np.sin(angle) return np.array([[cos, -sin, 0], @@ -33,6 +36,7 @@ def Az(angle): def euler2A(euler_param): + from site import print_trace_now; print_trace_now() assert len(euler_param) == 4 e = euler_param return np.array([[e[0] ** 2 + e[1] ** 2 - e[2] ** 2 - e[3] ** 2, 2 * (e[1] * e[2] + e[0] * e[3]) , 2 * (e[1] * e[3] - e[0] * e[2]) ], @@ -40,6 +44,7 @@ def euler2A(euler_param): [2 * (e[1] * e[3] + e[0] * e[2]), 2 * (e[2] * e[3] - e[0] * e[1]), e[0] ** 2 - e[1] ** 2 - e[2] ** 2 + e[3] ** 2]]).T def A2euler(A): + from site import print_trace_now; print_trace_now() # method from http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm sqrt = np.sqrt (m00, m01, m02), (m10, m11, m12), (m20, m21, m22) = A @@ -104,6 +109,7 @@ def A2euler(A): # return xyz2euler(*A2xyz(A)) def euler2angle(euler): + from site import print_trace_now; print_trace_now() if euler[0] > 1: euler[0] = 1 if euler[0] < -1: @@ -112,4 +118,5 @@ def euler2angle(euler): return np.arccos(euler[0]) * 2 def euler2gl(euler): + from site import print_trace_now; print_trace_now() return np.r_[deg(euler2angle(euler)), euler[1:]] diff --git a/wetb/utils/ftp_file.py b/wetb/utils/ftp_file.py index b69b72fa9ecf1e7c65a3b4855fa531dfc8de3caa..8e89598337d5a92606b8fc8cdd675e3b171fb3e7 100644 --- a/wetb/utils/ftp_file.py +++ b/wetb/utils/ftp_file.py @@ -13,6 +13,7 @@ import getpass class FtpFile(): def __init__(self, url, username, password): + from site import print_trace_now; print_trace_now() if url.lower().startswith('ftp://'): url = url[6:] self.url = url @@ -25,6 +26,7 @@ class FtpFile(): self.password = password def load(self, open_file=None): + from site import print_trace_now; print_trace_now() ftp = FTP(self.domain) try: ftp.login(self.username, self.password) @@ -36,27 +38,33 @@ class FtpFile(): open_file.seek(0) def write(self, obj): + from site import print_trace_now; print_trace_now() raise NotImplementedError def __str__(self): + from site import print_trace_now; print_trace_now() return "%s(url='%s', username='%s', password=None)" % (self.__class__.__name__, self.url, self.username) def name(self): + from site import print_trace_now; print_trace_now() return self.path.split('/')[-1] def filename(self): + from site import print_trace_now; print_trace_now() return self.path class FtpTxtFile(io.StringIO, FtpFile): def __init__(self, url, username, password): + from site import print_trace_now; print_trace_now() FtpFile.__init__(self, url, username, password) io.StringIO.__init__(self) self.load() def write(self, s): + from site import print_trace_now; print_trace_now() if isinstance(s, bytes): s = s.decode('cp1251') io.StringIO.write(self, s) @@ -66,18 +74,21 @@ class FtpTxtFile(io.StringIO, FtpFile): class FtpZipFile(ZipFile, FtpFile): def __init__(self, url, username, password): + from site import print_trace_now; print_trace_now() FtpFile.__init__(self, url, username, password) byteIO = io.BytesIO() self.load(byteIO) ZipFile.__init__(self, byteIO) def FtpZipTxtFile(self, txt_filename): + from site import print_trace_now; print_trace_now() return FtpZipTxtFile(self.url, self.username, self.password, txt_filename) class FtpZipTxtFile(io.StringIO, FtpZipFile): def __init__(self, url, username, password, filename): + from site import print_trace_now; print_trace_now() FtpZipFile.__init__(self, url, username, password) io.StringIO.__init__(self, buf='') fid = self.open(filename) @@ -88,14 +99,17 @@ class FtpZipTxtFile(io.StringIO, FtpZipFile): self.filename = filename def __str__(self): + from site import print_trace_now; print_trace_now() return "%s(url='%s', username='%s', password=None, filename='%s')" % (self.__class__.__name__, self.url, self.username, self.filename) class FtpBinaryFile(io.BytesIO, FtpFile): def __init__(self, url, username, password): + from site import print_trace_now; print_trace_now() FtpFile.__init__(self, url, username, password) self.load() def __str__(self): + from site import print_trace_now; print_trace_now() return FtpFile.__str__(self) diff --git a/wetb/utils/geometry.py b/wetb/utils/geometry.py index a50b18be446662703d07c26ffb40393e86cd9fad..4ce69f4888edb3ba249d41e381a3a240b1c62250 100644 --- a/wetb/utils/geometry.py +++ b/wetb/utils/geometry.py @@ -8,21 +8,27 @@ standard_library.install_aliases() import numpy as np def rad(deg): + from site import print_trace_now; print_trace_now() return deg * np.pi / 180 def deg(rad): + from site import print_trace_now; print_trace_now() return rad / np.pi * 180 def sind(dir_deg): + from site import print_trace_now; print_trace_now() return np.sin(rad(dir_deg)) def cosd(dir_deg): + from site import print_trace_now; print_trace_now() return np.cos(rad(dir_deg)) def tand(dir_deg): + from site import print_trace_now; print_trace_now() return np.tan(rad(dir_deg)) def mean_deg(dir, axis=0): + from site import print_trace_now; print_trace_now() """Mean of angles in degrees Parameters @@ -40,6 +46,7 @@ def mean_deg(dir, axis=0): return deg(mean_rad(rad(dir), axis)) def mean_rad(dir, axis=0): + from site import print_trace_now; print_trace_now() """Mean of angles in radians Parameters @@ -58,6 +65,7 @@ def mean_rad(dir, axis=0): def std_deg(dir): + from site import print_trace_now; print_trace_now() """Standard deviation of angles in degrees Parameters @@ -73,6 +81,7 @@ def std_deg(dir): return deg(std_rad(rad(dir))) def std_rad(dir): + from site import print_trace_now; print_trace_now() """Standard deviation of angles in radians Parameters @@ -88,8 +97,10 @@ def std_rad(dir): return np.sqrt(1 - (np.nanmean(np.sin(dir)) ** 2 + np.nanmean(np.cos(dir)) ** 2)) def rpm2rads(rpm): + from site import print_trace_now; print_trace_now() return rpm * 2 * np.pi / 60 def rads2rpm(rads): - return rads/ (2 * np.pi) * 60 \ No newline at end of file + from site import print_trace_now; print_trace_now() + return rads/ (2 * np.pi) * 60 diff --git a/wetb/utils/process_exec.py b/wetb/utils/process_exec.py index 589024b8b5880acd2997dce5f061e7047c44c103..6b0c82ce129994eec3cf2d2c4cfe97bd62ccdb77 100644 --- a/wetb/utils/process_exec.py +++ b/wetb/utils/process_exec.py @@ -19,6 +19,7 @@ import os DEBUG = False def pexec(args, cwd=None): + from site import print_trace_now; print_trace_now() """ usage: errorcode, stdout, stderr, cmd = pexec("MyProgram.exe arg1, arg2", r"c:\tmp\") @@ -42,6 +43,7 @@ def pexec(args, cwd=None): def process(args, cwd=None): + from site import print_trace_now; print_trace_now() import subprocess if not isinstance(args, (list, tuple)): args = [args] @@ -56,6 +58,7 @@ def process(args, cwd=None): return subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False, cwd=cwd) def exec_process(process): + from site import print_trace_now; print_trace_now() stdout, stderr = process.communicate() errorcode = process.returncode diff --git a/wetb/utils/rotation.py b/wetb/utils/rotation.py index 22546305755de47d7004469179fc6dfbcfbb2e29..4a57a22c09213b4564eec116a724cd174e233739 100644 --- a/wetb/utils/rotation.py +++ b/wetb/utils/rotation.py @@ -7,6 +7,7 @@ import numpy as np def transformation_matrix(angles, xyz): + from site import print_trace_now; print_trace_now() """Create Transformation matrix(es) !!!Note that the columns of the returned matrix(es) is original(unrotate) xyz-axes in rotated coordinates\n !!!Multiplying a this matrix by a vector rotates the vector -angle radians (in right handed terminology). @@ -42,6 +43,7 @@ def transformation_matrix(angles, xyz): return m.reshape(n, 3, 3) def rotmat(angles, xyz): + from site import print_trace_now; print_trace_now() """Create rotation matrix(es) !!!Note that the columns of the returned matrix(es) is rotated xyz-axes in original(unrotated) coordinates\n Multiplying a this matrix by a vector rotates the vector +angle radians (in right handed terminology). @@ -77,6 +79,7 @@ def rotmat(angles, xyz): return m.reshape(n, 3, 3) def mdot(m1, m2): + from site import print_trace_now; print_trace_now() """Multiplication of matrix pairs Parameters @@ -113,6 +116,7 @@ def mdot(m1, m2): def dots(rotmats, v): + from site import print_trace_now; print_trace_now() """Rotate vector(s) v by rotation matrix(es) Parameters @@ -151,6 +155,7 @@ def dots(rotmats, v): def rotate(rotmats, v): + from site import print_trace_now; print_trace_now() global x, y, z v = np.array(v) if isinstance(rotmats, (list, tuple)): @@ -178,6 +183,7 @@ def rotate(rotmats, v): return v_rot.T def rotate_x(v, angle): + from site import print_trace_now; print_trace_now() """Rotate vector(s) around x axis Parameters @@ -195,6 +201,7 @@ def rotate_x(v, angle): return _rotate(v, angle, lambda x, y, z, cos, sin : [x, cos * y - sin * z, sin * y + cos * z]) def rotate_y(v, angle): + from site import print_trace_now; print_trace_now() """Rotate vector(s) around y axis Parameters @@ -212,6 +219,7 @@ def rotate_y(v, angle): return _rotate(v, angle, lambda x, y, z, cos, sin : [cos * x + sin * z, y, -sin * x + cos * z]) def rotate_z(v, angle): + from site import print_trace_now; print_trace_now() """Rotate vector(s) around z axis Parameters @@ -229,6 +237,7 @@ def rotate_z(v, angle): return _rotate(v, angle, lambda x, y, z, cos, sin : [cos * x - sin * y, sin * x + cos * y, z]) def _rotate(v, angle, rotfunc): + from site import print_trace_now; print_trace_now() angle = np.atleast_1d(angle) cos, sin = np.cos(angle), np.sin(angle) v = np.array(v) diff --git a/wetb/utils/timing.py b/wetb/utils/timing.py index 7e148cb8df5a70c4bf84784cae02548a726e749c..f383e430318dddec4ad388d3068131ac87d040a8 100644 --- a/wetb/utils/timing.py +++ b/wetb/utils/timing.py @@ -10,6 +10,7 @@ from six import exec_ import time import inspect def get_time(f): + from site import print_trace_now; print_trace_now() """Get time decorator returns (return_values, time_of_execution) @@ -22,6 +23,7 @@ def get_time(f): ('end', 0.999833492421551) """ def wrap(*args, **kwargs): + from site import print_trace_now; print_trace_now() t = time.time() res = f(*args, **kwargs) return res, time.time() - t @@ -31,6 +33,7 @@ def get_time(f): def print_time(f): + from site import print_trace_now; print_trace_now() """Print time decorator prints name of method and time of execution @@ -42,6 +45,7 @@ def print_time(f): test 1.000s """ def wrap(*args, **kwargs): + from site import print_trace_now; print_trace_now() t = time.time() res = f(*args, **kwargs) print ("%-12s\t%.3fs" % (f.__name__, time.time() - t)) @@ -53,6 +57,7 @@ def print_time(f): cum_time = {} def print_cum_time(f): + from site import print_trace_now; print_trace_now() """Print cumulated time decorator prints name of method and cumulated time of execution @@ -69,6 +74,7 @@ def print_cum_time(f): cum_time[f] = (0, 0) def wrap(*args, **kwargs): + from site import print_trace_now; print_trace_now() t = time.time() res = f(*args, **kwargs) ct = cum_time[f][1] + time.time() - t @@ -81,6 +87,7 @@ def print_cum_time(f): return w def print_line_time(f): + from site import print_trace_now; print_trace_now() """Execute one line at the time and prints the time of execution. Only for non-branching and non-looping code @@ -98,6 +105,7 @@ def print_line_time(f): """ def wrap(*args, **kwargs): + from site import print_trace_now; print_trace_now() arg_names, varargs, varkw, defaults = inspect.getargspec(f) kwargs[varargs] = args[len(arg_names):] kwargs[varkw] = {} diff --git a/wetb/utils/ui.py b/wetb/utils/ui.py index 57ca4dcff5ab02a95ae01b1e17d60f174ed2b27a..2e32a87702483a6232c6bc9e49d7d7bea9e18412 100644 --- a/wetb/utils/ui.py +++ b/wetb/utils/ui.py @@ -2,9 +2,11 @@ class OutputUI(object): def __init__(self, parent=None): + from site import print_trace_now; print_trace_now() self.parent = parent def run(self, f, *args, **kwargs): + from site import print_trace_now; print_trace_now() try: return f(*args, **kwargs) except Warning as e: @@ -14,53 +16,69 @@ class OutputUI(object): raise def show_error(self, msg, title="Error"): + from site import print_trace_now; print_trace_now() pass def show_message(self, msg, title="Information"): + from site import print_trace_now; print_trace_now() pass def show_warning(self, msg, title="Warning"): + from site import print_trace_now; print_trace_now() pass def show_text(self, text, end="\n", flush=False): + from site import print_trace_now; print_trace_now() pass class InputUI(object): def get_confirmation(self, title, msg): + from site import print_trace_now; print_trace_now() raise NotImplementedError def get_string(self, title, msg): + from site import print_trace_now; print_trace_now() raise NotImplementedError def get_open_filename(self, title="Open", filetype_filter="*.*", file_dir=None, selected_filter=None): + from site import print_trace_now; print_trace_now() raise NotImplementedError def get_save_filename(self, title, filetype_filter, file_dir=None, selected_filter=None): + from site import print_trace_now; print_trace_now() raise NotImplementedError def get_open_filenames(self, title, filetype_filter, file_dir=None): + from site import print_trace_now; print_trace_now() raise NotImplementedError def get_foldername(self, title='Select directory', file_dir=None): + from site import print_trace_now; print_trace_now() raise NotImplementedError class StatusUI(object): is_waiting = False def progress_iterator(self, sequence, text="Working... Please wait", allow_cancel=True): + from site import print_trace_now; print_trace_now() return sequence def exec_long_task(self, text, allow_cancel, task, *args, **kwargs): + from site import print_trace_now; print_trace_now() return task(*args, **kwargs) def progress_callback(self): + from site import print_trace_now; print_trace_now() def callback(n,N): + from site import print_trace_now; print_trace_now() pass return callback def start_wait(self): + from site import print_trace_now; print_trace_now() self.is_waiting = True def end_wait(self): + from site import print_trace_now; print_trace_now() self.is_waiting = False class UI(InputUI, OutputUI, StatusUI): diff --git a/wetb/wind/air_density.py b/wetb/wind/air_density.py index 13780781d4234b7047ce2da6ca5d4e1308f0f392..7498cb4ccf40033dc5b3b15c8cd916fc17ec1a4c 100644 --- a/wetb/wind/air_density.py +++ b/wetb/wind/air_density.py @@ -10,6 +10,7 @@ import numpy as np def saturated_vapor_pressure(T): + from site import print_trace_now; print_trace_now() """Calculate pressure of saturated water vapor at specified temperature as described at http://wahiduddin.net/calc/density_altitude.htm Parameters @@ -38,6 +39,7 @@ def saturated_vapor_pressure(T): return eso / p ** 8 def saturated_vapor_pressure2(t): + from site import print_trace_now; print_trace_now() """Calculate pressure of saturated water vapor at specified temperature as described at http://wahiduddin.net/calc/density_altitude.htm Parameters @@ -56,6 +58,7 @@ def saturated_vapor_pressure2(t): return c0 * 10 ** ((c1 * t) / (c2 + t)) def saturated_vapor_pressure3(t): + from site import print_trace_now; print_trace_now() """Calculate pressure of saturated water vapor at specified temperature according to The IAPWS Formulation 1995 for the Thermodynamic Properties of Ordinary Water Substance for General and Scientific Use @@ -86,6 +89,7 @@ def saturated_vapor_pressure3(t): return Pc * np.exp(Tc / T * (C1 * v + C2 * v ** 1.5 + C3 * v ** 3 + C4 * v ** 3.5 + C5 * v ** 4 + C6 * v ** 7.5)) def saturated_vapor_pressure4(t): + from site import print_trace_now; print_trace_now() """Calculate the saturated vapor pressure as described in http://www.vaisala.com/Vaisala%20Documents/Application%20notes/Humidity_Conversion_Formulas_B210973EN-F.pdf @@ -105,6 +109,7 @@ def saturated_vapor_pressure4(t): return A * 10 ** ((m * t) / (t + Tn)) def saturated_vapor_pressure_IEC(t): + from site import print_trace_now; print_trace_now() """Calculate the saturated vapor pressure according to IEC 61400-12-1 Parameters @@ -123,6 +128,7 @@ def saturated_vapor_pressure_IEC(t): def drew_point(t, RH): + from site import print_trace_now; print_trace_now() A = 6.116441 m = 7.591386 Tn = 240.7263 @@ -130,6 +136,7 @@ def drew_point(t, RH): return Tn / (m / np.log10(Pw / A) - 1) def air_density(P, t, rh=0, saturated_vapor_pressure_function=saturated_vapor_pressure): + from site import print_trace_now; print_trace_now() """Calculate the density of atmospheric air at specified pressure, temperature and humidity source: http://wahiduddin.net/calc/density_altitude.htm Equivalent to formulation in IEC61400-12-1 if used with the saturated_vapor_pressure_IEC function @@ -160,6 +167,7 @@ def air_density(P, t, rh=0, saturated_vapor_pressure_function=saturated_vapor_pr return (Pd * 100 / (Rd * Tk)) + (Pv * 100 / (Rv * Tk)) def R(rh=0, t=15, P=1014): + from site import print_trace_now; print_trace_now() """Specific gas constant ~287.058 J/(kg K) for dry air Parameters diff --git a/wetb/wind/masks.py b/wetb/wind/masks.py index a0c8beca8aa33591dbd7f6725b3f50416f08b6c1..962a97d8f803c26008b9f43fa0618b3f216f01dc 100644 --- a/wetb/wind/masks.py +++ b/wetb/wind/masks.py @@ -6,8 +6,10 @@ Created on 06/11/2015 def wsp_mask(x, wsp, pm_tolerance): + from site import print_trace_now; print_trace_now() return (wsp - pm_tolerance <= x) & (x < wsp + pm_tolerance) def wdir_mask(x, wdir, pm_tolerance): + from site import print_trace_now; print_trace_now() return ((x - wdir + pm_tolerance) % 360 >= 0) & ((x - wdir + pm_tolerance) % 360 < 2 * pm_tolerance) diff --git a/wetb/wind/shear.py b/wetb/wind/shear.py index de1acbb53e262566817ee9ae48171fb5fac9d658..e1749f453db7738586534b83c1c1af50b8a7de6e 100644 --- a/wetb/wind/shear.py +++ b/wetb/wind/shear.py @@ -15,11 +15,13 @@ import numpy as np def _z_u(z_u_lst): + from site import print_trace_now; print_trace_now() z = np.array([z for z, _ in z_u_lst]) u = np.array([np.mean(np.array([u])[:]) for _, u in z_u_lst]) return z, u def power_shear(alpha, z_ref, u_ref): + from site import print_trace_now; print_trace_now() """Power shear Parameters @@ -45,6 +47,7 @@ def power_shear(alpha, z_ref, u_ref): def fit_power_shear(z_u_lst): + from site import print_trace_now; print_trace_now() """Estimate power shear parameter, alpha, from the mean wind at hub height and one additional height Parameters @@ -71,6 +74,7 @@ def fit_power_shear(z_u_lst): return alpha def fit_power_shear_ref(z_u_lst, z_ref, plt=None): + from site import print_trace_now; print_trace_now() """Estimate power shear parameter, alpha, from two or more specific reference heights using polynomial fit. Parameters @@ -98,6 +102,7 @@ def fit_power_shear_ref(z_u_lst, z_ref, plt=None): [ 0.49938238 8.99192568] """ def shear_error(x, z_u_lst, z_ref): + from site import print_trace_now; print_trace_now() alpha, u_ref = x return np.nansum([(u - u_ref * (z / z_ref) ** alpha) ** 2 for z, u in z_u_lst]) z_u_lst = [(z, np.mean(u)) for z, u in z_u_lst] @@ -115,6 +120,7 @@ def fit_power_shear_ref(z_u_lst, z_ref, plt=None): def log_shear(u_star, z0): + from site import print_trace_now; print_trace_now() """logarithmic shear Parameters @@ -140,6 +146,7 @@ def log_shear(u_star, z0): """ K = 0.4 # von Karmans constant def log_shear(z,Obukhov_length=None): + from site import print_trace_now; print_trace_now() if Obukhov_length is None: return u_star / K * (np.log(np.array(z) / z0)) else: @@ -147,6 +154,7 @@ def log_shear(u_star, z0): return log_shear def stability_term(z, z0, L): + from site import print_trace_now; print_trace_now() """Calculate the stability term for the log shear Not validated!!! @@ -164,6 +172,7 @@ def stability_term(z, z0, L): def fit_log_shear(z_u_lst, include_R=False): + from site import print_trace_now; print_trace_now() """Estimate log shear parameter, u_star and z0 Parameters diff --git a/wetb/wind/stability.py b/wetb/wind/stability.py index b60a8d30a5216ffd47355489180cdc5ab085d512..c7e7af04fe8c3f75ab8bd4bd323a10faa7b0dfc8 100644 --- a/wetb/wind/stability.py +++ b/wetb/wind/stability.py @@ -10,6 +10,7 @@ from scipy.signal.signaltools import detrend def MoninObukhov_length(u,v,w, T): + from site import print_trace_now; print_trace_now() """Calculate the Monin Obukhov length Not validated!!! @@ -37,6 +38,7 @@ def MoninObukhov_length(u,v,w, T): def L2category(L, full_category_name=False): + from site import print_trace_now; print_trace_now() """Stability category from Monin-Obukhov length Categories: @@ -75,6 +77,7 @@ def L2category(L, full_category_name=False): return np.array(['eu', 'vu','u','nu','n','ns','s','vs','es','-'])[index] def MoninObukhov_length2(u_star, w, T, specific_humidity=None): + from site import print_trace_now; print_trace_now() """Calculate the Monin Obukhov length Not validated!!! @@ -98,6 +101,7 @@ def MoninObukhov_length2(u_star, w, T, specific_humidity=None): def humidity_relative2specific(relative_humidity, T, P): + from site import print_trace_now; print_trace_now() """Not validated parameters ---------- @@ -111,6 +115,7 @@ def humidity_relative2specific(relative_humidity, T, P): return relative_humidity * np.exp(17.67 * T / (T + 273.15 - 29.65)) / 0.263 / P def humidity_specific2relative2(specific_humidity, T, P): + from site import print_trace_now; print_trace_now() """Not validated parameters ---------- diff --git a/wetb/wind/turbulence/constraint_file.py b/wetb/wind/turbulence/constraint_file.py index 0d2002437c69aadb625f35542aa581ea7d375620..965c18d5c97abace41146e7c9443cbbe864a37ca 100644 --- a/wetb/wind/turbulence/constraint_file.py +++ b/wetb/wind/turbulence/constraint_file.py @@ -4,6 +4,7 @@ from wetb.hawc2.htc_file import HTCFile class ConstraintFile(object): def __init__(self, center_gl_xyz, box_transport_speed, no_grid_points=(4096, 32, 32), box_size=(6000, 100, 100)): + from site import print_trace_now; print_trace_now() """Generate list of constraints for turbulence constraint simulator Parameters @@ -26,6 +27,7 @@ class ConstraintFile(object): self.constraints = {'u':[], 'v':[], 'w':[]} def load(self, filename): + from site import print_trace_now; print_trace_now() """Load constraint from existing constraint file (usable for plotting constraints via time_series()""" with open(filename) as fid: lines = fid.readlines() @@ -37,6 +39,7 @@ class ConstraintFile(object): def add_constraints(self, glpos, tuvw, subtract_mean=True, fail_outside_box=True, nearest=True): + from site import print_trace_now; print_trace_now() """Add constraints to constraint file parameters @@ -108,10 +111,12 @@ class ConstraintFile(object): def __str__(self): + from site import print_trace_now; print_trace_now() return "\n".join(["%d;%d;%d;%s;%.10f" % (mx, my, mz, comp, value) for comp in ['u', 'v', 'w'] for mx, my, mz, value in self.constraints[comp]]) def save(self, path, name, folder="./constraints/"): + from site import print_trace_now; print_trace_now() path = os.path.join(path, folder) if not os.path.isdir(path): os.makedirs(path, exist_ok=True) @@ -119,6 +124,7 @@ class ConstraintFile(object): fid.write(str(self)) def time_series(self, y_position=0): + from site import print_trace_now; print_trace_now() time = (np.arange(self.no_grid_points[0])*float(self.dxyz[0]) + y_position)/ self.box_transport_speed u,v,w = [(np.zeros_like(time)+ np.nan)]*3 for uvw, constr in zip([u,v,w], [np.array(self.constraints[uvw]) for uvw in 'uvw']): @@ -128,6 +134,7 @@ class ConstraintFile(object): def simulation_cmd(self, ae23, L, Gamma, seed, name, folder="./constraints/"): + from site import print_trace_now; print_trace_now() assert isinstance(seed, int) and seed > 0, "seed must be a positive integer" cmd = "./csimu2.exe %d %d %d %.3f %.3f %.3f " % (self.no_grid_points + self.box_size) cmd += "%.6f %.2f %.2f %d " % (ae23, L, Gamma, seed) @@ -135,6 +142,7 @@ class ConstraintFile(object): return cmd def hawc2_mann_section(self, name, seed): + from site import print_trace_now; print_trace_now() htc = HTCFile() mann = htc.wind.add_section("mann") for uvw in 'uvw': diff --git a/wetb/wind/turbulence/mann_parameters.py b/wetb/wind/turbulence/mann_parameters.py index 9799b49f9e7c3eff06ec9208ff52e1d0f0c587d8..38e78cb81e780608ca317be409dada0c9493cd6c 100644 --- a/wetb/wind/turbulence/mann_parameters.py +++ b/wetb/wind/turbulence/mann_parameters.py @@ -46,6 +46,7 @@ RBS4 = RectBivariateSpline(xp, yp, sp4) def get_mann_model_spectra(ae, L, G, k1): + from site import print_trace_now; print_trace_now() """Mann model spectra Parameters @@ -83,6 +84,7 @@ def get_mann_model_spectra(ae, L, G, k1): def _local_error(x, k1, uu, vv, ww=None, uw=None): + from site import print_trace_now; print_trace_now() ae, L, G = x val = 10 ** 99 @@ -96,6 +98,7 @@ def _local_error(x, k1, uu, vv, ww=None, uw=None): return val def fit_mann_model_spectra(k1, uu, vv=None, ww=None, uw=None, log10_bin_size=.2, min_bin_count=2, start_vals_for_optimisation=(0.01, 50, 3.3), plt=False): + from site import print_trace_now; print_trace_now() """Fit a mann model to the spectra Bins the spectra, into logarithmic sized bins and find the mann model parameters, @@ -156,6 +159,7 @@ def fit_mann_model_spectra(k1, uu, vv=None, ww=None, uw=None, log10_bin_size=.2, return x def residual(ae, L, G, k1, uu, vv=None, ww=None, uw=None, log10_bin_size=.2): + from site import print_trace_now; print_trace_now() """Fit a mann model to the spectra Bins the spectra, into logarithmic sized bins and find the mann model parameters, @@ -199,6 +203,7 @@ def residual(ae, L, G, k1, uu, vv=None, ww=None, uw=None, log10_bin_size=.2): def var2ae(variance, spatial_resolution, N, L, G): + from site import print_trace_now; print_trace_now() """Fit alpha-epsilon to match variance of time series Parameters @@ -224,6 +229,7 @@ def var2ae(variance, spatial_resolution, N, L, G): k1 = np.logspace(1,10,1000)/100000000 def get_var(uu): + from site import print_trace_now; print_trace_now() return np.trapz(2 * uu[:], k1[:]) v1 = get_var(get_mann_model_spectra(0.1, L, G, k1)[0]) @@ -234,6 +240,7 @@ def var2ae(variance, spatial_resolution, N, L, G): def fit_ae(spatial_resolution, u, L, G, plt=False): + from site import print_trace_now; print_trace_now() """Fit alpha-epsilon to match variance of time series Parameters @@ -261,6 +268,7 @@ def fit_ae(spatial_resolution, u, L, G, plt=False): # min_bin_count = max(2, 6 - u.shape[0] / 2) # min_bin_count = 1 def get_var(k1, uu): + from site import print_trace_now; print_trace_now() l = 0 #128 // np.sqrt(u.shape[1]) return np.trapz(2 * uu[l:], k1[l:]) @@ -296,6 +304,7 @@ def fit_ae(spatial_resolution, u, L, G, plt=False): def plot_fit(ae, L, G, k1, uu, vv=None, ww=None, uw=None, mean_u=1, log10_bin_size=.2, plt=None): + from site import print_trace_now; print_trace_now() # if plt is None: # import matplotlib.pyplot as plt plot_spectra(k1, uu, vv, ww, uw, mean_u, log10_bin_size, plt) @@ -304,6 +313,7 @@ def plot_fit(ae, L, G, k1, uu, vv=None, ww=None, uw=None, mean_u=1, log10_bin_si def plot_mann_spectra(ae, L, G, style='-', u_ref=1, plt=None, spectra=['uu', 'vv', 'ww', 'uw']): + from site import print_trace_now; print_trace_now() if plt is None: import matplotlib.pyplot as plt mf = 10 ** (np.linspace(-4, 1, 1000)) @@ -373,4 +383,4 @@ if __name__ == "__main__": # #ae, L, G = fit_mann_model_spectra(*spectra(sf, u, v, w), plt=plt) # #print (fit_ae(sf, u, 73.0730383576, 2.01636095317)) # print (u.std()) -# #print (ae, L, G) \ No newline at end of file +# #print (ae, L, G) diff --git a/wetb/wind/turbulence/mann_turbulence.py b/wetb/wind/turbulence/mann_turbulence.py index efe42360529559b35fe356ae41433e41f3279d28..3ed527d344c341eb613a1f26568ff407af01307f 100644 --- a/wetb/wind/turbulence/mann_turbulence.py +++ b/wetb/wind/turbulence/mann_turbulence.py @@ -9,6 +9,7 @@ from wetb.wind.turbulence.spectra import spectra, spectra_from_time_series name_format = "mann_l%.1f_ae%.4f_g%.1f_h%d_%dx%dx%d_%.3fx%.2fx%.2f_s%04d%c.turb" def load(filename, N=(32,32)): + from site import print_trace_now; print_trace_now() """Load mann turbulence box Parameters @@ -38,6 +39,7 @@ def load(filename, N=(32,32)): return data.reshape(nx , ny * nz) def load_uvw(filenames, N=(1024,32,32)): + from site import print_trace_now; print_trace_now() """Load u, v and w turbulence boxes Parameters @@ -62,12 +64,14 @@ def load_uvw(filenames, N=(1024,32,32)): return [load(f, N) for f in filenames] def parameters2name(no_grid_points,box_dimension,ae23,L, Gamma,high_frq_compensation, seed, folder="./turb/"): + from site import print_trace_now; print_trace_now() dxyz = tuple(np.array(box_dimension) / no_grid_points) return ["./turb/" + name_format % ((L, ae23, Gamma, high_frq_compensation) + no_grid_points + dxyz + (seed, uvw)) for uvw in ['u', 'v', 'w']] def fit_mann_parameters(spatial_resolution, u, v, w=None, plt=None): + from site import print_trace_now; print_trace_now() """Fit mann parameters, ae, L, G Parameters @@ -104,5 +108,6 @@ def fit_mann_parameters(spatial_resolution, u, v, w=None, plt=None): def fit_mann_parameters_from_time_series(sample_frq, Uvw_lst, plt=None): + from site import print_trace_now; print_trace_now() from wetb.wind.turbulence.mann_parameters import fit_mann_model_spectra - return fit_mann_model_spectra(*spectra_from_time_series(sample_frq, Uvw_lst), plt=plt) \ No newline at end of file + return fit_mann_model_spectra(*spectra_from_time_series(sample_frq, Uvw_lst), plt=plt) diff --git a/wetb/wind/turbulence/spectra.py b/wetb/wind/turbulence/spectra.py index 1a226c5309876045064291bf53889f02edab446d..8fdf97059b0b17a63cb6542c2934d8a28a7d45a9 100644 --- a/wetb/wind/turbulence/spectra.py +++ b/wetb/wind/turbulence/spectra.py @@ -8,6 +8,7 @@ Created on 27/11/2015 import numpy as np import warnings def spectrum(x, y=None, k=1): + from site import print_trace_now; print_trace_now() """PSD or Cross spectrum (only positive half) If input time series are two dimensional, then columns are interpreted @@ -26,6 +27,7 @@ def spectrum(x, y=None, k=1): if x is None: return None def fft(x): + from site import print_trace_now; print_trace_now() return np.fft.fft(x.T).T / len(x) if y is None or x is y: @@ -43,6 +45,7 @@ def spectrum(x, y=None, k=1): return np.real(fftx * len(x) / (2 * k))[1:] def spectra(spatial_resolution, u, v=None, w=None, detrend=True): + from site import print_trace_now; print_trace_now() """Return the wave number, the uu, vv, ww autospectra and the uw cross spectra Parameters @@ -106,6 +109,7 @@ def spectra(spatial_resolution, u, v=None, w=None, detrend=True): def spectra_from_time_series(sample_frq, Uvw_lst): + from site import print_trace_now; print_trace_now() """Return the wave number, the uu, vv, ww autospectra and the uw cross spectra Parameters @@ -150,6 +154,7 @@ def spectra_from_time_series(sample_frq, Uvw_lst): 'vu':( 468, 0.0218274041889, 73.0730383576, 2.01636095317, 0.00196337613117)} def bin_spectrum(x, y, bin_size, min_bin_count=2): + from site import print_trace_now; print_trace_now() assert min_bin_count > 0 x = x / bin_size low, high = np.floor(np.nanmin(x)), np.ceil(np.nanmax(x)) @@ -162,6 +167,7 @@ def bin_spectrum(x, y, bin_size, min_bin_count=2): def logbin_spectrum(k1, xx, log10_bin_size=.2, min_bin_count=2): + from site import print_trace_now; print_trace_now() ln_bin_size = np.log(10) * log10_bin_size if xx is None: return None @@ -169,9 +175,11 @@ def logbin_spectrum(k1, xx, log10_bin_size=.2, min_bin_count=2): def logbin_spectra(k1, uu, vv=None, ww=None, uw=None, log10_bin_size=0.2, min_bin_count=2): + from site import print_trace_now; print_trace_now() return tuple([logbin_spectrum(k1, xx, log10_bin_size, min_bin_count) for xx in [k1, uu, vv, ww, uw]]) def plot_spectrum(spacial_frq, u, plt=None): + from site import print_trace_now; print_trace_now() if plt is None: import matplotlib.pyplot as plt k1, uu = logbin_spectra(*spectra(spacial_frq, u))[:2] @@ -180,7 +188,9 @@ def plot_spectrum(spacial_frq, u, plt=None): def detrend_wsp(u, v=None, w=None): + from site import print_trace_now; print_trace_now() def _detrend(wsp): + from site import print_trace_now; print_trace_now() if wsp is None: return None dwsp = np.atleast_2d(wsp.copy().T).T @@ -194,10 +204,12 @@ def detrend_wsp(u, v=None, w=None): def plot_spectra(k1, uu, vv=None, ww=None, uw=None, mean_u=1, log10_bin_size=.2, plt=None, marker_style='.'): + from site import print_trace_now; print_trace_now() if plt is None: import matplotlib.pyplot as plt bk1, buu, bvv, bww, buw = logbin_spectra(k1, uu, vv, ww, uw, log10_bin_size) def plot(xx, label, color, plt): + from site import print_trace_now; print_trace_now() plt.semilogx(bk1, bk1 * xx * 10 ** 0 / mean_u ** 2 , marker_style + color, label=label) plot(buu, 'uu', 'r', plt) plt.xlabel('Wavenumber $k_{1}$ [$m^{-1}$]') @@ -209,4 +221,4 @@ def plot_spectra(k1, uu, vv=None, ww=None, uw=None, mean_u=1, log10_bin_size=.2, plot(bvv, 'vv', 'g', plt) if bww is not None: plot(bww, 'ww', 'b', plt) - plot(buw, 'uw', 'm', plt) \ No newline at end of file + plot(buw, 'uw', 'm', plt) diff --git a/wetb/wind/utils.py b/wetb/wind/utils.py index 8125699eaf59e4720e8951992c10d18e7b6f9f3e..b414266a953ca855f1e273f481cca855e67e0584 100644 --- a/wetb/wind/utils.py +++ b/wetb/wind/utils.py @@ -11,6 +11,7 @@ from scipy.signal import detrend def wsp_dir2uv(wsp, dir, dir_ref=None): + from site import print_trace_now; print_trace_now() """Convert horizontal wind speed and direction to u,v Parameters @@ -39,6 +40,7 @@ def wsp_dir2uv(wsp, dir, dir_ref=None): return np.array([u, v]) def wsp_dir_tilt2uvw(wsp, dir, tilt, wsp_horizontal, dir_ref=None): + from site import print_trace_now; print_trace_now() """Convert horizontal wind speed and direction to u,v,w Parameters @@ -78,6 +80,7 @@ def wsp_dir_tilt2uvw(wsp, dir, tilt, wsp_horizontal, dir_ref=None): def xyz2uvw(x, y, z, left_handed=True): + from site import print_trace_now; print_trace_now() """Convert sonic x,y,z measurements to u,v,w wind components Parameters @@ -123,6 +126,7 @@ def xyz2uvw(x, y, z, left_handed=True): def abvrel2xyz_old(alpha, beta, vrel): + from site import print_trace_now; print_trace_now() """Convert pitot tube alpha, beta and relative velocity to local Cartesian wind speed velocities Parameters @@ -165,6 +169,7 @@ def abvrel2xyz_old(alpha, beta, vrel): return x, y, z def abvrel2xyz(alpha, beta, vrel): + from site import print_trace_now; print_trace_now() """Convert pitot tube alpha, beta and relative velocity to local Cartesian wind speed velocities x : parallel to pitot tube, direction pitot tube root to tip, i.e. normal flow gives negative x\n @@ -220,6 +225,7 @@ def abvrel2xyz(alpha, beta, vrel): def detrend_uvw(u, v=None, w=None): + from site import print_trace_now; print_trace_now() # def _detrend(wsp): # if wsp is None: # return None @@ -231,7 +237,8 @@ def detrend_uvw(u, v=None, w=None): # dwsp[:, i] = dwsp[:, i] - t * trend + t[-1] / 2 * trend # return dwsp.reshape(wsp.shape) def _detrend(y): + from site import print_trace_now; print_trace_now() if y is None: return None return detrend(y) - return [_detrend(uvw) for uvw in [u, v, w]] \ No newline at end of file + return [_detrend(uvw) for uvw in [u, v, w]] diff --git a/wetb/wind/weibull.py b/wetb/wind/weibull.py index 43ef0188ca9a11dc39cdf45aae2a0821f196a61e..cee5cc0d380e6a6e1382d4d93331726db91ee907 100644 --- a/wetb/wind/weibull.py +++ b/wetb/wind/weibull.py @@ -9,6 +9,7 @@ import numpy as np import math gamma = math.gamma def pdf(A, k): + from site import print_trace_now; print_trace_now() """Create Weibull pdf function Parameters @@ -38,9 +39,11 @@ def pdf(A, k): return lambda x: k * x ** (k - 1) / A ** k * np.exp(-(x / A) ** k) def cdf(A,k): + from site import print_trace_now; print_trace_now() return lambda x: 1-np.exp(-(x/A)**k) def random(A, k, n): + from site import print_trace_now; print_trace_now() """Create a list of n random Weibull distributed values Parameters @@ -67,6 +70,7 @@ def random(A, k, n): return A * np.random.weibull(k, n) def fit(wsp): + from site import print_trace_now; print_trace_now() """Fit a weibull distribution, in terms of the parameters k and A, to the provided wind speeds Parameters