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,17 @@
|
|
|
1
|
+
from .metadata import metadata
|
|
2
|
+
from .powermeasurement import PowerMeasurement
|
|
3
|
+
from .root import Root
|
|
4
|
+
from .scatterer import Scatterer
|
|
5
|
+
from .utils import (
|
|
6
|
+
dataset_to_frequencyseries,
|
|
7
|
+
frequencyseries_to_dataset,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"PowerMeasurement",
|
|
12
|
+
"Root",
|
|
13
|
+
"Scatterer",
|
|
14
|
+
"dataset_to_frequencyseries",
|
|
15
|
+
"frequencyseries_to_dataset",
|
|
16
|
+
"metadata",
|
|
17
|
+
]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from .metadata import metadata as metadata
|
|
2
|
+
from .powermeasurement import PowerMeasurement as PowerMeasurement
|
|
3
|
+
from .root import Root as Root
|
|
4
|
+
from .scatterer import Scatterer as Scatterer
|
|
5
|
+
from .utils import (
|
|
6
|
+
dataset_to_frequencyseries as dataset_to_frequencyseries,
|
|
7
|
+
)
|
|
8
|
+
from .utils import (
|
|
9
|
+
frequencyseries_to_dataset as frequencyseries_to_dataset,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"PowerMeasurement",
|
|
14
|
+
"Root",
|
|
15
|
+
"Scatterer",
|
|
16
|
+
"dataset_to_frequencyseries",
|
|
17
|
+
"frequencyseries_to_dataset",
|
|
18
|
+
"metadata",
|
|
19
|
+
]
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from .git import Git
|
|
2
|
+
from .interferometer import Interferometer
|
|
3
|
+
from .map import Map, MapType
|
|
4
|
+
from .modelmodifier import ModelModifier
|
|
5
|
+
from .pointabsorber import PointAbsorber
|
|
6
|
+
from .powermeasurement import (
|
|
7
|
+
PowerMeasurement as MetadataPowerMeasurement,
|
|
8
|
+
)
|
|
9
|
+
from .root import Root as MetadataRoot
|
|
10
|
+
from .scatterer import Scatterer as MetadataScatterer
|
|
11
|
+
from .simulation import Simulation
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"Git",
|
|
15
|
+
"Interferometer",
|
|
16
|
+
"Map",
|
|
17
|
+
"MapType",
|
|
18
|
+
"MetadataPowerMeasurement",
|
|
19
|
+
"MetadataRoot",
|
|
20
|
+
"MetadataScatterer",
|
|
21
|
+
"ModelModifier",
|
|
22
|
+
"PointAbsorber",
|
|
23
|
+
"Simulation",
|
|
24
|
+
]
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from .git import Git as Git
|
|
2
|
+
from .interferometer import Interferometer as Interferometer
|
|
3
|
+
from .map import Map as Map
|
|
4
|
+
from .map import MapType as MapType
|
|
5
|
+
from .modelmodifier import ModelModifier as ModelModifier
|
|
6
|
+
from .pointabsorber import PointAbsorber as PointAbsorber
|
|
7
|
+
from .powermeasurement import (
|
|
8
|
+
PowerMeasurement as MetadataPowerMeasurement,
|
|
9
|
+
)
|
|
10
|
+
from .root import Root as MetadataRoot
|
|
11
|
+
from .scatterer import Scatterer as MetadataScatterer
|
|
12
|
+
from .simulation import Simulation as Simulation
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"Git",
|
|
16
|
+
"Interferometer",
|
|
17
|
+
"Map",
|
|
18
|
+
"MapType",
|
|
19
|
+
"MetadataPowerMeasurement",
|
|
20
|
+
"MetadataRoot",
|
|
21
|
+
"MetadataScatterer",
|
|
22
|
+
"ModelModifier",
|
|
23
|
+
"PointAbsorber",
|
|
24
|
+
"Simulation",
|
|
25
|
+
]
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
from urllib.parse import ParseResult, urlparse
|
|
2
|
+
|
|
3
|
+
from h5py import File, Group
|
|
4
|
+
|
|
5
|
+
from .metadata import Metadata
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Git(Metadata):
|
|
9
|
+
"""
|
|
10
|
+
Information about the git repo of the algorithm which generated the
|
|
11
|
+
simulation data
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
def __init__(
|
|
15
|
+
self,
|
|
16
|
+
remote: ParseResult,
|
|
17
|
+
commit: str,
|
|
18
|
+
version: str,
|
|
19
|
+
branch: str,
|
|
20
|
+
) -> None:
|
|
21
|
+
"""Parameters
|
|
22
|
+
----------
|
|
23
|
+
remote : ParseResult
|
|
24
|
+
Repo location, must be the remote URI
|
|
25
|
+
commit : str
|
|
26
|
+
Latest commit hash when the simulation was computed
|
|
27
|
+
version : str
|
|
28
|
+
Version of the script which generated the simulation data
|
|
29
|
+
branch : str
|
|
30
|
+
Name of the branch of the git repo
|
|
31
|
+
|
|
32
|
+
"""
|
|
33
|
+
self.remote = remote
|
|
34
|
+
self.commit = commit
|
|
35
|
+
self.version = version
|
|
36
|
+
self.branch = branch
|
|
37
|
+
|
|
38
|
+
@staticmethod
|
|
39
|
+
def from_hdf5(store: File | Group) -> "Git":
|
|
40
|
+
for attribute in [
|
|
41
|
+
"remote",
|
|
42
|
+
"commit",
|
|
43
|
+
"version",
|
|
44
|
+
"branch",
|
|
45
|
+
]:
|
|
46
|
+
if attribute not in store.attrs:
|
|
47
|
+
raise ValueError("no {} in git information")
|
|
48
|
+
remote = store.attrs["remote"]
|
|
49
|
+
commit = store.attrs["commit"]
|
|
50
|
+
version = store.attrs["version"]
|
|
51
|
+
branch = store.attrs["branch"]
|
|
52
|
+
|
|
53
|
+
message = "git {} should be a string, not {}"
|
|
54
|
+
if not isinstance(remote, str):
|
|
55
|
+
raise ValueError(message.format("remote", type(remote)))
|
|
56
|
+
if not isinstance(commit, str):
|
|
57
|
+
raise ValueError(message.format("commit", type(commit)))
|
|
58
|
+
if not isinstance(version, str):
|
|
59
|
+
raise ValueError(message.format("version", type(version)))
|
|
60
|
+
if not isinstance(branch, str):
|
|
61
|
+
raise ValueError(message.format("branch", type(branch)))
|
|
62
|
+
|
|
63
|
+
remote = urlparse(remote)
|
|
64
|
+
|
|
65
|
+
return Git(
|
|
66
|
+
remote=remote,
|
|
67
|
+
commit=commit,
|
|
68
|
+
version=version,
|
|
69
|
+
branch=branch,
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
def to_hdf5(self, store: File | Group) -> File | Group:
|
|
73
|
+
store.attrs["remote"] = self.remote.geturl()
|
|
74
|
+
store.attrs["commit"] = self.commit
|
|
75
|
+
store.attrs["version"] = self.version
|
|
76
|
+
store.attrs["branch"] = self.branch
|
|
77
|
+
return store
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from urllib.parse import ParseResult as ParseResult
|
|
2
|
+
|
|
3
|
+
from _typeshed import Incomplete
|
|
4
|
+
from h5py import File as File
|
|
5
|
+
from h5py import Group as Group
|
|
6
|
+
|
|
7
|
+
from .metadata import Metadata as Metadata
|
|
8
|
+
|
|
9
|
+
class Git(Metadata):
|
|
10
|
+
remote: Incomplete
|
|
11
|
+
commit: Incomplete
|
|
12
|
+
version: Incomplete
|
|
13
|
+
branch: Incomplete
|
|
14
|
+
def __init__(
|
|
15
|
+
self,
|
|
16
|
+
remote: ParseResult,
|
|
17
|
+
commit: str,
|
|
18
|
+
version: str,
|
|
19
|
+
branch: str,
|
|
20
|
+
) -> None: ...
|
|
21
|
+
@staticmethod
|
|
22
|
+
def from_hdf5(store: File | Group) -> Git: ...
|
|
23
|
+
def to_hdf5(self, store: File | Group) -> File | Group: ...
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
from astropy.units import Quantity
|
|
2
|
+
from astropy.units.physical import angle, length, power
|
|
3
|
+
from h5py import File, Group
|
|
4
|
+
|
|
5
|
+
from .metadata import Metadata
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Interferometer(Metadata):
|
|
9
|
+
"""Information about the interferometer state"""
|
|
10
|
+
|
|
11
|
+
def __init__(
|
|
12
|
+
self,
|
|
13
|
+
dark_fringe_power: Quantity[power],
|
|
14
|
+
injection_power: Quantity[power],
|
|
15
|
+
sr_yaw: Quantity[angle],
|
|
16
|
+
north_arm: Quantity[length],
|
|
17
|
+
west_arm: Quantity[length],
|
|
18
|
+
) -> None:
|
|
19
|
+
"""Parameters
|
|
20
|
+
----------
|
|
21
|
+
dark_fringe_power : Quantity[power]
|
|
22
|
+
Power on dark fringe (dark fringe offset)
|
|
23
|
+
injection_power : Quantity[power]
|
|
24
|
+
Power injected in the interferometer
|
|
25
|
+
sr_yaw : Quantity[angle]
|
|
26
|
+
Yaw angle of SR
|
|
27
|
+
north_arm : Quantity[length]
|
|
28
|
+
Length of the north arm
|
|
29
|
+
west_arm : Quantity[length]
|
|
30
|
+
Length of the west arm
|
|
31
|
+
|
|
32
|
+
"""
|
|
33
|
+
if (
|
|
34
|
+
dark_fringe_power.unit is None
|
|
35
|
+
or injection_power.unit is None
|
|
36
|
+
or sr_yaw.unit is None
|
|
37
|
+
or north_arm.unit is None
|
|
38
|
+
or west_arm.unit is None
|
|
39
|
+
):
|
|
40
|
+
raise TypeError("every quantities must have an unit")
|
|
41
|
+
if (
|
|
42
|
+
dark_fringe_power.unit.physical_type != "power"
|
|
43
|
+
or injection_power.unit.physical_type != "power"
|
|
44
|
+
):
|
|
45
|
+
raise TypeError("dark fringe and injection must be power")
|
|
46
|
+
if sr_yaw.unit.physical_type != "angle":
|
|
47
|
+
raise TypeError("sr yaw must be an angle")
|
|
48
|
+
if (
|
|
49
|
+
north_arm.unit.physical_type != "length"
|
|
50
|
+
or west_arm.unit.physical_type != "length"
|
|
51
|
+
):
|
|
52
|
+
raise TypeError("north arm and west arm must be length")
|
|
53
|
+
if dark_fringe_power < Quantity(0, "W"):
|
|
54
|
+
raise ValueError("dark fringe power must be positive")
|
|
55
|
+
if injection_power < Quantity(0, "W"):
|
|
56
|
+
raise ValueError("injection power must be positive")
|
|
57
|
+
if north_arm < Quantity(0, "m"):
|
|
58
|
+
raise ValueError("north arm length must be positive")
|
|
59
|
+
if west_arm < Quantity(0, "m"):
|
|
60
|
+
raise ValueError("west arm length must be positive")
|
|
61
|
+
|
|
62
|
+
self.dark_fringe_power = dark_fringe_power
|
|
63
|
+
self.injection_power = injection_power
|
|
64
|
+
self.sr_yaw = sr_yaw
|
|
65
|
+
self.north_arm = north_arm
|
|
66
|
+
self.west_arm = west_arm
|
|
67
|
+
|
|
68
|
+
@staticmethod
|
|
69
|
+
def from_hdf5(store: File | Group) -> "Interferometer":
|
|
70
|
+
for attribute in [
|
|
71
|
+
"dark fringe power",
|
|
72
|
+
"injection power",
|
|
73
|
+
"SR yaw",
|
|
74
|
+
"north arm",
|
|
75
|
+
"west arm",
|
|
76
|
+
]:
|
|
77
|
+
if attribute not in store.attrs:
|
|
78
|
+
raise ValueError(
|
|
79
|
+
f"no {attribute} in interferometer information",
|
|
80
|
+
)
|
|
81
|
+
dark_fringe_power = store.attrs["dark fringe power"]
|
|
82
|
+
injection_power = store.attrs["injection power"]
|
|
83
|
+
sr_yaw = store.attrs["SR yaw"]
|
|
84
|
+
north_arm = store.attrs["north arm"]
|
|
85
|
+
west_arm = store.attrs["west arm"]
|
|
86
|
+
|
|
87
|
+
message = "interferometer {} should be a string, not {}"
|
|
88
|
+
if not isinstance(dark_fringe_power, str):
|
|
89
|
+
raise ValueError(
|
|
90
|
+
message.format(
|
|
91
|
+
"dark fringe power",
|
|
92
|
+
type(dark_fringe_power),
|
|
93
|
+
),
|
|
94
|
+
)
|
|
95
|
+
if not isinstance(injection_power, str):
|
|
96
|
+
raise ValueError(
|
|
97
|
+
message.format(
|
|
98
|
+
"injection power",
|
|
99
|
+
type(injection_power),
|
|
100
|
+
),
|
|
101
|
+
)
|
|
102
|
+
if not isinstance(sr_yaw, str):
|
|
103
|
+
raise ValueError(message.format("SR yaw", type(sr_yaw)))
|
|
104
|
+
if not isinstance(north_arm, str):
|
|
105
|
+
raise ValueError(
|
|
106
|
+
message.format("north arm", type(north_arm)),
|
|
107
|
+
)
|
|
108
|
+
if not isinstance(west_arm, str):
|
|
109
|
+
raise ValueError(message.format("west arm", type(west_arm)))
|
|
110
|
+
|
|
111
|
+
dark_fringe_power = Quantity(dark_fringe_power)
|
|
112
|
+
injection_power = Quantity(injection_power)
|
|
113
|
+
sr_yaw = Quantity(sr_yaw)
|
|
114
|
+
north_arm = Quantity(north_arm)
|
|
115
|
+
west_arm = Quantity(west_arm)
|
|
116
|
+
|
|
117
|
+
return Interferometer(
|
|
118
|
+
dark_fringe_power=dark_fringe_power,
|
|
119
|
+
injection_power=injection_power,
|
|
120
|
+
sr_yaw=sr_yaw,
|
|
121
|
+
north_arm=north_arm,
|
|
122
|
+
west_arm=west_arm,
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
def to_hdf5(self, store: File | Group) -> File | Group:
|
|
126
|
+
store.attrs["dark fringe power"] = (
|
|
127
|
+
self.dark_fringe_power.to_string()
|
|
128
|
+
)
|
|
129
|
+
store.attrs["injection power"] = (
|
|
130
|
+
self.injection_power.to_string()
|
|
131
|
+
)
|
|
132
|
+
store.attrs["SR yaw"] = self.sr_yaw.to_string()
|
|
133
|
+
store.attrs["north arm"] = self.north_arm.to_string()
|
|
134
|
+
store.attrs["west arm"] = self.west_arm.to_string()
|
|
135
|
+
return store
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
from astropy.units import Quantity
|
|
3
|
+
from astropy.units.physical import (
|
|
4
|
+
angle as angle,
|
|
5
|
+
)
|
|
6
|
+
from astropy.units.physical import (
|
|
7
|
+
length as length,
|
|
8
|
+
)
|
|
9
|
+
from astropy.units.physical import (
|
|
10
|
+
power as power,
|
|
11
|
+
)
|
|
12
|
+
from h5py import File as File
|
|
13
|
+
from h5py import Group as Group
|
|
14
|
+
|
|
15
|
+
from .metadata import Metadata as Metadata
|
|
16
|
+
|
|
17
|
+
class Interferometer(Metadata):
|
|
18
|
+
dark_fringe_power: Incomplete
|
|
19
|
+
injection_power: Incomplete
|
|
20
|
+
sr_yaw: Incomplete
|
|
21
|
+
north_arm: Incomplete
|
|
22
|
+
west_arm: Incomplete
|
|
23
|
+
def __init__(
|
|
24
|
+
self,
|
|
25
|
+
dark_fringe_power: Quantity[power],
|
|
26
|
+
injection_power: Quantity[power],
|
|
27
|
+
sr_yaw: Quantity[angle],
|
|
28
|
+
north_arm: Quantity[length],
|
|
29
|
+
west_arm: Quantity[length],
|
|
30
|
+
) -> None: ...
|
|
31
|
+
@staticmethod
|
|
32
|
+
def from_hdf5(store: File | Group) -> Interferometer: ...
|
|
33
|
+
def to_hdf5(self, store: File | Group) -> File | Group: ...
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
from enum import StrEnum
|
|
2
|
+
|
|
3
|
+
from astropy.units import Quantity
|
|
4
|
+
from h5py import File, Group
|
|
5
|
+
|
|
6
|
+
from .metadata import Metadata
|
|
7
|
+
from .pointabsorber import PointAbsorber
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class MapType(StrEnum):
|
|
11
|
+
FREE = "free"
|
|
12
|
+
CIRCULAR = "circular"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Map(Metadata):
|
|
16
|
+
"""Information about a map on a given mirror in the simulation"""
|
|
17
|
+
|
|
18
|
+
def __init__(
|
|
19
|
+
self,
|
|
20
|
+
mirror: str,
|
|
21
|
+
length: Quantity,
|
|
22
|
+
resolution: Quantity,
|
|
23
|
+
points_absorber: list[PointAbsorber],
|
|
24
|
+
type_: MapType,
|
|
25
|
+
) -> None:
|
|
26
|
+
"""Parameters
|
|
27
|
+
----------
|
|
28
|
+
mirror: str
|
|
29
|
+
Name of the mirror associated to this map
|
|
30
|
+
length : Quantity[length]
|
|
31
|
+
Total length of eaqh side of the squared map
|
|
32
|
+
resolution : Quantity[length]
|
|
33
|
+
Distance between two pixel on the squared map
|
|
34
|
+
absorber_point : list[PointAbsorber]
|
|
35
|
+
List of point absorber considered in this simulation
|
|
36
|
+
map_type : MapType
|
|
37
|
+
Type of the amplitude map
|
|
38
|
+
|
|
39
|
+
"""
|
|
40
|
+
if length.unit is None or resolution.unit is None:
|
|
41
|
+
raise TypeError("every quantities must have an unit")
|
|
42
|
+
if (
|
|
43
|
+
length.unit.physical_type != "length"
|
|
44
|
+
or resolution.unit.physical_type != "length"
|
|
45
|
+
):
|
|
46
|
+
raise TypeError(
|
|
47
|
+
"length, resolution and roc offset must be length",
|
|
48
|
+
)
|
|
49
|
+
if length <= Quantity(0, "m"):
|
|
50
|
+
raise ValueError("length must be positive")
|
|
51
|
+
if resolution <= Quantity(0, "m"):
|
|
52
|
+
raise ValueError("resolution must be positive")
|
|
53
|
+
if length <= resolution:
|
|
54
|
+
raise ValueError("resolution must be lower than length")
|
|
55
|
+
|
|
56
|
+
self.mirror = mirror
|
|
57
|
+
self.length = length
|
|
58
|
+
self.resolution = resolution
|
|
59
|
+
self.points_absorber = points_absorber
|
|
60
|
+
self.type = type_
|
|
61
|
+
|
|
62
|
+
@staticmethod
|
|
63
|
+
def from_hdf5(store: File | Group) -> "Map":
|
|
64
|
+
for attribute in [
|
|
65
|
+
"mirror",
|
|
66
|
+
"length",
|
|
67
|
+
"resolution",
|
|
68
|
+
"type",
|
|
69
|
+
]:
|
|
70
|
+
if attribute not in store.attrs:
|
|
71
|
+
raise ValueError(f"no {attribute} in map metadata")
|
|
72
|
+
mirror = store.attrs["mirror"]
|
|
73
|
+
length = store.attrs["length"]
|
|
74
|
+
resolution = store.attrs["resolution"]
|
|
75
|
+
map_type = store.attrs["type"]
|
|
76
|
+
|
|
77
|
+
message = "map {} should be a string, not {}"
|
|
78
|
+
if not isinstance(mirror, str):
|
|
79
|
+
raise TypeError(message.format("mirror", type(mirror)))
|
|
80
|
+
if not isinstance(length, str):
|
|
81
|
+
raise TypeError(message.format("length", type(length)))
|
|
82
|
+
if not isinstance(resolution, str):
|
|
83
|
+
raise TypeError(
|
|
84
|
+
message.format("resolution", type(resolution)),
|
|
85
|
+
)
|
|
86
|
+
if not isinstance(map_type, str):
|
|
87
|
+
raise TypeError(message.format("map type", type(map_type)))
|
|
88
|
+
|
|
89
|
+
length = Quantity(length)
|
|
90
|
+
resolution = Quantity(resolution)
|
|
91
|
+
map_type = MapType(map_type)
|
|
92
|
+
|
|
93
|
+
points_absorber_group = store.get("points absorber")
|
|
94
|
+
if not isinstance(points_absorber_group, Group):
|
|
95
|
+
message = (
|
|
96
|
+
"points absorber information should be stored in a "
|
|
97
|
+
f"group, not {type(points_absorber_group)}"
|
|
98
|
+
)
|
|
99
|
+
raise TypeError(message)
|
|
100
|
+
points_absorber = points_absorber_group.values()
|
|
101
|
+
|
|
102
|
+
return Map(
|
|
103
|
+
mirror=mirror,
|
|
104
|
+
length=length,
|
|
105
|
+
resolution=resolution,
|
|
106
|
+
points_absorber=[
|
|
107
|
+
PointAbsorber.from_hdf5(point_absorber)
|
|
108
|
+
for point_absorber in points_absorber
|
|
109
|
+
],
|
|
110
|
+
type_=map_type,
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
def to_hdf5(self, store: Group | File) -> Group | File:
|
|
114
|
+
store.attrs["mirror"] = self.mirror
|
|
115
|
+
store.attrs["length"] = self.length.to_string()
|
|
116
|
+
store.attrs["resolution"] = self.resolution.to_string()
|
|
117
|
+
store.attrs["type"] = str(self.type)
|
|
118
|
+
_ = store.create_group("points absorber")
|
|
119
|
+
|
|
120
|
+
for index in range(len(self.points_absorber)):
|
|
121
|
+
point_absorber = self.points_absorber[index]
|
|
122
|
+
_ = point_absorber.to_hdf5(
|
|
123
|
+
store.require_group("points absorber").create_group(
|
|
124
|
+
str(index),
|
|
125
|
+
),
|
|
126
|
+
)
|
|
127
|
+
return store
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from enum import StrEnum
|
|
2
|
+
|
|
3
|
+
from _typeshed import Incomplete
|
|
4
|
+
from astropy.units import Quantity
|
|
5
|
+
from h5py import File as File
|
|
6
|
+
from h5py import Group
|
|
7
|
+
|
|
8
|
+
from .metadata import Metadata as Metadata
|
|
9
|
+
from .pointabsorber import PointAbsorber as PointAbsorber
|
|
10
|
+
|
|
11
|
+
class MapType(StrEnum):
|
|
12
|
+
FREE = "free"
|
|
13
|
+
CIRCULAR = "circular"
|
|
14
|
+
|
|
15
|
+
class Map(Metadata):
|
|
16
|
+
mirror: Incomplete
|
|
17
|
+
length: Incomplete
|
|
18
|
+
resolution: Incomplete
|
|
19
|
+
points_absorber: Incomplete
|
|
20
|
+
type: Incomplete
|
|
21
|
+
def __init__(
|
|
22
|
+
self,
|
|
23
|
+
mirror: str,
|
|
24
|
+
length: Quantity,
|
|
25
|
+
resolution: Quantity,
|
|
26
|
+
points_absorber: list[PointAbsorber],
|
|
27
|
+
type_: MapType,
|
|
28
|
+
) -> None: ...
|
|
29
|
+
@staticmethod
|
|
30
|
+
def from_hdf5(store: File | Group) -> Map: ...
|
|
31
|
+
def to_hdf5(self, store: Group | File) -> Group | File: ...
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from h5py import Group
|
|
2
|
+
|
|
3
|
+
from .metadata import Metadata
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ModelModifier(Metadata):
|
|
7
|
+
"""Information about a modification of the finesse model"""
|
|
8
|
+
|
|
9
|
+
@staticmethod
|
|
10
|
+
def from_hdf5(store: Group) -> "ModelModifier":
|
|
11
|
+
if "type" not in store.attrs:
|
|
12
|
+
raise ValueError("no type in model modifier metadata")
|
|
13
|
+
|
|
14
|
+
type_ = store.attrs["type"]
|
|
15
|
+
|
|
16
|
+
if not isinstance(type_, str):
|
|
17
|
+
raise TypeError("type must be a string")
|
|
18
|
+
|
|
19
|
+
if type_ == "addition":
|
|
20
|
+
from .modifiers import ElementAddition
|
|
21
|
+
|
|
22
|
+
return ElementAddition.from_hdf5(store)
|
|
23
|
+
if type_ == "deletion":
|
|
24
|
+
from .modifiers import ElementDeletion
|
|
25
|
+
|
|
26
|
+
return ElementDeletion.from_hdf5(store)
|
|
27
|
+
if type_ == "update":
|
|
28
|
+
from .modifiers import ElementUpdate
|
|
29
|
+
|
|
30
|
+
return ElementUpdate.from_hdf5(store)
|
|
31
|
+
raise ValueError(f"unknown type {type_}")
|
|
32
|
+
|
|
33
|
+
def to_hdf5(self, store: Group) -> Group:
|
|
34
|
+
from .modifiers import (
|
|
35
|
+
ElementAddition,
|
|
36
|
+
ElementDeletion,
|
|
37
|
+
ElementUpdate,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
if isinstance(self, ElementAddition):
|
|
41
|
+
store.attrs["type"] = "addition"
|
|
42
|
+
elif isinstance(self, ElementDeletion):
|
|
43
|
+
store.attrs["type"] = "deletion"
|
|
44
|
+
elif isinstance(self, ElementUpdate):
|
|
45
|
+
store.attrs["type"] = "update"
|
|
46
|
+
|
|
47
|
+
return store
|