Skip to content
Snippets Groups Projects
Commit 564151b0 authored by Mads M. Pedersen's avatar Mads M. Pedersen
Browse files

add support for

htc.wind.mann['filename_u'] = 'testu.bin'
parent f14b72d9
No related branches found
No related tags found
No related merge requests found
Pipeline #7366 passed
...@@ -54,15 +54,6 @@ class HTCContents(object): ...@@ -54,15 +54,6 @@ class HTCContents(object):
name_ = "" name_ = ""
parent = None 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): def __getitem__(self, key):
if isinstance(key, str): if isinstance(key, str):
key = key.replace(".", "/") key = key.replace(".", "/")
...@@ -152,11 +143,6 @@ class HTCContents(object): ...@@ -152,11 +143,6 @@ class HTCContents(object):
for k in keys: for k in keys:
del self.parent.contents[k] 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): def location(self):
if self.parent is None: if self.parent is None:
return os.path.basename(self.filename) return os.path.basename(self.filename)
...@@ -192,6 +178,20 @@ class HTCSection(HTCContents): ...@@ -192,6 +178,20 @@ class HTCSection(HTCContents):
self.end_comments = end_comments.strip(" \t") self.end_comments = end_comments.strip(" \t")
self.contents = OrderedDict() 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 @staticmethod
def from_lines(lines): def from_lines(lines):
line, begin_comments = parse_next_line(lines) line, begin_comments = parse_next_line(lines)
...@@ -266,6 +266,12 @@ class HTCLine(HTCContents): ...@@ -266,6 +266,12 @@ class HTCLine(HTCContents):
except: except:
raise IndexError("Parameter %s does not exists for %s" % (key + 1, self.location())) 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 @staticmethod
def from_lines(lines): def from_lines(lines):
line, end_comments = parse_next_line(lines) line, end_comments = parse_next_line(lines)
......
...@@ -19,21 +19,21 @@ class TurbulenceFile(object): ...@@ -19,21 +19,21 @@ class TurbulenceFile(object):
self.mean_wsp = mean_wsp self.mean_wsp = mean_wsp
self.center_position = center_position self.center_position = center_position
self.data = mann_turbulence.load(filename, Nxyz) self.data = mann_turbulence.load(filename, Nxyz)
@property
def data3d(self):
return self.data.reshape(self.Nxyz)
@staticmethod @staticmethod
def load_from_htc(htcfilename, modelpath=None, type='mann'): def load_from_htc(htcfilename, modelpath=None, type='mann'):
htc = HTCFile(htcfilename, modelpath) htc = HTCFile(htcfilename, modelpath)
Nxyz = np.array([htc.wind[type]['box_dim_%s'%uvw][0] 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']) dxyz = np.array([htc.wind[type]['box_dim_%s' % uvw][1] for uvw in 'uvw'])
center_position = htc.wind.center_pos0.values center_position = htc.wind.center_pos0.values
wsp = htc.wind.wsp 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__': if __name__ == '__main__':
pass pass
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment