das2numpy 1.1.2__tar.gz → 1.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (21) hide show
  1. {das2numpy-1.1.2/src/das2numpy.egg-info → das2numpy-1.2.0}/PKG-INFO +1 -1
  2. {das2numpy-1.1.2 → das2numpy-1.2.0}/pyproject.toml +1 -1
  3. {das2numpy-1.1.2 → das2numpy-1.2.0}/src/das2numpy/__init__.py +3 -0
  4. das2numpy-1.2.0/src/das2numpy/setups/hdas.py +106 -0
  5. {das2numpy-1.1.2 → das2numpy-1.2.0/src/das2numpy.egg-info}/PKG-INFO +1 -1
  6. {das2numpy-1.1.2 → das2numpy-1.2.0}/src/das2numpy.egg-info/SOURCES.txt +1 -0
  7. {das2numpy-1.1.2 → das2numpy-1.2.0}/src/example.py +1 -0
  8. {das2numpy-1.1.2 → das2numpy-1.2.0}/LICENSE +0 -0
  9. {das2numpy-1.1.2 → das2numpy-1.2.0}/README.md +0 -0
  10. {das2numpy-1.1.2 → das2numpy-1.2.0}/setup.cfg +0 -0
  11. {das2numpy-1.1.2 → das2numpy-1.2.0}/src/das2numpy/__main__.py +0 -0
  12. {das2numpy-1.1.2 → das2numpy-1.2.0}/src/das2numpy/chunk.py +0 -0
  13. {das2numpy-1.1.2 → das2numpy-1.2.0}/src/das2numpy/filefinder.py +0 -0
  14. {das2numpy-1.1.2 → das2numpy-1.2.0}/src/das2numpy/setups/flac_200hz.py +0 -0
  15. {das2numpy-1.1.2 → das2numpy-1.2.0}/src/das2numpy/setups/light_tdms_reader.py +0 -0
  16. {das2numpy-1.1.2 → das2numpy-1.2.0}/src/das2numpy/setups/optasense_b35idefix.py +0 -0
  17. {das2numpy-1.1.2 → das2numpy-1.2.0}/src/das2numpy/setups/silixa.py +0 -0
  18. {das2numpy-1.1.2 → das2numpy-1.2.0}/src/das2numpy/utils.py +0 -0
  19. {das2numpy-1.1.2 → das2numpy-1.2.0}/src/das2numpy.egg-info/dependency_links.txt +0 -0
  20. {das2numpy-1.1.2 → das2numpy-1.2.0}/src/das2numpy.egg-info/requires.txt +0 -0
  21. {das2numpy-1.1.2 → das2numpy-1.2.0}/src/das2numpy.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: das2numpy
3
- Version: 1.1.2
3
+ Version: 1.2.0
4
4
  Summary: A simple and universal package for loading large amounts of distributed acoustic sensing (DAS) data.
5
5
  Author-email: Erik Genthe <erik.genthe@desy.de>
6
6
  Project-URL: Homepage, https://gitlab.desy.de/wave/tools/das2numpy
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "das2numpy"
7
- version = "1.1.2"
7
+ version = "1.2.0"
8
8
  authors = [
9
9
  { name="Erik Genthe", email="erik.genthe@desy.de" },
10
10
  ]
@@ -26,6 +26,9 @@ def loader(root_path:str, predefined_setup:str, num_worker_threads):
26
26
  elif predefined_setup.upper() == "FLAC_200HZ":
27
27
  from .setups import flac_200hz
28
28
  chunk = flac_200hz.init(root_path, num_worker_threads)
29
+ elif predefined_setup.upper() == "HDAS":
30
+ from .setups import hdas
31
+ chunk = hdas.init(root_path, num_worker_threads)
29
32
  elif predefined_setup.upper() == "OPTASENSE":
30
33
  from .setups import optasense_b35idefix
31
34
  chunk = optasense_b35idefix.init()
@@ -0,0 +1,106 @@
1
+ """ Setup file for hDAS.
2
+ """
3
+
4
+ import sys as SYS
5
+ from os import path as P
6
+ import datetime as DT
7
+ import numpy as NP
8
+ import h5py as H5PY
9
+ from ..filefinder import FileFinder, to_posix_timestamp_ms
10
+ from ..chunk import Chunk
11
+ from .light_tdms_reader import TdmsReader
12
+ from ..utils import bin
13
+
14
+
15
+ CALIBRATE = True
16
+
17
+
18
+
19
+
20
+ def init(root_path, num_worker_threads):
21
+ assert P.isdir(root_path)
22
+ file_finder = FileFinder(root_path, ".h5", filename_to_posix_timestamp)
23
+ assert num_worker_threads >= 1
24
+ multithreaded = num_worker_threads > 1
25
+ sample_rate = 1000
26
+ return Chunk(
27
+ file_finder,
28
+ sample_rate,
29
+ multithreaded,
30
+ num_worker_threads,
31
+ False,
32
+ load_file
33
+ )
34
+
35
+ def filename_to_posix_timestamp(file_name:str) -> int:
36
+ # Example path: 2026_05_08_15h02m22s_HDAS_StrainRate_ch1.h5
37
+ # TODO Known bug: The timestamps array in the file has milliseconds! So the milliseonds are missing in the file name! h5['Timestamps']['Timestamps_Data']
38
+ timestamp_dt = DT.datetime.strptime(file_name.split("s_")[0], "%Y_%m_%d_%Hh%Mm%S")
39
+ timestamp_ms = to_posix_timestamp_ms(timestamp_dt)
40
+ return timestamp_ms
41
+
42
+
43
+ def load_file(file_path, file_timestamp, t_start, t_end, t_step, channel_start, channel_end, channel_step) -> NP.ndarray:
44
+ """ Loads a single file, trims it. And returns the trimmed data as a numpy array. Downsampling (t_step, channel_step) is also possible!
45
+ """
46
+
47
+ with H5PY.File(file_path, "r") as h5:
48
+ # Known bug: The file_timestamp is not accurate to milliseconds, because milliseconds are missing in the file name
49
+ #timestamps_unix_sec = h5['Timestamps']['Timestamps_Data']
50
+ #print(file_timestamp)
51
+ #file_timestamp = int(timestamps_unix_sec[0][0] * 1000.0) # Overwrite inaccurate file_timestamp
52
+ #file_timestamp -= 7200000 # TODO: This is a dirty fix: Internal timestamp is CEST, when hDAS system time is CEST.
53
+ data = NP.array(h5["StrainRate"]["StrainRate_Data"])
54
+ #print(file_timestamp)
55
+
56
+ # Trim data
57
+ rel_t_start = 0
58
+ if t_start > file_timestamp: # Check if beginning should be trimmed.
59
+ rel_t_start = t_start - file_timestamp
60
+ rel_t_end = -1
61
+ if t_end < file_timestamp + data.shape[0]: # Check if end should be trimmed
62
+ rel_t_end = t_end - file_timestamp
63
+ if rel_t_start == rel_t_end:
64
+ return NP.zeros(shape=[0, 0]) # No data should be loaded. Do nothing
65
+ if file_timestamp + data.shape[0] <= t_start:
66
+ print("Warning: File does not contain any parts of the requested data.",
67
+ "This can happen if there are leaks in the data. The corresponding output will be left filled with zeros.\n",
68
+ f" Requested range (Posixtimestamps in ms): [{t_start}, {t_end}[\n",
69
+ f" Filepath: {file_path}.")
70
+ return NP.zeros(shape=[0, 0])
71
+ assert rel_t_end == -1 or rel_t_end > rel_t_start, f"rel_t_start={rel_t_start}, rel_t_end={rel_t_end}."
72
+ if channel_end == -1: # Avoids that last channel is missing when channel_end == -1
73
+ channel_end = None
74
+ data = data[rel_t_start:rel_t_end, channel_start:channel_end]
75
+
76
+
77
+ # Downsample data
78
+ if t_step != 1 or channel_step != 1:
79
+ data = bin(data, (t_step, channel_step))
80
+ #if t_step != 1:
81
+ # data = data[::t_step]
82
+ #if channel_step != 1:
83
+ # data = data[:, ::channel_step]
84
+ assert len(data) > 0
85
+
86
+ if CALIBRATE:
87
+ data = calibrate(data)
88
+
89
+ return data
90
+
91
+
92
+
93
+
94
+
95
+ def calibrate(data:NP.ndarray) -> NP.ndarray:
96
+ """ Convert raw data to strain rate data. """
97
+ if data.dtype not in (float, NP.float32, NP.float64):
98
+ NEW_TYPE = NP.float32
99
+ #print("Warning: For calibration the data has to be of type float. Converting from {data.dtype} to {NEW_TYPE}")
100
+ data = data.astype(NEW_TYPE)
101
+ factor = 10 * 1e-9
102
+ return data * factor # Result: 1 / s
103
+
104
+
105
+
106
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: das2numpy
3
- Version: 1.1.2
3
+ Version: 1.2.0
4
4
  Summary: A simple and universal package for loading large amounts of distributed acoustic sensing (DAS) data.
5
5
  Author-email: Erik Genthe <erik.genthe@desy.de>
6
6
  Project-URL: Homepage, https://gitlab.desy.de/wave/tools/das2numpy
@@ -13,6 +13,7 @@ src/das2numpy.egg-info/dependency_links.txt
13
13
  src/das2numpy.egg-info/requires.txt
14
14
  src/das2numpy.egg-info/top_level.txt
15
15
  src/das2numpy/setups/flac_200hz.py
16
+ src/das2numpy/setups/hdas.py
16
17
  src/das2numpy/setups/light_tdms_reader.py
17
18
  src/das2numpy/setups/optasense_b35idefix.py
18
19
  src/das2numpy/setups/silixa.py
@@ -11,6 +11,7 @@ t_end = datetime(2024, 7, 23, 1, 1, 0)
11
11
  channel_start = 0
12
12
  channel_end = -1
13
13
  #loader = loader("/pnfs/desy.de/m/project/iDAS/raw/2024-DESY/2024-07-23-desy", "SILIXA", 1) # 1000 Hz
14
+ #loader = loader("/pnfs/desy.de/m/project/iDAS/raw/2026-DESY/2026_das_comparison/hdas", "HDAS", 1) # 1000 Hz
14
15
  loader = loader("/pnfs/desy.de/m/project/iDAS/work/IDAS_200HZ/", "FLAC_200HZ", 1) # 200 Hz
15
16
  data = loader.load_array(t_start, t_end, channel_start, channel_end)
16
17
 
File without changes
File without changes
File without changes