|
@@ -1,11 +1,13 @@
|
|
|
from abc import ABCMeta, abstractmethod, ABC
|
|
|
from datetime import timedelta
|
|
|
-from mpi4py import MPI
|
|
|
+# from mpi4py import MPI
|
|
|
import h5py
|
|
|
from enum import IntEnum
|
|
|
|
|
|
__all__ = ['DataWriteStream', 'DataReadStream', 'day_stamp', 'EMchPosmap', 'EChPosmap', 'ENetPosmap', 'open_hdf5']
|
|
|
|
|
|
+import logging
|
|
|
+log = logging.getLogger('stream')
|
|
|
|
|
|
def day_stamp(stamp):
|
|
|
import time as stime
|
|
@@ -19,9 +21,10 @@ def day_stamp(stamp):
|
|
|
|
|
|
def open_hdf5(file, is_wirte):
|
|
|
if is_wirte:
|
|
|
- return h5py.File(file, 'a', driver='mpio', comm=MPI.COMM_WORLD)
|
|
|
+ # return h5py.File(file, 'a', driver='mpio', comm=MPI.COMM_WORLD)
|
|
|
+ return h5py.File(file, 'a')
|
|
|
else:
|
|
|
- return h5py.File(file, 'r', driver='mpio', comm=MPI.COMM_WORLD)
|
|
|
+ return h5py.File(file, 'r')
|
|
|
|
|
|
|
|
|
class DataWriteStream(metaclass=ABCMeta):
|
|
@@ -47,11 +50,14 @@ class DataWriteStream(metaclass=ABCMeta):
|
|
|
def close(self):
|
|
|
if self._hfive is not None:
|
|
|
self._hfive.close()
|
|
|
-pass
|
|
|
+ self._hfive = None
|
|
|
+
|
|
|
+ pass
|
|
|
|
|
|
|
|
|
class DataReadStream(metaclass=ABCMeta):
|
|
|
_version = 20200618
|
|
|
+
|
|
|
def __init__(self, hfive):
|
|
|
self._hfive = hfive
|
|
|
|
|
@@ -72,31 +78,52 @@ class DataReadStream(metaclass=ABCMeta):
|
|
|
def close(self):
|
|
|
if self._hfive is not None:
|
|
|
self._hfive.close()
|
|
|
+ self._hfive = None
|
|
|
|
|
|
- def _days(self, root):
|
|
|
+ def _sub_dirs(self, root):
|
|
|
result = []
|
|
|
try:
|
|
|
for name, sub in root.items():
|
|
|
if isinstance(sub, h5py.Group):
|
|
|
result.append(name)
|
|
|
except Exception as ex:
|
|
|
- print(ex)
|
|
|
+ log.error(ex)
|
|
|
finally:
|
|
|
return result
|
|
|
|
|
|
+ def dir(self, group):
|
|
|
+ result = []
|
|
|
+ for name, sub in group.items():
|
|
|
+ if isinstance(sub, h5py.Group):
|
|
|
+ result.extend(self.dir(sub))
|
|
|
+ else:
|
|
|
+ result.append(sub.name)
|
|
|
+ return result
|
|
|
+
|
|
|
def _root_path(self):
|
|
|
- return f'/{self._version}'
|
|
|
+ return f'/{self._version}/'
|
|
|
+
|
|
|
+ def dirs(self):
|
|
|
+ try:
|
|
|
+ root_ptah = self._root_path()
|
|
|
+ root = self.file.require_group(root_ptah)
|
|
|
+ days = self.dir(root)
|
|
|
+ return days
|
|
|
+ except Exception as ex:
|
|
|
+ log.error(ex)
|
|
|
+ return []
|
|
|
|
|
|
def days(self):
|
|
|
try:
|
|
|
root_ptah = self._root_path()
|
|
|
root = self.file.require_group(root_ptah)
|
|
|
- days = self._days(root)
|
|
|
+ days = self._sub_dirs(root)
|
|
|
return days
|
|
|
except Exception as ex:
|
|
|
- print(ex)
|
|
|
+ log.error(ex)
|
|
|
return []
|
|
|
-pass
|
|
|
+
|
|
|
+ pass
|
|
|
|
|
|
|
|
|
class EMchPosmap(IntEnum):
|
|
@@ -111,7 +138,8 @@ class EMchPosmap(IntEnum):
|
|
|
@staticmethod
|
|
|
def dim():
|
|
|
return 7
|
|
|
-pass
|
|
|
+
|
|
|
+ pass
|
|
|
|
|
|
|
|
|
class EChPosmap(IntEnum):
|
|
@@ -127,7 +155,9 @@ class EChPosmap(IntEnum):
|
|
|
@staticmethod
|
|
|
def dim():
|
|
|
return 8
|
|
|
-pass
|
|
|
+
|
|
|
+ pass
|
|
|
+
|
|
|
|
|
|
class ENetPosmap(IntEnum):
|
|
|
succ_count = 0
|
|
@@ -136,4 +166,5 @@ class ENetPosmap(IntEnum):
|
|
|
@staticmethod
|
|
|
def dim():
|
|
|
return 2
|
|
|
-pass
|
|
|
+
|
|
|
+ pass
|