pyhough 0.0.1__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.
pyhough-0.0.1/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2018 The Python Packaging Authority
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
pyhough-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,22 @@
1
+ Metadata-Version: 2.1
2
+ Name: pyhough
3
+ Version: 0.0.1
4
+ Summary: Package to compute the Frequency-Hough Transform to search for continuous gravitational waves in LIGO, Virgo and KAGRA data
5
+ Project-URL: Homepage, https://github.com/andrew-l-miller/pyhough
6
+ Project-URL: Issues, https://github.com/andrew-l-miller/pyhough/issues
7
+ Author-email: "Andrew L. Miller" <andrew.miller.ligo@gmail.com>
8
+ License-File: LICENSE
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+
15
+ # pyhough Package
16
+
17
+ This package provides codes to perform the frequency-Hough transform to search for continuous gravitational waves from asymetrically rotating neutron stars.
18
+
19
+ In the package, which builds off of spectrograms created by Pyfstat, one can create a time/frequency peakmap, doppler correct it, and perform the Hough Transform.
20
+
21
+ The Hough Transform can be applied to either the spectrogrma directly or the peakmap.
22
+
@@ -0,0 +1,8 @@
1
+ # pyhough Package
2
+
3
+ This package provides codes to perform the frequency-Hough transform to search for continuous gravitational waves from asymetrically rotating neutron stars.
4
+
5
+ In the package, which builds off of spectrograms created by Pyfstat, one can create a time/frequency peakmap, doppler correct it, and perform the Hough Transform.
6
+
7
+ The Hough Transform can be applied to either the spectrogrma directly or the peakmap.
8
+
@@ -0,0 +1,22 @@
1
+ [build-system]
2
+ requires = ["hatchling","numpy","pyfstat","matplotlib"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "pyhough"
7
+ version = "0.0.1"
8
+ authors = [
9
+ { name="Andrew L. Miller", email="andrew.miller.ligo@gmail.com" },
10
+ ]
11
+ description = "Package to compute the Frequency-Hough Transform to search for continuous gravitational waves in LIGO, Virgo and KAGRA data"
12
+ readme = "README.md"
13
+ requires-python = ">=3.8"
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Operating System :: OS Independent",
18
+ ]
19
+
20
+ [project.urls]
21
+ Homepage = "https://github.com/andrew-l-miller/pyhough"
22
+ Issues = "https://github.com/andrew-l-miller/pyhough/issues"
File without changes
@@ -0,0 +1,79 @@
1
+ import numpy as np
2
+ from pm import *
3
+
4
+ def hfdf_hough_spectrogram(times,freqs,power,Tsft,sdgrid,threshold,vec_n,vels,ref_perc_time):
5
+ #### times: unique times array
6
+ #### freqs: unique freqs array
7
+ #### power: spectrogram of size len(freqs) x len(times)
8
+ inif = np.min(freqs)
9
+ finf = np.max(freqs)
10
+ df = 1/Tsft
11
+ Nsds = len(sdgrid)
12
+ Ntts = len(times)
13
+
14
+ Nf0s = int(np.ceil((finf-inif)/df))
15
+
16
+ binh_df0 = np.zeros((Nsds,Nf0s))
17
+ t0 = np.percentile(times,ref_perc_time)
18
+
19
+ times = times - t0
20
+ for t in range(Ntts):
21
+ inds_above_thr = np.array(select_local_max(power[:,t],threshold))
22
+ if inds_above_thr.shape[0] == 0:
23
+ continue
24
+
25
+ freqs_peaks = freqs[inds_above_thr]
26
+ freqs_dopp_corr = remove_doppler(freqs_peaks,vec_n,vels[:,t])
27
+ these_fs = ( freqs_dopp_corr - inif ) / df ;
28
+ tt_df = times[t] / df
29
+ for k in range(Nsds):
30
+ td = sdgrid[k] * tt_df
31
+ inds = np.round(these_fs - td).astype(int) ### f = f0 + fdot(t-t0) solve for f0, f0 = f - fdot(t-t0)
32
+ ind_of_inds = np.argwhere(inds>=0);
33
+ a = inds[ind_of_inds];
34
+ log_inds = a <= Nf0s-1;
35
+ a = a[log_inds];
36
+ binh_df0[k,a] = binh_df0[k,a] + 1
37
+
38
+ return binh_df0
39
+
40
+
41
+ def hfdf_hough(times,peak_freqs,Tsft,sdgrid,ref_perc_time):
42
+
43
+ inif = np.min(peak_freqs)
44
+ finf = np.max(peak_freqs)
45
+ df = 1/Tsft
46
+ Nsds = len(sdgrid)
47
+ Nf0s = int(np.ceil((finf-inif)/df))
48
+
49
+ binh_df0 = np.zeros((Nsds,Nf0s))
50
+ t0 = np.percentile(times,ref_perc_time)
51
+
52
+ ii0 = 0
53
+ ii = np.squeeze(np.argwhere(np.diff(times)))
54
+ times = times - t0
55
+ Ntts = len(ii)
56
+ for t in range(Ntts):
57
+ these_fs = ( peak_freqs[ii0:ii[t]+1] - inif ) / df
58
+ tt_df = times[ii0] / df
59
+ for k in range(Nsds):
60
+ td = sdgrid[k] * tt_df
61
+ inds = np.round(these_fs - td).astype(int) ### f = f0 + fdot(t-t0) solve for f0, f0 = f - fdot(t-t0)
62
+ ind_of_inds = np.argwhere(inds>=0);
63
+ a = inds[ind_of_inds];
64
+ log_inds = a <= Nf0s-1;
65
+ a = a[log_inds];
66
+ binh_df0[k,a] = binh_df0[k,a] + 1
67
+
68
+
69
+ ii0 = ii[t]+1
70
+ return binh_df0
71
+
72
+ def make_sd_grid(sig_fdot,dsd):
73
+ min_fdot_search = sig_fdot * 10
74
+ max_fdot_search = np.abs(sig_fdot * 10)
75
+ if min_fdot_search == 0:
76
+ min_fdot_search = -10 * dsd
77
+ max_fdot_search = 10 * dsd
78
+ sdgrid = np.arange(min_fdot_search,max_fdot_search,dsd)
79
+ return sdgrid
@@ -0,0 +1,167 @@
1
+ import numpy as np
2
+ import pyfstat
3
+ import matplotlib.pyplot as plt
4
+
5
+ def get_detector_velocities(data):
6
+ states = pyfstat.DetectorStates().get_multi_detector_states_from_sfts(data.sftfilepath, central_frequency=data.F0, time_offset=0)
7
+ ts = np.array([data.tGPS.gpsSeconds for data in states.data[0].data])
8
+ velocities = np.vstack([data.vDetector for data in states.data[0].data]).T
9
+ return ts, velocities
10
+
11
+
12
+ def astro2rect(a, icrad=0):
13
+ # Conversion from astronomical to rectangular coordinates
14
+ # position = [signal_parameters["Alpha"], signal_parameters["Delta"]]
15
+ # r = astro2rect(position,1) #icrad = 1: inputs are in rads; 0: inputs degs
16
+
17
+ if len(a) == 2:
18
+ a = np.append(a, 1)
19
+
20
+ if icrad == 0:
21
+ deg2rad = np.pi / 180
22
+ a[0] = a[0] * deg2rad
23
+ a[1] = a[1] * deg2rad
24
+
25
+ r = np.zeros(3)
26
+ r[0] = np.cos(a[0]) * np.cos(a[1]) * a[2]
27
+ r[1] = np.sin(a[0]) * np.cos(a[1]) * a[2]
28
+ r[2] = np.sin(a[1]) * a[2]
29
+
30
+ return r
31
+
32
+
33
+ def remove_doppler(freqs,vec_n,velocities):
34
+
35
+ freqs_dopp_corr = freqs / (1 + np.dot(vec_n, velocities))
36
+
37
+ return freqs_dopp_corr
38
+
39
+ def python_plot_triplets(x,y,z,marker,label='',flag_logx=0,flag_logy=0,flag_log_cb=0,colorm='inferno'):
40
+
41
+ if flag_log_cb==1:
42
+ z=np.log10(z);
43
+
44
+ #cmap=plt.get_cmap('inferno')
45
+ cmap=plt.get_cmap(colorm)
46
+ nc=cmap.N
47
+ mi=np.min(z);
48
+ ma=np.max(z);
49
+ mami=ma-mi;
50
+ zz=np.floor(nc*0.9999*(z-mi)/mami+1);
51
+
52
+ fig,ax=plt.subplots()
53
+
54
+ for i in range(nc):
55
+ col=cmap(i)
56
+ # if flag_logx==1 & flag_logy!=1:
57
+ # plt.semilogx(x[zz==i],y[zz==i],marker,markerfacecolor=col,markeredgecolor=col)
58
+ # elif flag_logy==1 & flag_logx!=1:
59
+ # plt.semilogy(x[zz==i],y[zz==i],marker,markerfacecolor=col,markeredgecolor=col)
60
+ # elif flag_logy==1 &flag_logx==1:
61
+ # plt.loglog(x[zz==i],y[zz==i],marker,markerfacecolor=col,markeredgecolor=col)
62
+ # else:
63
+ #cmaplist = [cmap(i) for i in range(cmap.N)]
64
+ plt.plot(x[zz==i],y[zz==i],marker,markerfacecolor=col,markeredgecolor=col)
65
+ sm = plt.cm.ScalarMappable(cmap=cmap, norm=plt.Normalize(vmin=mi, vmax=ma))
66
+ plt.colorbar(sm,label=label)
67
+ #plt.clim(mi, ma)
68
+ plt.grid(True)
69
+
70
+ return fig,ax
71
+
72
+ def make_peakmap_from_spectrogram(alltimes,freqs,normalized_power,threshold=3):
73
+ Ntts = len(alltimes)
74
+ freqs_new = []
75
+ times_new = []
76
+ powss_new = []
77
+ index = [0]
78
+ num_peaks = 0
79
+ for t in range(Ntts):
80
+ inds_above_thr = np.array(select_local_max(normalized_power[:,t],threshold))
81
+ num_peaks = num_peaks + len(inds_above_thr)
82
+ index.extend([num_peaks])
83
+ if inds_above_thr.shape[0] == 0:
84
+ continue
85
+
86
+ freqs_peaks = freqs[inds_above_thr]
87
+ freqs_new.extend(freqs_peaks)
88
+ times_new.extend(alltimes[t] * np.ones((len(freqs_peaks),1)))
89
+ powss_new.extend(normalized_power[inds_above_thr,t])
90
+
91
+
92
+ times_new = np.squeeze(times_new)
93
+ freqs_new = np.squeeze(freqs_new)
94
+ powss_new = np.squeeze(powss_new)
95
+
96
+ return times_new,freqs_new,powss_new,index
97
+
98
+ def remove_doppler_from_peakmap(times_new,freqs_new,index,vec_n,vs,Nts):
99
+ freqs_undop = []
100
+ for t in range(Nts):
101
+ if t == Nts:
102
+ freqs_one_time = freqs_new[index[t]:]
103
+ else:
104
+ freqs_one_time = freqs_new[index[t]:index[t+1]]
105
+
106
+ freqs_nodop = remove_doppler(freqs_one_time,vec_n,vs[:,t])
107
+ freqs_undop.extend(freqs_nodop)
108
+
109
+ return freqs_undop
110
+
111
+
112
+ def select_local_max(pows,threshold):
113
+
114
+ peaks_index = list()
115
+ for eqpow in range(1,len(pows)-1):
116
+ if pows[eqpow]>threshold:
117
+ if pows[eqpow]>pows[eqpow+1]:
118
+ if pows[eqpow]>pows[eqpow-1]:
119
+ peaks_index.append(eqpow)
120
+ return peaks_index
121
+
122
+ def remove_doppler_from_spectrogram_and_local_max_thresh(alltimes,freqs,normalized_power,vec_n,vs,threshold=3):
123
+ # alltimes = times["H1"]
124
+ # position = [signal_parameters["Alpha"], signal_parameters["Delta"]]
125
+ # vec_n = astro2rect(position,1)
126
+ # ts,vs = get_detector_velocities(data)
127
+ Ntts = len(alltimes)
128
+ freqs_new = []
129
+ times_new = []
130
+ powss_new = []
131
+ for t in range(Ntts):
132
+ inds_above_thr = np.array(select_local_max(normalized_power[:,t],threshold))
133
+ if inds_above_thr.shape[0] == 0:
134
+ continue
135
+ freqs_peaks = freqs[inds_above_thr]
136
+ freqs_dopp = remove_doppler(freqs_peaks,vec_n,vs[:,t])
137
+ freqs_new.extend(freqs_dopp)
138
+ times_new.extend(alltimes[t] * np.ones((len(freqs_dopp),1)))
139
+ powss_new.extend(normalized_power[inds_above_thr,t])
140
+
141
+
142
+
143
+ times_new = np.squeeze(times_new)
144
+ freqs_new = np.squeeze(freqs_new)
145
+ powss_new = np.squeeze(powss_new)
146
+
147
+ return times_new,freqs_new,powss_new
148
+
149
+
150
+ def flatten_spectrogram(alltimes,freqs,normalized_power):
151
+ Ntts = len(alltimes)
152
+ freqs_flat = []
153
+ times_flat = []
154
+ powss_flat = []
155
+ index = [0]
156
+ num_peaks = 0
157
+ for t in range(Ntts):
158
+ freqs_flat.extend(freqs)
159
+ times_flat.extend(alltimes[t] * np.ones((len(freqs),1)))
160
+ powss_flat.extend(normalized_power[:,t])
161
+
162
+
163
+ times_flat = np.squeeze(times_flat)
164
+ freqs_flat = np.squeeze(freqs_flat)
165
+ powss_flat = np.squeeze(powss_flat)
166
+
167
+ return times_flat,freqs_flat,powss_flat