NetchkReader.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. from .DataStream import DataReadStream,open_hdf5
  2. from .DataStream import ENetPosmap as pos_map
  3. import numpy as np
  4. import re
  5. from collections import defaultdict
  6. import time as time
  7. __all__ = ['NetchkReader']
  8. import logging
  9. log = logging.getLogger('reader')
  10. class NetchkReader(DataReadStream):
  11. def __init__(self):
  12. file = '/var/www/html/data/stdata/netchk.hdf5'
  13. hfive = open_hdf5(file,False)
  14. super(NetchkReader,self).__init__(hfive)
  15. def __del__(self):
  16. self.close()
  17. super(NetchkReader, self).__del__()
  18. def tuple_path(self, day: int, chnames: set = None):
  19. def parse(path):
  20. items = re.split(r'/', path)
  21. (_prifix, _version, today, chname) = items
  22. return chname
  23. all = True if chnames is None or len(chnames) == 0 else False
  24. channels = set()
  25. pathes = self.datasets(day)
  26. for path in pathes:
  27. _chname = parse(path)
  28. if all:
  29. channels.add(_chname)
  30. elif _chname in chnames:
  31. channels.add(_chname)
  32. else:
  33. continue
  34. return channels
  35. def many_tuple_path(self, days: list, chnames: set = None):
  36. all = set()
  37. for day in days:
  38. channels = self.tuple_path(day, chnames)
  39. all = all.union(channels)
  40. return all
  41. def init_data(self, days):
  42. dim = pos_map.dim()
  43. return np.zeros((dim, 86400 * days))
  44. def read(self, today, chname):
  45. path = f'/{self._version}/{today}/{chname}'
  46. hfive = self.file
  47. if path in hfive:
  48. return hfive[path]
  49. else:
  50. return None
  51. pass
  52. pass