forked from viscid-hub/Viscid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
athena_xdmf.py
58 lines (45 loc) · 1.74 KB
/
athena_xdmf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import os
import re
from viscid.readers import xdmf
from viscid.readers import athena
class AthenaFileXDMF(athena.AthenaFile, xdmf.FileXDMF): # pylint: disable=abstract-method
"""File type for Athena style convenience stuff
Makes AthenaGrid the default grid and handles grouping multiple
files.
"""
_detector = r"^\s*(.*)\.([0-9]+)\.(ath.xdmf)\s*$"
_collection = None
@classmethod
def group_fnames(cls, fnames):
return athena.group_athena_files_common(cls._detector, fnames)
@classmethod
def collective_name_from_group(cls, fnames):
return athena.athena_collective_name_from_group(cls._detector,
fnames)
def load(self, fname):
if not isinstance(fname, list):
fname = [fname]
if len(fname) > 1:
self._collection = fname
else:
self._collection = None
super(AthenaFileXDMF, self).load(fname[0])
basename = os.path.basename(self.fname)
self.set_info('run', re.match(self._detector, basename).group(1))
def _parse(self):
if self._collection is not None:
# assume we have a collection of temporal files, because why not
data_temporal = self._make_dataset(self, dset_type="temporal",
name="AthenaXDMFTemporalCollection")
for fname in self._collection:
grids = self._parse_file(fname, data_temporal)
for _grid in grids:
data_temporal.add(_grid)
data_temporal.activate(0)
self.add(data_temporal)
self.activate(0)
else:
super(AthenaFileXDMF, self)._parse()
##
## EOF
##