backscattering_simulation_data 1.0.1__py3-none-any.whl
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.
- backscattering_simulation_data/__init__.py +17 -0
- backscattering_simulation_data/__init__.pyi +19 -0
- backscattering_simulation_data/metadata/__init__.py +24 -0
- backscattering_simulation_data/metadata/__init__.pyi +25 -0
- backscattering_simulation_data/metadata/elementtype.py +6 -0
- backscattering_simulation_data/metadata/elementtype.pyi +5 -0
- backscattering_simulation_data/metadata/git.py +77 -0
- backscattering_simulation_data/metadata/git.pyi +23 -0
- backscattering_simulation_data/metadata/interferometer.py +135 -0
- backscattering_simulation_data/metadata/interferometer.pyi +33 -0
- backscattering_simulation_data/metadata/map.py +127 -0
- backscattering_simulation_data/metadata/map.pyi +31 -0
- backscattering_simulation_data/metadata/metadata.py +7 -0
- backscattering_simulation_data/metadata/metadata.pyi +3 -0
- backscattering_simulation_data/metadata/modelmodifier.py +47 -0
- backscattering_simulation_data/metadata/modelmodifier.pyi +8 -0
- backscattering_simulation_data/metadata/modifiers/__init__.py +9 -0
- backscattering_simulation_data/metadata/modifiers/__init__.pyi +5 -0
- backscattering_simulation_data/metadata/modifiers/addition.py +101 -0
- backscattering_simulation_data/metadata/modifiers/addition.pyi +25 -0
- backscattering_simulation_data/metadata/modifiers/deletion.py +31 -0
- backscattering_simulation_data/metadata/modifiers/deletion.pyi +11 -0
- backscattering_simulation_data/metadata/modifiers/update.py +55 -0
- backscattering_simulation_data/metadata/modifiers/update.pyi +13 -0
- backscattering_simulation_data/metadata/pointabsorber.py +94 -0
- backscattering_simulation_data/metadata/pointabsorber.pyi +22 -0
- backscattering_simulation_data/metadata/powermeasurement.py +48 -0
- backscattering_simulation_data/metadata/powermeasurement.pyi +13 -0
- backscattering_simulation_data/metadata/root.py +108 -0
- backscattering_simulation_data/metadata/root.pyi +26 -0
- backscattering_simulation_data/metadata/scatterer.py +71 -0
- backscattering_simulation_data/metadata/scatterer.pyi +17 -0
- backscattering_simulation_data/metadata/simulation.py +68 -0
- backscattering_simulation_data/metadata/simulation.pyi +17 -0
- backscattering_simulation_data/powermeasurement.py +47 -0
- backscattering_simulation_data/powermeasurement.pyi +15 -0
- backscattering_simulation_data/root.py +146 -0
- backscattering_simulation_data/root.pyi +35 -0
- backscattering_simulation_data/scatterer.py +61 -0
- backscattering_simulation_data/scatterer.pyi +27 -0
- backscattering_simulation_data/section.py +105 -0
- backscattering_simulation_data/section.pyi +22 -0
- backscattering_simulation_data/typed.py +0 -0
- backscattering_simulation_data/typed.pyi +0 -0
- backscattering_simulation_data/utils.py +90 -0
- backscattering_simulation_data/utils.pyi +9 -0
- backscattering_simulation_data-1.0.1.dist-info/METADATA +113 -0
- backscattering_simulation_data-1.0.1.dist-info/RECORD +50 -0
- backscattering_simulation_data-1.0.1.dist-info/WHEEL +4 -0
- backscattering_simulation_data-1.0.1.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
from h5py import File, Group
|
|
2
|
+
|
|
3
|
+
from .map import Map
|
|
4
|
+
from .metadata import Metadata
|
|
5
|
+
from .modelmodifier import ModelModifier
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Simulation(Metadata):
|
|
9
|
+
"""Information about the simulation state"""
|
|
10
|
+
|
|
11
|
+
def __init__(
|
|
12
|
+
self,
|
|
13
|
+
maps: list[Map],
|
|
14
|
+
model_modifiers: list[ModelModifier],
|
|
15
|
+
) -> None:
|
|
16
|
+
"""Parameters
|
|
17
|
+
----------
|
|
18
|
+
maps: list[Map]
|
|
19
|
+
List of simulated maps associated to mirrors in the
|
|
20
|
+
simulation
|
|
21
|
+
|
|
22
|
+
"""
|
|
23
|
+
self.maps = maps
|
|
24
|
+
self.model_modifiers = model_modifiers
|
|
25
|
+
|
|
26
|
+
@staticmethod
|
|
27
|
+
def from_hdf5(store: File | Group) -> "Simulation":
|
|
28
|
+
maps_group = store.get("maps")
|
|
29
|
+
model_modifiers_group = store.get("model modifiers")
|
|
30
|
+
if not isinstance(maps_group, Group):
|
|
31
|
+
message = (
|
|
32
|
+
"Maps information should be stored in a group, not "
|
|
33
|
+
f"{type(maps_group)}"
|
|
34
|
+
)
|
|
35
|
+
raise ValueError(message)
|
|
36
|
+
if not isinstance(model_modifiers_group, Group):
|
|
37
|
+
message = (
|
|
38
|
+
"Model modifiers must be stored in a group, not "
|
|
39
|
+
f"{type(model_modifiers_group)}"
|
|
40
|
+
)
|
|
41
|
+
raise ValueError(message)
|
|
42
|
+
|
|
43
|
+
maps = maps_group.values()
|
|
44
|
+
model_modifiers = model_modifiers_group.values()
|
|
45
|
+
|
|
46
|
+
return Simulation(
|
|
47
|
+
maps=[Map.from_hdf5(map_) for map_ in maps],
|
|
48
|
+
model_modifiers=[
|
|
49
|
+
ModelModifier.from_hdf5(model_modifier)
|
|
50
|
+
for model_modifier in model_modifiers
|
|
51
|
+
],
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
def to_hdf5(self, store: File | Group) -> File | Group:
|
|
55
|
+
_ = store.create_group("maps")
|
|
56
|
+
_ = store.create_group("model modifiers")
|
|
57
|
+
for map_ in self.maps:
|
|
58
|
+
_ = map_.to_hdf5(
|
|
59
|
+
store.require_group("maps").create_group(map_.mirror),
|
|
60
|
+
)
|
|
61
|
+
for i in range(len(self.model_modifiers)):
|
|
62
|
+
model_modifier = self.model_modifiers[i]
|
|
63
|
+
_ = model_modifier.to_hdf5(
|
|
64
|
+
store.require_group("model modifiers").create_group(
|
|
65
|
+
str(i),
|
|
66
|
+
),
|
|
67
|
+
)
|
|
68
|
+
return store
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
from h5py import File as File
|
|
3
|
+
from h5py import Group
|
|
4
|
+
|
|
5
|
+
from .map import Map as Map
|
|
6
|
+
from .metadata import Metadata as Metadata
|
|
7
|
+
from .modelmodifier import ModelModifier as ModelModifier
|
|
8
|
+
|
|
9
|
+
class Simulation(Metadata):
|
|
10
|
+
maps: Incomplete
|
|
11
|
+
model_modifiers: Incomplete
|
|
12
|
+
def __init__(
|
|
13
|
+
self, maps: list[Map], model_modifiers: list[ModelModifier]
|
|
14
|
+
) -> None: ...
|
|
15
|
+
@staticmethod
|
|
16
|
+
def from_hdf5(store: File | Group) -> Simulation: ...
|
|
17
|
+
def to_hdf5(self, store: File | Group) -> File | Group: ...
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from astropy.table import QTable
|
|
2
|
+
from h5py import File, Group
|
|
3
|
+
|
|
4
|
+
from .metadata import MetadataPowerMeasurement as Metadata
|
|
5
|
+
from .section import Section
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class PowerMeasurement(Section):
|
|
9
|
+
"""A power measurement in a specific place in the simulated
|
|
10
|
+
interferometer
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
def __init__(
|
|
14
|
+
self,
|
|
15
|
+
metadata: Metadata,
|
|
16
|
+
modes: QTable,
|
|
17
|
+
) -> None:
|
|
18
|
+
"""Paremeters
|
|
19
|
+
----------
|
|
20
|
+
metadata : Metadata
|
|
21
|
+
Information about this power measurement
|
|
22
|
+
modes : QTable
|
|
23
|
+
Power on the different modes (can be 1D if only TEM00)
|
|
24
|
+
"""
|
|
25
|
+
self.metadata = metadata
|
|
26
|
+
self.modes = modes
|
|
27
|
+
|
|
28
|
+
@staticmethod
|
|
29
|
+
def from_hdf5(store: Group | File) -> "PowerMeasurement":
|
|
30
|
+
return PowerMeasurement(
|
|
31
|
+
metadata=Metadata.from_hdf5(store),
|
|
32
|
+
modes=QTable.read(
|
|
33
|
+
store,
|
|
34
|
+
format="hdf5",
|
|
35
|
+
path="modes",
|
|
36
|
+
),
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
def to_hdf5(self, store: File | Group) -> Group | File:
|
|
40
|
+
_ = self.metadata.to_hdf5(store)
|
|
41
|
+
self.modes.write(
|
|
42
|
+
store,
|
|
43
|
+
format="hdf5",
|
|
44
|
+
path="modes",
|
|
45
|
+
serialize_meta=True,
|
|
46
|
+
)
|
|
47
|
+
return store
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
from astropy.table import QTable
|
|
3
|
+
from h5py import File as File
|
|
4
|
+
from h5py import Group as Group
|
|
5
|
+
|
|
6
|
+
from .metadata import MetadataPowerMeasurement as Metadata
|
|
7
|
+
from .section import Section as Section
|
|
8
|
+
|
|
9
|
+
class PowerMeasurement(Section):
|
|
10
|
+
metadata: Incomplete
|
|
11
|
+
modes: Incomplete
|
|
12
|
+
def __init__(self, metadata: Metadata, modes: QTable) -> None: ...
|
|
13
|
+
@staticmethod
|
|
14
|
+
def from_hdf5(store: Group | File) -> PowerMeasurement: ...
|
|
15
|
+
def to_hdf5(self, store: File | Group) -> Group | File: ...
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import TYPE_CHECKING
|
|
3
|
+
|
|
4
|
+
from gwpy.frequencyseries import FrequencySeries
|
|
5
|
+
from h5py import Dataset, File, Group
|
|
6
|
+
from numpy import array, mean
|
|
7
|
+
from scipy.io.matlab import savemat
|
|
8
|
+
|
|
9
|
+
from .metadata.root import Root as Metadata
|
|
10
|
+
from .powermeasurement import PowerMeasurement
|
|
11
|
+
from .scatterer import Scatterer
|
|
12
|
+
from .section import Section
|
|
13
|
+
from .utils import (
|
|
14
|
+
dataset_to_frequencyseries,
|
|
15
|
+
frequencyseries_to_dataset,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
if TYPE_CHECKING:
|
|
19
|
+
from numpy.typing import NDArray
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class Root(Section):
|
|
23
|
+
"""Simulation data identified with an unique name, with information
|
|
24
|
+
about the code that generated it
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def __init__(
|
|
28
|
+
self,
|
|
29
|
+
metadata: Metadata,
|
|
30
|
+
scatterers: list[Scatterer],
|
|
31
|
+
power_measurements: list[PowerMeasurement],
|
|
32
|
+
darm: FrequencySeries,
|
|
33
|
+
) -> None:
|
|
34
|
+
"""Parameters
|
|
35
|
+
----------
|
|
36
|
+
metadata : Metadata
|
|
37
|
+
Metadata associated to this data package
|
|
38
|
+
scatterers: list[Scatterer]
|
|
39
|
+
Scatterers data list
|
|
40
|
+
darm : FrequencySeries
|
|
41
|
+
common DARM transfer function for all this simulation data
|
|
42
|
+
|
|
43
|
+
"""
|
|
44
|
+
self.metadata = metadata
|
|
45
|
+
self.scatterers = scatterers
|
|
46
|
+
self.power_measurements = power_measurements
|
|
47
|
+
self.darm = darm
|
|
48
|
+
|
|
49
|
+
@staticmethod
|
|
50
|
+
def from_hdf5(store: File | Group) -> "Root":
|
|
51
|
+
scatterers_group = store.get("scatterers")
|
|
52
|
+
darm_dataset = store.get("DARM")
|
|
53
|
+
message = "{} should exists, and not be {}"
|
|
54
|
+
if not isinstance(scatterers_group, Group):
|
|
55
|
+
raise TypeError(
|
|
56
|
+
message.format(
|
|
57
|
+
"scatterers group",
|
|
58
|
+
type(scatterers_group),
|
|
59
|
+
),
|
|
60
|
+
)
|
|
61
|
+
if not isinstance(darm_dataset, Dataset):
|
|
62
|
+
raise ValueError(
|
|
63
|
+
message.format("DARM dataset", type(darm_dataset)),
|
|
64
|
+
)
|
|
65
|
+
scatterers = scatterers_group.values()
|
|
66
|
+
|
|
67
|
+
try:
|
|
68
|
+
power_measurements_group = store["power measurements"]
|
|
69
|
+
if not isinstance(power_measurements_group, Group):
|
|
70
|
+
raise TypeError(
|
|
71
|
+
message.format(
|
|
72
|
+
"power measurements",
|
|
73
|
+
type(power_measurements_group),
|
|
74
|
+
),
|
|
75
|
+
)
|
|
76
|
+
power_measurements_values = (
|
|
77
|
+
power_measurements_group.values()
|
|
78
|
+
)
|
|
79
|
+
power_measurements = [
|
|
80
|
+
PowerMeasurement.from_hdf5(power_measurement)
|
|
81
|
+
for power_measurement in power_measurements_values
|
|
82
|
+
]
|
|
83
|
+
except KeyError:
|
|
84
|
+
# Legcay support, power measurements is not defined for file
|
|
85
|
+
# generated before 0.3.0
|
|
86
|
+
power_measurements = []
|
|
87
|
+
|
|
88
|
+
return Root(
|
|
89
|
+
metadata=Metadata.from_hdf5(store),
|
|
90
|
+
scatterers=[
|
|
91
|
+
Scatterer.from_hdf5(scatterer)
|
|
92
|
+
for scatterer in scatterers
|
|
93
|
+
],
|
|
94
|
+
power_measurements=power_measurements,
|
|
95
|
+
darm=dataset_to_frequencyseries(darm_dataset),
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
def to_hdf5(self, store: File | Group) -> File | Group:
|
|
99
|
+
_ = self.metadata.to_hdf5(store)
|
|
100
|
+
_ = store.create_group(
|
|
101
|
+
"scatterers",
|
|
102
|
+
) # create the group even if scatterers list is empty
|
|
103
|
+
_ = store.create_group("power measurements")
|
|
104
|
+
for scatterer in self.scatterers:
|
|
105
|
+
_ = scatterer.to_hdf5(
|
|
106
|
+
store.require_group("scatterers").create_group(
|
|
107
|
+
scatterer.metadata.name,
|
|
108
|
+
),
|
|
109
|
+
)
|
|
110
|
+
for power_measurement in self.power_measurements:
|
|
111
|
+
_ = power_measurement.to_hdf5(
|
|
112
|
+
store.require_group("power measurements").create_group(
|
|
113
|
+
power_measurement.metadata.name,
|
|
114
|
+
),
|
|
115
|
+
)
|
|
116
|
+
_ = frequencyseries_to_dataset(store, "DARM", self.darm)
|
|
117
|
+
return store
|
|
118
|
+
|
|
119
|
+
def to_matlab(self, path: Path) -> None:
|
|
120
|
+
if len(self.scatterers) < 1:
|
|
121
|
+
raise ValueError("no scatterer to save")
|
|
122
|
+
data: dict[str, NDArray] = {}
|
|
123
|
+
for scatterer in self.scatterers:
|
|
124
|
+
data[f"{scatterer.metadata.name}mat"] = array(
|
|
125
|
+
[tf.to_value() for tf in [scatterer.kn, scatterer.kp]],
|
|
126
|
+
)
|
|
127
|
+
north_arm = self.metadata.interferometer.north_arm.to_value(
|
|
128
|
+
"m",
|
|
129
|
+
)
|
|
130
|
+
west_arm = self.metadata.interferometer.west_arm.to_value(
|
|
131
|
+
"m",
|
|
132
|
+
)
|
|
133
|
+
if not isinstance(north_arm, float):
|
|
134
|
+
raise TypeError
|
|
135
|
+
if not isinstance(west_arm, float):
|
|
136
|
+
raise TypeError
|
|
137
|
+
arm_length = mean([north_arm, west_arm])
|
|
138
|
+
data[f"{scatterer.metadata.name}coupling"] = array(
|
|
139
|
+
[
|
|
140
|
+
tf.to_value() / self.darm.to_value() / arm_length
|
|
141
|
+
for tf in [scatterer.kn, scatterer.kp]
|
|
142
|
+
],
|
|
143
|
+
)
|
|
144
|
+
data["freq"] = self.scatterers[0].kn.frequencies
|
|
145
|
+
|
|
146
|
+
savemat(str(path), data)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
from _typeshed import Incomplete
|
|
4
|
+
from gwpy.frequencyseries import FrequencySeries as FrequencySeries
|
|
5
|
+
from h5py import File as File
|
|
6
|
+
from h5py import Group
|
|
7
|
+
from numpy.typing import NDArray as NDArray
|
|
8
|
+
|
|
9
|
+
from .metadata.root import Root as Metadata
|
|
10
|
+
from .powermeasurement import PowerMeasurement as PowerMeasurement
|
|
11
|
+
from .scatterer import Scatterer as Scatterer
|
|
12
|
+
from .section import Section as Section
|
|
13
|
+
from .utils import (
|
|
14
|
+
dataset_to_frequencyseries as dataset_to_frequencyseries,
|
|
15
|
+
)
|
|
16
|
+
from .utils import (
|
|
17
|
+
frequencyseries_to_dataset as frequencyseries_to_dataset,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
class Root(Section):
|
|
21
|
+
metadata: Incomplete
|
|
22
|
+
scatterers: Incomplete
|
|
23
|
+
power_measurements: Incomplete
|
|
24
|
+
darm: Incomplete
|
|
25
|
+
def __init__(
|
|
26
|
+
self,
|
|
27
|
+
metadata: Metadata,
|
|
28
|
+
scatterers: list[Scatterer],
|
|
29
|
+
power_measurements: list[PowerMeasurement],
|
|
30
|
+
darm: FrequencySeries,
|
|
31
|
+
) -> None: ...
|
|
32
|
+
@staticmethod
|
|
33
|
+
def from_hdf5(store: File | Group) -> Root: ...
|
|
34
|
+
def to_hdf5(self, store: File | Group) -> File | Group: ...
|
|
35
|
+
def to_matlab(self, path: Path) -> None: ...
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
from gwpy.frequencyseries import FrequencySeries
|
|
2
|
+
from h5py import Dataset, File, Group
|
|
3
|
+
|
|
4
|
+
from .metadata.scatterer import Scatterer as MetadataScatterer
|
|
5
|
+
from .section import Section
|
|
6
|
+
from .utils import (
|
|
7
|
+
dataset_to_frequencyseries,
|
|
8
|
+
frequencyseries_to_dataset,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Scatterer(Section):
|
|
13
|
+
"""Contains Transfer Function between a scatterer and the DC dark
|
|
14
|
+
fringe power
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def __init__(
|
|
18
|
+
self,
|
|
19
|
+
metadata: MetadataScatterer,
|
|
20
|
+
kn: FrequencySeries,
|
|
21
|
+
kp: FrequencySeries,
|
|
22
|
+
) -> None:
|
|
23
|
+
"""Parameters
|
|
24
|
+
----------
|
|
25
|
+
metadata : MetadataScatterer
|
|
26
|
+
Metadata associated to this scatterer
|
|
27
|
+
kn : FrequencySeries
|
|
28
|
+
Kp transfer function (scatterer is located so that the
|
|
29
|
+
reflected light is out of phase with the recoupled beam)
|
|
30
|
+
kp : FrequencySeries
|
|
31
|
+
Kn transfer function (scatterer is located so that the
|
|
32
|
+
reflected light is in phase with the recoupled beam)
|
|
33
|
+
|
|
34
|
+
"""
|
|
35
|
+
self.metadata = metadata
|
|
36
|
+
self.kn = kn
|
|
37
|
+
self.kp = kp
|
|
38
|
+
|
|
39
|
+
@staticmethod
|
|
40
|
+
def from_hdf5(store: File | Group) -> "Scatterer":
|
|
41
|
+
kn_dataset = store.get("kn")
|
|
42
|
+
kp_dataset = store.get("kp")
|
|
43
|
+
if not isinstance(kn_dataset, Dataset):
|
|
44
|
+
raise ValueError(
|
|
45
|
+
f"kn should exists, and not be {type(kn_dataset)}",
|
|
46
|
+
)
|
|
47
|
+
if not isinstance(kp_dataset, Dataset):
|
|
48
|
+
raise ValueError(
|
|
49
|
+
f"kp should exists, and not be {type(kp_dataset)}",
|
|
50
|
+
)
|
|
51
|
+
return Scatterer(
|
|
52
|
+
metadata=MetadataScatterer.from_hdf5(store),
|
|
53
|
+
kn=dataset_to_frequencyseries(kn_dataset),
|
|
54
|
+
kp=dataset_to_frequencyseries(kp_dataset),
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
def to_hdf5(self, store: File | Group) -> Group | File:
|
|
58
|
+
_ = self.metadata.to_hdf5(store)
|
|
59
|
+
_ = frequencyseries_to_dataset(store, "kn", self.kn)
|
|
60
|
+
_ = frequencyseries_to_dataset(store, "kp", self.kp)
|
|
61
|
+
return store
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
from gwpy.frequencyseries import FrequencySeries as FrequencySeries
|
|
3
|
+
from h5py import File as File
|
|
4
|
+
from h5py import Group as Group
|
|
5
|
+
|
|
6
|
+
from .metadata.scatterer import Scatterer as MetadataScatterer
|
|
7
|
+
from .section import Section as Section
|
|
8
|
+
from .utils import (
|
|
9
|
+
dataset_to_frequencyseries as dataset_to_frequencyseries,
|
|
10
|
+
)
|
|
11
|
+
from .utils import (
|
|
12
|
+
frequencyseries_to_dataset as frequencyseries_to_dataset,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
class Scatterer(Section):
|
|
16
|
+
metadata: Incomplete
|
|
17
|
+
kn: Incomplete
|
|
18
|
+
kp: Incomplete
|
|
19
|
+
def __init__(
|
|
20
|
+
self,
|
|
21
|
+
metadata: MetadataScatterer,
|
|
22
|
+
kn: FrequencySeries,
|
|
23
|
+
kp: FrequencySeries,
|
|
24
|
+
) -> None: ...
|
|
25
|
+
@staticmethod
|
|
26
|
+
def from_hdf5(store: File | Group) -> Scatterer: ...
|
|
27
|
+
def to_hdf5(self, store: File | Group) -> Group | File: ...
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import TYPE_CHECKING
|
|
3
|
+
|
|
4
|
+
from h5py import File, Group
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from astropy.table import QTable
|
|
8
|
+
from astropy.units import Quantity
|
|
9
|
+
from gwpy.frequencyseries import FrequencySeries
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Section:
|
|
13
|
+
"""Any class that represent a set of data."""
|
|
14
|
+
|
|
15
|
+
def get(
|
|
16
|
+
self,
|
|
17
|
+
attribute: str,
|
|
18
|
+
) -> "Section | FrequencySeries | QTable | Quantity | int":
|
|
19
|
+
"""Get an attribute of this section
|
|
20
|
+
|
|
21
|
+
Parameters
|
|
22
|
+
----------
|
|
23
|
+
attribute : str
|
|
24
|
+
Attribute to get
|
|
25
|
+
|
|
26
|
+
Returns
|
|
27
|
+
-------
|
|
28
|
+
Any : The value of the given attribute
|
|
29
|
+
|
|
30
|
+
"""
|
|
31
|
+
return getattr(self, attribute)
|
|
32
|
+
|
|
33
|
+
def set(
|
|
34
|
+
self,
|
|
35
|
+
attribute: str,
|
|
36
|
+
value: "Section | FrequencySeries | QTable | Quantity | int",
|
|
37
|
+
) -> None:
|
|
38
|
+
"""Set an attribute of this section
|
|
39
|
+
|
|
40
|
+
Parameters
|
|
41
|
+
----------
|
|
42
|
+
attribute : str
|
|
43
|
+
Attribute to set
|
|
44
|
+
value : Any
|
|
45
|
+
Value to set
|
|
46
|
+
|
|
47
|
+
"""
|
|
48
|
+
return setattr(self, attribute, value)
|
|
49
|
+
|
|
50
|
+
@staticmethod
|
|
51
|
+
def from_hdf5(store: File | Group) -> "Section": # pyright: ignore [reportUnusedParameter]
|
|
52
|
+
"""Convert an hdf5 file or group to the corresponding section
|
|
53
|
+
|
|
54
|
+
Parameters
|
|
55
|
+
----------
|
|
56
|
+
store : File | Group
|
|
57
|
+
Group corresponding to a given section
|
|
58
|
+
|
|
59
|
+
Returns
|
|
60
|
+
-------
|
|
61
|
+
An instance of a subclass of Section
|
|
62
|
+
|
|
63
|
+
"""
|
|
64
|
+
raise NotImplementedError(
|
|
65
|
+
"this method has not been implemented for this class",
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
@staticmethod
|
|
69
|
+
def from_folder(folder: Path) -> "Section": # pyright: ignore [reportUnusedParameter]
|
|
70
|
+
"""Convert a folder to the corresponding section
|
|
71
|
+
|
|
72
|
+
Parameters
|
|
73
|
+
----------
|
|
74
|
+
folder : Path
|
|
75
|
+
Folder containing all the data
|
|
76
|
+
|
|
77
|
+
Returns
|
|
78
|
+
-------
|
|
79
|
+
An instance of a subclass of Section
|
|
80
|
+
|
|
81
|
+
"""
|
|
82
|
+
raise NotImplementedError(
|
|
83
|
+
"this method has not been implemented for this class",
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
def to_hdf5(self, store: File | Group) -> Group | File: # pyright: ignore [reportUnusedParameter]
|
|
87
|
+
"""Convert this set of data to a HDF5 group
|
|
88
|
+
|
|
89
|
+
Parameters
|
|
90
|
+
----------
|
|
91
|
+
store : File | Group
|
|
92
|
+
Where to insert this group
|
|
93
|
+
|
|
94
|
+
Notes
|
|
95
|
+
-----
|
|
96
|
+
It recursively create sub groups
|
|
97
|
+
|
|
98
|
+
Returns
|
|
99
|
+
-------
|
|
100
|
+
Group : new created group
|
|
101
|
+
|
|
102
|
+
"""
|
|
103
|
+
raise NotImplementedError(
|
|
104
|
+
"this method has not been implemented for this class",
|
|
105
|
+
)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
from astropy.table import QTable as QTable
|
|
4
|
+
from astropy.units import Quantity as Quantity
|
|
5
|
+
from gwpy.frequencyseries import FrequencySeries as FrequencySeries
|
|
6
|
+
from h5py import File as File
|
|
7
|
+
from h5py import Group as Group
|
|
8
|
+
|
|
9
|
+
class Section:
|
|
10
|
+
def get(
|
|
11
|
+
self, attribute: str
|
|
12
|
+
) -> Section | FrequencySeries | QTable | Quantity | int: ...
|
|
13
|
+
def set(
|
|
14
|
+
self,
|
|
15
|
+
attribute: str,
|
|
16
|
+
value: Section | FrequencySeries | QTable | Quantity | int,
|
|
17
|
+
) -> None: ...
|
|
18
|
+
@staticmethod
|
|
19
|
+
def from_hdf5(store: File | Group) -> Section: ...
|
|
20
|
+
@staticmethod
|
|
21
|
+
def from_folder(folder: Path) -> Section: ...
|
|
22
|
+
def to_hdf5(self, store: File | Group) -> Group | File: ...
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
from astropy.units import Quantity, Unit
|
|
2
|
+
from gwpy.frequencyseries import FrequencySeries
|
|
3
|
+
from h5py import Dataset, File, Group
|
|
4
|
+
from numpy import array
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def dataset_to_frequencyseries(dataset: Dataset) -> FrequencySeries:
|
|
8
|
+
"""
|
|
9
|
+
Convert a h5df dataset to a FrequencySeries keeping the units right
|
|
10
|
+
|
|
11
|
+
Parameters
|
|
12
|
+
----------
|
|
13
|
+
dataset : Dataset
|
|
14
|
+
Dataset to convert
|
|
15
|
+
|
|
16
|
+
Returns
|
|
17
|
+
-------
|
|
18
|
+
TimeSeries : TimeSeries with a good unit
|
|
19
|
+
|
|
20
|
+
"""
|
|
21
|
+
unit = None
|
|
22
|
+
if "units" in dataset.attrs:
|
|
23
|
+
units = dataset.attrs["units"]
|
|
24
|
+
if isinstance(units, str):
|
|
25
|
+
unit = Unit(units)
|
|
26
|
+
else:
|
|
27
|
+
raise ValueError(f"cannot convert {units} to a unit")
|
|
28
|
+
if "f0" not in dataset.attrs:
|
|
29
|
+
raise ValueError(
|
|
30
|
+
"no starting time defined for this frequencyseries",
|
|
31
|
+
)
|
|
32
|
+
if "df" not in dataset.attrs:
|
|
33
|
+
message = (
|
|
34
|
+
"no time sample separation defined for the",
|
|
35
|
+
"frequencyseries",
|
|
36
|
+
)
|
|
37
|
+
raise ValueError(message)
|
|
38
|
+
f0 = dataset.attrs["f0"]
|
|
39
|
+
df = dataset.attrs["df"]
|
|
40
|
+
if not isinstance(f0, str):
|
|
41
|
+
raise ValueError(f"f0 must be stored as string, not {type(f0)}")
|
|
42
|
+
if not isinstance(df, str):
|
|
43
|
+
raise ValueError(f"df must be stored as string, not {type(df)}")
|
|
44
|
+
f0 = Quantity(f0)
|
|
45
|
+
df = Quantity(df)
|
|
46
|
+
return FrequencySeries(
|
|
47
|
+
data=array(dataset),
|
|
48
|
+
unit=unit,
|
|
49
|
+
f0=f0,
|
|
50
|
+
df=df,
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def frequencyseries_to_dataset(
|
|
55
|
+
store: File | Group,
|
|
56
|
+
name: str,
|
|
57
|
+
frequencyseries: FrequencySeries,
|
|
58
|
+
) -> Dataset:
|
|
59
|
+
"""
|
|
60
|
+
Convert a gwpy FrequencySeries to a hdf5 dataset keeping the units
|
|
61
|
+
right
|
|
62
|
+
|
|
63
|
+
Parameters
|
|
64
|
+
----------
|
|
65
|
+
store : File | Group
|
|
66
|
+
hdf5 element which will store the Dataset
|
|
67
|
+
name : str
|
|
68
|
+
Name of the dataset in the store
|
|
69
|
+
timeseries : TimeSeries
|
|
70
|
+
Data to store in the Dataset
|
|
71
|
+
|
|
72
|
+
Returns
|
|
73
|
+
-------
|
|
74
|
+
Dataset : Created dataset
|
|
75
|
+
|
|
76
|
+
"""
|
|
77
|
+
dataset = store.create_dataset(name, data=frequencyseries.data)
|
|
78
|
+
if frequencyseries.unit is not None:
|
|
79
|
+
dataset.attrs["units"] = frequencyseries.unit.to_string()
|
|
80
|
+
if not isinstance(frequencyseries.f0, Quantity):
|
|
81
|
+
raise ValueError(
|
|
82
|
+
f"f0 must be a quantity, not {type(frequencyseries.f0)}",
|
|
83
|
+
)
|
|
84
|
+
if not isinstance(frequencyseries.df, Quantity):
|
|
85
|
+
raise ValueError(
|
|
86
|
+
f"f0 must be a quantity, not {type(frequencyseries.df)}",
|
|
87
|
+
)
|
|
88
|
+
dataset.attrs["f0"] = frequencyseries.f0.to_string()
|
|
89
|
+
dataset.attrs["df"] = frequencyseries.df.to_string()
|
|
90
|
+
return dataset
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
from gwpy.frequencyseries import FrequencySeries
|
|
2
|
+
from h5py import Dataset as Dataset
|
|
3
|
+
from h5py import File as File
|
|
4
|
+
from h5py import Group as Group
|
|
5
|
+
|
|
6
|
+
def dataset_to_frequencyseries(dataset: Dataset) -> FrequencySeries: ...
|
|
7
|
+
def frequencyseries_to_dataset(
|
|
8
|
+
store: File | Group, name: str, frequencyseries: FrequencySeries
|
|
9
|
+
) -> Dataset: ...
|