• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nz-gravity / LogPSplinePSD / 17657445007

11 Sep 2025 09:12PM UTC coverage: 89.856% (-0.06%) from 89.917%
17657445007

push

github

avivajpeyi
Merge branch 'main' of github.com:nz-gravity/LogPSplinePSD

179 of 190 branches covered (94.21%)

Branch coverage included in aggregate %.

77 of 94 new or added lines in 8 files covered. (81.91%)

9 existing lines in 3 files now uncovered.

1566 of 1752 relevant lines covered (89.38%)

1.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.05
/src/log_psplines/example_datasets/lvk_data.py
1
import matplotlib.pyplot as plt
2✔
2
import numpy as np
2✔
3
from gwosc import datasets as gwosc_datasets
2✔
4
from gwpy.frequencyseries import FrequencySeries
2✔
5
from gwpy.timeseries import TimeSeries
2✔
6

7

8
class LVKData:
2✔
9
    def __init__(self, strain: np.ndarray, psd: np.ndarray, freqs: np.ndarray):
2✔
10
        self.strain = strain
2✔
11
        self.psd = psd
2✔
12
        self.freqs = freqs
2✔
13

14
    @classmethod
2✔
15
    def download_data(
2✔
16
        cls,
17
        detector: str = "H1",
18
        gps_start: int = 1126259462,
19
        duration: int = 1024,
20
        fmin: float = 20,
21
        fmax: float = 512,
22
    ) -> "LVKData":
23
        gps_end = gps_start + duration
2✔
24
        print(f"Downloading {detector} data [{gps_start} - {gps_end}]")
2✔
25
        strain = TimeSeries.fetch_open_data(detector, gps_start, gps_end)
2✔
26
        strain = (strain - strain.mean()) / strain.std()
2✔
27
        psd = strain.psd()
2✔
28
        psd = psd.crop(fmin, fmax)
2✔
29
        return cls(
2✔
30
            strain=strain.value, psd=psd.value, freqs=psd.frequencies.value
31
        )
32

33
    @classmethod
2✔
34
    def from_event(
2✔
35
        cls,
36
        event_name: str,
37
        detector: str = "H1",
38
        event_duration: int = 4,
39
        psd_duration: int = 4,
40
        fmin: float = 20,
41
        fmax: float = 2048,
42
    ) -> "LVKData":
NEW
43
        try:
×
NEW
44
            event_gps = gwosc_datasets.event_gps(event_name)
×
NEW
45
        except ValueError:
×
NEW
46
            avail_events = gwosc_datasets.find_datasets()
×
NEW
47
            raise ValueError(
×
48
                f"Event {event_name} not found in GWOSC datasets. Avail datasets: {avail_events}"
49
            )
50

NEW
51
        gps_start = event_gps - event_duration - psd_duration
×
NEW
52
        return cls.download_data(
×
53
            detector=detector,
54
            gps_start=gps_start,
55
            duration=psd_duration,
56
            fmin=fmin,
57
            fmax=fmax,
58
        )
59

60
    def plot_psd(self, fname: str = None) -> None:
2✔
61
        freq = FrequencySeries(self.psd, frequencies=self.freqs)
2✔
62
        fig, ax = plt.subplots()
2✔
63
        ax.loglog(freq, color="black")
2✔
64
        ax.set_xlabel("Frequency [Hz]")
2✔
65
        ax.set_ylabel("Power/Frequency [1/Hz]")
2✔
66
        ax.set_title("Power Spectral Density")
2✔
67
        if fname:
2✔
68
            plt.savefig(fname, bbox_inches="tight")
2✔
69
        return fig, ax
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc