From e8e82a29659af778c9e902507bfe9ceefcbb67e7 Mon Sep 17 00:00:00 2001 From: "Mads M. Pedersen" <mmpe@dtu.dk> Date: Wed, 18 Oct 2017 10:03:48 +0200 Subject: [PATCH] some changes and modifications --- wetb/hawc2/ae_file.py | 6 +++--- wetb/hawc2/htc_contents.py | 4 ++-- wetb/utils/cluster_tools/cluster_resource.py | 1 - wetb/utils/cluster_tools/ssh_client.py | 5 +++++ wetb/wind/stability.py | 17 ++++++++++++++--- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/wetb/hawc2/ae_file.py b/wetb/hawc2/ae_file.py index 1372bfc1..4557bb03 100644 --- a/wetb/hawc2/ae_file.py +++ b/wetb/hawc2/ae_file.py @@ -67,10 +67,10 @@ class AEFile(object): ae_data = self.ae_sets[set_nr] index = np.searchsorted(ae_data[:, 0], radius) index = max(1, index) - setnr1, setnr2 = ae_data[index - 1:index + 1, 3] - if setnr1 != setnr2: + setnrs = ae_data[index - 1:index + 1, 3] + if setnrs[0] != setnrs[-1]: raise NotImplementedError - return setnr1 + return setnrs[0] diff --git a/wetb/hawc2/htc_contents.py b/wetb/hawc2/htc_contents.py index 4e184974..fa9bf71b 100644 --- a/wetb/hawc2/htc_contents.py +++ b/wetb/hawc2/htc_contents.py @@ -176,8 +176,8 @@ class HTCSection(HTCContents): s += "%send %s;%s\n" % (" "*level, self.name_, (("", "\t" + self.end_comments)[self.end_comments.strip() != ""]).replace("\t\n","\n")) return s - def get_subsection_by_name(self, name): - lst = [s for s in self if 'name' in s and s.name[0]==name] + def get_subsection_by_name(self, name, field='name'): + lst = [s for s in self if field in s and s[field][0]==name] if len(lst)==1: return lst[0] else: diff --git a/wetb/utils/cluster_tools/cluster_resource.py b/wetb/utils/cluster_tools/cluster_resource.py index 04c287df..d196a372 100644 --- a/wetb/utils/cluster_tools/cluster_resource.py +++ b/wetb/utils/cluster_tools/cluster_resource.py @@ -140,7 +140,6 @@ class SSHPBSClusterResource(Resource): _, output, _ = self.ssh.execute('qstat -n1') users, host, nodesload = pbswrap.parse_qstat_n1(output.split("\n"), self.ssh.host) - # if the user does not have any jobs, this will not exist try: cpu_user = users[self.ssh.username]['cpus'] diff --git a/wetb/utils/cluster_tools/ssh_client.py b/wetb/utils/cluster_tools/ssh_client.py index 7492b1a8..12277503 100644 --- a/wetb/utils/cluster_tools/ssh_client.py +++ b/wetb/utils/cluster_tools/ssh_client.py @@ -241,6 +241,9 @@ class SSHClient(object): size = len(localfile.read()) localfile.seek(0) ret = self.sftp.putfo(localfile, filepath, file_size=size, callback=callback) + except Exception as e: + print ("upload failed ", str(e)) + raise e finally: SSHClient.__exit__(self) if verbose: @@ -271,6 +274,8 @@ class SSHClient(object): self.upload(zn, remote_zn, callback=callback) self.execute("unzip %s -d %s && rm %s"%(remote_zn, remotepath, remote_zn)) except: + print ("upload files failed", ) + traceback.print_exc() raise finally: os.remove(zn) diff --git a/wetb/wind/stability.py b/wetb/wind/stability.py index 2af9ea8e..6826d581 100644 --- a/wetb/wind/stability.py +++ b/wetb/wind/stability.py @@ -40,6 +40,17 @@ def MoninObukhov_length(u,v,w, T): def L2category(L, full_category_name=False): """Stability category from Monin-Obukhov length + Categories: + 0>L>-50: Extreme unstable (eu) + -50>L>-100: Very unstable (vu) + -100>L>-200: Unstable (u) + -200>L>-500: Near unstable (nu) + 500<|L|: Neutral (n) + 200<L<500: Near stable (ns) + 50<L<200: Stable (s) + 10<L<50: Very stable (vs) + 0<L<10: Extreme stable (es) + L=NaN: Undefined (-) Parameters ---------- L : float or int @@ -57,12 +68,12 @@ def L2category(L, full_category_name=False): >>> L2category(1000) n """ - cat_limits = np.array([-50,-100,-200,-500,500,200,50,10]) + cat_limits = np.array([-1e-99,-50,-100,-200,-500,500,200,50,10,1e-99]) index = np.searchsorted( 1/cat_limits, 1/np.array(L))-1 if full_category_name: - return np.array(['Very unstable','Unstable','Near unstable','Neutral','Near stable','Stable','Very stable','undefined'])[index] + return np.array(['Extreme unstable', 'Very unstable','Unstable','Near unstable','Neutral','Near stable','Stable','Very stable','Extreme stable','Undefined'])[index] else: - return np.array(['vu','u','nu','n','ns','s','vs','-'])[index] + return np.array(['eu', 'vu','u','nu','n','ns','s','vs','es','-'])[index] def MoninObukhov_length2(u_star, w, T, specific_humidity=None): """Calculate the Monin Obukhov length -- GitLab