Fix a typo & add option to be faster

This commit is contained in:
linarphy 2025-07-11 19:54:02 +02:00
parent 7a645f6572
commit a3cc8ce1d5
Signed by: linarphy
GPG key ID: 0CBF02E039B4FFFF
4 changed files with 119 additions and 57 deletions

View file

@ -17,6 +17,7 @@ class ComponentFactory:
start_time: Time, start_time: Time,
duration: Quantity[time], duration: Quantity[time],
metadata: MetadataComponent, metadata: MetadataComponent,
force_virgotools: bool = False,
) -> Component: ) -> Component:
""" """
Fetch a component from online data Fetch a component from online data
@ -31,11 +32,18 @@ class ComponentFactory:
Duration Duration
metadata : MetadataComponent metadata : MetadataComponent
Component's metadata Component's metadata
force_virgotools : bool
Force the use of the virgotools library in place of gwpy
first to be faster. Default to False
Returns
-------
Component
""" """
sensor = download_timeseries( sensor = download_timeseries(
channel="V1:Sc_{}_MIR_Z".format(metadata.name), channel="V1:Sc_{}_MIR_Z".format(metadata.name),
start_time=start_time, start_time=start_time,
duration=duration, duration=duration,
unit=uV, # in um, but the calibration factor is considered as m/V unit=uV, # in um, but the calibration factor is considered as m/V
force_virgotools=force_virgotools,
) )
return Component(metadata=metadata, sensor=sensor) return Component(metadata=metadata, sensor=sensor)

View file

@ -36,6 +36,7 @@ class MeasurementFactory:
start_time: Time, start_time: Time,
duration: Quantity[time], duration: Quantity[time],
initializer_metadata: list[InitializerScatterer], initializer_metadata: list[InitializerScatterer],
force_virgotools: bool = False,
) -> Measurement: ) -> Measurement:
""" """
Fetch a measurement from online data Fetch a measurement from online data
@ -55,6 +56,32 @@ class MeasurementFactory:
initializer_metadata : list[InitializerScatterer] initializer_metadata : list[InitializerScatterer]
List of component's and scatterer's pre-initialized List of component's and scatterer's pre-initialized
metadata that will be used in the created measurement metadata that will be used in the created measurement
force_virgotools : bool
Force the use of the virgotools library in place of gwpy
first to be faster. Default to False
Examples
--------
>>> data = MeasurementFactory.fetch(
... name="a name",
... description="a detailed description",
... start_time=Time(
... "2025-01-01T00:00:00.000000000",
... format="isot",
... scale="utc",
... ),
... duration=10 * s,
... initializer_metadata=[
... InitializerScatterer(
... name="SDB1",
... calibration_factor=1.0 * m / V,
... associated_component=InitializerComponent(
... name="SR",
... calibration_factor=1.0 * m / V,
... ),
... injection=None,
... ),
... ],
... )
Returns Returns
------- -------
Measurement : constructed Measurement from these metadata Measurement : constructed Measurement from these metadata
@ -70,6 +97,7 @@ class MeasurementFactory:
duration=duration, duration=duration,
units=list(channels_map.values()), units=list(channels_map.values()),
frame="trend", frame="trend",
force_virgotools=force_virgotools,
) )
if sum(data["V1:META_ITF_LOCK_index"].diff().abs()) != 0: if sum(data["V1:META_ITF_LOCK_index"].diff().abs()) != 0:
raise Exception( raise Exception(
@ -101,6 +129,7 @@ class MeasurementFactory:
name=initializer_scatterer.associated_component.name, name=initializer_scatterer.associated_component.name,
calibration_factor=initializer_scatterer.associated_component.calibration_factor, calibration_factor=initializer_scatterer.associated_component.calibration_factor,
), ),
force_virgotools=force_virgotools,
) )
components.append(component) components.append(component)
scatterers.append( scatterers.append(
@ -120,6 +149,7 @@ class MeasurementFactory:
start_time=start_time, start_time=start_time,
duration=duration, duration=duration,
unit=None, unit=None,
force_virgotools=force_virgotools,
) )
return Measurement( return Measurement(
metadata=metadata, metadata=metadata,

View file

@ -17,6 +17,7 @@ class ScattererFactory:
start_time: Time, start_time: Time,
duration: Quantity[time], duration: Quantity[time],
metadata: MetadataScatterer, metadata: MetadataScatterer,
force_virgotools: bool = False,
) -> Scatterer: ) -> Scatterer:
""" """
Fetch a component from online data Fetch a component from online data
@ -31,11 +32,18 @@ class ScattererFactory:
Duration Duration
metadata : MetadataComponent metadata : MetadataComponent
Component's metadata Component's metadata
force_virgotools : bool
Force the use of the virgotools library in place of gwpy
first to be faster. Default to False
Returns
-------
Scatterer
""" """
sensor = download_timeseries( sensor = download_timeseries(
channel="V1:{}_LC_Z".format(metadata.name), channel="V1:{}_LC_Z".format(metadata.name),
start_time=start_time, start_time=start_time,
duration=duration, duration=duration,
unit=uV, # in um, but the calibration factor is considered as m/V unit=uV, # in um, but the calibration factor is considered as m/V
force_virgotools=force_virgotools,
) )
return Scatterer(metadata=metadata, sensor=sensor) return Scatterer(metadata=metadata, sensor=sensor)

View file

@ -11,9 +11,9 @@ from gwpy.timeseries import TimeSeries, TimeSeriesDict
try: try:
from virgotools.frame_lib import FrameFile, FrVect # pyright: ignore[reportMissingImports] from virgotools.frame_lib import FrameFile, FrVect # pyright: ignore[reportMissingImports]
virgotool = True virgotools = True
except ImportError: except ImportError:
virgotool = False virgotools = False
pass pass
@ -51,6 +51,7 @@ def download_timeseries(
duration: Quantity[time], duration: Quantity[time],
unit: Unit | None = None, unit: Unit | None = None,
frame: Literal["raw"] | Literal["trend"] = "raw", frame: Literal["raw"] | Literal["trend"] = "raw",
force_virgotools: bool = False,
) -> TimeSeries: ) -> TimeSeries:
""" """
Download a TimeSeries from an online channel Download a TimeSeries from an online channel
@ -66,10 +67,14 @@ def download_timeseries(
Unit of the TimeSeries (default ot None) Unit of the TimeSeries (default ot None)
frame : raw|trend frame : raw|trend
Which frame to take the data from. Default to raw Which frame to take the data from. Default to raw
force_virgotools : bool
Force the use of the virgotools library in place of gwpy first
to be faster. Default to False
Notes Notes
----- -----
It first try to use gwpy, and fallback to virgotools It first try to use gwpy, and fallback to virgotools
""" """
if not force_virgotools:
try: try:
return TimeSeries.get( return TimeSeries.get(
channel=channel, channel=channel,
@ -77,11 +82,14 @@ def download_timeseries(
end=to_gps(start_time + duration), end=to_gps(start_time + duration),
) )
except HTTPError: except HTTPError:
if virgotool: pass
if virgotools:
vect: FrVect | None = None # pyright: ignore[reportPossiblyUnboundVariable] vect: FrVect | None = None # pyright: ignore[reportPossiblyUnboundVariable]
with FrameFile(frame) as ffl: # pyright: ignore[reportPossiblyUnboundVariable] with FrameFile(frame) as ffl: # pyright: ignore[reportPossiblyUnboundVariable]
vect = ffl.getChannel( # pyright: ignore[reportPossiblyUnboundVariable] vect = ffl.getChannel( # pyright: ignore[reportPossiblyUnboundVariable]
channel, to_gps(start_time), duration.to(s) channel,
to_gps(start_time),
duration.to(s).value,
) )
if vect is None: # pyright: ignore[reportPossiblyUnboundVariable] if vect is None: # pyright: ignore[reportPossiblyUnboundVariable]
raise RuntimeError( raise RuntimeError(
@ -105,6 +113,7 @@ def download_dicttimeseries(
duration: Quantity[time], duration: Quantity[time],
units: list[Unit | None] | None = None, units: list[Unit | None] | None = None,
frame: Literal["raw"] | Literal["trend"] = "raw", frame: Literal["raw"] | Literal["trend"] = "raw",
force_virgotools: bool = False,
) -> TimeSeriesDict: ) -> TimeSeriesDict:
""" """
Download multiple TimeSeries at the same time to be more efficient Download multiple TimeSeries at the same time to be more efficient
@ -121,10 +130,14 @@ def download_dicttimeseries(
channels. Default to None channels. Default to None
frame : raw|trend frame : raw|trend
Which frame to take the data from. Default to raw Which frame to take the data from. Default to raw
force_virgotools : bool
Force the use of the virgotools library in place of gwpy first
to be faster. Default to False
Notes Notes
----- -----
It first try to use gwpy, and fallback to virgotools It first try to use gwpy, and fallback to virgotools
""" """
if not force_virgotools:
try: try:
return TimeSeriesDict.get( return TimeSeriesDict.get(
channels=channels, channels=channels,
@ -132,13 +145,16 @@ def download_dicttimeseries(
end=to_gps(start_time + duration), end=to_gps(start_time + duration),
) )
except HTTPError: except HTTPError:
if virgotool: pass
if virgotools:
vects: list[FrVect] = [] # pyright: ignore[reportPossiblyUnboundVariable] vects: list[FrVect] = [] # pyright: ignore[reportPossiblyUnboundVariable]
with FrameFile(frame) as ffl: # pyright: ignore[reportPossiblyUnboundVariable] with FrameFile(frame) as ffl: # pyright: ignore[reportPossiblyUnboundVariable]
for channel in channels: for channel in channels:
vects.append( vects.append(
ffl.getChannel( ffl.getChannel(
channel, to_gps(start_time), duration.to(s) channel,
to_gps(start_time),
duration.to(s).value,
) )
) )
timeseries_dict: dict[str, TimeSeries] = dict() timeseries_dict: dict[str, TimeSeries] = dict()