diff --git a/wetb/hawc2/htc_contents.py b/wetb/hawc2/htc_contents.py index 1bad073895a1ebb59c59c419958f701178a4b27a..6ab2e0fbe454742bfed0d790b7df76c57cd44434 100644 --- a/wetb/hawc2/htc_contents.py +++ b/wetb/hawc2/htc_contents.py @@ -54,15 +54,6 @@ class HTCContents(object): name_ = "" parent = None - def __setitem__(self, key, value): - if isinstance(key, str): - self.contents[key] = value - value.parent = self - elif isinstance(key, int): - self.values[key] = value - else: - raise NotImplementedError - def __getitem__(self, key): if isinstance(key, str): key = key.replace(".", "/") @@ -152,11 +143,6 @@ class HTCContents(object): for k in keys: del self.parent.contents[k] - def add_line(self, name, values, comments=""): - line = HTCLine(name, values, comments) - self._add_contents(line) - return line - def location(self): if self.parent is None: return os.path.basename(self.filename) @@ -192,6 +178,20 @@ class HTCSection(HTCContents): self.end_comments = end_comments.strip(" \t") self.contents = OrderedDict() + def add_line(self, name, values, comments=""): + line = HTCLine(name, values, comments) + self._add_contents(line) + return line + + def __setitem__(self, key, value): + if isinstance(value, HTCContents): + self.contents[key] = value + value.parent = self + elif isinstance(value, str): + self.add_line(key, [value]) + else: + self.add_line(key, value) + @staticmethod def from_lines(lines): line, begin_comments = parse_next_line(lines) @@ -266,6 +266,12 @@ class HTCLine(HTCContents): except: raise IndexError("Parameter %s does not exists for %s" % (key + 1, self.location())) + def __setitem__(self, key, value): + if isinstance(key, int): + self.values[key] = value + else: + raise NotImplementedError + @staticmethod def from_lines(lines): line, end_comments = parse_next_line(lines) diff --git a/wetb/hawc2/turbulence_file.py b/wetb/hawc2/turbulence_file.py index c7875e624ac08a51970e5a6b35225deb9f5df1cf..b78a880bc5f304fd1b3658b6d0238580a024ec95 100644 --- a/wetb/hawc2/turbulence_file.py +++ b/wetb/hawc2/turbulence_file.py @@ -19,21 +19,21 @@ class TurbulenceFile(object): self.mean_wsp = mean_wsp self.center_position = center_position self.data = mann_turbulence.load(filename, Nxyz) - - - + + @property + def data3d(self): + return self.data.reshape(self.Nxyz) + @staticmethod def load_from_htc(htcfilename, modelpath=None, type='mann'): htc = HTCFile(htcfilename, modelpath) - - Nxyz = np.array([htc.wind[type]['box_dim_%s'%uvw][0] for uvw in 'uvw']) - dxyz = np.array([htc.wind[type]['box_dim_%s'%uvw][1] for uvw in 'uvw']) + + Nxyz = np.array([htc.wind[type]['box_dim_%s' % uvw][0] for uvw in 'uvw']) + dxyz = np.array([htc.wind[type]['box_dim_%s' % uvw][1] for uvw in 'uvw']) center_position = htc.wind.center_pos0.values wsp = htc.wind.wsp - return [TurbulenceFile(os.path.join(htc.modelpath , htc.wind[type]['filename_%s'%uvw][0]), Nxyz, dxyz,wsp, (0,wsp)[uvw=='u'], center_position) for uvw in 'uvw'] - - - + return [TurbulenceFile(os.path.join(htc.modelpath, htc.wind[type]['filename_%s' % uvw][0]), Nxyz, dxyz, wsp, (0, wsp)[uvw == 'u'], center_position) for uvw in 'uvw'] + if __name__ == '__main__': - pass \ No newline at end of file + pass